@chainfuse/ai-tools 1.0.16 → 1.0.17

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/dist/base.mjs CHANGED
@@ -8,6 +8,14 @@ export class AiBase {
8
8
  get config() {
9
9
  return {
10
10
  ...Object.freeze(this._config),
11
+ gateway: {
12
+ ...Object.freeze(this._config.gateway),
13
+ binding: this._config.gateway.binding,
14
+ },
15
+ providers: {
16
+ ...Object.freeze(this._config.providers),
17
+ workersAi: this._config.providers.workersAi,
18
+ },
11
19
  backgroundContext: this._config.backgroundContext,
12
20
  };
13
21
  }
@@ -24,8 +24,8 @@ export class AiRawProviders extends AiBase {
24
24
  };
25
25
  if (logId) {
26
26
  const updateMetadata = (() => {
27
- if ('gateway' in this.config.providers.workersAi && typeof this.config.providers.workersAi.gateway === 'function') {
28
- return this.config.providers.workersAi
27
+ if ('binding' in this.config.gateway && typeof this.config.gateway.binding?.gateway === 'function') {
28
+ return this.config.gateway.binding
29
29
  .gateway(this.gatewayName)
30
30
  .patchLog(logId, {
31
31
  metadata: {
@@ -220,8 +220,8 @@ export class AiRawProviders extends AiBase {
220
220
  if (args.logging ?? this.gatewayLog)
221
221
  console.info(new Date().toISOString(), this.chalk.rgb(...Helpers.uniqueIdColor(metadataHeader.idempotencyId))(`[${metadataHeader.idempotencyId}]`), this.chalk.magenta(rawInit?.method), this.chalk.magenta(new URL(new Request(input).url).pathname));
222
222
  return (() => {
223
- if ('gateway' in this.config.providers.workersAi && typeof this.config.providers.workersAi.gateway === 'function') {
224
- return this.config.providers.workersAi.gateway(this.gatewayName).run(fallbackedBody, {
223
+ if ('binding' in this.config.gateway && typeof this.config.gateway.binding?.gateway === 'function') {
224
+ return this.config.gateway.binding.gateway(this.gatewayName).run(fallbackedBody, {
225
225
  extraHeaders: (() => {
226
226
  // Prevent duplicates
227
227
  headers.delete('cf-aig-authorization');
package/dist/types.d.mts CHANGED
@@ -1,12 +1,13 @@
1
1
  import type { Coordinate } from '@chainfuse/types/ai-tools';
2
2
  import type { azureCatalog } from '@chainfuse/types/ai-tools/azure/catalog';
3
3
  import type { PrefixedUuid, UuidExport } from '@chainfuse/types/d1';
4
- import type { Ai, ExecutionContext, IncomingRequestCfProperties } from '@cloudflare/workers-types/experimental';
4
+ import type { Ai, DurableObjectState, ExecutionContext, IncomingRequestCfProperties } from '@cloudflare/workers-types/experimental';
5
5
  import type haversine from 'haversine-distance';
6
- export interface AiConfig {
6
+ export interface AiConfig<C extends Pick<ExecutionContext | DurableObjectState, 'waitUntil'> = Pick<ExecutionContext | DurableObjectState, 'waitUntil'>> {
7
7
  gateway: {
8
8
  accountId: string;
9
9
  apiToken: string;
10
+ binding?: AiConfigWorkersAiBinding;
10
11
  };
11
12
  geoRouting?: {
12
13
  userCoordinate?: Coordinate;
@@ -26,7 +27,7 @@ export interface AiConfig {
26
27
  action: 'active';
27
28
  }));
28
29
  providers: AiConfigProviders;
29
- backgroundContext?: ExecutionContext;
30
+ backgroundContext?: C;
30
31
  }
31
32
  export interface AiConfigProviders {
32
33
  anthropic: AiConfigAnthropic;
@@ -62,11 +63,11 @@ export interface AiConfigOaiOpenai {
62
63
  apiToken: `sk-${string}`;
63
64
  organization: `org-${string}`;
64
65
  }
65
- export type AiConfigWorkersai = AiConfigWorkersaiRest | AiConfigWorkersaiBinding;
66
+ export type AiConfigWorkersai = AiConfigWorkersaiRest | AiConfigWorkersAiBinding;
66
67
  export interface AiConfigWorkersaiRest {
67
68
  apiToken: string;
68
69
  }
69
- export type AiConfigWorkersaiBinding<T extends Ai = Ai> = T;
70
+ export type AiConfigWorkersAiBinding<T extends Ai = Ai> = T;
70
71
  export type AzureServers = typeof azureCatalog;
71
72
  export type Servers = AzureServers;
72
73
  export type PrivacyRegion = Extract<Servers[number], {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainfuse/ai-tools",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "",
5
5
  "author": "ChainFuse",
6
6
  "homepage": "https://github.com/ChainFuse/packages/tree/main/packages/ai-tools#readme",
@@ -66,5 +66,5 @@
66
66
  "@cloudflare/workers-types": "^4.20251127.0",
67
67
  "openai": "^6.9.1"
68
68
  },
69
- "gitHead": "a7ba85aa01dd1c54356ef54b1af743cd9f6a767e"
69
+ "gitHead": "018281c52a87f850cd721399db3785b65c1cf39f"
70
70
  }