@chainfuse/ai-tools 0.11.2 → 0.12.0

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.
@@ -41,7 +41,7 @@ export class AiRawProviders extends AiBase {
41
41
  'cf-aig-authorization': `Bearer ${this.config.gateway.apiToken}`,
42
42
  'cf-aig-metadata': JSON.stringify({
43
43
  dataspaceId: (await BufferHelpers.uuidConvert(args.dataspaceId)).utf8,
44
- messageId: (await BufferHelpers.uuidConvert(args.messageId)).utf8,
44
+ ...(args.groupBillingId && { groupBillingId: (await BufferHelpers.uuidConvert(args.groupBillingId)).utf8 }),
45
45
  serverInfo: JSON.stringify({
46
46
  name: 'openai',
47
47
  }),
@@ -96,7 +96,7 @@ export class AiRawProviders extends AiBase {
96
96
  ...(cost && { 'cf-aig-custom-cost': JSON.stringify({ per_token_in: cost.inputTokenCost ?? undefined, per_token_out: cost.outputTokenCost ?? undefined }) }),
97
97
  'cf-aig-metadata': JSON.stringify({
98
98
  dataspaceId: (await BufferHelpers.uuidConvert(args.dataspaceId)).utf8,
99
- messageId: (await BufferHelpers.uuidConvert(args.messageId)).utf8,
99
+ ...(args.groupBillingId && { groupBillingId: (await BufferHelpers.uuidConvert(args.groupBillingId)).utf8 }),
100
100
  serverInfo: JSON.stringify({
101
101
  name: `azure-${server.id}`,
102
102
  distance: await import('haversine-distance').then(async ({ default: haversine }) => haversine(await import("../serverSelector.mjs").then(({ ServerSelector }) => new ServerSelector(this.config).determineLocation().then(({ coordinate }) => ({
@@ -151,7 +151,7 @@ export class AiRawProviders extends AiBase {
151
151
  'cf-aig-authorization': `Bearer ${this.config.gateway.apiToken}`,
152
152
  'cf-aig-metadata': JSON.stringify({
153
153
  dataspaceId: (await BufferHelpers.uuidConvert(args.dataspaceId)).utf8,
154
- messageId: (await BufferHelpers.uuidConvert(args.messageId)).utf8,
154
+ ...(args.groupBillingId && { groupBillingId: (await BufferHelpers.uuidConvert(args.groupBillingId)).utf8 }),
155
155
  serverInfo: JSON.stringify({
156
156
  name: 'anthropic',
157
157
  }),
@@ -311,7 +311,7 @@ export class AiRawProviders extends AiBase {
311
311
  'cf-aig-authorization': `Bearer ${this.config.gateway.apiToken}`,
312
312
  'cf-aig-metadata': JSON.stringify({
313
313
  dataspaceId: (await BufferHelpers.uuidConvert(args.dataspaceId)).utf8,
314
- messageId: (await BufferHelpers.uuidConvert(args.messageId)).utf8,
314
+ ...(args.groupBillingId && { groupBillingId: (await BufferHelpers.uuidConvert(args.groupBillingId)).utf8 }),
315
315
  serverInfo: JSON.stringify({
316
316
  name: 'googleai',
317
317
  }),
@@ -359,7 +359,7 @@ export class AiRawProviders extends AiBase {
359
359
  'cf-aig-authorization': `Bearer ${this.config.gateway.apiToken}`,
360
360
  'cf-aig-metadata': JSON.stringify({
361
361
  dataspaceId: (await BufferHelpers.uuidConvert(args.dataspaceId)).utf8,
362
- messageId: (await BufferHelpers.uuidConvert(args.messageId)).utf8,
362
+ ...(args.groupBillingId && { groupBillingId: (await BufferHelpers.uuidConvert(args.groupBillingId)).utf8 }),
363
363
  serverInfo: JSON.stringify({
364
364
  name: 'cloudflare',
365
365
  }),
@@ -409,7 +409,7 @@ export class AiRawProviders extends AiBase {
409
409
  ...(args.skipCache && { skipCache: true }),
410
410
  metadata: {
411
411
  dataspaceId: (await BufferHelpers.uuidConvert(args.dataspaceId)).utf8,
412
- messageId: (await BufferHelpers.uuidConvert(args.messageId)).utf8,
412
+ ...(args.groupBillingId && { groupBillingId: (await BufferHelpers.uuidConvert(args.groupBillingId)).utf8 }),
413
413
  serverInfo: JSON.stringify({
414
414
  name: 'cloudflare',
415
415
  }),
package/dist/types.d.mts CHANGED
@@ -85,7 +85,7 @@ export interface AiRequestConfig {
85
85
  * @default true
86
86
  */
87
87
  cache?: boolean | number;
88
- messageId: PrefixedUuid | UuidExport['utf8'] | UuidExport['hex'];
88
+ groupBillingId?: UuidExport['utf8'] | UuidExport['hex'];
89
89
  dataspaceId: PrefixedUuid | UuidExport['utf8'] | UuidExport['hex'];
90
90
  /**
91
91
  * Service identification of caller
@@ -124,14 +124,16 @@ export interface AiRequestMetadataServerInfoWithLocation {
124
124
  }
125
125
  export interface AiRequestMetadata {
126
126
  dataspaceId: AiRequestConfig['dataspaceId'];
127
- messageId: AiRequestConfig['messageId'];
127
+ groupBillingId?: AiRequestConfig['groupBillingId'];
128
128
  serverInfo: (AiRequestMetadataServerInfo | AiRequestMetadataServerInfoWithLocation) & {
129
129
  timing?: AiRequestMetadataTiming;
130
130
  };
131
131
  idempotencyId: AiRequestIdempotencyId;
132
132
  executor: AiRequestExecutor;
133
133
  }
134
- export type AiRequestMetadataStringified = Record<keyof AiRequestMetadata, string>;
134
+ export type AiRequestMetadataStringified = {
135
+ [K in keyof AiRequestMetadata]: AiRequestMetadata[K] extends undefined ? undefined : string;
136
+ };
135
137
  /**
136
138
  * Extracts the chunk type from an asynchronous iterable.
137
139
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainfuse/ai-tools",
3
- "version": "0.11.2",
3
+ "version": "0.12.0",
4
4
  "description": "",
5
5
  "author": "ChainFuse",
6
6
  "homepage": "https://github.com/ChainFuse/packages/tree/main/packages/ai-tools#readme",
@@ -54,7 +54,7 @@
54
54
  "@ai-sdk/openai": "^1.0.5",
55
55
  "@ai-sdk/openai-compatible": "^0.2.2",
56
56
  "@chainfuse/helpers": "^2.2.2",
57
- "@chainfuse/types": "^2.2.1",
57
+ "@chainfuse/types": "^2.2.2",
58
58
  "ai": "^4.2.6",
59
59
  "chalk": "^5.4.1",
60
60
  "haversine-distance": "^1.2.3",
@@ -64,5 +64,5 @@
64
64
  "@cloudflare/workers-types": "^4.20250321.0",
65
65
  "openai": "^4.89.1"
66
66
  },
67
- "gitHead": "34dfde6bed7a2935ed783fed477c6357b3fa9b5e"
67
+ "gitHead": "a37c92d38b22fa15b650aa80af11967d6bc56ec0"
68
68
  }