@metamask-previews/ai-controllers 0.1.0-preview-685dbf46b → 0.2.0-preview-bc00f2c
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 +13 -1
- package/dist/AiDigestController.cjs +38 -0
- package/dist/AiDigestController.cjs.map +1 -1
- package/dist/AiDigestController.d.cts +13 -2
- package/dist/AiDigestController.d.cts.map +1 -1
- package/dist/AiDigestController.d.mts +13 -2
- package/dist/AiDigestController.d.mts.map +1 -1
- package/dist/AiDigestController.mjs +38 -0
- package/dist/AiDigestController.mjs.map +1 -1
- package/dist/AiDigestService.cjs +69 -15
- package/dist/AiDigestService.cjs.map +1 -1
- package/dist/AiDigestService.d.cts +10 -2
- package/dist/AiDigestService.d.cts.map +1 -1
- package/dist/AiDigestService.d.mts +10 -2
- package/dist/AiDigestService.d.mts.map +1 -1
- package/dist/AiDigestService.mjs +70 -16
- package/dist/AiDigestService.mjs.map +1 -1
- package/dist/ai-digest-types.cjs.map +1 -1
- package/dist/ai-digest-types.d.cts +67 -22
- package/dist/ai-digest-types.d.cts.map +1 -1
- package/dist/ai-digest-types.d.mts +67 -22
- package/dist/ai-digest-types.d.mts.map +1 -1
- package/dist/ai-digest-types.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,9 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add `fetchMarketOverview` method to `AiDigestService`, with superstruct validation of the `MarketOverview` response shape ([#8109](https://github.com/MetaMask/core/pull/8109)).
|
|
15
|
+
- Export new shared sub-types `Article`, `Tweet`, `Source`, `AIResponseMetadata`, `MarketOverview`, `MarketOverviewEntry`, `MarketOverviewTrend`, and `AiDigestControllerFetchMarketOverviewAction` ([#8109](https://github.com/MetaMask/core/pull/8109)).
|
|
16
|
+
|
|
10
17
|
### Changed
|
|
11
18
|
|
|
12
19
|
- Strengthen `AiDigestService` response validation using nested `superstruct` schemas for market insights payloads, including deep validation of `trends`/`sources` items and support for optional top-level `social` entries while allowing additional unknown API fields for forward compatibility ([#8006](https://github.com/MetaMask/core/pull/8006)).
|
|
20
|
+
- Rename shared sub-types `MarketInsightsArticle`, `MarketInsightsTweet`, and `MarketInsightsSource` to `Article`, `Tweet`, and `Source`; original names are kept as type aliases for backward compatibility ([#8109](https://github.com/MetaMask/core/pull/8109)).
|
|
21
|
+
- Tighten `MarketInsightsTrend.category` and `MarketInsightsTrend.impact` to closed string unions matching the API spec; `Source.type` is also now a closed union (`'news' | 'data' | 'social'`) ([#8109](https://github.com/MetaMask/core/pull/8109)).
|
|
22
|
+
- Update `searchDigest` endpoint from `/digests` to `/asset-summary` ([#8109](https://github.com/MetaMask/core/pull/8109)).
|
|
23
|
+
- Add optional `metadata` field to `MarketInsightsReport` ([#8109](https://github.com/MetaMask/core/pull/8109)).
|
|
13
24
|
|
|
14
25
|
## [0.1.0]
|
|
15
26
|
|
|
@@ -31,5 +42,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
31
42
|
- Removes `fetchDigest`, `clearDigest`, and `clearAllDigests` actions from the controller action surface.
|
|
32
43
|
- Removes `DigestData`/`DigestEntry` types and the `digests` state branch.
|
|
33
44
|
|
|
34
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/ai-controllers@0.
|
|
45
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/ai-controllers@0.2.0...HEAD
|
|
46
|
+
[0.2.0]: https://github.com/MetaMask/core/compare/@metamask/ai-controllers@0.1.0...@metamask/ai-controllers@0.2.0
|
|
35
47
|
[0.1.0]: https://github.com/MetaMask/core/releases/tag/@metamask/ai-controllers@0.1.0
|
|
@@ -19,6 +19,7 @@ const ai_digest_constants_1 = require("./ai-digest-constants.cjs");
|
|
|
19
19
|
function getDefaultAiDigestControllerState() {
|
|
20
20
|
return {
|
|
21
21
|
marketInsights: {},
|
|
22
|
+
marketOverview: null,
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
25
|
exports.getDefaultAiDigestControllerState = getDefaultAiDigestControllerState;
|
|
@@ -29,6 +30,12 @@ const aiDigestControllerMetadata = {
|
|
|
29
30
|
includeInStateLogs: true,
|
|
30
31
|
usedInUi: true,
|
|
31
32
|
},
|
|
33
|
+
marketOverview: {
|
|
34
|
+
persist: true,
|
|
35
|
+
includeInDebugSnapshot: true,
|
|
36
|
+
includeInStateLogs: true,
|
|
37
|
+
usedInUi: true,
|
|
38
|
+
},
|
|
32
39
|
};
|
|
33
40
|
class AiDigestController extends base_controller_1.BaseController {
|
|
34
41
|
constructor({ messenger, state, digestService }) {
|
|
@@ -83,10 +90,41 @@ class AiDigestController extends base_controller_1.BaseController {
|
|
|
83
90
|
});
|
|
84
91
|
return data;
|
|
85
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Fetches the market overview report.
|
|
95
|
+
* Returns cached data if still fresh, otherwise calls the service.
|
|
96
|
+
*
|
|
97
|
+
* @returns The market overview report, or `null` if none exists.
|
|
98
|
+
*/
|
|
99
|
+
async fetchMarketOverview() {
|
|
100
|
+
const existing = this.state.marketOverview;
|
|
101
|
+
if (existing) {
|
|
102
|
+
const age = Date.now() - existing.fetchedAt;
|
|
103
|
+
if (age < ai_digest_constants_1.CACHE_DURATION_MS) {
|
|
104
|
+
return existing.data;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const data = await __classPrivateFieldGet(this, _AiDigestController_digestService, "f").fetchMarketOverview();
|
|
108
|
+
if (data === null) {
|
|
109
|
+
this.update((state) => {
|
|
110
|
+
state.marketOverview = null;
|
|
111
|
+
});
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
const entry = {
|
|
115
|
+
fetchedAt: Date.now(),
|
|
116
|
+
data,
|
|
117
|
+
};
|
|
118
|
+
this.update((state) => {
|
|
119
|
+
state.marketOverview = entry;
|
|
120
|
+
});
|
|
121
|
+
return data;
|
|
122
|
+
}
|
|
86
123
|
}
|
|
87
124
|
exports.AiDigestController = AiDigestController;
|
|
88
125
|
_AiDigestController_digestService = new WeakMap(), _AiDigestController_instances = new WeakSet(), _AiDigestController_registerMessageHandlers = function _AiDigestController_registerMessageHandlers() {
|
|
89
126
|
this.messenger.registerActionHandler(`${ai_digest_constants_1.controllerName}:fetchMarketInsights`, this.fetchMarketInsights.bind(this));
|
|
127
|
+
this.messenger.registerActionHandler(`${ai_digest_constants_1.controllerName}:fetchMarketOverview`, this.fetchMarketOverview.bind(this));
|
|
90
128
|
}, _AiDigestController_evictStaleCachedEntries = function _AiDigestController_evictStaleCachedEntries(cache) {
|
|
91
129
|
const now = Date.now();
|
|
92
130
|
const entries = Object.entries(cache);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiDigestController.cjs","sourceRoot":"","sources":["../src/AiDigestController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,+DAA2D;AAE3D,2CAAkD;AAElD,mEAK+B;AAyC/B,SAAgB,iCAAiC;IAC/C,OAAO;QACL,cAAc,EAAE,EAAE;KACnB,CAAC;AACJ,CAAC;AAJD,8EAIC;AAED,MAAM,0BAA0B,GAA2C;IACzE,cAAc,EAAE;QACd,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,kBAAkB,EAAE,IAAI;QACxB,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF,MAAa,kBAAmB,SAAQ,gCAIvC;IAGC,YAAY,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAA6B;QACxE,KAAK,CAAC;YACJ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Ae,EAAE,CAAC,EAAE,EAAE,CAAC;YACzC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC;AACH,CAAC","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';\nimport { isCaipAssetType } from '@metamask/utils';\n\nimport {\n AiDigestControllerErrorMessage,\n controllerName,\n CACHE_DURATION_MS,\n MAX_CACHE_ENTRIES,\n} from './ai-digest-constants';\nimport type {\n AiDigestControllerState,\n DigestService,\n MarketInsightsReport,\n MarketInsightsEntry,\n} from './ai-digest-types';\n\nexport type AiDigestControllerFetchMarketInsightsAction = {\n type: `${typeof controllerName}:fetchMarketInsights`;\n handler: AiDigestController['fetchMarketInsights'];\n};\n\nexport type AiDigestControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AiDigestControllerState\n>;\n\nexport type AiDigestControllerActions =\n | AiDigestControllerFetchMarketInsightsAction\n | AiDigestControllerGetStateAction;\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 };\n}\n\nconst aiDigestControllerMetadata: StateMetadata<AiDigestControllerState> = {\n marketInsights: {\n persist: true,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n};\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.#registerMessageHandlers();\n }\n\n #registerMessageHandlers(): void {\n this.messenger.registerActionHandler(\n `${controllerName}:fetchMarketInsights`,\n this.fetchMarketInsights.bind(this),\n );\n }\n\n /**\n * Fetches market insights for a given CAIP-19 asset identifier.\n * Returns cached data if still fresh, otherwise calls the service.\n *\n * @param caip19Id - The CAIP-19 identifier of the asset.\n * @returns The market insights report, or `null` if none exists.\n */\n async fetchMarketInsights(\n caip19Id: string,\n ): Promise<MarketInsightsReport | null> {\n if (!isCaipAssetType(caip19Id)) {\n throw new Error(AiDigestControllerErrorMessage.INVALID_CAIP_ASSET_TYPE);\n }\n\n const existing = this.state.marketInsights[caip19Id];\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(caip19Id);\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[caip19Id];\n });\n return null;\n }\n\n const entry: MarketInsightsEntry = {\n caip19Id,\n fetchedAt: Date.now(),\n data,\n };\n\n this.update((state) => {\n state.marketInsights[caip19Id] = entry;\n this.#evictStaleCachedEntries(state.marketInsights);\n });\n\n return data;\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
|
+
{"version":3,"file":"AiDigestController.cjs","sourceRoot":"","sources":["../src/AiDigestController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,+DAA2D;AAE3D,2CAAkD;AAElD,mEAK+B;AAiD/B,SAAgB,iCAAiC;IAC/C,OAAO;QACL,cAAc,EAAE,EAAE;QAClB,cAAc,EAAE,IAAI;KACrB,CAAC;AACJ,CAAC;AALD,8EAKC;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,MAAa,kBAAmB,SAAQ,gCAIvC;IAGC,YAAY,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAA6B;QACxE,KAAK,CAAC;YACJ,IAAI,EAAE,oCAAc;YACpB,QAAQ,EAAE,0BAA0B;YACpC,KAAK,EAAE;gBACL,GAAG,iCAAiC,EAAE;gBACtC,GAAG,KAAK;aACT;YACD,SAAS;SACV,CAAC,CAAC;;QAXI,oDAA8B;QAarC,uBAAA,IAAI,qCAAkB,a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IACvB,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACtC,MAAM,YAAY,GAAa,EAAE,CAAC;IAClC,MAAM,YAAY,GAA0B,EAAE,CAAC;IAE/C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;QACnC,IAAI,GAAG,GAAG,KAAK,CAAC,SAAS,IAAI,uCAAiB,EAAE,CAAC;YAC/C,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;aAAM,CAAC;YACN,YAAY,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;IAED,IAAI,YAAY,CAAC,MAAM,GAAG,uCAAiB,EAAE,CAAC;QAC5C,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;QAC7D,MAAM,eAAe,GAAG,YAAY,CAAC,MAAM,GAAG,uCAAiB,CAAC;QAChE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,eAAe,EAAE,CAAC,EAAE,EAAE,CAAC;YACzC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC;AACH,CAAC","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';\nimport { isCaipAssetType } from '@metamask/utils';\n\nimport {\n AiDigestControllerErrorMessage,\n controllerName,\n CACHE_DURATION_MS,\n MAX_CACHE_ENTRIES,\n} from './ai-digest-constants';\nimport type {\n AiDigestControllerState,\n DigestService,\n MarketInsightsReport,\n MarketInsightsEntry,\n MarketOverview,\n MarketOverviewEntry,\n} from './ai-digest-types';\n\nexport type AiDigestControllerFetchMarketInsightsAction = {\n type: `${typeof controllerName}:fetchMarketInsights`;\n handler: AiDigestController['fetchMarketInsights'];\n};\n\nexport type AiDigestControllerFetchMarketOverviewAction = {\n type: `${typeof controllerName}:fetchMarketOverview`;\n handler: AiDigestController['fetchMarketOverview'];\n};\n\nexport type AiDigestControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AiDigestControllerState\n>;\n\nexport type AiDigestControllerActions =\n | AiDigestControllerFetchMarketInsightsAction\n | AiDigestControllerFetchMarketOverviewAction\n | AiDigestControllerGetStateAction;\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\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.#registerMessageHandlers();\n }\n\n #registerMessageHandlers(): void {\n this.messenger.registerActionHandler(\n `${controllerName}:fetchMarketInsights`,\n this.fetchMarketInsights.bind(this),\n );\n this.messenger.registerActionHandler(\n `${controllerName}:fetchMarketOverview`,\n this.fetchMarketOverview.bind(this),\n );\n }\n\n /**\n * Fetches market insights for a given CAIP-19 asset identifier.\n * Returns cached data if still fresh, otherwise calls the service.\n *\n * @param caip19Id - The CAIP-19 identifier of the asset.\n * @returns The market insights report, or `null` if none exists.\n */\n async fetchMarketInsights(\n caip19Id: string,\n ): Promise<MarketInsightsReport | null> {\n if (!isCaipAssetType(caip19Id)) {\n throw new Error(AiDigestControllerErrorMessage.INVALID_CAIP_ASSET_TYPE);\n }\n\n const existing = this.state.marketInsights[caip19Id];\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(caip19Id);\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[caip19Id];\n });\n return null;\n }\n\n const entry: MarketInsightsEntry = {\n caip19Id,\n fetchedAt: Date.now(),\n data,\n };\n\n this.update((state) => {\n state.marketInsights[caip19Id] = 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 * 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"]}
|
|
@@ -2,13 +2,17 @@ import type { ControllerStateChangeEvent, ControllerGetStateAction } from "@meta
|
|
|
2
2
|
import { BaseController } from "@metamask/base-controller";
|
|
3
3
|
import type { Messenger } from "@metamask/messenger";
|
|
4
4
|
import { controllerName } from "./ai-digest-constants.cjs";
|
|
5
|
-
import type { AiDigestControllerState, DigestService, MarketInsightsReport } from "./ai-digest-types.cjs";
|
|
5
|
+
import type { AiDigestControllerState, DigestService, MarketInsightsReport, MarketOverview } from "./ai-digest-types.cjs";
|
|
6
6
|
export type AiDigestControllerFetchMarketInsightsAction = {
|
|
7
7
|
type: `${typeof controllerName}:fetchMarketInsights`;
|
|
8
8
|
handler: AiDigestController['fetchMarketInsights'];
|
|
9
9
|
};
|
|
10
|
+
export type AiDigestControllerFetchMarketOverviewAction = {
|
|
11
|
+
type: `${typeof controllerName}:fetchMarketOverview`;
|
|
12
|
+
handler: AiDigestController['fetchMarketOverview'];
|
|
13
|
+
};
|
|
10
14
|
export type AiDigestControllerGetStateAction = ControllerGetStateAction<typeof controllerName, AiDigestControllerState>;
|
|
11
|
-
export type AiDigestControllerActions = AiDigestControllerFetchMarketInsightsAction | AiDigestControllerGetStateAction;
|
|
15
|
+
export type AiDigestControllerActions = AiDigestControllerFetchMarketInsightsAction | AiDigestControllerFetchMarketOverviewAction | AiDigestControllerGetStateAction;
|
|
12
16
|
export type AiDigestControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, AiDigestControllerState>;
|
|
13
17
|
export type AiDigestControllerEvents = AiDigestControllerStateChangeEvent;
|
|
14
18
|
export type AiDigestControllerMessenger = Messenger<typeof controllerName, AiDigestControllerActions, AiDigestControllerEvents>;
|
|
@@ -29,5 +33,12 @@ export declare class AiDigestController extends BaseController<typeof controller
|
|
|
29
33
|
* @returns The market insights report, or `null` if none exists.
|
|
30
34
|
*/
|
|
31
35
|
fetchMarketInsights(caip19Id: string): Promise<MarketInsightsReport | null>;
|
|
36
|
+
/**
|
|
37
|
+
* Fetches the market overview report.
|
|
38
|
+
* Returns cached data if still fresh, otherwise calls the service.
|
|
39
|
+
*
|
|
40
|
+
* @returns The market overview report, or `null` if none exists.
|
|
41
|
+
*/
|
|
42
|
+
fetchMarketOverview(): Promise<MarketOverview | null>;
|
|
32
43
|
}
|
|
33
44
|
//# sourceMappingURL=AiDigestController.d.cts.map
|
|
@@ -1 +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;AAGrD,OAAO,EAEL,cAAc,EAGf,kCAA8B;AAC/B,OAAO,KAAK,EACV,uBAAuB,EACvB,aAAa,EACb,oBAAoB,
|
|
1
|
+
{"version":3,"file":"AiDigestController.d.cts","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,kBAAmB,SAAQ,cAAc,CACpD,OAAO,cAAc,EACrB,uBAAuB,EACvB,2BAA2B,CAC5B;;gBAGa,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,EAAE,yBAAyB;IA0B1E;;;;;;OAMG;IACG,mBAAmB,CACvB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAqCvC;;;;;OAKG;IACG,mBAAmB,IAAI,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;CA+D5D"}
|
|
@@ -2,13 +2,17 @@ import type { ControllerStateChangeEvent, ControllerGetStateAction } from "@meta
|
|
|
2
2
|
import { BaseController } from "@metamask/base-controller";
|
|
3
3
|
import type { Messenger } from "@metamask/messenger";
|
|
4
4
|
import { controllerName } from "./ai-digest-constants.mjs";
|
|
5
|
-
import type { AiDigestControllerState, DigestService, MarketInsightsReport } from "./ai-digest-types.mjs";
|
|
5
|
+
import type { AiDigestControllerState, DigestService, MarketInsightsReport, MarketOverview } from "./ai-digest-types.mjs";
|
|
6
6
|
export type AiDigestControllerFetchMarketInsightsAction = {
|
|
7
7
|
type: `${typeof controllerName}:fetchMarketInsights`;
|
|
8
8
|
handler: AiDigestController['fetchMarketInsights'];
|
|
9
9
|
};
|
|
10
|
+
export type AiDigestControllerFetchMarketOverviewAction = {
|
|
11
|
+
type: `${typeof controllerName}:fetchMarketOverview`;
|
|
12
|
+
handler: AiDigestController['fetchMarketOverview'];
|
|
13
|
+
};
|
|
10
14
|
export type AiDigestControllerGetStateAction = ControllerGetStateAction<typeof controllerName, AiDigestControllerState>;
|
|
11
|
-
export type AiDigestControllerActions = AiDigestControllerFetchMarketInsightsAction | AiDigestControllerGetStateAction;
|
|
15
|
+
export type AiDigestControllerActions = AiDigestControllerFetchMarketInsightsAction | AiDigestControllerFetchMarketOverviewAction | AiDigestControllerGetStateAction;
|
|
12
16
|
export type AiDigestControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, AiDigestControllerState>;
|
|
13
17
|
export type AiDigestControllerEvents = AiDigestControllerStateChangeEvent;
|
|
14
18
|
export type AiDigestControllerMessenger = Messenger<typeof controllerName, AiDigestControllerActions, AiDigestControllerEvents>;
|
|
@@ -29,5 +33,12 @@ export declare class AiDigestController extends BaseController<typeof controller
|
|
|
29
33
|
* @returns The market insights report, or `null` if none exists.
|
|
30
34
|
*/
|
|
31
35
|
fetchMarketInsights(caip19Id: string): Promise<MarketInsightsReport | null>;
|
|
36
|
+
/**
|
|
37
|
+
* Fetches the market overview report.
|
|
38
|
+
* Returns cached data if still fresh, otherwise calls the service.
|
|
39
|
+
*
|
|
40
|
+
* @returns The market overview report, or `null` if none exists.
|
|
41
|
+
*/
|
|
42
|
+
fetchMarketOverview(): Promise<MarketOverview | null>;
|
|
32
43
|
}
|
|
33
44
|
//# sourceMappingURL=AiDigestController.d.mts.map
|
|
@@ -1 +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;AAGrD,OAAO,EAEL,cAAc,EAGf,kCAA8B;AAC/B,OAAO,KAAK,EACV,uBAAuB,EACvB,aAAa,EACb,oBAAoB,
|
|
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;AAGrD,OAAO,EAEL,cAAc,EAGf,kCAA8B;AAC/B,OAAO,KAAK,EACV,uBAAuB,EACvB,aAAa,EACb,oBAAoB,EAEpB,cAAc,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AG,IAAI,CAAC;CA+D5D"}
|
|
@@ -16,6 +16,7 @@ import { AiDigestControllerErrorMessage, controllerName, CACHE_DURATION_MS, MAX_
|
|
|
16
16
|
export function getDefaultAiDigestControllerState() {
|
|
17
17
|
return {
|
|
18
18
|
marketInsights: {},
|
|
19
|
+
marketOverview: null,
|
|
19
20
|
};
|
|
20
21
|
}
|
|
21
22
|
const aiDigestControllerMetadata = {
|
|
@@ -25,6 +26,12 @@ const aiDigestControllerMetadata = {
|
|
|
25
26
|
includeInStateLogs: true,
|
|
26
27
|
usedInUi: true,
|
|
27
28
|
},
|
|
29
|
+
marketOverview: {
|
|
30
|
+
persist: true,
|
|
31
|
+
includeInDebugSnapshot: true,
|
|
32
|
+
includeInStateLogs: true,
|
|
33
|
+
usedInUi: true,
|
|
34
|
+
},
|
|
28
35
|
};
|
|
29
36
|
export class AiDigestController extends BaseController {
|
|
30
37
|
constructor({ messenger, state, digestService }) {
|
|
@@ -79,9 +86,40 @@ export class AiDigestController extends BaseController {
|
|
|
79
86
|
});
|
|
80
87
|
return data;
|
|
81
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Fetches the market overview report.
|
|
91
|
+
* Returns cached data if still fresh, otherwise calls the service.
|
|
92
|
+
*
|
|
93
|
+
* @returns The market overview report, or `null` if none exists.
|
|
94
|
+
*/
|
|
95
|
+
async fetchMarketOverview() {
|
|
96
|
+
const existing = this.state.marketOverview;
|
|
97
|
+
if (existing) {
|
|
98
|
+
const age = Date.now() - existing.fetchedAt;
|
|
99
|
+
if (age < CACHE_DURATION_MS) {
|
|
100
|
+
return existing.data;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const data = await __classPrivateFieldGet(this, _AiDigestController_digestService, "f").fetchMarketOverview();
|
|
104
|
+
if (data === null) {
|
|
105
|
+
this.update((state) => {
|
|
106
|
+
state.marketOverview = null;
|
|
107
|
+
});
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
const entry = {
|
|
111
|
+
fetchedAt: Date.now(),
|
|
112
|
+
data,
|
|
113
|
+
};
|
|
114
|
+
this.update((state) => {
|
|
115
|
+
state.marketOverview = entry;
|
|
116
|
+
});
|
|
117
|
+
return data;
|
|
118
|
+
}
|
|
82
119
|
}
|
|
83
120
|
_AiDigestController_digestService = new WeakMap(), _AiDigestController_instances = new WeakSet(), _AiDigestController_registerMessageHandlers = function _AiDigestController_registerMessageHandlers() {
|
|
84
121
|
this.messenger.registerActionHandler(`${controllerName}:fetchMarketInsights`, this.fetchMarketInsights.bind(this));
|
|
122
|
+
this.messenger.registerActionHandler(`${controllerName}:fetchMarketOverview`, this.fetchMarketOverview.bind(this));
|
|
85
123
|
}, _AiDigestController_evictStaleCachedEntries = function _AiDigestController_evictStaleCachedEntries(cache) {
|
|
86
124
|
const now = Date.now();
|
|
87
125
|
const entries = Object.entries(cache);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiDigestController.mjs","sourceRoot":"","sources":["../src/AiDigestController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,EAAE,eAAe,EAAE,wBAAwB;AAElD,OAAO,EACL,8BAA8B,EAC9B,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EAClB,kCAA8B;AAyC/B,MAAM,UAAU,iCAAiC;IAC/C,OAAO;QACL,cAAc,EAAE,EAAE;KACnB,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;CACF,CAAC;AAEF,MAAM,OAAO,kBAAmB,SAAQ,cAIvC;IAGC,YAAY,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAA6B;QACxE,KAAK,CAAC;YACJ,IAAI,EAAE,cAAc;YACpB,QAAQ,EAAE,0BAA0B;YACpC,KAA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CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC;AACH,CAAC","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';\nimport { isCaipAssetType } from '@metamask/utils';\n\nimport {\n AiDigestControllerErrorMessage,\n controllerName,\n CACHE_DURATION_MS,\n MAX_CACHE_ENTRIES,\n} from './ai-digest-constants';\nimport type {\n AiDigestControllerState,\n DigestService,\n MarketInsightsReport,\n MarketInsightsEntry,\n} from './ai-digest-types';\n\nexport type AiDigestControllerFetchMarketInsightsAction = {\n type: `${typeof controllerName}:fetchMarketInsights`;\n handler: AiDigestController['fetchMarketInsights'];\n};\n\nexport type AiDigestControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AiDigestControllerState\n>;\n\nexport type AiDigestControllerActions =\n | AiDigestControllerFetchMarketInsightsAction\n | AiDigestControllerGetStateAction;\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 };\n}\n\nconst aiDigestControllerMetadata: StateMetadata<AiDigestControllerState> = {\n marketInsights: {\n persist: true,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n};\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.#registerMessageHandlers();\n }\n\n #registerMessageHandlers(): void {\n this.messenger.registerActionHandler(\n `${controllerName}:fetchMarketInsights`,\n this.fetchMarketInsights.bind(this),\n );\n }\n\n /**\n * Fetches market insights for a given CAIP-19 asset identifier.\n * Returns cached data if still fresh, otherwise calls the service.\n *\n * @param caip19Id - The CAIP-19 identifier of the asset.\n * @returns The market insights report, or `null` if none exists.\n */\n async fetchMarketInsights(\n caip19Id: string,\n ): Promise<MarketInsightsReport | null> {\n if (!isCaipAssetType(caip19Id)) {\n throw new Error(AiDigestControllerErrorMessage.INVALID_CAIP_ASSET_TYPE);\n }\n\n const existing = this.state.marketInsights[caip19Id];\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(caip19Id);\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[caip19Id];\n });\n return null;\n }\n\n const entry: MarketInsightsEntry = {\n caip19Id,\n fetchedAt: Date.now(),\n data,\n };\n\n this.update((state) => {\n state.marketInsights[caip19Id] = entry;\n this.#evictStaleCachedEntries(state.marketInsights);\n });\n\n return data;\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
|
+
{"version":3,"file":"AiDigestController.mjs","sourceRoot":"","sources":["../src/AiDigestController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,EAAE,eAAe,EAAE,wBAAwB;AAElD,OAAO,EACL,8BAA8B,EAC9B,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EAClB,kCAA8B;AAiD/B,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,OAAO,kBAAmB,SAAQ,cAIvC;IAGC,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;;QAXI,oDAA8B;QAar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;IACvB,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACtC,MAAM,YAAY,GAAa,EAAE,CAAC;IAClC,MAAM,YAAY,GAA0B,EAAE,CAAC;IAE/C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;QACnC,IAAI,GAAG,GAAG,KAAK,CAAC,SAAS,IAAI,iBAAiB,EAAE,CAAC;YAC/C,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;aAAM,CAAC;YACN,YAAY,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;IAED,IAAI,YAAY,CAAC,MAAM,GAAG,iBAAiB,EAAE,CAAC;QAC5C,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;QAC7D,MAAM,eAAe,GAAG,YAAY,CAAC,MAAM,GAAG,iBAAiB,CAAC;QAChE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,eAAe,EAAE,CAAC,EAAE,EAAE,CAAC;YACzC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC;AACH,CAAC","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';\nimport { isCaipAssetType } from '@metamask/utils';\n\nimport {\n AiDigestControllerErrorMessage,\n controllerName,\n CACHE_DURATION_MS,\n MAX_CACHE_ENTRIES,\n} from './ai-digest-constants';\nimport type {\n AiDigestControllerState,\n DigestService,\n MarketInsightsReport,\n MarketInsightsEntry,\n MarketOverview,\n MarketOverviewEntry,\n} from './ai-digest-types';\n\nexport type AiDigestControllerFetchMarketInsightsAction = {\n type: `${typeof controllerName}:fetchMarketInsights`;\n handler: AiDigestController['fetchMarketInsights'];\n};\n\nexport type AiDigestControllerFetchMarketOverviewAction = {\n type: `${typeof controllerName}:fetchMarketOverview`;\n handler: AiDigestController['fetchMarketOverview'];\n};\n\nexport type AiDigestControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AiDigestControllerState\n>;\n\nexport type AiDigestControllerActions =\n | AiDigestControllerFetchMarketInsightsAction\n | AiDigestControllerFetchMarketOverviewAction\n | AiDigestControllerGetStateAction;\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\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.#registerMessageHandlers();\n }\n\n #registerMessageHandlers(): void {\n this.messenger.registerActionHandler(\n `${controllerName}:fetchMarketInsights`,\n this.fetchMarketInsights.bind(this),\n );\n this.messenger.registerActionHandler(\n `${controllerName}:fetchMarketOverview`,\n this.fetchMarketOverview.bind(this),\n );\n }\n\n /**\n * Fetches market insights for a given CAIP-19 asset identifier.\n * Returns cached data if still fresh, otherwise calls the service.\n *\n * @param caip19Id - The CAIP-19 identifier of the asset.\n * @returns The market insights report, or `null` if none exists.\n */\n async fetchMarketInsights(\n caip19Id: string,\n ): Promise<MarketInsightsReport | null> {\n if (!isCaipAssetType(caip19Id)) {\n throw new Error(AiDigestControllerErrorMessage.INVALID_CAIP_ASSET_TYPE);\n }\n\n const existing = this.state.marketInsights[caip19Id];\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(caip19Id);\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[caip19Id];\n });\n return null;\n }\n\n const entry: MarketInsightsEntry = {\n caip19Id,\n fetchedAt: Date.now(),\n data,\n };\n\n this.update((state) => {\n state.marketInsights[caip19Id] = 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 * 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"]}
|
package/dist/AiDigestService.cjs
CHANGED
|
@@ -15,30 +15,44 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.AiDigestService = void 0;
|
|
16
16
|
const superstruct_1 = require("@metamask/superstruct");
|
|
17
17
|
const ai_digest_constants_1 = require("./ai-digest-constants.cjs");
|
|
18
|
-
|
|
18
|
+
// Shared sub-type structs
|
|
19
|
+
const ArticleStruct = (0, superstruct_1.type)({
|
|
19
20
|
title: (0, superstruct_1.string)(),
|
|
20
21
|
url: (0, superstruct_1.string)(),
|
|
21
22
|
source: (0, superstruct_1.string)(),
|
|
22
23
|
date: (0, superstruct_1.string)(),
|
|
23
24
|
});
|
|
24
|
-
const
|
|
25
|
+
const TweetStruct = (0, superstruct_1.type)({
|
|
25
26
|
contentSummary: (0, superstruct_1.string)(),
|
|
26
27
|
url: (0, superstruct_1.string)(),
|
|
27
28
|
author: (0, superstruct_1.string)(),
|
|
28
29
|
date: (0, superstruct_1.string)(),
|
|
29
30
|
});
|
|
31
|
+
const SourceStruct = (0, superstruct_1.type)({
|
|
32
|
+
name: (0, superstruct_1.string)(),
|
|
33
|
+
url: (0, superstruct_1.string)(),
|
|
34
|
+
type: (0, superstruct_1.enums)(['news', 'data', 'social']),
|
|
35
|
+
});
|
|
36
|
+
const AIResponseMetadataStruct = (0, superstruct_1.type)({
|
|
37
|
+
provider: (0, superstruct_1.string)(),
|
|
38
|
+
});
|
|
39
|
+
const trendCategoryValues = [
|
|
40
|
+
'geopolitical',
|
|
41
|
+
'macro',
|
|
42
|
+
'regulatory',
|
|
43
|
+
'technical',
|
|
44
|
+
'social',
|
|
45
|
+
'other',
|
|
46
|
+
];
|
|
47
|
+
const trendImpactValues = ['positive', 'negative', 'neutral'];
|
|
48
|
+
// Market Insights structs
|
|
30
49
|
const MarketInsightsTrendStruct = (0, superstruct_1.type)({
|
|
31
50
|
title: (0, superstruct_1.string)(),
|
|
32
51
|
description: (0, superstruct_1.string)(),
|
|
33
|
-
category: (0, superstruct_1.
|
|
34
|
-
impact: (0, superstruct_1.
|
|
35
|
-
articles: (0, superstruct_1.array)(
|
|
36
|
-
tweets: (0, superstruct_1.array)(
|
|
37
|
-
});
|
|
38
|
-
const MarketInsightsSourceStruct = (0, superstruct_1.type)({
|
|
39
|
-
name: (0, superstruct_1.string)(),
|
|
40
|
-
url: (0, superstruct_1.string)(),
|
|
41
|
-
type: (0, superstruct_1.string)(),
|
|
52
|
+
category: (0, superstruct_1.enums)(trendCategoryValues),
|
|
53
|
+
impact: (0, superstruct_1.enums)(trendImpactValues),
|
|
54
|
+
articles: (0, superstruct_1.array)(ArticleStruct),
|
|
55
|
+
tweets: (0, superstruct_1.array)(TweetStruct),
|
|
42
56
|
});
|
|
43
57
|
const MarketInsightsReportStruct = (0, superstruct_1.type)({
|
|
44
58
|
version: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
@@ -47,12 +61,31 @@ const MarketInsightsReportStruct = (0, superstruct_1.type)({
|
|
|
47
61
|
headline: (0, superstruct_1.string)(),
|
|
48
62
|
summary: (0, superstruct_1.string)(),
|
|
49
63
|
trends: (0, superstruct_1.array)(MarketInsightsTrendStruct),
|
|
50
|
-
social: (0, superstruct_1.optional)((0, superstruct_1.array)(
|
|
51
|
-
sources: (0, superstruct_1.array)(
|
|
64
|
+
social: (0, superstruct_1.optional)((0, superstruct_1.array)(TweetStruct)),
|
|
65
|
+
sources: (0, superstruct_1.array)(SourceStruct),
|
|
66
|
+
metadata: (0, superstruct_1.optional)((0, superstruct_1.array)(AIResponseMetadataStruct)),
|
|
52
67
|
});
|
|
53
68
|
const MarketInsightsDigestEnvelopeStruct = (0, superstruct_1.type)({
|
|
54
69
|
digest: MarketInsightsReportStruct,
|
|
55
70
|
});
|
|
71
|
+
// Market Overview structs
|
|
72
|
+
const MarketOverviewTrendStruct = (0, superstruct_1.type)({
|
|
73
|
+
title: (0, superstruct_1.string)(),
|
|
74
|
+
description: (0, superstruct_1.string)(),
|
|
75
|
+
category: (0, superstruct_1.enums)(trendCategoryValues),
|
|
76
|
+
impact: (0, superstruct_1.enums)(trendImpactValues),
|
|
77
|
+
articles: (0, superstruct_1.array)(ArticleStruct),
|
|
78
|
+
relatedAssets: (0, superstruct_1.array)((0, superstruct_1.string)()),
|
|
79
|
+
});
|
|
80
|
+
const MarketOverviewStruct = (0, superstruct_1.type)({
|
|
81
|
+
version: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
82
|
+
generatedAt: (0, superstruct_1.string)(),
|
|
83
|
+
headline: (0, superstruct_1.string)(),
|
|
84
|
+
summary: (0, superstruct_1.string)(),
|
|
85
|
+
trends: (0, superstruct_1.array)(MarketOverviewTrendStruct),
|
|
86
|
+
sources: (0, superstruct_1.array)(SourceStruct),
|
|
87
|
+
metadata: (0, superstruct_1.optional)((0, superstruct_1.array)(AIResponseMetadataStruct)),
|
|
88
|
+
});
|
|
56
89
|
const getNormalizedMarketInsightsReport = (value) => {
|
|
57
90
|
if ((0, superstruct_1.is)(value, MarketInsightsReportStruct)) {
|
|
58
91
|
return value;
|
|
@@ -67,16 +100,37 @@ class AiDigestService {
|
|
|
67
100
|
_AiDigestService_baseUrl.set(this, void 0);
|
|
68
101
|
__classPrivateFieldSet(this, _AiDigestService_baseUrl, config.baseUrl, "f");
|
|
69
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Fetch the market overview report.
|
|
105
|
+
*
|
|
106
|
+
* Calls `GET ${this.#baseUrl}/market-overview`.
|
|
107
|
+
*
|
|
108
|
+
* @returns The market overview report, or `null` if none exists (404).
|
|
109
|
+
*/
|
|
110
|
+
async fetchMarketOverview() {
|
|
111
|
+
const response = await fetch(`${__classPrivateFieldGet(this, _AiDigestService_baseUrl, "f")}/market-overview`);
|
|
112
|
+
if (response.status === 404) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
if (!response.ok) {
|
|
116
|
+
throw new Error(`${ai_digest_constants_1.AiDigestControllerErrorMessage.API_REQUEST_FAILED}: ${response.status}`);
|
|
117
|
+
}
|
|
118
|
+
const body = await response.json();
|
|
119
|
+
if (!(0, superstruct_1.is)(body, MarketOverviewStruct)) {
|
|
120
|
+
throw new Error(ai_digest_constants_1.AiDigestControllerErrorMessage.API_INVALID_RESPONSE);
|
|
121
|
+
}
|
|
122
|
+
return body;
|
|
123
|
+
}
|
|
70
124
|
/**
|
|
71
125
|
* Search for market insights by CAIP-19 asset identifier.
|
|
72
126
|
*
|
|
73
|
-
* Calls `GET ${this.#baseUrl}/
|
|
127
|
+
* Calls `GET ${this.#baseUrl}/asset-summary?caipAssetType=${encodeURIComponent(caip19Id)}`.
|
|
74
128
|
*
|
|
75
129
|
* @param caip19Id - The CAIP-19 identifier of the asset.
|
|
76
130
|
* @returns The market insights report, or `null` if none exists (404).
|
|
77
131
|
*/
|
|
78
132
|
async searchDigest(caip19Id) {
|
|
79
|
-
const response = await fetch(`${__classPrivateFieldGet(this, _AiDigestService_baseUrl, "f")}/
|
|
133
|
+
const response = await fetch(`${__classPrivateFieldGet(this, _AiDigestService_baseUrl, "f")}/asset-summary?caipAssetType=${encodeURIComponent(caip19Id)}`);
|
|
80
134
|
if (response.status === 404) {
|
|
81
135
|
return null;
|
|
82
136
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiDigestService.cjs","sourceRoot":"","sources":["../src/AiDigestService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"AiDigestService.cjs","sourceRoot":"","sources":["../src/AiDigestService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAO+B;AAG/B,mEAAuE;AAWvE,0BAA0B;AAE1B,MAAM,aAAa,GAAG,IAAA,kBAAU,EAAC;IAC/B,KAAK,EAAE,IAAA,oBAAM,GAAE;IACf,GAAG,EAAE,IAAA,oBAAM,GAAE;IACb,MAAM,EAAE,IAAA,oBAAM,GAAE;IAChB,IAAI,EAAE,IAAA,oBAAM,GAAE;CACf,CAAC,CAAC;AAEH,MAAM,WAAW,GAAG,IAAA,kBAAU,EAAC;IAC7B,cAAc,EAAE,IAAA,oBAAM,GAAE;IACxB,GAAG,EAAE,IAAA,oBAAM,GAAE;IACb,MAAM,EAAE,IAAA,oBAAM,GAAE;IAChB,IAAI,EAAE,IAAA,oBAAM,GAAE;CACf,CAAC,CAAC;AAEH,MAAM,YAAY,GAAG,IAAA,kBAAU,EAAC;IAC9B,IAAI,EAAE,IAAA,oBAAM,GAAE;IACd,GAAG,EAAE,IAAA,oBAAM,GAAE;IACb,IAAI,EAAE,IAAA,mBAAK,EAAC,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAU,CAAC;CACjD,CAAC,CAAC;AAEH,MAAM,wBAAwB,GAAG,IAAA,kBAAU,EAAC;IAC1C,QAAQ,EAAE,IAAA,oBAAM,GAAE;CACnB,CAAC,CAAC;AAEH,MAAM,mBAAmB,GAAG;IAC1B,cAAc;IACd,OAAO;IACP,YAAY;IAC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,\n type as structType,\n} from '@metamask/superstruct';\nimport type { CaipAssetType } from '@metamask/utils';\n\nimport { AiDigestControllerErrorMessage } from './ai-digest-constants';\nimport type {\n DigestService,\n MarketInsightsReport,\n MarketOverview,\n} from './ai-digest-types';\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 digest: MarketInsightsReportStruct,\n});\n\n// Market Overview structs\n\nconst MarketOverviewTrendStruct = structType({\n title: string(),\n description: string(),\n category: enums(trendCategoryValues),\n impact: enums(trendImpactValues),\n articles: array(ArticleStruct),\n relatedAssets: array(string()),\n});\n\nconst MarketOverviewStruct = structType({\n version: optional(string()),\n generatedAt: string(),\n headline: string(),\n summary: string(),\n trends: array(MarketOverviewTrendStruct),\n sources: array(SourceStruct),\n metadata: optional(array(AIResponseMetadataStruct)),\n});\n\nconst getNormalizedMarketInsightsReport = (\n value: unknown,\n): MarketInsightsReport | null => {\n if (is(value, MarketInsightsReportStruct)) {\n return value;\n }\n\n if (is(value, MarketInsightsDigestEnvelopeStruct)) {\n return value.digest;\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 body: unknown = await response.json();\n\n if (!is(body, MarketOverviewStruct)) {\n throw new Error(AiDigestControllerErrorMessage.API_INVALID_RESPONSE);\n }\n\n return body;\n }\n\n /**\n * Search for market insights by CAIP-19 asset identifier.\n *\n * Calls `GET ${this.#baseUrl}/asset-summary?caipAssetType=${encodeURIComponent(caip19Id)}`.\n *\n * @param caip19Id - The CAIP-19 identifier of the asset.\n * @returns The market insights report, or `null` if none exists (404).\n */\n async searchDigest(\n caip19Id: CaipAssetType,\n ): Promise<MarketInsightsReport | null> {\n const response = await fetch(\n `${this.#baseUrl}/asset-summary?caipAssetType=${encodeURIComponent(caip19Id)}`,\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"]}
|
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import type { CaipAssetType } from "@metamask/utils";
|
|
2
|
-
import type { DigestService, MarketInsightsReport } from "./ai-digest-types.cjs";
|
|
2
|
+
import type { DigestService, MarketInsightsReport, MarketOverview } from "./ai-digest-types.cjs";
|
|
3
3
|
export type AiDigestServiceConfig = {
|
|
4
4
|
baseUrl: string;
|
|
5
5
|
};
|
|
6
6
|
export declare class AiDigestService implements DigestService {
|
|
7
7
|
#private;
|
|
8
8
|
constructor(config: AiDigestServiceConfig);
|
|
9
|
+
/**
|
|
10
|
+
* Fetch the market overview report.
|
|
11
|
+
*
|
|
12
|
+
* Calls `GET ${this.#baseUrl}/market-overview`.
|
|
13
|
+
*
|
|
14
|
+
* @returns The market overview report, or `null` if none exists (404).
|
|
15
|
+
*/
|
|
16
|
+
fetchMarketOverview(): Promise<MarketOverview | null>;
|
|
9
17
|
/**
|
|
10
18
|
* Search for market insights by CAIP-19 asset identifier.
|
|
11
19
|
*
|
|
12
|
-
* Calls `GET ${this.#baseUrl}/
|
|
20
|
+
* Calls `GET ${this.#baseUrl}/asset-summary?caipAssetType=${encodeURIComponent(caip19Id)}`.
|
|
13
21
|
*
|
|
14
22
|
* @param caip19Id - The CAIP-19 identifier of the asset.
|
|
15
23
|
* @returns The market insights report, or `null` if none exists (404).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiDigestService.d.cts","sourceRoot":"","sources":["../src/AiDigestService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AiDigestService.d.cts","sourceRoot":"","sources":["../src/AiDigestService.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAGrD,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACpB,cAAc,EACf,8BAA0B;AAE3B,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAqGF,qBAAa,eAAgB,YAAW,aAAa;;gBAGvC,MAAM,EAAE,qBAAqB;IAIzC;;;;;;OAMG;IACG,mBAAmB,IAAI,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAsB3D;;;;;;;OAOG;IACG,YAAY,CAChB,QAAQ,EAAE,aAAa,GACtB,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;CAuBxC"}
|
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import type { CaipAssetType } from "@metamask/utils";
|
|
2
|
-
import type { DigestService, MarketInsightsReport } from "./ai-digest-types.mjs";
|
|
2
|
+
import type { DigestService, MarketInsightsReport, MarketOverview } from "./ai-digest-types.mjs";
|
|
3
3
|
export type AiDigestServiceConfig = {
|
|
4
4
|
baseUrl: string;
|
|
5
5
|
};
|
|
6
6
|
export declare class AiDigestService implements DigestService {
|
|
7
7
|
#private;
|
|
8
8
|
constructor(config: AiDigestServiceConfig);
|
|
9
|
+
/**
|
|
10
|
+
* Fetch the market overview report.
|
|
11
|
+
*
|
|
12
|
+
* Calls `GET ${this.#baseUrl}/market-overview`.
|
|
13
|
+
*
|
|
14
|
+
* @returns The market overview report, or `null` if none exists (404).
|
|
15
|
+
*/
|
|
16
|
+
fetchMarketOverview(): Promise<MarketOverview | null>;
|
|
9
17
|
/**
|
|
10
18
|
* Search for market insights by CAIP-19 asset identifier.
|
|
11
19
|
*
|
|
12
|
-
* Calls `GET ${this.#baseUrl}/
|
|
20
|
+
* Calls `GET ${this.#baseUrl}/asset-summary?caipAssetType=${encodeURIComponent(caip19Id)}`.
|
|
13
21
|
*
|
|
14
22
|
* @param caip19Id - The CAIP-19 identifier of the asset.
|
|
15
23
|
* @returns The market insights report, or `null` if none exists (404).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiDigestService.d.mts","sourceRoot":"","sources":["../src/AiDigestService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AiDigestService.d.mts","sourceRoot":"","sources":["../src/AiDigestService.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAGrD,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACpB,cAAc,EACf,8BAA0B;AAE3B,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAqGF,qBAAa,eAAgB,YAAW,aAAa;;gBAGvC,MAAM,EAAE,qBAAqB;IAIzC;;;;;;OAMG;IACG,mBAAmB,IAAI,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAsB3D;;;;;;;OAOG;IACG,YAAY,CAChB,QAAQ,EAAE,aAAa,GACtB,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;CAuBxC"}
|
package/dist/AiDigestService.mjs
CHANGED
|
@@ -10,32 +10,46 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _AiDigestService_baseUrl;
|
|
13
|
-
import { array, is, optional, string, type as structType } from "@metamask/superstruct";
|
|
13
|
+
import { array, enums, is, optional, string, type as structType } from "@metamask/superstruct";
|
|
14
14
|
import { AiDigestControllerErrorMessage } from "./ai-digest-constants.mjs";
|
|
15
|
-
|
|
15
|
+
// Shared sub-type structs
|
|
16
|
+
const ArticleStruct = structType({
|
|
16
17
|
title: string(),
|
|
17
18
|
url: string(),
|
|
18
19
|
source: string(),
|
|
19
20
|
date: string(),
|
|
20
21
|
});
|
|
21
|
-
const
|
|
22
|
+
const TweetStruct = structType({
|
|
22
23
|
contentSummary: string(),
|
|
23
24
|
url: string(),
|
|
24
25
|
author: string(),
|
|
25
26
|
date: string(),
|
|
26
27
|
});
|
|
28
|
+
const SourceStruct = structType({
|
|
29
|
+
name: string(),
|
|
30
|
+
url: string(),
|
|
31
|
+
type: enums(['news', 'data', 'social']),
|
|
32
|
+
});
|
|
33
|
+
const AIResponseMetadataStruct = structType({
|
|
34
|
+
provider: string(),
|
|
35
|
+
});
|
|
36
|
+
const trendCategoryValues = [
|
|
37
|
+
'geopolitical',
|
|
38
|
+
'macro',
|
|
39
|
+
'regulatory',
|
|
40
|
+
'technical',
|
|
41
|
+
'social',
|
|
42
|
+
'other',
|
|
43
|
+
];
|
|
44
|
+
const trendImpactValues = ['positive', 'negative', 'neutral'];
|
|
45
|
+
// Market Insights structs
|
|
27
46
|
const MarketInsightsTrendStruct = structType({
|
|
28
47
|
title: string(),
|
|
29
48
|
description: string(),
|
|
30
|
-
category:
|
|
31
|
-
impact:
|
|
32
|
-
articles: array(
|
|
33
|
-
tweets: array(
|
|
34
|
-
});
|
|
35
|
-
const MarketInsightsSourceStruct = structType({
|
|
36
|
-
name: string(),
|
|
37
|
-
url: string(),
|
|
38
|
-
type: string(),
|
|
49
|
+
category: enums(trendCategoryValues),
|
|
50
|
+
impact: enums(trendImpactValues),
|
|
51
|
+
articles: array(ArticleStruct),
|
|
52
|
+
tweets: array(TweetStruct),
|
|
39
53
|
});
|
|
40
54
|
const MarketInsightsReportStruct = structType({
|
|
41
55
|
version: optional(string()),
|
|
@@ -44,12 +58,31 @@ const MarketInsightsReportStruct = structType({
|
|
|
44
58
|
headline: string(),
|
|
45
59
|
summary: string(),
|
|
46
60
|
trends: array(MarketInsightsTrendStruct),
|
|
47
|
-
social: optional(array(
|
|
48
|
-
sources: array(
|
|
61
|
+
social: optional(array(TweetStruct)),
|
|
62
|
+
sources: array(SourceStruct),
|
|
63
|
+
metadata: optional(array(AIResponseMetadataStruct)),
|
|
49
64
|
});
|
|
50
65
|
const MarketInsightsDigestEnvelopeStruct = structType({
|
|
51
66
|
digest: MarketInsightsReportStruct,
|
|
52
67
|
});
|
|
68
|
+
// Market Overview structs
|
|
69
|
+
const MarketOverviewTrendStruct = structType({
|
|
70
|
+
title: string(),
|
|
71
|
+
description: string(),
|
|
72
|
+
category: enums(trendCategoryValues),
|
|
73
|
+
impact: enums(trendImpactValues),
|
|
74
|
+
articles: array(ArticleStruct),
|
|
75
|
+
relatedAssets: array(string()),
|
|
76
|
+
});
|
|
77
|
+
const MarketOverviewStruct = structType({
|
|
78
|
+
version: optional(string()),
|
|
79
|
+
generatedAt: string(),
|
|
80
|
+
headline: string(),
|
|
81
|
+
summary: string(),
|
|
82
|
+
trends: array(MarketOverviewTrendStruct),
|
|
83
|
+
sources: array(SourceStruct),
|
|
84
|
+
metadata: optional(array(AIResponseMetadataStruct)),
|
|
85
|
+
});
|
|
53
86
|
const getNormalizedMarketInsightsReport = (value) => {
|
|
54
87
|
if (is(value, MarketInsightsReportStruct)) {
|
|
55
88
|
return value;
|
|
@@ -64,16 +97,37 @@ export class AiDigestService {
|
|
|
64
97
|
_AiDigestService_baseUrl.set(this, void 0);
|
|
65
98
|
__classPrivateFieldSet(this, _AiDigestService_baseUrl, config.baseUrl, "f");
|
|
66
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Fetch the market overview report.
|
|
102
|
+
*
|
|
103
|
+
* Calls `GET ${this.#baseUrl}/market-overview`.
|
|
104
|
+
*
|
|
105
|
+
* @returns The market overview report, or `null` if none exists (404).
|
|
106
|
+
*/
|
|
107
|
+
async fetchMarketOverview() {
|
|
108
|
+
const response = await fetch(`${__classPrivateFieldGet(this, _AiDigestService_baseUrl, "f")}/market-overview`);
|
|
109
|
+
if (response.status === 404) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
if (!response.ok) {
|
|
113
|
+
throw new Error(`${AiDigestControllerErrorMessage.API_REQUEST_FAILED}: ${response.status}`);
|
|
114
|
+
}
|
|
115
|
+
const body = await response.json();
|
|
116
|
+
if (!is(body, MarketOverviewStruct)) {
|
|
117
|
+
throw new Error(AiDigestControllerErrorMessage.API_INVALID_RESPONSE);
|
|
118
|
+
}
|
|
119
|
+
return body;
|
|
120
|
+
}
|
|
67
121
|
/**
|
|
68
122
|
* Search for market insights by CAIP-19 asset identifier.
|
|
69
123
|
*
|
|
70
|
-
* Calls `GET ${this.#baseUrl}/
|
|
124
|
+
* Calls `GET ${this.#baseUrl}/asset-summary?caipAssetType=${encodeURIComponent(caip19Id)}`.
|
|
71
125
|
*
|
|
72
126
|
* @param caip19Id - The CAIP-19 identifier of the asset.
|
|
73
127
|
* @returns The market insights report, or `null` if none exists (404).
|
|
74
128
|
*/
|
|
75
129
|
async searchDigest(caip19Id) {
|
|
76
|
-
const response = await fetch(`${__classPrivateFieldGet(this, _AiDigestService_baseUrl, "f")}/
|
|
130
|
+
const response = await fetch(`${__classPrivateFieldGet(this, _AiDigestService_baseUrl, "f")}/asset-summary?caipAssetType=${encodeURIComponent(caip19Id)}`);
|
|
77
131
|
if (response.status === 404) {
|
|
78
132
|
return null;
|
|
79
133
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiDigestService.mjs","sourceRoot":"","sources":["../src/AiDigestService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,KAAK,EACL,EAAE,EACF,QAAQ,EACR,MAAM,EACN,IAAI,IAAI,UAAU,EACnB,8BAA8B;AAG/B,OAAO,EAAE,8BAA8B,EAAE,kCAA8B;
|
|
1
|
+
{"version":3,"file":"AiDigestService.mjs","sourceRoot":"","sources":["../src/AiDigestService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,KAAK,EACL,KAAK,EACL,EAAE,EACF,QAAQ,EACR,MAAM,EACN,IAAI,IAAI,UAAU,EACnB,8BAA8B;AAG/B,OAAO,EAAE,8BAA8B,EAAE,kCAA8B;AAWvE,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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enums,\n is,\n optional,\n string,\n type as structType,\n} from '@metamask/superstruct';\nimport type { CaipAssetType } from '@metamask/utils';\n\nimport { AiDigestControllerErrorMessage } from './ai-digest-constants';\nimport type {\n DigestService,\n MarketInsightsReport,\n MarketOverview,\n} from './ai-digest-types';\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 digest: MarketInsightsReportStruct,\n});\n\n// Market Overview structs\n\nconst MarketOverviewTrendStruct = structType({\n title: string(),\n description: string(),\n category: enums(trendCategoryValues),\n impact: enums(trendImpactValues),\n articles: array(ArticleStruct),\n relatedAssets: array(string()),\n});\n\nconst MarketOverviewStruct = structType({\n version: optional(string()),\n generatedAt: string(),\n headline: string(),\n summary: string(),\n trends: array(MarketOverviewTrendStruct),\n sources: array(SourceStruct),\n metadata: optional(array(AIResponseMetadataStruct)),\n});\n\nconst getNormalizedMarketInsightsReport = (\n value: unknown,\n): MarketInsightsReport | null => {\n if (is(value, MarketInsightsReportStruct)) {\n return value;\n }\n\n if (is(value, MarketInsightsDigestEnvelopeStruct)) {\n return value.digest;\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 body: unknown = await response.json();\n\n if (!is(body, MarketOverviewStruct)) {\n throw new Error(AiDigestControllerErrorMessage.API_INVALID_RESPONSE);\n }\n\n return body;\n }\n\n /**\n * Search for market insights by CAIP-19 asset identifier.\n *\n * Calls `GET ${this.#baseUrl}/asset-summary?caipAssetType=${encodeURIComponent(caip19Id)}`.\n *\n * @param caip19Id - The CAIP-19 identifier of the asset.\n * @returns The market insights report, or `null` if none exists (404).\n */\n async searchDigest(\n caip19Id: CaipAssetType,\n ): Promise<MarketInsightsReport | null> {\n const response = await fetch(\n `${this.#baseUrl}/asset-summary?caipAssetType=${encodeURIComponent(caip19Id)}`,\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-digest-types.cjs","sourceRoot":"","sources":["../src/ai-digest-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { CaipAssetType } from '@metamask/utils';\n\n// ---------------------------------------------------------------------------\n//
|
|
1
|
+
{"version":3,"file":"ai-digest-types.cjs","sourceRoot":"","sources":["../src/ai-digest-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { CaipAssetType } from '@metamask/utils';\n\n// ---------------------------------------------------------------------------\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 /digests?caipAssetType=<caip19Id>`.\n */\nexport type MarketInsightsReport = {\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 /** CAIP-19 asset identifier */\n caip19Id: CaipAssetType;\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\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: string[];\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 headline: string;\n summary: string;\n trends: MarketOverviewTrend[];\n sources: Source[];\n metadata?: AIResponseMetadata[];\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 CAIP-19 asset identifier.\n * Calls `GET /asset-summary?caipAssetType=<caip19Id>`.\n *\n * @param caip19Id - The CAIP-19 identifier of the asset.\n * @returns The market insights report, or `null` if no insights exist (404).\n */\n searchDigest(caip19Id: CaipAssetType): 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"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { CaipAssetType } from "@metamask/utils";
|
|
2
2
|
/**
|
|
3
|
-
* A news article referenced by a
|
|
3
|
+
* A news article referenced by a trend.
|
|
4
4
|
*/
|
|
5
|
-
export type
|
|
5
|
+
export type Article = {
|
|
6
6
|
/** Article title */
|
|
7
7
|
title: string;
|
|
8
8
|
/** Full URL to the article */
|
|
@@ -13,9 +13,9 @@ export type MarketInsightsArticle = {
|
|
|
13
13
|
date: string;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
|
-
* A social media post referenced by a
|
|
16
|
+
* A social media post referenced by a trend.
|
|
17
17
|
*/
|
|
18
|
-
export type
|
|
18
|
+
export type Tweet = {
|
|
19
19
|
/** Summary of the tweet content */
|
|
20
20
|
contentSummary: string;
|
|
21
21
|
/** Full URL to the tweet */
|
|
@@ -25,6 +25,20 @@ export type MarketInsightsTweet = {
|
|
|
25
25
|
/** ISO date string */
|
|
26
26
|
date: string;
|
|
27
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* A data source used to generate a report.
|
|
30
|
+
*/
|
|
31
|
+
export type Source = {
|
|
32
|
+
/** Source name (e.g. "CoinDesk") */
|
|
33
|
+
name: string;
|
|
34
|
+
/** Source URL */
|
|
35
|
+
url: string;
|
|
36
|
+
/** Source type */
|
|
37
|
+
type: 'news' | 'data' | 'social';
|
|
38
|
+
};
|
|
39
|
+
export type MarketInsightsArticle = Article;
|
|
40
|
+
export type MarketInsightsTweet = Tweet;
|
|
41
|
+
export type MarketInsightsSource = Source;
|
|
28
42
|
/**
|
|
29
43
|
* A key market trend identified in the insights report.
|
|
30
44
|
*/
|
|
@@ -34,24 +48,13 @@ export type MarketInsightsTrend = {
|
|
|
34
48
|
/** Detailed description of the trend */
|
|
35
49
|
description: string;
|
|
36
50
|
/** Category of the trend */
|
|
37
|
-
category: 'macro' | 'technical' | 'social' |
|
|
51
|
+
category: 'geopolitical' | 'macro' | 'regulatory' | 'technical' | 'social' | 'other';
|
|
38
52
|
/** Impact direction */
|
|
39
|
-
impact: 'positive' | 'negative' | 'neutral'
|
|
53
|
+
impact: 'positive' | 'negative' | 'neutral';
|
|
40
54
|
/** Related news articles */
|
|
41
|
-
articles:
|
|
55
|
+
articles: Article[];
|
|
42
56
|
/** Related social media posts */
|
|
43
|
-
tweets:
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* A data source used to generate the market insights report.
|
|
47
|
-
*/
|
|
48
|
-
export type MarketInsightsSource = {
|
|
49
|
-
/** Source name (e.g. "CoinDesk") */
|
|
50
|
-
name: string;
|
|
51
|
-
/** Source URL */
|
|
52
|
-
url: string;
|
|
53
|
-
/** Source type */
|
|
54
|
-
type: 'news' | 'data' | 'social' | string;
|
|
57
|
+
tweets: Tweet[];
|
|
55
58
|
};
|
|
56
59
|
/**
|
|
57
60
|
* AI-generated market insights report for a crypto asset.
|
|
@@ -71,9 +74,11 @@ export type MarketInsightsReport = {
|
|
|
71
74
|
/** Key market trends */
|
|
72
75
|
trends: MarketInsightsTrend[];
|
|
73
76
|
/** Optional top-level social posts included by the API */
|
|
74
|
-
social?:
|
|
77
|
+
social?: Tweet[];
|
|
75
78
|
/** Data sources used to generate the report */
|
|
76
|
-
sources:
|
|
79
|
+
sources: Source[];
|
|
80
|
+
/** Provider metadata */
|
|
81
|
+
metadata?: AIResponseMetadata[];
|
|
77
82
|
};
|
|
78
83
|
/**
|
|
79
84
|
* A cached market insights entry.
|
|
@@ -86,17 +91,57 @@ export type MarketInsightsEntry = {
|
|
|
86
91
|
/** The market insights report data */
|
|
87
92
|
data: MarketInsightsReport;
|
|
88
93
|
};
|
|
94
|
+
/**
|
|
95
|
+
* A cached market overview entry.
|
|
96
|
+
*/
|
|
97
|
+
export type MarketOverviewEntry = {
|
|
98
|
+
/** Timestamp when the entry was fetched */
|
|
99
|
+
fetchedAt: number;
|
|
100
|
+
/** The market overview data */
|
|
101
|
+
data: MarketOverview;
|
|
102
|
+
};
|
|
103
|
+
export type MarketOverviewTrend = {
|
|
104
|
+
title: string;
|
|
105
|
+
description: string;
|
|
106
|
+
category: 'geopolitical' | 'macro' | 'regulatory' | 'technical' | 'social' | 'other';
|
|
107
|
+
impact: 'positive' | 'negative' | 'neutral';
|
|
108
|
+
articles: Article[];
|
|
109
|
+
relatedAssets: string[];
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Provider metadata included in AI API responses.
|
|
113
|
+
*/
|
|
114
|
+
export type AIResponseMetadata = {
|
|
115
|
+
provider: string;
|
|
116
|
+
};
|
|
117
|
+
export type MarketOverview = {
|
|
118
|
+
version?: string;
|
|
119
|
+
generatedAt: string;
|
|
120
|
+
headline: string;
|
|
121
|
+
summary: string;
|
|
122
|
+
trends: MarketOverviewTrend[];
|
|
123
|
+
sources: Source[];
|
|
124
|
+
metadata?: AIResponseMetadata[];
|
|
125
|
+
};
|
|
89
126
|
export type AiDigestControllerState = {
|
|
90
127
|
marketInsights: Record<string, MarketInsightsEntry>;
|
|
128
|
+
marketOverview: MarketOverviewEntry | null;
|
|
91
129
|
};
|
|
92
130
|
export type DigestService = {
|
|
93
131
|
/**
|
|
94
132
|
* Search for market insights by CAIP-19 asset identifier.
|
|
95
|
-
* Calls `GET /
|
|
133
|
+
* Calls `GET /asset-summary?caipAssetType=<caip19Id>`.
|
|
96
134
|
*
|
|
97
135
|
* @param caip19Id - The CAIP-19 identifier of the asset.
|
|
98
136
|
* @returns The market insights report, or `null` if no insights exist (404).
|
|
99
137
|
*/
|
|
100
138
|
searchDigest(caip19Id: CaipAssetType): Promise<MarketInsightsReport | null>;
|
|
139
|
+
/**
|
|
140
|
+
* Fetch the market overview report.
|
|
141
|
+
* Calls `GET /market-overview`.
|
|
142
|
+
*
|
|
143
|
+
* @returns The market overview report, or `null` if none exists (404).
|
|
144
|
+
*/
|
|
145
|
+
fetchMarketOverview(): Promise<MarketOverview | null>;
|
|
101
146
|
};
|
|
102
147
|
//# sourceMappingURL=ai-digest-types.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-digest-types.d.cts","sourceRoot":"","sources":["../src/ai-digest-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAMrD;;GAEG;AACH,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"ai-digest-types.d.cts","sourceRoot":"","sources":["../src/ai-digest-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAMrD;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,oBAAoB;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,8BAA8B;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG;IAClB,mCAAmC;IACnC,cAAc,EAAE,MAAM,CAAC;IACvB,4BAA4B;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB,oCAAoC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,kBAAkB;IAClB,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,OAAO,CAAC;AAC5C,MAAM,MAAM,mBAAmB,GAA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CaipAssetType } from "@metamask/utils";
|
|
2
2
|
/**
|
|
3
|
-
* A news article referenced by a
|
|
3
|
+
* A news article referenced by a trend.
|
|
4
4
|
*/
|
|
5
|
-
export type
|
|
5
|
+
export type Article = {
|
|
6
6
|
/** Article title */
|
|
7
7
|
title: string;
|
|
8
8
|
/** Full URL to the article */
|
|
@@ -13,9 +13,9 @@ export type MarketInsightsArticle = {
|
|
|
13
13
|
date: string;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
|
-
* A social media post referenced by a
|
|
16
|
+
* A social media post referenced by a trend.
|
|
17
17
|
*/
|
|
18
|
-
export type
|
|
18
|
+
export type Tweet = {
|
|
19
19
|
/** Summary of the tweet content */
|
|
20
20
|
contentSummary: string;
|
|
21
21
|
/** Full URL to the tweet */
|
|
@@ -25,6 +25,20 @@ export type MarketInsightsTweet = {
|
|
|
25
25
|
/** ISO date string */
|
|
26
26
|
date: string;
|
|
27
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* A data source used to generate a report.
|
|
30
|
+
*/
|
|
31
|
+
export type Source = {
|
|
32
|
+
/** Source name (e.g. "CoinDesk") */
|
|
33
|
+
name: string;
|
|
34
|
+
/** Source URL */
|
|
35
|
+
url: string;
|
|
36
|
+
/** Source type */
|
|
37
|
+
type: 'news' | 'data' | 'social';
|
|
38
|
+
};
|
|
39
|
+
export type MarketInsightsArticle = Article;
|
|
40
|
+
export type MarketInsightsTweet = Tweet;
|
|
41
|
+
export type MarketInsightsSource = Source;
|
|
28
42
|
/**
|
|
29
43
|
* A key market trend identified in the insights report.
|
|
30
44
|
*/
|
|
@@ -34,24 +48,13 @@ export type MarketInsightsTrend = {
|
|
|
34
48
|
/** Detailed description of the trend */
|
|
35
49
|
description: string;
|
|
36
50
|
/** Category of the trend */
|
|
37
|
-
category: 'macro' | 'technical' | 'social' |
|
|
51
|
+
category: 'geopolitical' | 'macro' | 'regulatory' | 'technical' | 'social' | 'other';
|
|
38
52
|
/** Impact direction */
|
|
39
|
-
impact: 'positive' | 'negative' | 'neutral'
|
|
53
|
+
impact: 'positive' | 'negative' | 'neutral';
|
|
40
54
|
/** Related news articles */
|
|
41
|
-
articles:
|
|
55
|
+
articles: Article[];
|
|
42
56
|
/** Related social media posts */
|
|
43
|
-
tweets:
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* A data source used to generate the market insights report.
|
|
47
|
-
*/
|
|
48
|
-
export type MarketInsightsSource = {
|
|
49
|
-
/** Source name (e.g. "CoinDesk") */
|
|
50
|
-
name: string;
|
|
51
|
-
/** Source URL */
|
|
52
|
-
url: string;
|
|
53
|
-
/** Source type */
|
|
54
|
-
type: 'news' | 'data' | 'social' | string;
|
|
57
|
+
tweets: Tweet[];
|
|
55
58
|
};
|
|
56
59
|
/**
|
|
57
60
|
* AI-generated market insights report for a crypto asset.
|
|
@@ -71,9 +74,11 @@ export type MarketInsightsReport = {
|
|
|
71
74
|
/** Key market trends */
|
|
72
75
|
trends: MarketInsightsTrend[];
|
|
73
76
|
/** Optional top-level social posts included by the API */
|
|
74
|
-
social?:
|
|
77
|
+
social?: Tweet[];
|
|
75
78
|
/** Data sources used to generate the report */
|
|
76
|
-
sources:
|
|
79
|
+
sources: Source[];
|
|
80
|
+
/** Provider metadata */
|
|
81
|
+
metadata?: AIResponseMetadata[];
|
|
77
82
|
};
|
|
78
83
|
/**
|
|
79
84
|
* A cached market insights entry.
|
|
@@ -86,17 +91,57 @@ export type MarketInsightsEntry = {
|
|
|
86
91
|
/** The market insights report data */
|
|
87
92
|
data: MarketInsightsReport;
|
|
88
93
|
};
|
|
94
|
+
/**
|
|
95
|
+
* A cached market overview entry.
|
|
96
|
+
*/
|
|
97
|
+
export type MarketOverviewEntry = {
|
|
98
|
+
/** Timestamp when the entry was fetched */
|
|
99
|
+
fetchedAt: number;
|
|
100
|
+
/** The market overview data */
|
|
101
|
+
data: MarketOverview;
|
|
102
|
+
};
|
|
103
|
+
export type MarketOverviewTrend = {
|
|
104
|
+
title: string;
|
|
105
|
+
description: string;
|
|
106
|
+
category: 'geopolitical' | 'macro' | 'regulatory' | 'technical' | 'social' | 'other';
|
|
107
|
+
impact: 'positive' | 'negative' | 'neutral';
|
|
108
|
+
articles: Article[];
|
|
109
|
+
relatedAssets: string[];
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Provider metadata included in AI API responses.
|
|
113
|
+
*/
|
|
114
|
+
export type AIResponseMetadata = {
|
|
115
|
+
provider: string;
|
|
116
|
+
};
|
|
117
|
+
export type MarketOverview = {
|
|
118
|
+
version?: string;
|
|
119
|
+
generatedAt: string;
|
|
120
|
+
headline: string;
|
|
121
|
+
summary: string;
|
|
122
|
+
trends: MarketOverviewTrend[];
|
|
123
|
+
sources: Source[];
|
|
124
|
+
metadata?: AIResponseMetadata[];
|
|
125
|
+
};
|
|
89
126
|
export type AiDigestControllerState = {
|
|
90
127
|
marketInsights: Record<string, MarketInsightsEntry>;
|
|
128
|
+
marketOverview: MarketOverviewEntry | null;
|
|
91
129
|
};
|
|
92
130
|
export type DigestService = {
|
|
93
131
|
/**
|
|
94
132
|
* Search for market insights by CAIP-19 asset identifier.
|
|
95
|
-
* Calls `GET /
|
|
133
|
+
* Calls `GET /asset-summary?caipAssetType=<caip19Id>`.
|
|
96
134
|
*
|
|
97
135
|
* @param caip19Id - The CAIP-19 identifier of the asset.
|
|
98
136
|
* @returns The market insights report, or `null` if no insights exist (404).
|
|
99
137
|
*/
|
|
100
138
|
searchDigest(caip19Id: CaipAssetType): Promise<MarketInsightsReport | null>;
|
|
139
|
+
/**
|
|
140
|
+
* Fetch the market overview report.
|
|
141
|
+
* Calls `GET /market-overview`.
|
|
142
|
+
*
|
|
143
|
+
* @returns The market overview report, or `null` if none exists (404).
|
|
144
|
+
*/
|
|
145
|
+
fetchMarketOverview(): Promise<MarketOverview | null>;
|
|
101
146
|
};
|
|
102
147
|
//# sourceMappingURL=ai-digest-types.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-digest-types.d.mts","sourceRoot":"","sources":["../src/ai-digest-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAMrD;;GAEG;AACH,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"ai-digest-types.d.mts","sourceRoot":"","sources":["../src/ai-digest-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAMrD;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,oBAAoB;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,8BAA8B;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG;IAClB,mCAAmC;IACnC,cAAc,EAAE,MAAM,CAAC;IACvB,4BAA4B;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB,oCAAoC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,kBAAkB;IAClB,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,OAAO,CAAC;AAC5C,MAAM,MAAM,mBAAmB,GAAG,KAAK,CAAC;AACxC,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAM1C;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,uDAAuD;IACvD,KAAK,EAAE,MAAM,CAAC;IACd,wCAAwC;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,4BAA4B;IA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,EACJ,cAAc,GACd,OAAO,GACP,YAAY,GACZ,WAAW,GACX,QAAQ,GACR,OAAO,CAAC;IACZ,MAAM,EAAE,UAAU,GAAG,UAAU,GAAG,SAAS,CAAC;IAC5C,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,mBAAmB,EAAE,CAAC;IAC9B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,kBAAkB,EAAE,CAAC;CACjC,CAAC;AAMF,MAAM,MAAM,uBAAuB,GAAG;IACpC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IACpD,cAAc,EAAE,mBAAmB,GAAG,IAAI,CAAC;CAC5C,CAAC;AAMF,MAAM,MAAM,aAAa,GAAG;IAC1B;;;;;;OAMG;IACH,YAAY,CAAC,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAAC;IAE5E;;;;;OAKG;IACH,mBAAmB,IAAI,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;CACvD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-digest-types.mjs","sourceRoot":"","sources":["../src/ai-digest-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { CaipAssetType } from '@metamask/utils';\n\n// ---------------------------------------------------------------------------\n//
|
|
1
|
+
{"version":3,"file":"ai-digest-types.mjs","sourceRoot":"","sources":["../src/ai-digest-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { CaipAssetType } from '@metamask/utils';\n\n// ---------------------------------------------------------------------------\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 /digests?caipAssetType=<caip19Id>`.\n */\nexport type MarketInsightsReport = {\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 /** CAIP-19 asset identifier */\n caip19Id: CaipAssetType;\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\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: string[];\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 headline: string;\n summary: string;\n trends: MarketOverviewTrend[];\n sources: Source[];\n metadata?: AIResponseMetadata[];\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 CAIP-19 asset identifier.\n * Calls `GET /asset-summary?caipAssetType=<caip19Id>`.\n *\n * @param caip19Id - The CAIP-19 identifier of the asset.\n * @returns The market insights report, or `null` if no insights exist (404).\n */\n searchDigest(caip19Id: CaipAssetType): 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"]}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAUA,+DAG8B;AAF5B,wHAAA,kBAAkB,OAAA;AAClB,uIAAA,iCAAiC,OAAA;AAInC,yDAAoD;AAA3C,kHAAA,eAAe,OAAA;AAoBxB,iEAK+B;AAJ7B,6HAAA,cAAc,OAA0B;AACxC,wHAAA,iBAAiB,OAAA;AACjB,wHAAA,iBAAiB,OAAA;AACjB,qIAAA,8BAA8B,OAAA","sourcesContent":["export type {\n AiDigestControllerActions,\n AiDigestControllerEvents,\n AiDigestControllerFetchMarketInsightsAction,\n AiDigestControllerFetchMarketOverviewAction,\n AiDigestControllerGetStateAction,\n AiDigestControllerMessenger,\n AiDigestControllerOptions,\n AiDigestControllerStateChangeEvent,\n} from './AiDigestController';\nexport {\n AiDigestController,\n getDefaultAiDigestControllerState,\n} from './AiDigestController';\n\nexport type { AiDigestServiceConfig } from './AiDigestService';\nexport { AiDigestService } from './AiDigestService';\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 MarketOverviewTrend,\n Source,\n Tweet,\n} from './ai-digest-types';\n\nexport {\n controllerName as aiDigestControllerName,\n CACHE_DURATION_MS,\n MAX_CACHE_ENTRIES,\n AiDigestControllerErrorMessage,\n} from './ai-digest-constants';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export type { AiDigestControllerActions, AiDigestControllerEvents, AiDigestControllerFetchMarketInsightsAction, AiDigestControllerGetStateAction, AiDigestControllerMessenger, AiDigestControllerOptions, AiDigestControllerStateChangeEvent, } from "./AiDigestController.cjs";
|
|
1
|
+
export type { AiDigestControllerActions, AiDigestControllerEvents, AiDigestControllerFetchMarketInsightsAction, AiDigestControllerFetchMarketOverviewAction, AiDigestControllerGetStateAction, AiDigestControllerMessenger, AiDigestControllerOptions, AiDigestControllerStateChangeEvent, } from "./AiDigestController.cjs";
|
|
2
2
|
export { AiDigestController, getDefaultAiDigestControllerState, } from "./AiDigestController.cjs";
|
|
3
3
|
export type { AiDigestServiceConfig } from "./AiDigestService.cjs";
|
|
4
4
|
export { AiDigestService } from "./AiDigestService.cjs";
|
|
5
|
-
export type { AiDigestControllerState, DigestService, MarketInsightsArticle,
|
|
5
|
+
export type { AiDigestControllerState, AIResponseMetadata, Article, DigestService, MarketInsightsArticle, MarketInsightsEntry, MarketInsightsReport, MarketInsightsSource, MarketInsightsTrend, MarketInsightsTweet, MarketOverview, MarketOverviewEntry, MarketOverviewTrend, Source, Tweet, } from "./ai-digest-types.cjs";
|
|
6
6
|
export { controllerName as aiDigestControllerName, CACHE_DURATION_MS, MAX_CACHE_ENTRIES, AiDigestControllerErrorMessage, } from "./ai-digest-constants.cjs";
|
|
7
7
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,yBAAyB,EACzB,wBAAwB,EACxB,2CAA2C,EAC3C,gCAAgC,EAChC,2BAA2B,EAC3B,yBAAyB,EACzB,kCAAkC,GACnC,iCAA6B;AAC9B,OAAO,EACL,kBAAkB,EAClB,iCAAiC,GAClC,iCAA6B;AAE9B,YAAY,EAAE,qBAAqB,EAAE,8BAA0B;AAC/D,OAAO,EAAE,eAAe,EAAE,8BAA0B;AAEpD,YAAY,EACV,uBAAuB,EACvB,aAAa,EACb,qBAAqB,EACrB,mBAAmB,EACnB,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,yBAAyB,EACzB,wBAAwB,EACxB,2CAA2C,EAC3C,2CAA2C,EAC3C,gCAAgC,EAChC,2BAA2B,EAC3B,yBAAyB,EACzB,kCAAkC,GACnC,iCAA6B;AAC9B,OAAO,EACL,kBAAkB,EAClB,iCAAiC,GAClC,iCAA6B;AAE9B,YAAY,EAAE,qBAAqB,EAAE,8BAA0B;AAC/D,OAAO,EAAE,eAAe,EAAE,8BAA0B;AAEpD,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,mBAAmB,EACnB,MAAM,EACN,KAAK,GACN,8BAA0B;AAE3B,OAAO,EACL,cAAc,IAAI,sBAAsB,EACxC,iBAAiB,EACjB,iBAAiB,EACjB,8BAA8B,GAC/B,kCAA8B"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export type { AiDigestControllerActions, AiDigestControllerEvents, AiDigestControllerFetchMarketInsightsAction, AiDigestControllerGetStateAction, AiDigestControllerMessenger, AiDigestControllerOptions, AiDigestControllerStateChangeEvent, } from "./AiDigestController.mjs";
|
|
1
|
+
export type { AiDigestControllerActions, AiDigestControllerEvents, AiDigestControllerFetchMarketInsightsAction, AiDigestControllerFetchMarketOverviewAction, AiDigestControllerGetStateAction, AiDigestControllerMessenger, AiDigestControllerOptions, AiDigestControllerStateChangeEvent, } from "./AiDigestController.mjs";
|
|
2
2
|
export { AiDigestController, getDefaultAiDigestControllerState, } from "./AiDigestController.mjs";
|
|
3
3
|
export type { AiDigestServiceConfig } from "./AiDigestService.mjs";
|
|
4
4
|
export { AiDigestService } from "./AiDigestService.mjs";
|
|
5
|
-
export type { AiDigestControllerState, DigestService, MarketInsightsArticle,
|
|
5
|
+
export type { AiDigestControllerState, AIResponseMetadata, Article, DigestService, MarketInsightsArticle, MarketInsightsEntry, MarketInsightsReport, MarketInsightsSource, MarketInsightsTrend, MarketInsightsTweet, MarketOverview, MarketOverviewEntry, MarketOverviewTrend, Source, Tweet, } from "./ai-digest-types.mjs";
|
|
6
6
|
export { controllerName as aiDigestControllerName, CACHE_DURATION_MS, MAX_CACHE_ENTRIES, AiDigestControllerErrorMessage, } from "./ai-digest-constants.mjs";
|
|
7
7
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,yBAAyB,EACzB,wBAAwB,EACxB,2CAA2C,EAC3C,gCAAgC,EAChC,2BAA2B,EAC3B,yBAAyB,EACzB,kCAAkC,GACnC,iCAA6B;AAC9B,OAAO,EACL,kBAAkB,EAClB,iCAAiC,GAClC,iCAA6B;AAE9B,YAAY,EAAE,qBAAqB,EAAE,8BAA0B;AAC/D,OAAO,EAAE,eAAe,EAAE,8BAA0B;AAEpD,YAAY,EACV,uBAAuB,EACvB,aAAa,EACb,qBAAqB,EACrB,mBAAmB,EACnB,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,yBAAyB,EACzB,wBAAwB,EACxB,2CAA2C,EAC3C,2CAA2C,EAC3C,gCAAgC,EAChC,2BAA2B,EAC3B,yBAAyB,EACzB,kCAAkC,GACnC,iCAA6B;AAC9B,OAAO,EACL,kBAAkB,EAClB,iCAAiC,GAClC,iCAA6B;AAE9B,YAAY,EAAE,qBAAqB,EAAE,8BAA0B;AAC/D,OAAO,EAAE,eAAe,EAAE,8BAA0B;AAEpD,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,mBAAmB,EACnB,MAAM,EACN,KAAK,GACN,8BAA0B;AAE3B,OAAO,EACL,cAAc,IAAI,sBAAsB,EACxC,iBAAiB,EACjB,iBAAiB,EACjB,8BAA8B,GAC/B,kCAA8B"}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,kBAAkB,EAClB,iCAAiC,EAClC,iCAA6B;AAG9B,OAAO,EAAE,eAAe,EAAE,8BAA0B;AAoBpD,OAAO,EACL,cAAc,IAAI,sBAAsB,EACxC,iBAAiB,EACjB,iBAAiB,EACjB,8BAA8B,EAC/B,kCAA8B","sourcesContent":["export type {\n AiDigestControllerActions,\n AiDigestControllerEvents,\n AiDigestControllerFetchMarketInsightsAction,\n AiDigestControllerFetchMarketOverviewAction,\n AiDigestControllerGetStateAction,\n AiDigestControllerMessenger,\n AiDigestControllerOptions,\n AiDigestControllerStateChangeEvent,\n} from './AiDigestController';\nexport {\n AiDigestController,\n getDefaultAiDigestControllerState,\n} from './AiDigestController';\n\nexport type { AiDigestServiceConfig } from './AiDigestService';\nexport { AiDigestService } from './AiDigestService';\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 MarketOverviewTrend,\n Source,\n Tweet,\n} from './ai-digest-types';\n\nexport {\n controllerName as aiDigestControllerName,\n CACHE_DURATION_MS,\n MAX_CACHE_ENTRIES,\n AiDigestControllerErrorMessage,\n} from './ai-digest-constants';\n"]}
|