@chainfuse/ai-tools 0.12.1 → 0.12.2

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.
@@ -4,32 +4,38 @@ export class AiRawProviders extends AiBase {
4
4
  // 2628288 seconds is what cf defines as 1 month in their cache rules
5
5
  cacheTtl = 2628288;
6
6
  async updateGatewayLog(response, metadataHeader, startRoundTrip, modelTime) {
7
- const updateMetadata = import('@chainfuse/helpers')
8
- .then(({ NetHelpers }) => NetHelpers.cfApi(this.config.gateway.apiToken))
9
- .then((cf) => cf.aiGateway.logs.edit(this.gatewayName, response.headers.get('cf-aig-log-id'), {
10
- account_id: this.config.gateway.accountId,
11
- metadata: {
12
- ...Object.entries({
13
- ...metadataHeader,
14
- serverInfo: {
15
- ...JSON.parse(metadataHeader.serverInfo),
16
- timing: {
17
- fromCache: response.headers.get('cf-aig-cache-status')?.toLowerCase() === 'hit',
18
- totalRoundtripTime: performance.now() - startRoundTrip,
19
- modelTime,
7
+ const logId = response.headers.get('cf-aig-log-id');
8
+ if (logId) {
9
+ const updateMetadata = import('@chainfuse/helpers')
10
+ .then(({ NetHelpers }) => NetHelpers.cfApi(this.config.gateway.apiToken))
11
+ .then((cf) => cf.aiGateway.logs.edit(this.gatewayName, logId, {
12
+ account_id: this.config.gateway.accountId,
13
+ metadata: {
14
+ ...Object.entries({
15
+ ...metadataHeader,
16
+ serverInfo: {
17
+ ...JSON.parse(metadataHeader.serverInfo),
18
+ timing: {
19
+ fromCache: response.headers.get('cf-aig-cache-status')?.toLowerCase() === 'hit',
20
+ totalRoundtripTime: performance.now() - startRoundTrip,
21
+ modelTime,
22
+ },
20
23
  },
21
- },
22
- }).reduce((acc, [key, value]) => {
23
- acc[key] = typeof value === 'string' ? value : JSON.stringify(value);
24
- return acc;
25
- }, {}),
26
- },
27
- }));
28
- if (this.config.backgroundContext) {
29
- this.config.backgroundContext.waitUntil(updateMetadata);
24
+ }).reduce((acc, [key, value]) => {
25
+ acc[key] = typeof value === 'string' ? value : JSON.stringify(value);
26
+ return acc;
27
+ }, {}),
28
+ },
29
+ }));
30
+ if (this.config.backgroundContext) {
31
+ this.config.backgroundContext.waitUntil(updateMetadata);
32
+ }
33
+ else {
34
+ await updateMetadata;
35
+ }
30
36
  }
31
37
  else {
32
- await updateMetadata;
38
+ console.warn('Not updating gateway log, no cf-aig-log-id header');
33
39
  }
34
40
  }
35
41
  oaiOpenai(args) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainfuse/ai-tools",
3
- "version": "0.12.1",
3
+ "version": "0.12.2",
4
4
  "description": "",
5
5
  "author": "ChainFuse",
6
6
  "homepage": "https://github.com/ChainFuse/packages/tree/main/packages/ai-tools#readme",
@@ -64,5 +64,5 @@
64
64
  "@cloudflare/workers-types": "^4.20250327.0",
65
65
  "openai": "^4.91.0"
66
66
  },
67
- "gitHead": "0e791ace039e29822b615aa2091e07950797f52d"
67
+ "gitHead": "b3eaa1c1d0d525343521062a2b789fc961cf3dcf"
68
68
  }