agent-contracts-runtime 0.36.16 → 0.36.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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as SdkAdapter, T as TaskOutcome, b as TaskContractLike, c as AgentContractLike, d as TaskContext, P as PromptBuilderOptions, e as TaskRunResult } from './task-runner-CD8nnKpn.js';
2
- export { A as AdapterSendOptions, a as AgentExecutionRequest, f as AgentProgressEvent, C as CacheConfig, g as CandidateAgent, I as InMemoryStore, M as MemoryRef, h as MemoryStore, R as RetryDecision, i as SplitPrompt, j as TaskRunOptions, k as buildCandidateAgents, l as buildRetryFollowUp, m as buildSplitTaskPrompt, n as buildTaskPrompt, o as extractStructuredResult, r as renderAgentSystemPrompt, p as runTask, z as zodSchemaToPromptDescription, q as zodSchemaToYamlExample } from './task-runner-CD8nnKpn.js';
1
+ import { S as SdkAdapter, T as TaskOutcome, b as TaskContractLike, c as AgentContractLike, d as TaskContext, P as PromptBuilderOptions, e as TaskRunResult } from './task-runner-DJW49UGZ.js';
2
+ export { A as AdapterSendOptions, a as AgentExecutionRequest, f as AgentProgressEvent, C as CacheConfig, g as CandidateAgent, I as InMemoryStore, M as MemoryRef, h as MemoryStore, R as RetryDecision, i as SplitPrompt, j as TaskRunOptions, k as buildCandidateAgents, l as buildRetryFollowUp, m as buildSplitTaskPrompt, n as buildTaskPrompt, o as extractStructuredResult, r as renderAgentSystemPrompt, p as runTask, z as zodSchemaToPromptDescription, q as zodSchemaToYamlExample } from './task-runner-DJW49UGZ.js';
3
3
  import { z } from 'zod';
4
4
  import { a as GuardrailRuleData, G as GuardrailHooks } from './guardrail-hooks-CFd3a8tQ.js';
5
5
  export { b as GuardrailCheckFunctions, c as GuardrailCheckResult, d as GuardrailRule, H as HookContext, e as HookResponse, f as createGuardrailHooks, g as createGuardrailHooksForAgent, h as createGuardrailHooksFromRules, i as getBlockingViolations, j as getWarnings, k as hasBlockingViolation } from './guardrail-hooks-CFd3a8tQ.js';
@@ -539,7 +539,7 @@ interface CreateAdapterOptions {
539
539
  /**
540
540
  * Create an SDK adapter instance by name.
541
541
  *
542
- * @param name - One of: "mock", "claude", "openai", "gemini"
542
+ * @param name - One of: "mock", "claude", "openai"
543
543
  * @param options - Adapter-specific configuration
544
544
  */
545
545
  declare function createAdapter(name: string, options?: CreateAdapterOptions): Promise<SdkAdapter>;
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  InMemoryStore,
3
+ PluginRegistry,
3
4
  WorkflowBuilder,
4
5
  buildCandidateAgents,
5
6
  buildGateEvaluationPrompt,
@@ -7,21 +8,31 @@ import {
7
8
  buildSplitTaskPrompt,
8
9
  buildTaskPrompt,
9
10
  createAdapter,
11
+ createGuardrailHooks,
12
+ createGuardrailHooksForAgent,
13
+ createGuardrailHooksFromRules,
10
14
  createProgressSink,
11
15
  createRuntime,
12
16
  executeTask,
13
17
  executeWorkflow,
14
18
  extractStructuredResult,
19
+ getBlockingViolations,
20
+ getWarnings,
21
+ hasBlockingViolation,
15
22
  loadPlugins,
16
23
  loadPluginsFromDirectory,
17
24
  loadPluginsFromPaths,
18
25
  parseGateEvaluationResponse,
26
+ pluginRegistry,
19
27
  renderAgentSystemPrompt,
20
28
  runTask,
21
29
  runWorkflow,
22
30
  zodSchemaToPromptDescription,
23
31
  zodSchemaToYamlExample
24
- } from "./chunk-6JVGBBP3.js";
32
+ } from "./chunk-VKCNOSMQ.js";
33
+ import {
34
+ createModelResolver
35
+ } from "./chunk-AWBHN3LI.js";
25
36
  import {
26
37
  BoundResolver,
27
38
  buildPerAgentGuardrails,
@@ -29,19 +40,6 @@ import {
29
40
  getGuardrailRulesForAgent,
30
41
  guardrailContextToRuleData
31
42
  } from "./chunk-2E2LWE6C.js";
32
- import {
33
- createModelResolver
34
- } from "./chunk-AWBHN3LI.js";
35
- import {
36
- PluginRegistry,
37
- createGuardrailHooks,
38
- createGuardrailHooksForAgent,
39
- createGuardrailHooksFromRules,
40
- getBlockingViolations,
41
- getWarnings,
42
- hasBlockingViolation,
43
- pluginRegistry
44
- } from "./chunk-M57HVYUU.js";
45
43
  import "./chunk-KKJW4TE5.js";
46
44
  import {
47
45
  DslValidationError,
@@ -21,9 +21,9 @@ interface MemoryRef {
21
21
  /**
22
22
  * Pluggable store for memory content that backs MemoryRef pointers.
23
23
  *
24
- * Adapters that use server-side state (OpenAI, Gemini) may not need
24
+ * Adapters that use server-side state (OpenAI) may not need
25
25
  * the store — the ref ID alone is sufficient for resume. Adapters
26
- * with local state (Claude transcript, Gemini chat history) use the
26
+ * with local state (Claude transcript) use the
27
27
  * store to persist and retrieve content.
28
28
  */
29
29
  interface MemoryStore {
@@ -50,7 +50,6 @@ declare class InMemoryStore implements MemoryStore {
50
50
  *
51
51
  * - Claude `Options.agents: Record<string, AgentDefinition>`
52
52
  * - OpenAI `Agent.handoffs: Agent[]`
53
- * - ADK `LlmAgent.subAgents: BaseAgent[]`
54
53
  *
55
54
  * `CandidateAgent` is the common, SDK-independent contract. Each adapter maps it
56
55
  * onto its provider's native shape. The selection rule (which agents become
@@ -215,7 +214,7 @@ interface AdapterSendOptions {
215
214
  /**
216
215
  * Candidate sub-agents the entry agent's LLM may delegate to (model B,
217
216
  * LLM-internal routing). Adapters register these via their native subagent
218
- * mechanism (Claude `agents`, OpenAI `handoffs`, ADK `subAgents`). When
217
+ * mechanism (Claude `agents`, OpenAI `handoffs`). When
219
218
  * omitted or empty, adapters behave exactly as before (single agent).
220
219
  */
221
220
  agents?: CandidateAgent[];
@@ -5,7 +5,7 @@ Generates typed contracts, handoff validators, and guardrail hooks from DSL,
5
5
  then runs workflows through pluggable SDK adapters.
6
6
 
7
7
 
8
- **Version:** 0.36.16
8
+ **Version:** 0.36.17
9
9
 
10
10
  ## Table of Contents
11
11
 
@@ -181,13 +181,14 @@ runtime が事前にエージェントを 1 つ選んで `systemPrompt` に入
181
181
 
182
182
  ### 判断(確定)
183
183
 
184
- - **採用 backend は Claude(要 `settingSources:[]`)/ OpenAI / Gemini-ADK の 3 つ**。いずれも
184
+ - **採用 backend は Claude(要 `settingSources:[]`)/ OpenAI の 2 つ**。いずれも
185
185
  ネイティブ subagent + in-code 注入でモデル B・隔離要件を満たす。
186
186
  - **生 `@google/genai` アダプタは不採用・廃止**。primitive 不足でモデル B を満たせず、runtime 自前合成は
187
- ADK で代替できるため保持価値がない。Google backend は **ADK 一本**。
187
+ 保持価値がない。
188
188
  - **Gemini CLI** はローカル markdown 定義依存(`~/.gemini/agents`)→ 非隔離。採用外。
189
189
  - **Cursor は サポート廃止**。理由は ①`@cursor/sdk` が依存関係 audit を通らない、
190
190
  ②候補 subagent を in-code 登録する機構が SDK に無くモデル B 不適、の 2 点。
191
+ - **Gemini-ADK(`@google/adk`)は サポート廃止**。`@google/adk` の全版が、推移的な依存の uuid の既知の脆弱性(GHSA-w5hq-g745-h8pq)を利用者の依存の木に導入し、範囲内に該当しない版が無いため。`adk-sdk.ts` と `@google/adk` を撤去。
191
192
  `src/adapters/cursor-sdk.ts` と `@cursor/sdk`(optional peer dep)を撤去する。
192
193
  - → ブリッジは採用 3 backend に対し、共通の最小契約(候補 AgentDefinition 群)を各機構
193
194
  (Claude `agents` / OpenAI `handoffs` / ADK `sub_agents`)へ写像する。
@@ -206,6 +207,6 @@ runtime が事前にエージェントを 1 つ選んで `systemPrompt` に入
206
207
  > **確定事項**:
207
208
  > - ルーティングは **LLM 内部ルーティング(モデル B)一択**。候補登録(`agents`/`handoffs`/`sub_agents`)は必須。
208
209
  > - 外部ルーティング(systemPrompt 丸投げ)は不採用。
209
- > - **採用 backend = Claude / OpenAI / Gemini-ADK**。生 `@google/genai` アダプタは廃止。
210
+ > - **採用 backend = Claude / OpenAI**。生 `@google/genai` アダプタと Gemini-ADK アダプタは廃止。
210
211
  > - **Cursor サポート廃止**(依存 audit 不通過+in-code subagent 機構なし)。`cursor-sdk.ts` と `@cursor/sdk` を撤去。Gemini CLI は採用外(非隔離)。
211
212
  > - **skills は in-code 合成**(subagent or TS ハンドラ tool)。ネイティブ `skills` ディスク discovery は不使用 → `settingSources:[]` 隔離を維持。skill と agent は同じ subagent 登録機構に統合。
@@ -123,7 +123,6 @@ llm-feature-implementer:
123
123
  NEVER create custom adapter classes. Import from agent-contracts-runtime:
124
124
  ClaudeAgentSdkAdapter from agent-contracts-runtime/adapters/claude-agent-sdk,
125
125
  OpenAIAgentsSdkAdapter from agent-contracts-runtime/adapters/openai-agents-sdk,
126
- GeminiSdkAdapter from agent-contracts-runtime/adapters/gemini-sdk,
127
126
  MockAdapter from agent-contracts-runtime/adapters/mock.
128
127
 
129
128
  - >-
@@ -152,7 +151,7 @@ llm-feature-implementer:
152
151
 
153
152
  - >-
154
153
  Standard LLM command options (all must be present):
155
- --adapter <name> (mock|claude|openai|gemini, default varies),
154
+ --adapter <name> (mock|claude|openai, default varies),
156
155
  --model <name> (optional override),
157
156
  --show-prompt (output prompt without LLM call),
158
157
  --fail-on <level> (warning|error|critical, default error),
@@ -211,8 +210,7 @@ llm-feature-implementer:
211
210
  Adapter constructors:
212
211
  MockAdapter({responses?, defaultLatencyMs?}),
213
212
  ClaudeAgentSdkAdapter({cwd?, model?, tools?, permissionMode?, maxTurns?, guardrailHooks?}),
214
- OpenAIAgentsSdkAdapter({model?, maxTurns?, guardrailHooks?, tools?, agentName?, signal?}),
215
- GeminiSdkAdapter({apiKey?, model?, systemInstruction?, temperature?, maxOutputTokens?, guardrailHooks?}).
213
+ OpenAIAgentsSdkAdapter({model?, maxTurns?, guardrailHooks?, tools?, agentName?, signal?}).
216
214
 
217
215
  - >-
218
216
  Generated contract imports: import { agentRegistry, taskRegistry,
package/dsl/tasks.yaml CHANGED
@@ -236,10 +236,6 @@ implement-llm-feature:
236
236
  const m = await import(`${pkg}/adapters/openai-agents-sdk`);
237
237
  return new m.OpenAIAgentsSdkAdapter({ model: config.model });
238
238
  }
239
- case "gemini": {
240
- const m = await import(`${pkg}/adapters/gemini-sdk`);
241
- return new m.GeminiSdkAdapter({ apiKey: process.env.GEMINI_API_KEY, model: config.model });
242
- }
243
239
  }
244
240
  }
245
241
 
@@ -346,7 +342,7 @@ implement-llm-feature:
346
342
  arguments: [...]
347
343
  options:
348
344
  - name: adapter
349
- schema: { type: string, enum: [mock, claude, openai, gemini] }
345
+ schema: { type: string, enum: [mock, claude, openai] }
350
346
  - name: model
351
347
  schema: { type: string }
352
348
  - name: show-prompt
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-contracts-runtime",
3
- "version": "0.36.16",
3
+ "version": "0.36.17",
4
4
  "description": "Runtime bridge for executing agent-contracts workflows on Agent SDKs",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -21,10 +21,6 @@
21
21
  "types": "./dist/adapters/openai-agents-sdk.d.ts",
22
22
  "import": "./dist/adapters/openai-agents-sdk.js"
23
23
  },
24
- "./adapters/adk-sdk": {
25
- "types": "./dist/adapters/adk-sdk.d.ts",
26
- "import": "./dist/adapters/adk-sdk.js"
27
- },
28
24
  "./adapters/mock": {
29
25
  "types": "./dist/adapters/mock.d.ts",
30
26
  "import": "./dist/adapters/mock.js"
@@ -57,7 +53,8 @@
57
53
  "prepublishOnly": "npm run build && npm run bundle:min",
58
54
  "test:ci": "vitest run",
59
55
  "bundle": "node esbuild.bundle.mjs",
60
- "bundle:min": "node esbuild.bundle.mjs --minify"
56
+ "bundle:min": "node esbuild.bundle.mjs --minify",
57
+ "audit:signatures": "npx --yes npm@11.19.1 audit signatures"
61
58
  },
62
59
  "keywords": [
63
60
  "agent-contracts",
@@ -88,9 +85,8 @@
88
85
  "node": ">=22.0.0"
89
86
  },
90
87
  "dependencies": {
91
- "agent-contracts": "^0.34.0",
88
+ "agent-contracts": "^0.35.13",
92
89
  "commander": "^12.1.0",
93
- "dotenv": "^17.4.2",
94
90
  "handlebars": "^4.7.10",
95
91
  "tsx": "^4.22.0",
96
92
  "yaml": "^2.8.3",
@@ -98,7 +94,6 @@
98
94
  },
99
95
  "devDependencies": {
100
96
  "@anthropic-ai/claude-agent-sdk": "^0.3.323",
101
- "@google/adk": "^2.5.0",
102
97
  "@openai/agents": "^0.22.0",
103
98
  "@types/node": "^26.6.6",
104
99
  "cli-contracts": "^0.34.12",
@@ -109,13 +104,9 @@
109
104
  },
110
105
  "peerDependencies": {
111
106
  "@anthropic-ai/claude-agent-sdk": ">=0.2.0",
112
- "@google/adk": ">=2.2.0",
113
107
  "@openai/agents": ">=0.10.0"
114
108
  },
115
109
  "peerDependenciesMeta": {
116
- "@google/adk": {
117
- "optional": true
118
- },
119
110
  "@anthropic-ai/claude-agent-sdk": {
120
111
  "optional": true
121
112
  },
@@ -124,12 +115,6 @@
124
115
  }
125
116
  },
126
117
  "overrides": {
127
- "uuid": "^11.1.1",
128
- "@opentelemetry/core": "^2.8.0",
129
- "adm-zip": "^0.6.0",
130
- "esbuild": "$esbuild",
131
- "gcp-metadata@^8": {
132
- "gaxios": "^7.3.1"
133
- }
118
+ "esbuild": "$esbuild"
134
119
  }
135
120
  }
@@ -431,24 +431,10 @@ async function createAdapter(runtimePkg: string, name: string, config: AgentConf
431
431
  const mod = await import(`${runtimePkg}/adapters/mock`);
432
432
  return new mod.MockAdapter();
433
433
  }
434
- case "cursor": {
435
- const mod = await import(`${runtimePkg}/adapters/cursor-sdk`);
436
- const apiKey = process.env.CURSOR_API_KEY;
437
- if (!apiKey) throw new Error("CURSOR_API_KEY environment variable is required");
438
- return mod.CursorSdkAdapter.create({ apiKey, model: config.model });
439
- }
440
434
  case "openai": {
441
435
  const mod = await import(`${runtimePkg}/adapters/openai-agents-sdk`);
442
436
  return new mod.OpenAIAgentsSdkAdapter({ model: config.model, maxTurns: 1 });
443
437
  }
444
- case "gemini": {
445
- const mod = await import(`${runtimePkg}/adapters/gemini-sdk`);
446
- return new mod.GeminiSdkAdapter({
447
- apiKey: process.env.GEMINI_API_KEY,
448
- model: config.model,
449
- temperature: config.temperature,
450
- });
451
- }
452
438
  case "claude": {
453
439
  const mod = await import(`${runtimePkg}/adapters/claude-agent-sdk`);
454
440
  return new mod.ClaudeAgentSdkAdapter({
@@ -458,7 +444,7 @@ async function createAdapter(runtimePkg: string, name: string, config: AgentConf
458
444
  });
459
445
  }
460
446
  default:
461
- throw new Error(`Unsupported adapter: "${name}". Available: mock, cursor, openai, gemini, claude.`);
447
+ throw new Error(`Unsupported adapter: "${name}". Available: mock, openai, claude.`);
462
448
  }
463
449
  }
464
450
 
@@ -591,7 +577,7 @@ import { Command } from "commander";
591
577
  const audit = new Command("audit")
592
578
  .description("Semantic safety audit via LLM")
593
579
  .argument("[target]", "file or directory to audit")
594
- .option("--adapter <name>", "LLM adapter (cursor, openai, gemini, claude, mock)", "mock")
580
+ .option("--adapter <name>", "LLM adapter (openai, claude, mock)", "mock")
595
581
  .option("--model <name>", "Model name to pass to the adapter")
596
582
  .option("--show-prompt", "Output the constructed prompt without calling the LLM API")
597
583
  .option("--fail-on <level>", "Minimum severity for non-zero exit", "error")
@@ -624,7 +610,7 @@ commands:
624
610
  valueName: name
625
611
  schema:
626
612
  type: string
627
- enum: [mock, cursor, claude, openai, gemini]
613
+ enum: [mock, claude, openai]
628
614
 
629
615
  - name: model
630
616
  description: Model name to pass to the adapter.
@@ -46,7 +46,7 @@ For each command, decide:
46
46
  ```bash
47
47
  npm install --save-dev agent-contracts
48
48
  npm install --save-dev agent-contracts-runtime zod
49
- npm install --save-dev @openai/agents @cursor/sdk # adapter SDKs
49
+ npm install --save-dev @openai/agents # adapter SDKs
50
50
  ```
51
51
 
52
52
  ### Phase 3: Create DSL definitions
@@ -104,7 +104,7 @@ Critical implementation details:
104
104
 
105
105
  **orchestrator.ts**:
106
106
  - Dynamic-import `agent-contracts-runtime` so the tool works without it installed (graceful degradation)
107
- - Dynamic-import adapter packages (`/adapters/cursor-sdk`, `/adapters/openai-agents-sdk`, etc.)
107
+ - Dynamic-import adapter packages (`/adapters/openai-agents-sdk`, `/adapters/claude-agent-sdk`, etc.)
108
108
  - Import generated DSL registries (including `workflowRegistry`) and pass to `runWorkflow()` — NEVER use `runTask()` (low-level internal API)
109
109
  - Support `--show-prompt` by returning the prompt without calling the LLM
110
110
  - Use exit codes: 0 = success, 1 = error, 10 = findings, 11 = runtime missing, 12 = adapter error
@@ -135,7 +135,7 @@ export async function command{Name}(config, target, opts) {
135
135
  ```
136
136
 
137
137
  Register in CLI with the **cli-contracts standard LLM command options**:
138
- - `--adapter <name>` — LLM adapter (cursor, openai, gemini, claude, mock)
138
+ - `--adapter <name>` — LLM adapter (openai, claude, mock)
139
139
  - `--model <name>` — Model name to pass to the adapter
140
140
  - `--show-prompt` — Output the constructed prompt without calling the LLM API
141
141
  - `--fail-on <level>` — Minimum severity that causes a non-zero exit (warning, error, critical)
@@ -1,129 +0,0 @@
1
- import { SdkAdapter, CacheConfig, AdapterSendOptions, AgentExecutionRequest, MemoryRef } from '../index.js';
2
- import { GuardrailHooks } from '../index.js';
3
- import 'zod';
4
-
5
- /**
6
- * Google ADK Adapter — implements SdkAdapter for @google/adk (ADK-TS / adk-js)
7
- *
8
- * Replaces the raw @google/genai adapter. ADK provides a native subagent
9
- * mechanism (`LlmAgent.subAgents` + description-based agent transfer), which is
10
- * required for model B (LLM-internal routing): the entry agent's LLM delegates
11
- * to candidate sub-agents registered in the agent tree.
12
- *
13
- * Supports:
14
- * - send() — build a root LlmAgent (+ candidate subAgents), run once,
15
- * return the final response text
16
- * - sendExecution() — rich path using full contract context
17
- *
18
- * No followUp(): ADK's InMemoryRunner uses ephemeral sessions, so the runtime's
19
- * recovery loop falls back to a fresh send() with reconstructed context.
20
- *
21
- * API used (verified against the installed package's type definitions under
22
- * node_modules/@google/adk/dist/types):
23
- * - class LlmAgent (agents/llm_agent.d.ts): constructor(config) where config
24
- * extends BaseAgentConfig { name; description?; subAgents?: BaseAgent[] }
25
- * and adds { model?: string | BaseLlm; instruction?: string; tools? }.
26
- * - class InMemoryRunner (runner/in_memory_runner.d.ts): constructor({ agent,
27
- * appName? }); inherits runEphemeral({ userId, newMessage: Content })
28
- * returning AsyncGenerator<Event> (runner/runner.d.ts).
29
- * - isFinalResponse(event) / stringifyContent(event) (events/event.d.ts).
30
- * - class Gemini (models/google_llm.d.ts): constructor({ model, apiKey })
31
- * — used to inject an explicit API key; otherwise ADK reads
32
- * GOOGLE_GENAI_API_KEY / GEMINI_API_KEY from the environment.
33
- */
34
-
35
- type AdkContentPart = {
36
- text?: string;
37
- functionCall?: {
38
- name?: string;
39
- args?: Record<string, unknown>;
40
- };
41
- functionResponse?: {
42
- name?: string;
43
- response?: unknown;
44
- };
45
- };
46
- type AdkContent = {
47
- role?: string;
48
- parts?: AdkContentPart[];
49
- };
50
- type AdkEvent = {
51
- author?: string;
52
- content?: AdkContent;
53
- [key: string]: unknown;
54
- };
55
- type LlmAgentConfig = {
56
- name: string;
57
- description?: string;
58
- model?: string | object;
59
- instruction?: string;
60
- tools?: unknown[];
61
- subAgents?: unknown[];
62
- };
63
- type LlmAgentInstance = object;
64
- type LlmAgentConstructor = new (config: LlmAgentConfig) => LlmAgentInstance;
65
- type RunnerInstance = {
66
- runEphemeral(params: {
67
- userId: string;
68
- newMessage: AdkContent;
69
- stateDelta?: Record<string, unknown>;
70
- }): AsyncGenerator<AdkEvent, void, unknown>;
71
- };
72
- type InMemoryRunnerConstructor = new (params: {
73
- agent: LlmAgentInstance;
74
- appName?: string;
75
- }) => RunnerInstance;
76
- type GeminiConstructor = new (params: {
77
- model?: string;
78
- apiKey?: string;
79
- }) => object;
80
- interface AdkSdk {
81
- LlmAgent: LlmAgentConstructor;
82
- InMemoryRunner: InMemoryRunnerConstructor;
83
- isFinalResponse: (event: AdkEvent) => boolean;
84
- stringifyContent: (event: AdkEvent) => string;
85
- Gemini: GeminiConstructor;
86
- }
87
- interface AdkSdkAdapterConfig {
88
- /** API key for the Gemini API. Falls back to GOOGLE_GENAI_API_KEY / GEMINI_API_KEY env. */
89
- apiKey?: string;
90
- /** Gemini model identifier (e.g. "gemini-2.5-flash", "gemini-2.5-pro"). */
91
- model?: string;
92
- /** Root agent name (must be a JS identifier). Defaults to "root_agent". */
93
- rootAgentName?: string;
94
- /** Runtime guardrail hooks. Applied as input-level checks before agent execution. */
95
- guardrailHooks?: GuardrailHooks;
96
- /** Prompt caching configuration. Enabled by default. */
97
- cacheConfig?: CacheConfig;
98
- }
99
- declare class AdkSdkAdapter implements SdkAdapter {
100
- private apiKey;
101
- private model;
102
- private rootAgentName;
103
- private guardrailHooks;
104
- private cacheConfig;
105
- private lastMemoryRef;
106
- private runCounter;
107
- private sdk;
108
- constructor(config?: AdkSdkAdapterConfig);
109
- private resolveSdk;
110
- /** Resolve the `model` field for LlmAgent — a Gemini instance when an explicit
111
- * API key is supplied, otherwise the bare model id (ADK reads env keys). */
112
- private resolveModel;
113
- /** Build the root LlmAgent with candidate sub-agents registered for transfer. */
114
- private buildRootAgent;
115
- private runAgent;
116
- private nextMemoryRef;
117
- send(prompt: string, options: AdapterSendOptions): Promise<string>;
118
- sendExecution(request: AgentExecutionRequest): Promise<string>;
119
- getLastMemoryRef(): MemoryRef | null;
120
- isCompatible(compat: string): boolean;
121
- /**
122
- * Inject the resolved ADK SDK surface for testing.
123
- * Bypasses the dynamic import of @google/adk and the API key requirement.
124
- */
125
- static withSdk(sdk: AdkSdk, config?: AdkSdkAdapterConfig): AdkSdkAdapter;
126
- }
127
-
128
- export { AdkSdkAdapter };
129
- export type { AdkSdkAdapterConfig };
@@ -1,185 +0,0 @@
1
- import {
2
- getBlockingViolations
3
- } from "../chunk-M57HVYUU.js";
4
-
5
- // src/adapters/adk-sdk.ts
6
- function sanitizeAgentName(name) {
7
- let id = name.replace(/[^a-zA-Z0-9_]/g, "_");
8
- if (id.length === 0 || /^[0-9]/.test(id)) id = `agent_${id}`;
9
- if (id === "user") id = "user_agent";
10
- return id;
11
- }
12
- function extractEventText(event) {
13
- const parts = event.content?.parts;
14
- if (!parts) return "";
15
- return parts.map((p) => p.text ?? "").join("");
16
- }
17
- var AdkSdkAdapter = class _AdkSdkAdapter {
18
- apiKey;
19
- model;
20
- rootAgentName;
21
- guardrailHooks;
22
- cacheConfig;
23
- lastMemoryRef = null;
24
- runCounter = 0;
25
- sdk = null;
26
- constructor(config = {}) {
27
- this.apiKey = config.apiKey;
28
- this.model = config.model ?? "gemini-2.5-flash";
29
- this.rootAgentName = config.rootAgentName ?? "root_agent";
30
- this.guardrailHooks = config.guardrailHooks;
31
- this.cacheConfig = config.cacheConfig ?? { enabled: true };
32
- }
33
- // -------------------------------------------------------------------------
34
- // Internal helpers
35
- // -------------------------------------------------------------------------
36
- async resolveSdk() {
37
- if (this.sdk) return this.sdk;
38
- const mod = await import("@google/adk");
39
- this.sdk = {
40
- LlmAgent: mod.LlmAgent,
41
- InMemoryRunner: mod.InMemoryRunner,
42
- isFinalResponse: mod.isFinalResponse,
43
- stringifyContent: mod.stringifyContent,
44
- Gemini: mod.Gemini
45
- };
46
- return this.sdk;
47
- }
48
- /** Resolve the `model` field for LlmAgent — a Gemini instance when an explicit
49
- * API key is supplied, otherwise the bare model id (ADK reads env keys). */
50
- resolveModel(sdk) {
51
- if (this.apiKey) {
52
- return new sdk.Gemini({ model: this.model, apiKey: this.apiKey });
53
- }
54
- return this.model;
55
- }
56
- /** Build the root LlmAgent with candidate sub-agents registered for transfer. */
57
- buildRootAgent(sdk, instruction, agents) {
58
- const subAgents = (agents ?? []).map((a) => {
59
- const config = {
60
- name: sanitizeAgentName(a.name),
61
- description: a.description,
62
- instruction: a.prompt,
63
- model: a.model ?? this.resolveModel(sdk)
64
- };
65
- if (a.tools) config.tools = a.tools;
66
- return new sdk.LlmAgent(config);
67
- });
68
- const rootConfig = {
69
- name: sanitizeAgentName(this.rootAgentName),
70
- instruction,
71
- model: this.resolveModel(sdk)
72
- };
73
- if (subAgents.length > 0) rootConfig.subAgents = subAgents;
74
- return new sdk.LlmAgent(rootConfig);
75
- }
76
- async runAgent(instruction, userMessage, agents, onProgress) {
77
- if (this.guardrailHooks) {
78
- const results = this.guardrailHooks.runChecks({ command: userMessage });
79
- const blocking = getBlockingViolations(results);
80
- if (blocking.length > 0) {
81
- const msg = blocking.map((r) => `[${r.guardrail_id}] ${r.message}`).join("\n");
82
- throw new Error(msg);
83
- }
84
- }
85
- const sdk = await this.resolveSdk();
86
- const root = this.buildRootAgent(sdk, instruction, agents);
87
- const runner = new sdk.InMemoryRunner({ agent: root });
88
- let finalText = "";
89
- const stream = runner.runEphemeral({
90
- userId: "agent-runtime",
91
- newMessage: { role: "user", parts: [{ text: userMessage }] }
92
- });
93
- for await (const event of stream) {
94
- if (onProgress) emitProgressFromAdkEvent(event, onProgress);
95
- const ev = event;
96
- if (ev.errorCode || ev.errorMessage) {
97
- throw new Error(
98
- `Gemini API error (${ev.errorCode ?? "unknown"}): ${ev.errorMessage ?? "no details"}`
99
- );
100
- }
101
- if (sdk.isFinalResponse(event) && event.content) {
102
- const text = sdk.stringifyContent(event) || extractEventText(event);
103
- if (text) finalText = text;
104
- }
105
- }
106
- return finalText;
107
- }
108
- nextMemoryRef() {
109
- return {
110
- id: `adk-run-${++this.runCounter}-${Date.now()}`,
111
- provider: "google-adk",
112
- compat: `google-adk@${this.model}`,
113
- created_at: (/* @__PURE__ */ new Date()).toISOString()
114
- };
115
- }
116
- // -------------------------------------------------------------------------
117
- // SdkAdapter interface
118
- // -------------------------------------------------------------------------
119
- async send(prompt, options) {
120
- this.lastMemoryRef = null;
121
- const split = options.splitPrompt;
122
- let instruction = "";
123
- let userMessage;
124
- if (split && this.cacheConfig.enabled !== false) {
125
- instruction = split.system.join("\n\n---\n\n");
126
- userMessage = split.user;
127
- } else {
128
- userMessage = prompt;
129
- }
130
- const text = await this.runAgent(instruction, userMessage, options.agents, options.onProgress);
131
- this.lastMemoryRef = this.nextMemoryRef();
132
- return text;
133
- }
134
- async sendExecution(request) {
135
- this.lastMemoryRef = null;
136
- const split = request.splitPrompt;
137
- let instruction = "";
138
- let userMessage;
139
- if (split && this.cacheConfig.enabled !== false) {
140
- instruction = split.system.join("\n\n---\n\n");
141
- userMessage = split.user;
142
- } else {
143
- userMessage = request.prompt;
144
- }
145
- const agents = request.options.agents ?? request.agents;
146
- const text = await this.runAgent(instruction, userMessage, agents, request.options.onProgress);
147
- this.lastMemoryRef = this.nextMemoryRef();
148
- return text;
149
- }
150
- getLastMemoryRef() {
151
- return this.lastMemoryRef;
152
- }
153
- isCompatible(compat) {
154
- return compat.startsWith("google-adk@");
155
- }
156
- // -------------------------------------------------------------------------
157
- // Test support
158
- // -------------------------------------------------------------------------
159
- /**
160
- * Inject the resolved ADK SDK surface for testing.
161
- * Bypasses the dynamic import of @google/adk and the API key requirement.
162
- */
163
- static withSdk(sdk, config) {
164
- const adapter = new _AdkSdkAdapter(config);
165
- adapter.sdk = sdk;
166
- return adapter;
167
- }
168
- };
169
- function emitProgressFromAdkEvent(event, onProgress) {
170
- const parts = event.content?.parts;
171
- if (!parts) return;
172
- for (const part of parts) {
173
- if (part.functionCall?.name) {
174
- onProgress({ type: "tool_use", tool_name: part.functionCall.name, input: part.functionCall.args });
175
- } else if (part.functionResponse?.name) {
176
- onProgress({ type: "tool_result", tool_name: part.functionResponse.name });
177
- } else if (part.text) {
178
- onProgress({ type: "text", message: part.text });
179
- }
180
- }
181
- }
182
- export {
183
- AdkSdkAdapter
184
- };
185
- //# sourceMappingURL=adk-sdk.js.map