@ai-sdk/harness-deepagents 0.0.0 → 1.0.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.
@@ -0,0 +1,77 @@
1
+ import { getAiGatewayAuthFromEnv } from '@ai-sdk/harness/utils';
2
+
3
+ export type DeepAgentsAuthOptions = {
4
+ readonly anthropic?: {
5
+ readonly apiKey?: string;
6
+ readonly authToken?: string;
7
+ readonly baseUrl?: string;
8
+ };
9
+ readonly gateway?: {
10
+ readonly apiKey?: string;
11
+ readonly baseUrl?: string;
12
+ };
13
+ };
14
+
15
+ // DeepAgents always drives the Anthropic client. Non-Anthropic models reach it
16
+ // through AI Gateway's Anthropic-compatible endpoint, which translates to any
17
+ // model (Gemini, OpenAI, etc.), tool calls included.
18
+ export function resolveDeepAgentsEnv({
19
+ auth,
20
+ processEnv = process.env,
21
+ }: {
22
+ auth?: DeepAgentsAuthOptions;
23
+ processEnv?: Record<string, string | undefined>;
24
+ }): Record<string, string> {
25
+ if (auth?.anthropic) {
26
+ return pickAnthropic({ explicit: auth.anthropic, processEnv });
27
+ }
28
+
29
+ const gatewayAuthFromEnv = getAiGatewayAuthFromEnv({ env: processEnv });
30
+ if (auth?.gateway) {
31
+ return pickGateway({ explicit: auth.gateway, gatewayAuthFromEnv });
32
+ }
33
+ if (gatewayAuthFromEnv.apiKey) {
34
+ return pickGateway({ explicit: {}, gatewayAuthFromEnv });
35
+ }
36
+
37
+ return pickAnthropic({ processEnv });
38
+ }
39
+
40
+ function pickAnthropic({
41
+ explicit,
42
+ processEnv,
43
+ }: {
44
+ explicit?: NonNullable<DeepAgentsAuthOptions['anthropic']>;
45
+ processEnv: Record<string, string | undefined>;
46
+ }): Record<string, string> {
47
+ const env: Record<string, string> = {};
48
+ const apiKey = explicit?.apiKey ?? processEnv.ANTHROPIC_API_KEY;
49
+ if (apiKey) env.ANTHROPIC_API_KEY = apiKey;
50
+ const authToken = explicit?.authToken ?? processEnv.ANTHROPIC_AUTH_TOKEN;
51
+ if (authToken) env.ANTHROPIC_AUTH_TOKEN = authToken;
52
+ const baseUrl = explicit?.baseUrl ?? processEnv.ANTHROPIC_BASE_URL;
53
+ if (baseUrl) env.ANTHROPIC_BASE_URL = baseUrl;
54
+ return env;
55
+ }
56
+
57
+ function pickGateway({
58
+ explicit,
59
+ gatewayAuthFromEnv,
60
+ }: {
61
+ explicit: NonNullable<DeepAgentsAuthOptions['gateway']>;
62
+ gatewayAuthFromEnv: ReturnType<typeof getAiGatewayAuthFromEnv>;
63
+ }): Record<string, string> {
64
+ const apiKey = explicit.apiKey ?? gatewayAuthFromEnv.apiKey;
65
+ // The Anthropic SDK appends `/v1/messages`, so the gateway base stays at its root.
66
+ const baseUrl = (explicit.baseUrl ?? gatewayAuthFromEnv.baseUrl).replace(
67
+ /\/+$/,
68
+ '',
69
+ );
70
+ const env: Record<string, string> = {};
71
+ if (apiKey) {
72
+ env.AI_GATEWAY_API_KEY = apiKey;
73
+ env.ANTHROPIC_API_KEY = apiKey;
74
+ }
75
+ env.ANTHROPIC_BASE_URL = baseUrl;
76
+ return env;
77
+ }
@@ -0,0 +1,31 @@
1
+ import {
2
+ harnessV1BridgeInboundCommandSchemas,
3
+ harnessV1BridgeOutboundMessageSchema,
4
+ harnessV1BridgeReadySchema,
5
+ harnessV1BridgeStartBaseSchema,
6
+ } from '@ai-sdk/harness';
7
+ import { z } from 'zod/v4';
8
+
9
+ // Deep Agents bridge wire protocol; only the `start` payload is adapter-specific.
10
+ export const outboundMessageSchema = harnessV1BridgeOutboundMessageSchema;
11
+ export type OutboundMessage = z.infer<typeof outboundMessageSchema>;
12
+
13
+ export const startMessageSchema = harnessV1BridgeStartBaseSchema.extend({
14
+ // Prepended to the first user message (createDeepAgent takes no instructions param).
15
+ instructions: z.string().optional(),
16
+ // In-backend skills source dirs ($HOME and <workDir>), passed to createDeepAgent({ skills }).
17
+ skillsPaths: z.array(z.string()).optional(),
18
+ // Max LangGraph super-steps per turn (streamEvents recursionLimit).
19
+ recursionLimit: z.number().optional(),
20
+ });
21
+
22
+ export type StartMessage = z.infer<typeof startMessageSchema>;
23
+
24
+ export const inboundMessageSchema = z.discriminatedUnion('type', [
25
+ startMessageSchema,
26
+ ...harnessV1BridgeInboundCommandSchemas,
27
+ ]);
28
+ export type InboundMessage = z.infer<typeof inboundMessageSchema>;
29
+
30
+ export const bridgeReadySchema = harnessV1BridgeReadySchema;
31
+ export type BridgeReady = z.infer<typeof bridgeReadySchema>;