@metamask-previews/ai-controllers 0.6.2-preview-4f74a56 → 0.6.3-preview-5231be986
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 +8 -1
- package/dist/AiDigestService.cjs +13 -3
- package/dist/AiDigestService.cjs.map +1 -1
- package/dist/AiDigestService.d.cts.map +1 -1
- package/dist/AiDigestService.d.mts.map +1 -1
- package/dist/AiDigestService.mjs +13 -3
- package/dist/AiDigestService.mjs.map +1 -1
- package/dist/ai-digest-types.cjs.map +1 -1
- package/dist/ai-digest-types.d.cts +6 -2
- package/dist/ai-digest-types.d.cts.map +1 -1
- package/dist/ai-digest-types.d.mts +6 -2
- package/dist/ai-digest-types.d.mts.map +1 -1
- package/dist/ai-digest-types.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.6.3]
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- `RelatedAsset.caip19` is now optional (`string[] | undefined`) to match the live API, which omits the field for perps-only synthetic assets (e.g. ETHFI). `AiDigestService.fetchMarketOverview` normalises absent `caip19` values to `[]` so consumers always receive a `string[]` ([#8326](https://github.com/MetaMask/core/pull/8326)).
|
|
15
|
+
|
|
10
16
|
## [0.6.2]
|
|
11
17
|
|
|
12
18
|
### Changed
|
|
@@ -90,7 +96,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
90
96
|
- Removes `fetchDigest`, `clearDigest`, and `clearAllDigests` actions from the controller action surface.
|
|
91
97
|
- Removes `DigestData`/`DigestEntry` types and the `digests` state branch.
|
|
92
98
|
|
|
93
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/ai-controllers@0.6.
|
|
99
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/ai-controllers@0.6.3...HEAD
|
|
100
|
+
[0.6.3]: https://github.com/MetaMask/core/compare/@metamask/ai-controllers@0.6.2...@metamask/ai-controllers@0.6.3
|
|
94
101
|
[0.6.2]: https://github.com/MetaMask/core/compare/@metamask/ai-controllers@0.6.1...@metamask/ai-controllers@0.6.2
|
|
95
102
|
[0.6.1]: https://github.com/MetaMask/core/compare/@metamask/ai-controllers@0.6.0...@metamask/ai-controllers@0.6.1
|
|
96
103
|
[0.6.0]: https://github.com/MetaMask/core/compare/@metamask/ai-controllers@0.5.0...@metamask/ai-controllers@0.6.0
|
package/dist/AiDigestService.cjs
CHANGED
|
@@ -73,7 +73,7 @@ const MarketInsightsDigestEnvelopeStruct = (0, superstruct_1.type)({
|
|
|
73
73
|
const RelatedAssetStruct = (0, superstruct_1.type)({
|
|
74
74
|
name: (0, superstruct_1.string)(),
|
|
75
75
|
symbol: (0, superstruct_1.string)(),
|
|
76
|
-
caip19: (0, superstruct_1.array)((0, superstruct_1.string)()),
|
|
76
|
+
caip19: (0, superstruct_1.optional)((0, superstruct_1.array)((0, superstruct_1.string)())),
|
|
77
77
|
sourceAssetId: (0, superstruct_1.string)(),
|
|
78
78
|
hlPerpsMarket: (0, superstruct_1.optional)((0, superstruct_1.array)((0, superstruct_1.string)())),
|
|
79
79
|
});
|
|
@@ -94,12 +94,22 @@ const MarketOverviewStruct = (0, superstruct_1.type)({
|
|
|
94
94
|
const MarketOverviewReportEnvelopeStruct = (0, superstruct_1.type)({
|
|
95
95
|
report: MarketOverviewStruct,
|
|
96
96
|
});
|
|
97
|
+
const normalizeRelatedAssets = (raw) => ({
|
|
98
|
+
...raw,
|
|
99
|
+
trends: raw.trends.map((trend) => ({
|
|
100
|
+
...trend,
|
|
101
|
+
relatedAssets: trend.relatedAssets.map((asset) => ({
|
|
102
|
+
...asset,
|
|
103
|
+
caip19: asset.caip19 ?? [],
|
|
104
|
+
})),
|
|
105
|
+
})),
|
|
106
|
+
});
|
|
97
107
|
const getNormalizedMarketOverview = (value) => {
|
|
98
108
|
if ((0, superstruct_1.is)(value, MarketOverviewStruct)) {
|
|
99
|
-
return value;
|
|
109
|
+
return normalizeRelatedAssets(value);
|
|
100
110
|
}
|
|
101
111
|
if ((0, superstruct_1.is)(value, MarketOverviewReportEnvelopeStruct)) {
|
|
102
|
-
return value.report;
|
|
112
|
+
return normalizeRelatedAssets(value.report);
|
|
103
113
|
}
|
|
104
114
|
return null;
|
|
105
115
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiDigestService.cjs","sourceRoot":"","sources":["../src/AiDigestService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAO+B;AAE/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;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CAAC,YAAY,CAChB,eAAuB;QAEvB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC1B,GAAG,uBAAA,IAAI,gCAAS,wBAAwB,kBAAkB,CAAC,eAAe,CAAC,EAAE,CAC9E,CAAC;QAEF,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CACb,GAAG,oDAA8B,CAAC,kBAAkB,KAAK,QAAQ,CAAC,MAAM,EAAE,CAC3E,CAAC;QACJ,CAAC;QAED,MAAM,MAAM,GAAG,iCAAiC,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;QAExE,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,oDAA8B,CAAC,oBAAoB,CAAC,CAAC;QACvE,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA1ED,0CA0EC","sourcesContent":["import {\n array,\n enums,\n is,\n optional,\n string,\n type as structType,\n} from '@metamask/superstruct';\n\nimport { AiDigestControllerErrorMessage } from './ai-digest-constants';\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 id: string(),\n digest: MarketInsightsReportStruct,\n});\n\n// Market Overview structs\n\nconst RelatedAssetStruct = structType({\n name: string(),\n symbol: string(),\n caip19: array(string()),\n sourceAssetId: string(),\n hlPerpsMarket: optional(array(string())),\n});\n\nconst MarketOverviewTrendStruct = structType({\n title: string(),\n description: string(),\n category: optional(enums(trendCategoryValues)),\n impact: optional(enums(trendImpactValues)),\n articles: array(ArticleStruct),\n relatedAssets: array(RelatedAssetStruct),\n});\n\nconst MarketOverviewStruct = structType({\n version: optional(string()),\n generatedAt: string(),\n trends: array(MarketOverviewTrendStruct),\n metadata: optional(array(AIResponseMetadataStruct)),\n});\n\nconst MarketOverviewReportEnvelopeStruct = structType({\n report: MarketOverviewStruct,\n});\n\nconst getNormalizedMarketOverview = (value: unknown): MarketOverview | null => {\n if (is(value, MarketOverviewStruct)) {\n return value;\n }\n\n if (is(value, MarketOverviewReportEnvelopeStruct)) {\n return value.report;\n }\n\n return null;\n};\n\nconst getNormalizedMarketInsightsReport = (\n value: unknown,\n): MarketInsightsReport | null => {\n if (is(value, MarketInsightsDigestEnvelopeStruct)) {\n return { ...value.digest, digestId: value.id };\n }\n\n return null;\n};\n\nexport class AiDigestService implements DigestService {\n readonly #baseUrl: string;\n\n constructor(config: AiDigestServiceConfig) {\n this.#baseUrl = config.baseUrl;\n }\n\n /**\n * Fetch the market overview report.\n *\n * Calls `GET ${this.#baseUrl}/market-overview`.\n *\n * @returns The market overview report, or `null` if none exists (404).\n */\n async fetchMarketOverview(): Promise<MarketOverview | null> {\n const response = await fetch(`${this.#baseUrl}/market-overview`);\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new Error(\n `${AiDigestControllerErrorMessage.API_REQUEST_FAILED}: ${response.status}`,\n );\n }\n\n const overview = getNormalizedMarketOverview(await response.json());\n\n if (!overview) {\n throw new Error(AiDigestControllerErrorMessage.API_INVALID_RESPONSE);\n }\n\n return overview;\n }\n\n /**\n * Search for market insights by asset identifier.\n *\n * Accepts any identifier the API understands (CAIP-19 asset type, ticker\n * symbol, asset name, HyperLiquid perps market id, etc.) and forwards it\n * unchanged via the universal `asset` query parameter.\n *\n * Calls `GET ${baseUrl}/asset-summary?asset=<assetIdentifier>`.\n *\n * @param assetIdentifier - The asset identifier (e.g. `eip155:1/slip44:60`,\n * `ETH`, `Bitcoin`, `xyz:TSLA`).\n * @returns The market insights report, or `null` if none exists (404).\n */\n async searchDigest(\n assetIdentifier: string,\n ): Promise<MarketInsightsReport | null> {\n const response = await fetch(\n `${this.#baseUrl}/asset-summary?asset=${encodeURIComponent(assetIdentifier)}`,\n );\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new Error(\n `${AiDigestControllerErrorMessage.API_REQUEST_FAILED}: ${response.status}`,\n );\n }\n\n const report = getNormalizedMarketInsightsReport(await response.json());\n\n if (!report) {\n throw new Error(AiDigestControllerErrorMessage.API_INVALID_RESPONSE);\n }\n\n return report;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AiDigestService.cjs","sourceRoot":"","sources":["../src/AiDigestService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAO+B;AAE/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,GA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CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CACb,GAAG,oDAA8B,CAAC,kBAAkB,KAAK,QAAQ,CAAC,MAAM,EAAE,CAC3E,CAAC;QACJ,CAAC;QAED,MAAM,MAAM,GAAG,iCAAiC,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;QAExE,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,oDAA8B,CAAC,oBAAoB,CAAC,CAAC;QACvE,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA1ED,0CA0EC","sourcesContent":["import {\n array,\n enums,\n is,\n optional,\n string,\n type as structType,\n} from '@metamask/superstruct';\n\nimport { AiDigestControllerErrorMessage } from './ai-digest-constants';\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 id: string(),\n digest: MarketInsightsReportStruct,\n});\n\n// Market Overview structs\n\nconst RelatedAssetStruct = structType({\n name: string(),\n symbol: string(),\n caip19: optional(array(string())),\n sourceAssetId: string(),\n hlPerpsMarket: optional(array(string())),\n});\n\nconst MarketOverviewTrendStruct = structType({\n title: string(),\n description: string(),\n category: optional(enums(trendCategoryValues)),\n impact: optional(enums(trendImpactValues)),\n articles: array(ArticleStruct),\n relatedAssets: array(RelatedAssetStruct),\n});\n\nconst MarketOverviewStruct = structType({\n version: optional(string()),\n generatedAt: string(),\n trends: array(MarketOverviewTrendStruct),\n metadata: optional(array(AIResponseMetadataStruct)),\n});\n\nconst MarketOverviewReportEnvelopeStruct = structType({\n report: MarketOverviewStruct,\n});\n\nconst normalizeRelatedAssets = (raw: MarketOverview): MarketOverview => ({\n ...raw,\n trends: raw.trends.map((trend) => ({\n ...trend,\n relatedAssets: trend.relatedAssets.map((asset) => ({\n ...asset,\n caip19: asset.caip19 ?? [],\n })),\n })),\n});\n\nconst getNormalizedMarketOverview = (value: unknown): MarketOverview | null => {\n if (is(value, MarketOverviewStruct)) {\n return normalizeRelatedAssets(value);\n }\n\n if (is(value, MarketOverviewReportEnvelopeStruct)) {\n return normalizeRelatedAssets(value.report);\n }\n\n return null;\n};\n\nconst getNormalizedMarketInsightsReport = (\n value: unknown,\n): MarketInsightsReport | null => {\n if (is(value, MarketInsightsDigestEnvelopeStruct)) {\n return { ...value.digest, digestId: value.id };\n }\n\n return null;\n};\n\nexport class AiDigestService implements DigestService {\n readonly #baseUrl: string;\n\n constructor(config: AiDigestServiceConfig) {\n this.#baseUrl = config.baseUrl;\n }\n\n /**\n * Fetch the market overview report.\n *\n * Calls `GET ${this.#baseUrl}/market-overview`.\n *\n * @returns The market overview report, or `null` if none exists (404).\n */\n async fetchMarketOverview(): Promise<MarketOverview | null> {\n const response = await fetch(`${this.#baseUrl}/market-overview`);\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new Error(\n `${AiDigestControllerErrorMessage.API_REQUEST_FAILED}: ${response.status}`,\n );\n }\n\n const overview = getNormalizedMarketOverview(await response.json());\n\n if (!overview) {\n throw new Error(AiDigestControllerErrorMessage.API_INVALID_RESPONSE);\n }\n\n return overview;\n }\n\n /**\n * Search for market insights by asset identifier.\n *\n * Accepts any identifier the API understands (CAIP-19 asset type, ticker\n * symbol, asset name, HyperLiquid perps market id, etc.) and forwards it\n * unchanged via the universal `asset` query parameter.\n *\n * Calls `GET ${baseUrl}/asset-summary?asset=<assetIdentifier>`.\n *\n * @param assetIdentifier - The asset identifier (e.g. `eip155:1/slip44:60`,\n * `ETH`, `Bitcoin`, `xyz:TSLA`).\n * @returns The market insights report, or `null` if none exists (404).\n */\n async searchDigest(\n assetIdentifier: string,\n ): Promise<MarketInsightsReport | null> {\n const response = await fetch(\n `${this.#baseUrl}/asset-summary?asset=${encodeURIComponent(assetIdentifier)}`,\n );\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new Error(\n `${AiDigestControllerErrorMessage.API_REQUEST_FAILED}: ${response.status}`,\n );\n }\n\n const report = getNormalizedMarketInsightsReport(await response.json());\n\n if (!report) {\n throw new Error(AiDigestControllerErrorMessage.API_INVALID_RESPONSE);\n }\n\n return report;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiDigestService.d.cts","sourceRoot":"","sources":["../src/AiDigestService.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACpB,cAAc,EACf,8BAA0B;AAE3B,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;
|
|
1
|
+
{"version":3,"file":"AiDigestService.d.cts","sourceRoot":"","sources":["../src/AiDigestService.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACpB,cAAc,EACf,8BAA0B;AAE3B,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAkIF,qBAAa,eAAgB,YAAW,aAAa;;gBAGvC,MAAM,EAAE,qBAAqB;IAIzC;;;;;;OAMG;IACG,mBAAmB,IAAI,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAsB3D;;;;;;;;;;;;OAYG;IACG,YAAY,CAChB,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;CAuBxC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiDigestService.d.mts","sourceRoot":"","sources":["../src/AiDigestService.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACpB,cAAc,EACf,8BAA0B;AAE3B,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;
|
|
1
|
+
{"version":3,"file":"AiDigestService.d.mts","sourceRoot":"","sources":["../src/AiDigestService.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACpB,cAAc,EACf,8BAA0B;AAE3B,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAkIF,qBAAa,eAAgB,YAAW,aAAa;;gBAGvC,MAAM,EAAE,qBAAqB;IAIzC;;;;;;OAMG;IACG,mBAAmB,IAAI,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAsB3D;;;;;;;;;;;;OAYG;IACG,YAAY,CAChB,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;CAuBxC"}
|
package/dist/AiDigestService.mjs
CHANGED
|
@@ -70,7 +70,7 @@ const MarketInsightsDigestEnvelopeStruct = structType({
|
|
|
70
70
|
const RelatedAssetStruct = structType({
|
|
71
71
|
name: string(),
|
|
72
72
|
symbol: string(),
|
|
73
|
-
caip19: array(string()),
|
|
73
|
+
caip19: optional(array(string())),
|
|
74
74
|
sourceAssetId: string(),
|
|
75
75
|
hlPerpsMarket: optional(array(string())),
|
|
76
76
|
});
|
|
@@ -91,12 +91,22 @@ const MarketOverviewStruct = structType({
|
|
|
91
91
|
const MarketOverviewReportEnvelopeStruct = structType({
|
|
92
92
|
report: MarketOverviewStruct,
|
|
93
93
|
});
|
|
94
|
+
const normalizeRelatedAssets = (raw) => ({
|
|
95
|
+
...raw,
|
|
96
|
+
trends: raw.trends.map((trend) => ({
|
|
97
|
+
...trend,
|
|
98
|
+
relatedAssets: trend.relatedAssets.map((asset) => ({
|
|
99
|
+
...asset,
|
|
100
|
+
caip19: asset.caip19 ?? [],
|
|
101
|
+
})),
|
|
102
|
+
})),
|
|
103
|
+
});
|
|
94
104
|
const getNormalizedMarketOverview = (value) => {
|
|
95
105
|
if (is(value, MarketOverviewStruct)) {
|
|
96
|
-
return value;
|
|
106
|
+
return normalizeRelatedAssets(value);
|
|
97
107
|
}
|
|
98
108
|
if (is(value, MarketOverviewReportEnvelopeStruct)) {
|
|
99
|
-
return value.report;
|
|
109
|
+
return normalizeRelatedAssets(value.report);
|
|
100
110
|
}
|
|
101
111
|
return null;
|
|
102
112
|
};
|
|
@@ -1 +1 @@
|
|
|
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;AAE/B,OAAO,EAAE,8BAA8B,EAAE,kCAA8B;AAWvE,0BAA0B;AAE1B,MAAM,aAAa,GAAG,UAAU,CAAC;IAC/B,KAAK,E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AAC,IAAI,EAAE,CAAC,CAAC;QAEpE,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,oBAAoB,CAAC,CAAC;QACvE,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,YAAY,CAChB,eAAuB;QAEvB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC1B,GAAG,uBAAA,IAAI,gCAAS,wBAAwB,kBAAkB,CAAC,eAAe,CAAC,EAAE,CAC9E,CAAC;QAEF,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CACb,GAAG,8BAA8B,CAAC,kBAAkB,KAAK,QAAQ,CAAC,MAAM,EAAE,CAC3E,CAAC;QACJ,CAAC;QAED,MAAM,MAAM,GAAG,iCAAiC,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;QAExE,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,oBAAoB,CAAC,CAAC;QACvE,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["import {\n array,\n enums,\n is,\n optional,\n string,\n type as structType,\n} from '@metamask/superstruct';\n\nimport { AiDigestControllerErrorMessage } from './ai-digest-constants';\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 id: string(),\n digest: MarketInsightsReportStruct,\n});\n\n// Market Overview structs\n\nconst RelatedAssetStruct = structType({\n name: string(),\n symbol: string(),\n caip19: array(string()),\n sourceAssetId: string(),\n hlPerpsMarket: optional(array(string())),\n});\n\nconst MarketOverviewTrendStruct = structType({\n title: string(),\n description: string(),\n category: optional(enums(trendCategoryValues)),\n impact: optional(enums(trendImpactValues)),\n articles: array(ArticleStruct),\n relatedAssets: array(RelatedAssetStruct),\n});\n\nconst MarketOverviewStruct = structType({\n version: optional(string()),\n generatedAt: string(),\n trends: array(MarketOverviewTrendStruct),\n metadata: optional(array(AIResponseMetadataStruct)),\n});\n\nconst MarketOverviewReportEnvelopeStruct = structType({\n report: MarketOverviewStruct,\n});\n\nconst getNormalizedMarketOverview = (value: unknown): MarketOverview | null => {\n if (is(value, MarketOverviewStruct)) {\n return value;\n }\n\n if (is(value, MarketOverviewReportEnvelopeStruct)) {\n return value.report;\n }\n\n return null;\n};\n\nconst getNormalizedMarketInsightsReport = (\n value: unknown,\n): MarketInsightsReport | null => {\n if (is(value, MarketInsightsDigestEnvelopeStruct)) {\n return { ...value.digest, digestId: value.id };\n }\n\n return null;\n};\n\nexport class AiDigestService implements DigestService {\n readonly #baseUrl: string;\n\n constructor(config: AiDigestServiceConfig) {\n this.#baseUrl = config.baseUrl;\n }\n\n /**\n * Fetch the market overview report.\n *\n * Calls `GET ${this.#baseUrl}/market-overview`.\n *\n * @returns The market overview report, or `null` if none exists (404).\n */\n async fetchMarketOverview(): Promise<MarketOverview | null> {\n const response = await fetch(`${this.#baseUrl}/market-overview`);\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new Error(\n `${AiDigestControllerErrorMessage.API_REQUEST_FAILED}: ${response.status}`,\n );\n }\n\n const overview = getNormalizedMarketOverview(await response.json());\n\n if (!overview) {\n throw new Error(AiDigestControllerErrorMessage.API_INVALID_RESPONSE);\n }\n\n return overview;\n }\n\n /**\n * Search for market insights by asset identifier.\n *\n * Accepts any identifier the API understands (CAIP-19 asset type, ticker\n * symbol, asset name, HyperLiquid perps market id, etc.) and forwards it\n * unchanged via the universal `asset` query parameter.\n *\n * Calls `GET ${baseUrl}/asset-summary?asset=<assetIdentifier>`.\n *\n * @param assetIdentifier - The asset identifier (e.g. `eip155:1/slip44:60`,\n * `ETH`, `Bitcoin`, `xyz:TSLA`).\n * @returns The market insights report, or `null` if none exists (404).\n */\n async searchDigest(\n assetIdentifier: string,\n ): Promise<MarketInsightsReport | null> {\n const response = await fetch(\n `${this.#baseUrl}/asset-summary?asset=${encodeURIComponent(assetIdentifier)}`,\n );\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new Error(\n `${AiDigestControllerErrorMessage.API_REQUEST_FAILED}: ${response.status}`,\n );\n }\n\n const report = getNormalizedMarketInsightsReport(await response.json());\n\n if (!report) {\n throw new Error(AiDigestControllerErrorMessage.API_INVALID_RESPONSE);\n }\n\n return report;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AiDigestService.mjs","sourceRoot":"","sources":["../src/AiDigestService.ts"],"names":[],"mappings":";;;;;;;;;;;;AA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AkB,KAAK,QAAQ,CAAC,MAAM,EAAE,CAC3E,CAAC;QACJ,CAAC;QAED,MAAM,MAAM,GAAG,iCAAiC,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;QAExE,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,oBAAoB,CAAC,CAAC;QACvE,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["import {\n array,\n enums,\n is,\n optional,\n string,\n type as structType,\n} from '@metamask/superstruct';\n\nimport { AiDigestControllerErrorMessage } from './ai-digest-constants';\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 id: string(),\n digest: MarketInsightsReportStruct,\n});\n\n// Market Overview structs\n\nconst RelatedAssetStruct = structType({\n name: string(),\n symbol: string(),\n caip19: optional(array(string())),\n sourceAssetId: string(),\n hlPerpsMarket: optional(array(string())),\n});\n\nconst MarketOverviewTrendStruct = structType({\n title: string(),\n description: string(),\n category: optional(enums(trendCategoryValues)),\n impact: optional(enums(trendImpactValues)),\n articles: array(ArticleStruct),\n relatedAssets: array(RelatedAssetStruct),\n});\n\nconst MarketOverviewStruct = structType({\n version: optional(string()),\n generatedAt: string(),\n trends: array(MarketOverviewTrendStruct),\n metadata: optional(array(AIResponseMetadataStruct)),\n});\n\nconst MarketOverviewReportEnvelopeStruct = structType({\n report: MarketOverviewStruct,\n});\n\nconst normalizeRelatedAssets = (raw: MarketOverview): MarketOverview => ({\n ...raw,\n trends: raw.trends.map((trend) => ({\n ...trend,\n relatedAssets: trend.relatedAssets.map((asset) => ({\n ...asset,\n caip19: asset.caip19 ?? [],\n })),\n })),\n});\n\nconst getNormalizedMarketOverview = (value: unknown): MarketOverview | null => {\n if (is(value, MarketOverviewStruct)) {\n return normalizeRelatedAssets(value);\n }\n\n if (is(value, MarketOverviewReportEnvelopeStruct)) {\n return normalizeRelatedAssets(value.report);\n }\n\n return null;\n};\n\nconst getNormalizedMarketInsightsReport = (\n value: unknown,\n): MarketInsightsReport | null => {\n if (is(value, MarketInsightsDigestEnvelopeStruct)) {\n return { ...value.digest, digestId: value.id };\n }\n\n return null;\n};\n\nexport class AiDigestService implements DigestService {\n readonly #baseUrl: string;\n\n constructor(config: AiDigestServiceConfig) {\n this.#baseUrl = config.baseUrl;\n }\n\n /**\n * Fetch the market overview report.\n *\n * Calls `GET ${this.#baseUrl}/market-overview`.\n *\n * @returns The market overview report, or `null` if none exists (404).\n */\n async fetchMarketOverview(): Promise<MarketOverview | null> {\n const response = await fetch(`${this.#baseUrl}/market-overview`);\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new Error(\n `${AiDigestControllerErrorMessage.API_REQUEST_FAILED}: ${response.status}`,\n );\n }\n\n const overview = getNormalizedMarketOverview(await response.json());\n\n if (!overview) {\n throw new Error(AiDigestControllerErrorMessage.API_INVALID_RESPONSE);\n }\n\n return overview;\n }\n\n /**\n * Search for market insights by asset identifier.\n *\n * Accepts any identifier the API understands (CAIP-19 asset type, ticker\n * symbol, asset name, HyperLiquid perps market id, etc.) and forwards it\n * unchanged via the universal `asset` query parameter.\n *\n * Calls `GET ${baseUrl}/asset-summary?asset=<assetIdentifier>`.\n *\n * @param assetIdentifier - The asset identifier (e.g. `eip155:1/slip44:60`,\n * `ETH`, `Bitcoin`, `xyz:TSLA`).\n * @returns The market insights report, or `null` if none exists (404).\n */\n async searchDigest(\n assetIdentifier: string,\n ): Promise<MarketInsightsReport | null> {\n const response = await fetch(\n `${this.#baseUrl}/asset-summary?asset=${encodeURIComponent(assetIdentifier)}`,\n );\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new Error(\n `${AiDigestControllerErrorMessage.API_REQUEST_FAILED}: ${response.status}`,\n );\n }\n\n const report = getNormalizedMarketInsightsReport(await response.json());\n\n if (!report) {\n throw new Error(AiDigestControllerErrorMessage.API_INVALID_RESPONSE);\n }\n\n return report;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-digest-types.cjs","sourceRoot":"","sources":["../src/ai-digest-types.ts"],"names":[],"mappings":";AAAA,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E","sourcesContent":["// ---------------------------------------------------------------------------\n// Shared sub-types\n// ---------------------------------------------------------------------------\n\n/**\n * A news article referenced by a trend.\n */\nexport type Article = {\n /** Article title */\n title: string;\n /** Full URL to the article */\n url: string;\n /** Source domain name (e.g. \"coindesk.com\") */\n source: string;\n /** ISO date string */\n date: string;\n};\n\n/**\n * A social media post referenced by a trend.\n */\nexport type Tweet = {\n /** Summary of the tweet content */\n contentSummary: string;\n /** Full URL to the tweet */\n url: string;\n /** Author handle (e.g. \"@saylordocs\") */\n author: string;\n /** ISO date string */\n date: string;\n};\n\n/**\n * A data source used to generate a report.\n */\nexport type Source = {\n /** Source name (e.g. \"CoinDesk\") */\n name: string;\n /** Source URL */\n url: string;\n /** Source type */\n type: 'news' | 'data' | 'social';\n};\n\nexport type MarketInsightsArticle = Article;\nexport type MarketInsightsTweet = Tweet;\nexport type MarketInsightsSource = Source;\n\n// ---------------------------------------------------------------------------\n// Market Insights types (asset-specific)\n// ---------------------------------------------------------------------------\n\n/**\n * A key market trend identified in the insights report.\n */\nexport type MarketInsightsTrend = {\n /** Trend title (e.g. \"Institutions Buying the Dip\") */\n title: string;\n /** Detailed description of the trend */\n description: string;\n /** Category of the trend */\n category:\n | 'geopolitical'\n | 'macro'\n | 'regulatory'\n | 'technical'\n | 'social'\n | 'other';\n /** Impact direction */\n impact: 'positive' | 'negative' | 'neutral';\n /** Related news articles */\n articles: Article[];\n /** Related social media posts */\n tweets: Tweet[];\n};\n\n/**\n * AI-generated market insights report for a crypto asset.\n * Returned by `GET /asset-summary?asset=<identifier>`.\n */\nexport type MarketInsightsReport = {\n /** Unique identifier for this digest, sourced from the API response envelope. */\n digestId: string;\n /** API version */\n version?: string;\n /** Asset symbol (lowercase, e.g. \"btc\") */\n asset: string;\n /** ISO date string when the report was generated */\n generatedAt: string;\n /** Main headline */\n headline: string;\n /** Summary paragraph */\n summary: string;\n /** Key market trends */\n trends: MarketInsightsTrend[];\n /** Optional top-level social posts included by the API */\n social?: Tweet[];\n /** Data sources used to generate the report */\n sources: Source[];\n /** Provider metadata */\n metadata?: AIResponseMetadata[];\n};\n\n/**\n * A cached market insights entry.\n */\nexport type MarketInsightsEntry = {\n /** Asset identifier — either a CAIP-19 ID (e.g. \"eip155:1/slip44:60\") or a perps market symbol (e.g. \"ETH\") */\n assetIdentifier: string;\n /** Timestamp when the entry was fetched */\n fetchedAt: number;\n /** The market insights report data */\n data: MarketInsightsReport;\n};\n\n/**\n * A cached market overview entry.\n */\nexport type MarketOverviewEntry = {\n /** Timestamp when the entry was fetched */\n fetchedAt: number;\n /** The market overview data */\n data: MarketOverview;\n};\n\n// ---------------------------------------------------------------------------\n// Market Overview types (non-asset-specific)\n// ---------------------------------------------------------------------------\n\n/**\n * A crypto asset related to a market overview trend.\n * Returned by the `/market-overview` API as a rich object.\n */\nexport type RelatedAsset = {\n /** Human-readable asset name (e.g. \"Bitcoin\") */\n name: string;\n /** Ticker symbol (e.g. \"BTC\") */\n symbol: string;\n
|
|
1
|
+
{"version":3,"file":"ai-digest-types.cjs","sourceRoot":"","sources":["../src/ai-digest-types.ts"],"names":[],"mappings":";AAAA,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E","sourcesContent":["// ---------------------------------------------------------------------------\n// Shared sub-types\n// ---------------------------------------------------------------------------\n\n/**\n * A news article referenced by a trend.\n */\nexport type Article = {\n /** Article title */\n title: string;\n /** Full URL to the article */\n url: string;\n /** Source domain name (e.g. \"coindesk.com\") */\n source: string;\n /** ISO date string */\n date: string;\n};\n\n/**\n * A social media post referenced by a trend.\n */\nexport type Tweet = {\n /** Summary of the tweet content */\n contentSummary: string;\n /** Full URL to the tweet */\n url: string;\n /** Author handle (e.g. \"@saylordocs\") */\n author: string;\n /** ISO date string */\n date: string;\n};\n\n/**\n * A data source used to generate a report.\n */\nexport type Source = {\n /** Source name (e.g. \"CoinDesk\") */\n name: string;\n /** Source URL */\n url: string;\n /** Source type */\n type: 'news' | 'data' | 'social';\n};\n\nexport type MarketInsightsArticle = Article;\nexport type MarketInsightsTweet = Tweet;\nexport type MarketInsightsSource = Source;\n\n// ---------------------------------------------------------------------------\n// Market Insights types (asset-specific)\n// ---------------------------------------------------------------------------\n\n/**\n * A key market trend identified in the insights report.\n */\nexport type MarketInsightsTrend = {\n /** Trend title (e.g. \"Institutions Buying the Dip\") */\n title: string;\n /** Detailed description of the trend */\n description: string;\n /** Category of the trend */\n category:\n | 'geopolitical'\n | 'macro'\n | 'regulatory'\n | 'technical'\n | 'social'\n | 'other';\n /** Impact direction */\n impact: 'positive' | 'negative' | 'neutral';\n /** Related news articles */\n articles: Article[];\n /** Related social media posts */\n tweets: Tweet[];\n};\n\n/**\n * AI-generated market insights report for a crypto asset.\n * Returned by `GET /asset-summary?asset=<identifier>`.\n */\nexport type MarketInsightsReport = {\n /** Unique identifier for this digest, sourced from the API response envelope. */\n digestId: string;\n /** API version */\n version?: string;\n /** Asset symbol (lowercase, e.g. \"btc\") */\n asset: string;\n /** ISO date string when the report was generated */\n generatedAt: string;\n /** Main headline */\n headline: string;\n /** Summary paragraph */\n summary: string;\n /** Key market trends */\n trends: MarketInsightsTrend[];\n /** Optional top-level social posts included by the API */\n social?: Tweet[];\n /** Data sources used to generate the report */\n sources: Source[];\n /** Provider metadata */\n metadata?: AIResponseMetadata[];\n};\n\n/**\n * A cached market insights entry.\n */\nexport type MarketInsightsEntry = {\n /** Asset identifier — either a CAIP-19 ID (e.g. \"eip155:1/slip44:60\") or a perps market symbol (e.g. \"ETH\") */\n assetIdentifier: string;\n /** Timestamp when the entry was fetched */\n fetchedAt: number;\n /** The market insights report data */\n data: MarketInsightsReport;\n};\n\n/**\n * A cached market overview entry.\n */\nexport type MarketOverviewEntry = {\n /** Timestamp when the entry was fetched */\n fetchedAt: number;\n /** The market overview data */\n data: MarketOverview;\n};\n\n// ---------------------------------------------------------------------------\n// Market Overview types (non-asset-specific)\n// ---------------------------------------------------------------------------\n\n/**\n * A crypto asset related to a market overview trend.\n * Returned by the `/market-overview` API as a rich object.\n */\nexport type RelatedAsset = {\n /** Human-readable asset name (e.g. \"Bitcoin\") */\n name: string;\n /** Ticker symbol (e.g. \"BTC\") */\n symbol: string;\n /**\n * CAIP-19 identifiers for this asset across chains. May be absent for\n * purely synthetic / perps-only assets (e.g. ETHFI). The service\n * normalises missing values to `[]`.\n */\n caip19?: string[];\n /** Canonical source asset identifier (e.g. \"bitcoin\") */\n sourceAssetId: string;\n /**\n * Optional HyperLiquid market identifiers for this asset (e.g. `BTC`, `ETH`,\n * `xyz:TSLA`). Covers both regular crypto tokens that trade on HyperLiquid\n * and purely synthetic perps assets. Use this to resolve Perps icon URLs via\n * `getAssetIconUrls` on clients when `caip19` is empty.\n */\n hlPerpsMarket?: string[];\n};\n\nexport type MarketOverviewTrend = {\n title: string;\n description: string;\n category?:\n | 'geopolitical'\n | 'macro'\n | 'regulatory'\n | 'technical'\n | 'social'\n | 'other';\n impact?: 'positive' | 'negative' | 'neutral';\n articles: Article[];\n relatedAssets: RelatedAsset[];\n};\n\n/**\n * Provider metadata included in AI API responses.\n */\nexport type AIResponseMetadata = {\n provider: string;\n};\n\nexport type MarketOverview = {\n version?: string;\n generatedAt: string;\n trends: MarketOverviewTrend[];\n metadata?: AIResponseMetadata[];\n};\n\n// ---------------------------------------------------------------------------\n// Controller state\n// ---------------------------------------------------------------------------\n\nexport type AiDigestControllerState = {\n marketInsights: Record<string, MarketInsightsEntry>;\n marketOverview: MarketOverviewEntry | null;\n};\n\n// ---------------------------------------------------------------------------\n// Service interface\n// ---------------------------------------------------------------------------\n\nexport type DigestService = {\n /**\n * Search for market insights by asset identifier.\n *\n * Accepts any identifier the API understands — CAIP-19 asset type\n * (e.g. `eip155:1/slip44:60`), ticker symbol (e.g. `ETH`), asset name\n * (e.g. `Bitcoin`), or HyperLiquid perps market id (e.g. `xyz:TSLA`).\n *\n * Calls `GET /asset-summary?asset=<assetIdentifier>`.\n *\n * @param assetIdentifier - The asset identifier.\n * @returns The market insights report, or `null` if no insights exist (404).\n */\n searchDigest(assetIdentifier: string): Promise<MarketInsightsReport | null>;\n\n /**\n * Fetch the market overview report.\n * Calls `GET /market-overview`.\n *\n * @returns The market overview report, or `null` if none exists (404).\n */\n fetchMarketOverview(): Promise<MarketOverview | null>;\n};\n"]}
|
|
@@ -110,8 +110,12 @@ export type RelatedAsset = {
|
|
|
110
110
|
name: string;
|
|
111
111
|
/** Ticker symbol (e.g. "BTC") */
|
|
112
112
|
symbol: string;
|
|
113
|
-
/**
|
|
114
|
-
|
|
113
|
+
/**
|
|
114
|
+
* CAIP-19 identifiers for this asset across chains. May be absent for
|
|
115
|
+
* purely synthetic / perps-only assets (e.g. ETHFI). The service
|
|
116
|
+
* normalises missing values to `[]`.
|
|
117
|
+
*/
|
|
118
|
+
caip19?: string[];
|
|
115
119
|
/** Canonical source asset identifier (e.g. "bitcoin") */
|
|
116
120
|
sourceAssetId: string;
|
|
117
121
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-digest-types.d.cts","sourceRoot":"","sources":["../src/ai-digest-types.ts"],"names":[],"mappings":"AAIA;;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,KAA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+110,12 @@ export type RelatedAsset = {
|
|
|
110
110
|
name: string;
|
|
111
111
|
/** Ticker symbol (e.g. "BTC") */
|
|
112
112
|
symbol: string;
|
|
113
|
-
/**
|
|
114
|
-
|
|
113
|
+
/**
|
|
114
|
+
* CAIP-19 identifiers for this asset across chains. May be absent for
|
|
115
|
+
* purely synthetic / perps-only assets (e.g. ETHFI). The service
|
|
116
|
+
* normalises missing values to `[]`.
|
|
117
|
+
*/
|
|
118
|
+
caip19?: string[];
|
|
115
119
|
/** Canonical source asset identifier (e.g. "bitcoin") */
|
|
116
120
|
sourceAssetId: string;
|
|
117
121
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-digest-types.d.mts","sourceRoot":"","sources":["../src/ai-digest-types.ts"],"names":[],"mappings":"AAIA;;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,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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":"AAAA,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E","sourcesContent":["// ---------------------------------------------------------------------------\n// Shared sub-types\n// ---------------------------------------------------------------------------\n\n/**\n * A news article referenced by a trend.\n */\nexport type Article = {\n /** Article title */\n title: string;\n /** Full URL to the article */\n url: string;\n /** Source domain name (e.g. \"coindesk.com\") */\n source: string;\n /** ISO date string */\n date: string;\n};\n\n/**\n * A social media post referenced by a trend.\n */\nexport type Tweet = {\n /** Summary of the tweet content */\n contentSummary: string;\n /** Full URL to the tweet */\n url: string;\n /** Author handle (e.g. \"@saylordocs\") */\n author: string;\n /** ISO date string */\n date: string;\n};\n\n/**\n * A data source used to generate a report.\n */\nexport type Source = {\n /** Source name (e.g. \"CoinDesk\") */\n name: string;\n /** Source URL */\n url: string;\n /** Source type */\n type: 'news' | 'data' | 'social';\n};\n\nexport type MarketInsightsArticle = Article;\nexport type MarketInsightsTweet = Tweet;\nexport type MarketInsightsSource = Source;\n\n// ---------------------------------------------------------------------------\n// Market Insights types (asset-specific)\n// ---------------------------------------------------------------------------\n\n/**\n * A key market trend identified in the insights report.\n */\nexport type MarketInsightsTrend = {\n /** Trend title (e.g. \"Institutions Buying the Dip\") */\n title: string;\n /** Detailed description of the trend */\n description: string;\n /** Category of the trend */\n category:\n | 'geopolitical'\n | 'macro'\n | 'regulatory'\n | 'technical'\n | 'social'\n | 'other';\n /** Impact direction */\n impact: 'positive' | 'negative' | 'neutral';\n /** Related news articles */\n articles: Article[];\n /** Related social media posts */\n tweets: Tweet[];\n};\n\n/**\n * AI-generated market insights report for a crypto asset.\n * Returned by `GET /asset-summary?asset=<identifier>`.\n */\nexport type MarketInsightsReport = {\n /** Unique identifier for this digest, sourced from the API response envelope. */\n digestId: string;\n /** API version */\n version?: string;\n /** Asset symbol (lowercase, e.g. \"btc\") */\n asset: string;\n /** ISO date string when the report was generated */\n generatedAt: string;\n /** Main headline */\n headline: string;\n /** Summary paragraph */\n summary: string;\n /** Key market trends */\n trends: MarketInsightsTrend[];\n /** Optional top-level social posts included by the API */\n social?: Tweet[];\n /** Data sources used to generate the report */\n sources: Source[];\n /** Provider metadata */\n metadata?: AIResponseMetadata[];\n};\n\n/**\n * A cached market insights entry.\n */\nexport type MarketInsightsEntry = {\n /** Asset identifier — either a CAIP-19 ID (e.g. \"eip155:1/slip44:60\") or a perps market symbol (e.g. \"ETH\") */\n assetIdentifier: string;\n /** Timestamp when the entry was fetched */\n fetchedAt: number;\n /** The market insights report data */\n data: MarketInsightsReport;\n};\n\n/**\n * A cached market overview entry.\n */\nexport type MarketOverviewEntry = {\n /** Timestamp when the entry was fetched */\n fetchedAt: number;\n /** The market overview data */\n data: MarketOverview;\n};\n\n// ---------------------------------------------------------------------------\n// Market Overview types (non-asset-specific)\n// ---------------------------------------------------------------------------\n\n/**\n * A crypto asset related to a market overview trend.\n * Returned by the `/market-overview` API as a rich object.\n */\nexport type RelatedAsset = {\n /** Human-readable asset name (e.g. \"Bitcoin\") */\n name: string;\n /** Ticker symbol (e.g. \"BTC\") */\n symbol: string;\n
|
|
1
|
+
{"version":3,"file":"ai-digest-types.mjs","sourceRoot":"","sources":["../src/ai-digest-types.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E","sourcesContent":["// ---------------------------------------------------------------------------\n// Shared sub-types\n// ---------------------------------------------------------------------------\n\n/**\n * A news article referenced by a trend.\n */\nexport type Article = {\n /** Article title */\n title: string;\n /** Full URL to the article */\n url: string;\n /** Source domain name (e.g. \"coindesk.com\") */\n source: string;\n /** ISO date string */\n date: string;\n};\n\n/**\n * A social media post referenced by a trend.\n */\nexport type Tweet = {\n /** Summary of the tweet content */\n contentSummary: string;\n /** Full URL to the tweet */\n url: string;\n /** Author handle (e.g. \"@saylordocs\") */\n author: string;\n /** ISO date string */\n date: string;\n};\n\n/**\n * A data source used to generate a report.\n */\nexport type Source = {\n /** Source name (e.g. \"CoinDesk\") */\n name: string;\n /** Source URL */\n url: string;\n /** Source type */\n type: 'news' | 'data' | 'social';\n};\n\nexport type MarketInsightsArticle = Article;\nexport type MarketInsightsTweet = Tweet;\nexport type MarketInsightsSource = Source;\n\n// ---------------------------------------------------------------------------\n// Market Insights types (asset-specific)\n// ---------------------------------------------------------------------------\n\n/**\n * A key market trend identified in the insights report.\n */\nexport type MarketInsightsTrend = {\n /** Trend title (e.g. \"Institutions Buying the Dip\") */\n title: string;\n /** Detailed description of the trend */\n description: string;\n /** Category of the trend */\n category:\n | 'geopolitical'\n | 'macro'\n | 'regulatory'\n | 'technical'\n | 'social'\n | 'other';\n /** Impact direction */\n impact: 'positive' | 'negative' | 'neutral';\n /** Related news articles */\n articles: Article[];\n /** Related social media posts */\n tweets: Tweet[];\n};\n\n/**\n * AI-generated market insights report for a crypto asset.\n * Returned by `GET /asset-summary?asset=<identifier>`.\n */\nexport type MarketInsightsReport = {\n /** Unique identifier for this digest, sourced from the API response envelope. */\n digestId: string;\n /** API version */\n version?: string;\n /** Asset symbol (lowercase, e.g. \"btc\") */\n asset: string;\n /** ISO date string when the report was generated */\n generatedAt: string;\n /** Main headline */\n headline: string;\n /** Summary paragraph */\n summary: string;\n /** Key market trends */\n trends: MarketInsightsTrend[];\n /** Optional top-level social posts included by the API */\n social?: Tweet[];\n /** Data sources used to generate the report */\n sources: Source[];\n /** Provider metadata */\n metadata?: AIResponseMetadata[];\n};\n\n/**\n * A cached market insights entry.\n */\nexport type MarketInsightsEntry = {\n /** Asset identifier — either a CAIP-19 ID (e.g. \"eip155:1/slip44:60\") or a perps market symbol (e.g. \"ETH\") */\n assetIdentifier: string;\n /** Timestamp when the entry was fetched */\n fetchedAt: number;\n /** The market insights report data */\n data: MarketInsightsReport;\n};\n\n/**\n * A cached market overview entry.\n */\nexport type MarketOverviewEntry = {\n /** Timestamp when the entry was fetched */\n fetchedAt: number;\n /** The market overview data */\n data: MarketOverview;\n};\n\n// ---------------------------------------------------------------------------\n// Market Overview types (non-asset-specific)\n// ---------------------------------------------------------------------------\n\n/**\n * A crypto asset related to a market overview trend.\n * Returned by the `/market-overview` API as a rich object.\n */\nexport type RelatedAsset = {\n /** Human-readable asset name (e.g. \"Bitcoin\") */\n name: string;\n /** Ticker symbol (e.g. \"BTC\") */\n symbol: string;\n /**\n * CAIP-19 identifiers for this asset across chains. May be absent for\n * purely synthetic / perps-only assets (e.g. ETHFI). The service\n * normalises missing values to `[]`.\n */\n caip19?: string[];\n /** Canonical source asset identifier (e.g. \"bitcoin\") */\n sourceAssetId: string;\n /**\n * Optional HyperLiquid market identifiers for this asset (e.g. `BTC`, `ETH`,\n * `xyz:TSLA`). Covers both regular crypto tokens that trade on HyperLiquid\n * and purely synthetic perps assets. Use this to resolve Perps icon URLs via\n * `getAssetIconUrls` on clients when `caip19` is empty.\n */\n hlPerpsMarket?: string[];\n};\n\nexport type MarketOverviewTrend = {\n title: string;\n description: string;\n category?:\n | 'geopolitical'\n | 'macro'\n | 'regulatory'\n | 'technical'\n | 'social'\n | 'other';\n impact?: 'positive' | 'negative' | 'neutral';\n articles: Article[];\n relatedAssets: RelatedAsset[];\n};\n\n/**\n * Provider metadata included in AI API responses.\n */\nexport type AIResponseMetadata = {\n provider: string;\n};\n\nexport type MarketOverview = {\n version?: string;\n generatedAt: string;\n trends: MarketOverviewTrend[];\n metadata?: AIResponseMetadata[];\n};\n\n// ---------------------------------------------------------------------------\n// Controller state\n// ---------------------------------------------------------------------------\n\nexport type AiDigestControllerState = {\n marketInsights: Record<string, MarketInsightsEntry>;\n marketOverview: MarketOverviewEntry | null;\n};\n\n// ---------------------------------------------------------------------------\n// Service interface\n// ---------------------------------------------------------------------------\n\nexport type DigestService = {\n /**\n * Search for market insights by asset identifier.\n *\n * Accepts any identifier the API understands — CAIP-19 asset type\n * (e.g. `eip155:1/slip44:60`), ticker symbol (e.g. `ETH`), asset name\n * (e.g. `Bitcoin`), or HyperLiquid perps market id (e.g. `xyz:TSLA`).\n *\n * Calls `GET /asset-summary?asset=<assetIdentifier>`.\n *\n * @param assetIdentifier - The asset identifier.\n * @returns The market insights report, or `null` if no insights exist (404).\n */\n searchDigest(assetIdentifier: string): Promise<MarketInsightsReport | null>;\n\n /**\n * Fetch the market overview report.\n * Calls `GET /market-overview`.\n *\n * @returns The market overview report, or `null` if none exists (404).\n */\n fetchMarketOverview(): Promise<MarketOverview | null>;\n};\n"]}
|