@economic/agents 2.7.2 → 3.0.0-alpha.32271766282.1.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.
- package/README.md +458 -108
- package/dist/index.d.mts +282 -164
- package/dist/index.mjs +1741 -675
- package/dist/providers.d.mts +4 -4
- package/dist/providers.mjs +47 -18
- package/package.json +38 -15
- package/dist/route-agent-request-D2ll--nF.d.mts +0 -21
- package/dist/route-agent-request-DBGSXu2O.mjs +0 -468
- package/dist/v1.d.mts +0 -264
- package/dist/v1.mjs +0 -1060
- package/schema/v1/0001_initial.sql +0 -35
- package/schema/v1/0002_add_rating_comment.sql +0 -1
- package/schema/v1/0003_drop_events.sql +0 -5
package/dist/providers.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AnthropicMessagesLanguageModel } from "@ai-sdk/anthropic/internal";
|
|
2
|
-
import { GoogleGenerativeAIProvider } from "@ai-sdk/google";
|
|
3
1
|
import { AnthropicProvider } from "@ai-sdk/anthropic";
|
|
2
|
+
import { GoogleGenerativeAIProvider } from "@ai-sdk/google";
|
|
3
|
+
import { LanguageModelV3 } from "@ai-sdk/provider";
|
|
4
4
|
|
|
5
5
|
//#region src/providers/metadata.d.ts
|
|
6
6
|
/** Custom metadata serialized into Cloudflare's `cf-aig-metadata` header. */
|
|
@@ -18,7 +18,7 @@ interface AnthropicVertexProviderOptions {
|
|
|
18
18
|
/** Custom metadata included on every request. `agentId` is injected by the SDK. */
|
|
19
19
|
metadata?: AiGatewayMetadata;
|
|
20
20
|
}
|
|
21
|
-
declare function createAnthropicProvider(options: AnthropicVertexProviderOptions): (modelId: AnthropicVertexModelId, metadata?: AiGatewayMetadata) =>
|
|
21
|
+
declare function createAnthropicProvider(options: AnthropicVertexProviderOptions): (modelId: AnthropicVertexModelId, metadata?: AiGatewayMetadata) => LanguageModelV3;
|
|
22
22
|
//#endregion
|
|
23
23
|
//#region src/providers/gemini.d.ts
|
|
24
24
|
type GeminiModelId = Parameters<GoogleGenerativeAIProvider>[0];
|
|
@@ -36,7 +36,7 @@ declare function createGeminiProvider(options: GeminiProviderOptions, metadata?:
|
|
|
36
36
|
//#region src/providers/index.d.ts
|
|
37
37
|
interface AiGatewayVertexProvidersOptions extends AnthropicVertexProviderOptions, GeminiProviderOptions {}
|
|
38
38
|
declare function createAiGatewayVertexProviders(options: AiGatewayVertexProvidersOptions): {
|
|
39
|
-
anthropic: (modelId: AnthropicVertexModelId, metadata?: AiGatewayMetadata) => import("@ai-sdk/
|
|
39
|
+
anthropic: (modelId: AnthropicVertexModelId, metadata?: AiGatewayMetadata) => import("@ai-sdk/provider").LanguageModelV3;
|
|
40
40
|
gemini: import("@ai-sdk/google").GoogleGenerativeAIProvider;
|
|
41
41
|
};
|
|
42
42
|
//#endregion
|
package/dist/providers.mjs
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { wrapLanguageModel } from "ai";
|
|
1
2
|
import { getCurrentAgent } from "agents";
|
|
2
|
-
import {
|
|
3
|
+
import { createAnthropic } from "@ai-sdk/anthropic";
|
|
3
4
|
import { createGoogleGenerativeAI } from "@ai-sdk/google";
|
|
4
5
|
//#region src/providers/metadata.ts
|
|
5
6
|
function getCurrentAgentId() {
|
|
6
7
|
const agent = getCurrentAgent().agent;
|
|
7
8
|
if (!agent) return void 0;
|
|
8
|
-
|
|
9
|
+
const agentName = agent.agentName;
|
|
10
|
+
return typeof agentName === "string" ? agentName : void 0;
|
|
9
11
|
}
|
|
10
12
|
function createAiGatewayHeaders(cloudflareApiToken, defaultMetadata, requestMetadata) {
|
|
11
13
|
const headers = { "cf-aig-authorization": `Bearer ${cloudflareApiToken}` };
|
|
@@ -34,22 +36,49 @@ function createAnthropicProvider(options) {
|
|
|
34
36
|
const { anthropicVersion = "vertex-2023-10-16", cloudflareAccountId, cloudflareAiGatewayId, cloudflareApiToken, googleCloudProjectId, location = "europe-west1", metadata: defaultMetadata } = options;
|
|
35
37
|
const anthropicBaseURL = `${`${`https://gateway.ai.cloudflare.com/v1/${cloudflareAccountId}/${cloudflareAiGatewayId}/`}google-vertex-ai/v1/projects/${googleCloudProjectId}/locations/${location}/publishers/`}anthropic/models/`;
|
|
36
38
|
return function anthropic(modelId, metadata) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
...
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
39
|
+
const gatewayFetch = createAiGatewayFetch(cloudflareApiToken, defaultMetadata, metadata);
|
|
40
|
+
return wrapLanguageModel({
|
|
41
|
+
model: createAnthropic({
|
|
42
|
+
apiKey: "unused",
|
|
43
|
+
baseURL: anthropicBaseURL,
|
|
44
|
+
name: "vertex.anthropic.messages",
|
|
45
|
+
fetch: async (_input, init) => {
|
|
46
|
+
if (typeof init?.body !== "string") throw new Error("Anthropic Vertex requests require a JSON body");
|
|
47
|
+
const requestBody = JSON.parse(init.body);
|
|
48
|
+
const { model: _model, ...body } = requestBody;
|
|
49
|
+
const headers = new Headers(init.headers);
|
|
50
|
+
headers.delete("anthropic-version");
|
|
51
|
+
headers.delete("user-agent");
|
|
52
|
+
headers.delete("x-api-key");
|
|
53
|
+
const operation = requestBody.stream === true ? "streamRawPredict" : "rawPredict";
|
|
54
|
+
return gatewayFetch(`${anthropicBaseURL}${modelId}:${operation}`, {
|
|
55
|
+
...init,
|
|
56
|
+
headers,
|
|
57
|
+
body: JSON.stringify({
|
|
58
|
+
...body,
|
|
59
|
+
anthropic_version: anthropicVersion
|
|
60
|
+
})
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
})(modelId),
|
|
64
|
+
middleware: {
|
|
65
|
+
specificationVersion: "v3",
|
|
66
|
+
overrideSupportedUrls: () => ({}),
|
|
67
|
+
transformParams: async ({ params }) => ({
|
|
68
|
+
...params,
|
|
69
|
+
providerOptions: {
|
|
70
|
+
...params.providerOptions,
|
|
71
|
+
anthropic: {
|
|
72
|
+
structuredOutputMode: "jsonTool",
|
|
73
|
+
...params.providerOptions?.anthropic
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
tools: params.tools?.map((tool) => tool.type === "function" ? {
|
|
77
|
+
...tool,
|
|
78
|
+
strict: void 0
|
|
79
|
+
} : tool)
|
|
80
|
+
})
|
|
81
|
+
}
|
|
53
82
|
});
|
|
54
83
|
};
|
|
55
84
|
}
|
package/package.json
CHANGED
|
@@ -1,34 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@economic/agents",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "3.0.0-alpha.32271766282.1.0",
|
|
4
|
+
"description": "Cloudflare Agents SDK for building e-conomic AI agents.",
|
|
5
|
+
"homepage": "https://github.com/e-conomic/agents#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/e-conomic/agents/issues"
|
|
8
|
+
},
|
|
5
9
|
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/e-conomic/agents.git",
|
|
13
|
+
"directory": "packages/agents"
|
|
14
|
+
},
|
|
6
15
|
"files": [
|
|
7
16
|
"dist",
|
|
8
17
|
"schema"
|
|
9
18
|
],
|
|
10
19
|
"type": "module",
|
|
20
|
+
"sideEffects": false,
|
|
11
21
|
"types": "./dist/index.d.mts",
|
|
12
22
|
"exports": {
|
|
13
|
-
".":
|
|
14
|
-
|
|
15
|
-
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.mts",
|
|
25
|
+
"import": "./dist/index.mjs",
|
|
26
|
+
"default": "./dist/index.mjs"
|
|
27
|
+
},
|
|
28
|
+
"./providers": {
|
|
29
|
+
"types": "./dist/providers.d.mts",
|
|
30
|
+
"import": "./dist/providers.mjs",
|
|
31
|
+
"default": "./dist/providers.mjs"
|
|
32
|
+
},
|
|
16
33
|
"./package.json": "./package.json"
|
|
17
34
|
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "restricted"
|
|
37
|
+
},
|
|
18
38
|
"scripts": {
|
|
19
39
|
"build": "tsdown",
|
|
20
40
|
"dev": "tsdown --watch",
|
|
21
|
-
"test": "vitest",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
41
|
+
"test": "vitest run && vitest run --config vitest.integration.config.ts",
|
|
42
|
+
"test:unit": "vitest run",
|
|
43
|
+
"test:integration": "vitest run --config vitest.integration.config.ts",
|
|
44
|
+
"typecheck": "tsc --noEmit && tsc --noEmit --project tsconfig.test.json",
|
|
45
|
+
"prepublishOnly": "npm test && npm run typecheck && npm run build"
|
|
24
46
|
},
|
|
25
47
|
"dependencies": {
|
|
26
48
|
"@ai-sdk/anthropic": "^3.0.77",
|
|
27
49
|
"@ai-sdk/google": "^3.0.73",
|
|
28
|
-
"@
|
|
29
|
-
"@cloudflare/think": "^0.12.1",
|
|
50
|
+
"@ai-sdk/provider": "^3.0.14",
|
|
30
51
|
"@opentelemetry/sdk-trace-base": "^2.8.0",
|
|
31
|
-
"agents": "^0.17.3",
|
|
32
52
|
"ai": "^6.0.197",
|
|
33
53
|
"jose": "^6.2.3",
|
|
34
54
|
"nanoid": "^5.1.11"
|
|
@@ -36,19 +56,22 @@
|
|
|
36
56
|
"devDependencies": {
|
|
37
57
|
"@babel/core": "^7.29.7",
|
|
38
58
|
"@babel/plugin-proposal-decorators": "^7.29.7",
|
|
59
|
+
"@cloudflare/think": "^0.12.1",
|
|
60
|
+
"@cloudflare/vitest-pool-workers": "^0.18.6",
|
|
39
61
|
"@cloudflare/workers-types": "^4.20260702.1",
|
|
40
62
|
"@rolldown/plugin-babel": "^0.2.3",
|
|
41
63
|
"@types/node": "^25.6.0",
|
|
42
64
|
"@typescript/native-preview": "7.0.0-dev.20260412.1",
|
|
65
|
+
"agents": "^0.17.3",
|
|
43
66
|
"tsdown": "^0.22.0",
|
|
44
67
|
"typescript": "^6.0.2",
|
|
45
68
|
"vitest": "^4.1.4"
|
|
46
69
|
},
|
|
47
70
|
"peerDependencies": {
|
|
48
71
|
"@cloudflare/think": "^0.12.1",
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
72
|
+
"agents": "^0.17.3"
|
|
73
|
+
},
|
|
74
|
+
"engines": {
|
|
75
|
+
"node": ">=22.12.0"
|
|
53
76
|
}
|
|
54
77
|
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { AgentOptions } from "agents";
|
|
2
|
-
|
|
3
|
-
//#region src/server/features/auth/index.d.ts
|
|
4
|
-
interface JwtAuthConfig<TClaims extends Record<string, unknown> = Record<string, unknown>> {
|
|
5
|
-
/** Issuers whose tokens are accepted (exact string or RegExp). */
|
|
6
|
-
allowedIssuers: readonly (string | RegExp)[];
|
|
7
|
-
/** Expected `aud` claim. */
|
|
8
|
-
audience: string;
|
|
9
|
-
/** Required OAuth scopes; token `scope` must include all (empty = no scope check). */
|
|
10
|
-
requiredScopes?: readonly string[];
|
|
11
|
-
/**
|
|
12
|
-
* Extract the claims you need from the verified JWT payload.
|
|
13
|
-
* These will be stored and made available in the agent's tool context.
|
|
14
|
-
*/
|
|
15
|
-
getClaims: (payload: Record<string, unknown>) => TClaims;
|
|
16
|
-
}
|
|
17
|
-
//#endregion
|
|
18
|
-
//#region src/server/route-agent-request.d.ts
|
|
19
|
-
declare function routeAgentRequest$1<Env>(request: Request, env: Env, options?: AgentOptions<Env>): Promise<Response | null>;
|
|
20
|
-
//#endregion
|
|
21
|
-
export { JwtAuthConfig as n, routeAgentRequest$1 as t };
|