@economic/agents 2.3.0 → 2.3.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.
package/README.md CHANGED
@@ -27,6 +27,65 @@ npm install -D wrangler vite @cloudflare/vite-plugin @cloudflare/worker-bundler
27
27
 
28
28
  `@economic/agents` provides the agent runtime. Worker apps install the Cloudflare/Agents host packages they import directly, including the Vite plugin stack used by native skills.
29
29
 
30
+ ## Providers
31
+
32
+ `@economic/agents/providers` ships two pre-configured AI SDK providers that route through **Cloudflare AI Gateway** to Google Vertex AI and Google AI Studio. Both providers require `@ai-sdk/anthropic` and `@ai-sdk/google` to be installed.
33
+
34
+ ### Anthropic via Vertex AI
35
+
36
+ Routes Claude models through Cloudflare AI Gateway → Google Vertex AI.
37
+
38
+ ```typescript
39
+ import { createAnthropicVertexProvider } from "@economic/agents/providers";
40
+
41
+ const anthropic = createAnthropicVertexProvider({
42
+ cloudflareAccountId: env.CLOUDFLARE_ACCOUNT_ID,
43
+ cloudflareAiGatewayId: env.AI_GATEWAY_ID,
44
+ cloudflareApiToken: env.CLOUDFLARE_API_TOKEN,
45
+ googleCloudProjectId: env.GOOGLE_CLOUD_PROJECT_ID,
46
+ location: "europe-west1", // optional, defaults to "europe-west1"
47
+ });
48
+
49
+ getModel() {
50
+ return anthropic("claude-3-7-sonnet-20250219");
51
+ }
52
+ ```
53
+
54
+ ### Gemini via Vertex AI
55
+
56
+ Routes Gemini models through Cloudflare AI Gateway → Google Vertex AI.
57
+
58
+ ```typescript
59
+ import { createGeminiProvider } from "@economic/agents/providers";
60
+
61
+ const gemini = createGeminiProvider({
62
+ cloudflareAccountId: env.CLOUDFLARE_ACCOUNT_ID,
63
+ cloudflareAiGatewayId: env.AI_GATEWAY_ID,
64
+ cloudflareApiToken: env.CLOUDFLARE_API_TOKEN,
65
+ googleCloudProjectId: env.GOOGLE_CLOUD_PROJECT_ID,
66
+ location: "europe-west1", // optional, defaults to "europe-west1"
67
+ });
68
+
69
+ getModel() {
70
+ return gemini("gemini-2.0-flash");
71
+ }
72
+ ```
73
+
74
+ ### Both together
75
+
76
+ `createAiGatewayVertexProviders` returns both providers from a single options object:
77
+
78
+ ```typescript
79
+ import { createAiGatewayVertexProviders } from "@economic/agents/providers";
80
+
81
+ const { anthropic, gemini } = createAiGatewayVertexProviders({
82
+ cloudflareAccountId: env.CLOUDFLARE_ACCOUNT_ID,
83
+ cloudflareAiGatewayId: env.AI_GATEWAY_ID,
84
+ cloudflareApiToken: env.CLOUDFLARE_API_TOKEN,
85
+ googleCloudProjectId: env.GOOGLE_CLOUD_PROJECT_ID,
86
+ });
87
+ ```
88
+
30
89
  ## Quick start: an agent
31
90
 
32
91
  Subclass `Agent` and implement `getModel` and `getSystemPrompt`. Add tools with `getTools`, skills with `getSkills`. Expose a `@callable` method to run a turn — `saveMessages` injects a message, runs the turn, and persists the result:
package/dist/index.d.mts CHANGED
@@ -103,7 +103,7 @@ declare abstract class Agent<RequestContext extends Record<string, unknown> = Re
103
103
  * The user context for the session.
104
104
  * Define getUserContext to set a user context.
105
105
  */
106
- private _userContext?;
106
+ protected userContext?: UserContext;
107
107
  /**
108
108
  * Returns the identity following verification of the JWT token - getJwtAuthConfig is required.
109
109
  * This method should not have side effects - return a single object from it.
package/dist/index.mjs CHANGED
@@ -121,7 +121,7 @@ var Agent = class extends Think {
121
121
  });
122
122
  const token = extractTokenFromConnectRequest(ctx.request);
123
123
  if (token && this.getUserContext) this._pendingUserContextRequest = this.getUserContext(token).then((userContext) => {
124
- this._userContext = userContext;
124
+ this.userContext = userContext;
125
125
  });
126
126
  }
127
127
  }
@@ -148,7 +148,7 @@ var Agent = class extends Think {
148
148
  if (this._pendingUserContextRequest) await this._pendingUserContextRequest;
149
149
  this._toolContextForCurrentTurn = {
150
150
  ...ctx.body ?? {},
151
- _userContext: this._userContext
151
+ _userContext: this.userContext
152
152
  };
153
153
  await this.session.refreshSystemPrompt();
154
154
  this._toolsForCurrentTurn = ctx.tools;
@@ -267,7 +267,7 @@ var Agent = class extends Think {
267
267
  * The user context for the session.
268
268
  * Define getUserContext to set a user context.
269
269
  */
270
- _userContext;
270
+ userContext;
271
271
  /**
272
272
  * Self-registers this DO in the global `agent_registry`. Only top-level DOs
273
273
  * are registered — facets are enumerable via their parent's own index, so
@@ -22,7 +22,8 @@ interface GeminiProviderOptions {
22
22
  cloudflareAccountId: string;
23
23
  cloudflareAiGatewayId: string;
24
24
  cloudflareApiToken: string;
25
- googleApiKey?: string;
25
+ googleCloudProjectId: string;
26
+ location?: string;
26
27
  }
27
28
  declare function createGeminiProvider(options: GeminiProviderOptions): GoogleGenerativeAIProvider;
28
29
  //#endregion
@@ -26,12 +26,12 @@ function createAnthropicVertexProvider(options) {
26
26
  //#endregion
27
27
  //#region src/providers/gemini.ts
28
28
  function createGeminiProvider(options) {
29
- const { cloudflareAccountId, cloudflareAiGatewayId, cloudflareApiToken, googleApiKey } = options;
29
+ const { cloudflareAccountId, cloudflareAiGatewayId, cloudflareApiToken, googleCloudProjectId, location = "europe-west1" } = options;
30
30
  return createGoogleGenerativeAI({
31
- apiKey: googleApiKey ?? "unused",
32
- baseURL: `https://gateway.ai.cloudflare.com/v1/${cloudflareAccountId}/${cloudflareAiGatewayId}/google-ai-studio/v1beta`,
31
+ apiKey: "unused",
32
+ baseURL: `https://gateway.ai.cloudflare.com/v1/${cloudflareAccountId}/${cloudflareAiGatewayId}/google-vertex-ai/v1/projects/${googleCloudProjectId}/locations/${location}/publishers/google/models`,
33
33
  headers: { "cf-aig-authorization": `Bearer ${cloudflareApiToken}` },
34
- name: "gateway.google.generative-ai"
34
+ name: "gateway.google.vertex-ai"
35
35
  });
36
36
  }
37
37
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@economic/agents",
3
- "version": "2.3.0",
3
+ "version": "2.3.2",
4
4
  "description": "A starter for creating a TypeScript package.",
5
5
  "license": "MIT",
6
6
  "bin": {