@aaac/runtime 0.3.1 → 0.3.3

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.
Files changed (41) hide show
  1. package/README.md +1 -1
  2. package/bin/dev-team.mjs +6018 -0
  3. package/dist/adapters/claude-agent-sdk.d.ts +1 -1
  4. package/dist/adapters/claude-agent-sdk.js +1 -1
  5. package/dist/adapters/mock.d.ts +1 -1
  6. package/dist/adapters/openai-agents-sdk.d.ts +1 -1
  7. package/dist/adapters/openai-agents-sdk.js +2 -2
  8. package/dist/{chunk-BHTHXGA3.js → chunk-4RFPLCKG.js} +7 -6
  9. package/dist/{chunk-BHTHXGA3.js.map → chunk-4RFPLCKG.js.map} +1 -1
  10. package/dist/{chunk-N2EA3TGS.js → chunk-BLPWSV4T.js} +7 -3
  11. package/dist/chunk-BLPWSV4T.js.map +1 -0
  12. package/dist/{chunk-EBMQHLXY.js → chunk-CRKN7CIO.js} +2 -2
  13. package/dist/{chunk-KTVMMG33.js → chunk-DX3RJTWJ.js} +2 -17
  14. package/dist/{chunk-KTVMMG33.js.map → chunk-DX3RJTWJ.js.map} +1 -1
  15. package/dist/{chunk-GGBNVCPV.js → chunk-EYK4E3XE.js} +3 -3
  16. package/dist/{chunk-5ZDW4RP7.js → chunk-K5XDDJFK.js} +2 -2
  17. package/dist/{chunk-2SG3TBI3.js → chunk-QQTFYLUX.js} +2 -2
  18. package/dist/{chunk-EA4V5DVD.js → chunk-RIXKPQFC.js} +1 -2
  19. package/dist/{chunk-EA4V5DVD.js.map → chunk-RIXKPQFC.js.map} +1 -1
  20. package/dist/claude-bundles/full.js +1 -1
  21. package/dist/claude-bundles/lean.js +1 -1
  22. package/dist/generator/index.js +2 -2
  23. package/dist/{hooks-lite-BtOGc2F_.d.ts → hooks-lite-inKV2rv8.d.ts} +5 -5
  24. package/dist/index.d.ts +16 -9
  25. package/dist/index.js +110 -139
  26. package/dist/index.js.map +1 -1
  27. package/dist/lib/claude-native/hooks-lite.d.ts +1 -1
  28. package/dist/lib/claude-native/hooks-lite.js +4 -4
  29. package/dist/lib/claude-native/hooks-prompt.js +4 -4
  30. package/dist/lib/claude-native/index.d.ts +1 -1
  31. package/dist/lib/claude-native/index.js +7 -7
  32. package/dist/{task-runner-CgQx1KUq.d.ts → task-runner-Cpr-GTrl.d.ts} +4 -6
  33. package/package.json +10 -18
  34. package/dist/adapters/adk-sdk.d.ts +0 -139
  35. package/dist/adapters/adk-sdk.js +0 -312
  36. package/dist/adapters/adk-sdk.js.map +0 -1
  37. package/dist/chunk-N2EA3TGS.js.map +0 -1
  38. /package/dist/{chunk-EBMQHLXY.js.map → chunk-CRKN7CIO.js.map} +0 -0
  39. /package/dist/{chunk-GGBNVCPV.js.map → chunk-EYK4E3XE.js.map} +0 -0
  40. /package/dist/{chunk-5ZDW4RP7.js.map → chunk-K5XDDJFK.js.map} +0 -0
  41. /package/dist/{chunk-2SG3TBI3.js.map → chunk-QQTFYLUX.js.map} +0 -0
@@ -1,3 +1,3 @@
1
1
  export { a as HookEventName, b as HookInput, H as HookOutput, P as PermissionDecision, c as PreToolUseInput, S as SessionStartInput, U as UserPromptSubmitInput, f as buildContextResponse, e as emitHookOutput, r as readHookInput } from '../../hook-protocol-BH86kCQB.js';
2
- export { A as ArtifactMatch, C as CacheEntry, a as CacheStore, b as CacheStoreOptions, D as DEFAULT_CACHE_KEY, d as FreshNavigationBuild, N as NavigationArtifact, P as PreToolUseHandlerConfig, W as WorkspaceFileSuggestionMember, f as WorkspaceMemberPreToolUseConfig, g as WorkspacePreToolUseConfig, j as createCacheStore, k as createPreToolUseHandler, l as createWorkspacePreToolUseHandler, o as handleFileSuggestion, p as handleWorkspaceFileSuggestion, q as isCachedRecord, s as listArtifacts, t as readFreshNavigationBuild } from '../../hooks-lite-BtOGc2F_.js';
2
+ export { A as ArtifactMatch, C as CacheEntry, a as CacheStore, b as CacheStoreOptions, D as DEFAULT_CACHE_KEY, d as FreshNavigationBuild, N as NavigationArtifact, P as PreToolUseHandlerConfig, W as WorkspaceFileSuggestionMember, f as WorkspaceMemberPreToolUseConfig, g as WorkspacePreToolUseConfig, j as createCacheStore, k as createPreToolUseHandler, l as createWorkspacePreToolUseHandler, o as handleFileSuggestion, p as handleWorkspaceFileSuggestion, q as isCachedRecord, s as listArtifacts, t as readFreshNavigationBuild } from '../../hooks-lite-inKV2rv8.js';
3
3
  import '../../guardrail-hooks-BgHe8PrP.js';
@@ -3,7 +3,7 @@ import {
3
3
  createWorkspacePreToolUseHandler,
4
4
  handleFileSuggestion,
5
5
  handleWorkspaceFileSuggestion
6
- } from "../../chunk-BHTHXGA3.js";
6
+ } from "../../chunk-4RFPLCKG.js";
7
7
  import {
8
8
  DEFAULT_CACHE_KEY,
9
9
  buildContextResponse,
@@ -12,11 +12,11 @@ import {
12
12
  isCachedRecord,
13
13
  readFreshNavigationBuild,
14
14
  readHookInput
15
- } from "../../chunk-2SG3TBI3.js";
15
+ } from "../../chunk-QQTFYLUX.js";
16
16
  import {
17
17
  listArtifacts
18
- } from "../../chunk-EBMQHLXY.js";
19
- import "../../chunk-EA4V5DVD.js";
18
+ } from "../../chunk-CRKN7CIO.js";
19
+ import "../../chunk-RIXKPQFC.js";
20
20
  import "../../chunk-BJ7B4R26.js";
21
21
  export {
22
22
  DEFAULT_CACHE_KEY,
@@ -6,7 +6,7 @@ import {
6
6
  renderMemberSection,
7
7
  renderNavigationDiagnostics,
8
8
  runEnsureNavigationIndexBin
9
- } from "../../chunk-GGBNVCPV.js";
9
+ } from "../../chunk-EYK4E3XE.js";
10
10
  import {
11
11
  isNavigationIndex,
12
12
  renderNavigationIndexPrompt
@@ -14,9 +14,9 @@ import {
14
14
  import {
15
15
  emitHookOutput,
16
16
  readHookInput
17
- } from "../../chunk-2SG3TBI3.js";
18
- import "../../chunk-EBMQHLXY.js";
19
- import "../../chunk-EA4V5DVD.js";
17
+ } from "../../chunk-QQTFYLUX.js";
18
+ import "../../chunk-CRKN7CIO.js";
19
+ import "../../chunk-RIXKPQFC.js";
20
20
  import "../../chunk-BJ7B4R26.js";
21
21
  export {
22
22
  createUserPromptSubmitHandler,
@@ -1,6 +1,6 @@
1
1
  import { S as SessionStartInput, H as HookOutput } from '../../hook-protocol-BH86kCQB.js';
2
2
  export { a as HookEventName, b as HookInput, P as PermissionDecision, c as PreToolUseInput, U as UserPromptSubmitInput, d as buildAllowResponse, f as buildContextResponse, g as buildDenyResponse, e as emitHookOutput, p as parseHookInput, r as readHookInput } from '../../hook-protocol-BH86kCQB.js';
3
- export { A as ArtifactMatch, C as CacheEntry, a as CacheStore, b as CacheStoreOptions, D as DEFAULT_CACHE_KEY, F as FileSuggestionCandidate, c as FileSuggestionOptions, d as FreshNavigationBuild, N as NavigationArtifact, P as PreToolUseHandlerConfig, W as WorkspaceFileSuggestionMember, e as WorkspaceMember, f as WorkspaceMemberPreToolUseConfig, g as WorkspacePreToolUseConfig, h as computeCurrentHash, i as computeSourceHash, j as createCacheStore, k as createPreToolUseHandler, l as createWorkspacePreToolUseHandler, m as formatNdjson, n as generateCandidates, o as handleFileSuggestion, p as handleWorkspaceFileSuggestion, q as isCachedRecord, r as isProtectedArtifact, s as listArtifacts, t as readFreshNavigationBuild, u as resolvePathToArtifacts, v as routePathToMember, w as stripMemberPrefix } from '../../hooks-lite-BtOGc2F_.js';
3
+ export { A as ArtifactMatch, C as CacheEntry, a as CacheStore, b as CacheStoreOptions, D as DEFAULT_CACHE_KEY, F as FileSuggestionCandidate, c as FileSuggestionOptions, d as FreshNavigationBuild, N as NavigationArtifact, P as PreToolUseHandlerConfig, W as WorkspaceFileSuggestionMember, e as WorkspaceMember, f as WorkspaceMemberPreToolUseConfig, g as WorkspacePreToolUseConfig, h as computeCurrentHash, i as computeSourceHash, j as createCacheStore, k as createPreToolUseHandler, l as createWorkspacePreToolUseHandler, m as formatNdjson, n as generateCandidates, o as handleFileSuggestion, p as handleWorkspaceFileSuggestion, q as isCachedRecord, r as isProtectedArtifact, s as listArtifacts, t as readFreshNavigationBuild, u as resolvePathToArtifacts, v as routePathToMember, w as stripMemberPrefix } from '../../hooks-lite-inKV2rv8.js';
4
4
  import { N as NavigationContextOptions } from '../../navigation-context-DJjCkrcj.js';
5
5
  import { i as EnsureNavigationIndexOptions, j as WorkspaceMemberNavConfig, a as WorkspaceMemberNavResult } from '../../workspace-user-prompt-submit-GZwUKUHi.js';
6
6
  export { E as EnsureBinOutput, N as NavigationDiagnostic, k as NavigationIndexResult, U as UserPromptSubmitHandlerConfig, W as WorkspaceMemberCacheConfig, b as WorkspaceUserPromptSubmitConfig, c as createUserPromptSubmitHandler, d as createWorkspaceUserPromptSubmitHandler, l as ensureNavigationIndex, r as readFreshMemberIndices, f as renderMemberSection, g as renderNavigationDiagnostics, h as runEnsureNavigationIndexBin } from '../../workspace-user-prompt-submit-GZwUKUHi.js';
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  buildNavigationContext,
3
3
  resolveNavigationSources
4
- } from "../../chunk-N2EA3TGS.js";
4
+ } from "../../chunk-BLPWSV4T.js";
5
5
  import "../../chunk-ET6TGQRT.js";
6
- import "../../chunk-5ZDW4RP7.js";
6
+ import "../../chunk-K5XDDJFK.js";
7
7
  import {
8
8
  createPreToolUseHandler,
9
9
  createWorkspacePreToolUseHandler,
@@ -13,7 +13,7 @@ import {
13
13
  handleWorkspaceFileSuggestion,
14
14
  routePathToMember,
15
15
  stripMemberPrefix
16
- } from "../../chunk-BHTHXGA3.js";
16
+ } from "../../chunk-4RFPLCKG.js";
17
17
  import {
18
18
  createUserPromptSubmitHandler,
19
19
  createWorkspaceUserPromptSubmitHandler,
@@ -21,7 +21,7 @@ import {
21
21
  renderMemberSection,
22
22
  renderNavigationDiagnostics,
23
23
  runEnsureNavigationIndexBin
24
- } from "../../chunk-GGBNVCPV.js";
24
+ } from "../../chunk-EYK4E3XE.js";
25
25
  import {
26
26
  renderNavigationIndexPrompt
27
27
  } from "../../chunk-3CLWG72V.js";
@@ -39,13 +39,13 @@ import {
39
39
  parseHookInput,
40
40
  readFreshNavigationBuild,
41
41
  readHookInput
42
- } from "../../chunk-2SG3TBI3.js";
42
+ } from "../../chunk-QQTFYLUX.js";
43
43
  import {
44
44
  isProtectedArtifact,
45
45
  listArtifacts,
46
46
  resolvePathToArtifacts
47
- } from "../../chunk-EBMQHLXY.js";
48
- import "../../chunk-EA4V5DVD.js";
47
+ } from "../../chunk-CRKN7CIO.js";
48
+ import "../../chunk-RIXKPQFC.js";
49
49
  import "../../chunk-BJ7B4R26.js";
50
50
 
51
51
  // src/lib/claude-native/latency.ts
@@ -23,9 +23,9 @@ interface MemoryRef {
23
23
  /**
24
24
  * Pluggable store for memory content that backs MemoryRef pointers.
25
25
  *
26
- * Adapters that use server-side state (OpenAI, Gemini) may not need
26
+ * Adapters that use server-side state (OpenAI) may not need
27
27
  * the store — the ref ID alone is sufficient for resume. Adapters
28
- * with local state (Claude transcript, Gemini chat history) use the
28
+ * with local state (Claude transcript) use the
29
29
  * store to persist and retrieve content.
30
30
  */
31
31
  interface MemoryStore {
@@ -265,7 +265,6 @@ declare function emitToolchainClose(observer: ObserverEmitFn | undefined, spanId
265
265
  * Each adapter receives tools in its native format:
266
266
  * - Claude Agent SDK: MCP tool via createSdkMcpServer + tool()
267
267
  * - OpenAI Agents SDK: function tool object
268
- * - Google ADK: FunctionDeclaration tool
269
268
  */
270
269
 
271
270
  /**
@@ -337,7 +336,6 @@ declare function adapterErrorKind(error: unknown): AdapterErrorKind;
337
336
  *
338
337
  * - Claude `Options.agents: Record<string, AgentDefinition>`
339
338
  * - OpenAI `Agent.handoffs: Agent[]`
340
- * - ADK `LlmAgent.subAgents: BaseAgent[]`
341
339
  *
342
340
  * `CandidateAgent` is the common, SDK-independent contract. Each adapter maps it
343
341
  * onto its provider's native shape. The selection rule (which agents become
@@ -600,7 +598,7 @@ interface AdapterSendOptions {
600
598
  /**
601
599
  * Candidate sub-agents the entry agent's LLM may delegate to (model B,
602
600
  * LLM-internal routing). Adapters register these via their native subagent
603
- * mechanism (Claude `agents`, OpenAI `handoffs`, ADK `subAgents`). When
601
+ * mechanism (Claude `agents`, OpenAI `handoffs`). When
604
602
  * omitted or empty, adapters behave exactly as before (single agent).
605
603
  */
606
604
  agents?: CandidateAgent[];
@@ -613,7 +611,7 @@ interface AdapterSendOptions {
613
611
  /**
614
612
  * In-process library tools to register with the SDK as function tools.
615
613
  * Adapters convert these to their native tool format (Claude MCP, OpenAI
616
- * function tools, ADK tools). I/O is validated against the tool's schemas.
614
+ * function tools). I/O is validated against the tool's schemas.
617
615
  */
618
616
  libraryTools?: LibraryToolRegistry;
619
617
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aaac/runtime",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Runtime SDK for the AaaC toolchain",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -18,10 +18,6 @@
18
18
  "types": "./dist/adapters/openai-agents-sdk.d.ts",
19
19
  "import": "./dist/adapters/openai-agents-sdk.js"
20
20
  },
21
- "./adapters/adk-sdk": {
22
- "types": "./dist/adapters/adk-sdk.d.ts",
23
- "import": "./dist/adapters/adk-sdk.js"
24
- },
25
21
  "./adapters/mock": {
26
22
  "types": "./dist/adapters/mock.d.ts",
27
23
  "import": "./dist/adapters/mock.js"
@@ -45,6 +41,7 @@
45
41
  },
46
42
  "files": [
47
43
  "dist/",
44
+ "bin/",
48
45
  "README.md",
49
46
  "LICENSE"
50
47
  ],
@@ -53,7 +50,9 @@
53
50
  "clean": "rm -rf dist",
54
51
  "typecheck": "tsc -p tsconfig.typecheck.json",
55
52
  "test": "vitest run",
56
- "prepublishOnly": "npm run clean && npm run build"
53
+ "prepublishOnly": "npm run clean && npm run build",
54
+ "prepack": "node scripts/pack-cli.mjs",
55
+ "postpack": "node scripts/pack-cli.mjs --clean"
57
56
  },
58
57
  "publishConfig": {
59
58
  "access": "public"
@@ -68,26 +67,19 @@
68
67
  "node": ">=22.0.0"
69
68
  },
70
69
  "dependencies": {
71
- "@aaac/contracts": "^0.3.1",
72
- "@aaac/observability": "^0.3.1",
73
- "@aaac/toolchain": "^0.3.1",
70
+ "@aaac/contracts": "^0.3.3",
71
+ "@aaac/observability": "^0.3.3",
72
+ "@aaac/toolchain": "^0.3.3",
74
73
  "agent-contracts": "^0.35.9",
75
- "commander": "^12.1.0",
76
- "dotenv": "^17.4.2",
77
- "tsx": "^4.22.0",
78
74
  "yaml": "^2.8.3",
79
75
  "zod": "^4.6.7"
80
76
  },
81
77
  "peerDependencies": {
82
78
  "@anthropic-ai/claude-agent-sdk": ">=0.2.0",
83
- "@google/adk": ">=2.2.0",
84
79
  "@openai/agents": ">=0.10.0",
85
- "artifact-contracts-analyzer": ">=0.3.9"
80
+ "artifact-contracts-analyzer": ">=0.3.11"
86
81
  },
87
82
  "peerDependenciesMeta": {
88
- "@google/adk": {
89
- "optional": true
90
- },
91
83
  "@anthropic-ai/claude-agent-sdk": {
92
84
  "optional": true
93
85
  },
@@ -100,7 +92,7 @@
100
92
  },
101
93
  "devDependencies": {
102
94
  "@opentelemetry/api": "^1.9.1",
103
- "artifact-contracts-analyzer": "^0.3.9",
95
+ "artifact-contracts-analyzer": "^0.3.11",
104
96
  "esbuild": "^0.28.0",
105
97
  "handlebars": "^4.7.10",
106
98
  "tsup": "^8.5.0",
@@ -1,139 +0,0 @@
1
- import { S as SdkAdapter, C as CacheConfig, A as AdapterSendOptions, a as AgentExecutionRequest, M as MemoryRef, T as TokenUsage } from '../task-runner-CgQx1KUq.js';
2
- import { G as GuardrailHooks } from '../guardrail-hooks-BgHe8PrP.js';
3
- import 'zod';
4
- import '@aaac/contracts';
5
- import '@aaac/observability';
6
-
7
- /**
8
- * Google ADK Adapter — implements SdkAdapter for @google/adk (ADK-TS / adk-js)
9
- *
10
- * Replaces the raw @google/genai adapter. ADK provides a native subagent
11
- * mechanism (`LlmAgent.subAgents` + description-based agent transfer), which is
12
- * required for model B (LLM-internal routing): the entry agent's LLM delegates
13
- * to candidate sub-agents registered in the agent tree.
14
- *
15
- * Supports:
16
- * - send() — build a root LlmAgent (+ candidate subAgents), run once,
17
- * return the final response text
18
- * - sendExecution() — rich path using full contract context
19
- *
20
- * No followUp(): ADK's InMemoryRunner uses ephemeral sessions, so the runtime's
21
- * recovery loop falls back to a fresh send() with reconstructed context.
22
- *
23
- * API used (verified against the installed package's type definitions under
24
- * node_modules/@google/adk/dist/types):
25
- * - class LlmAgent (agents/llm_agent.d.ts): constructor(config) where config
26
- * extends BaseAgentConfig { name; description?; subAgents?: BaseAgent[] }
27
- * and adds { model?: string | BaseLlm; instruction?: string; tools? }.
28
- * - class InMemoryRunner (runner/in_memory_runner.d.ts): constructor({ agent,
29
- * appName? }); inherits runEphemeral({ userId, newMessage: Content })
30
- * returning AsyncGenerator<Event> (runner/runner.d.ts).
31
- * - isFinalResponse(event) / stringifyContent(event) (events/event.d.ts).
32
- * - class Gemini (models/google_llm.d.ts): constructor({ model, apiKey })
33
- * — used to inject an explicit API key; otherwise ADK reads
34
- * GOOGLE_GENAI_API_KEY / GEMINI_API_KEY from the environment.
35
- */
36
-
37
- type AdkContentPart = {
38
- text?: string;
39
- functionCall?: {
40
- name?: string;
41
- args?: Record<string, unknown>;
42
- };
43
- functionResponse?: {
44
- name?: string;
45
- response?: unknown;
46
- };
47
- };
48
- type AdkContent = {
49
- role?: string;
50
- parts?: AdkContentPart[];
51
- };
52
- type AdkEvent = {
53
- author?: string;
54
- content?: AdkContent;
55
- usageMetadata?: {
56
- promptTokenCount?: number;
57
- candidatesTokenCount?: number;
58
- totalTokenCount?: number;
59
- cachedContentTokenCount?: number;
60
- };
61
- [key: string]: unknown;
62
- };
63
- type LlmAgentConfig = {
64
- name: string;
65
- description?: string;
66
- model?: string | object;
67
- instruction?: string;
68
- tools?: unknown[];
69
- subAgents?: unknown[];
70
- };
71
- type LlmAgentInstance = object;
72
- type LlmAgentConstructor = new (config: LlmAgentConfig) => LlmAgentInstance;
73
- type RunnerInstance = {
74
- runEphemeral(params: {
75
- userId: string;
76
- newMessage: AdkContent;
77
- stateDelta?: Record<string, unknown>;
78
- }): AsyncGenerator<AdkEvent, void, unknown>;
79
- };
80
- type InMemoryRunnerConstructor = new (params: {
81
- agent: LlmAgentInstance;
82
- appName?: string;
83
- }) => RunnerInstance;
84
- type GeminiConstructor = new (params: {
85
- model?: string;
86
- apiKey?: string;
87
- }) => object;
88
- interface AdkSdk {
89
- LlmAgent: LlmAgentConstructor;
90
- InMemoryRunner: InMemoryRunnerConstructor;
91
- isFinalResponse: (event: AdkEvent) => boolean;
92
- stringifyContent: (event: AdkEvent) => string;
93
- Gemini: GeminiConstructor;
94
- }
95
- interface AdkSdkAdapterConfig {
96
- /** API key for the Gemini API. Falls back to GOOGLE_GENAI_API_KEY / GEMINI_API_KEY env. */
97
- apiKey?: string;
98
- /** Gemini model identifier (e.g. "gemini-2.5-flash", "gemini-2.5-pro"). */
99
- model?: string;
100
- /** Root agent name (must be a JS identifier). Defaults to "root_agent". */
101
- rootAgentName?: string;
102
- /** Runtime guardrail hooks. Applied as input-level checks before agent execution. */
103
- guardrailHooks?: GuardrailHooks;
104
- /** Prompt caching configuration. Enabled by default. */
105
- cacheConfig?: CacheConfig;
106
- }
107
- declare class AdkSdkAdapter implements SdkAdapter {
108
- private apiKey;
109
- private model;
110
- private rootAgentName;
111
- private guardrailHooks;
112
- private cacheConfig;
113
- private lastMemoryRef;
114
- private lastTokenUsage;
115
- private runCounter;
116
- private sdk;
117
- constructor(config?: AdkSdkAdapterConfig);
118
- private resolveSdk;
119
- /** Resolve the `model` field for LlmAgent — a Gemini instance when an explicit
120
- * API key is supplied, otherwise the bare model id (ADK reads env keys). */
121
- private resolveModel;
122
- /** Build the root LlmAgent with candidate sub-agents registered for transfer. */
123
- private buildRootAgent;
124
- private resolveLibraryTools;
125
- private runAgent;
126
- private nextMemoryRef;
127
- send(prompt: string, options: AdapterSendOptions): Promise<string>;
128
- sendExecution(request: AgentExecutionRequest): Promise<string>;
129
- getLastMemoryRef(): MemoryRef | null;
130
- getLastTokenUsage(): TokenUsage | null;
131
- isCompatible(compat: string): boolean;
132
- /**
133
- * Inject the resolved ADK SDK surface for testing.
134
- * Bypasses the dynamic import of @google/adk and the API key requirement.
135
- */
136
- static withSdk(sdk: AdkSdk, config?: AdkSdkAdapterConfig): AdkSdkAdapter;
137
- }
138
-
139
- export { AdkSdkAdapter, type AdkSdkAdapterConfig };
@@ -1,312 +0,0 @@
1
- import {
2
- buildAdkFunctionTools,
3
- emitLlmTurnClose,
4
- emitLlmTurnOpen,
5
- emitToolExecClose,
6
- emitToolExecOpen
7
- } from "../chunk-KTVMMG33.js";
8
- import {
9
- getBlockingViolations,
10
- renderViolations
11
- } from "../chunk-EA4V5DVD.js";
12
- import "../chunk-BJ7B4R26.js";
13
-
14
- // src/adapters/adk-sdk.ts
15
- function sanitizeAgentName(name) {
16
- let id = name.replace(/[^a-zA-Z0-9_]/g, "_");
17
- if (id.length === 0 || /^[0-9]/.test(id)) id = `agent_${id}`;
18
- if (id === "user") id = "user_agent";
19
- return id;
20
- }
21
- function extractEventText(event) {
22
- const parts = event.content?.parts;
23
- if (!parts) return "";
24
- return parts.map((p) => p.text ?? "").join("");
25
- }
26
- function truncateInputSummary(input, maxLen = 80) {
27
- if (input == null) return "";
28
- let str;
29
- if (typeof input === "string") {
30
- str = input;
31
- } else {
32
- try {
33
- str = JSON.stringify(input);
34
- } catch {
35
- str = String(input);
36
- }
37
- }
38
- return str.length > maxLen ? str.slice(0, maxLen - 3) + "..." : str;
39
- }
40
- var AdkSdkAdapter = class _AdkSdkAdapter {
41
- apiKey;
42
- model;
43
- rootAgentName;
44
- guardrailHooks;
45
- cacheConfig;
46
- lastMemoryRef = null;
47
- lastTokenUsage = null;
48
- runCounter = 0;
49
- sdk = null;
50
- constructor(config = {}) {
51
- this.apiKey = config.apiKey;
52
- this.model = config.model ?? "gemini-2.5-flash";
53
- this.rootAgentName = config.rootAgentName ?? "root_agent";
54
- this.guardrailHooks = config.guardrailHooks;
55
- this.cacheConfig = config.cacheConfig ?? { enabled: true };
56
- }
57
- // -------------------------------------------------------------------------
58
- // Internal helpers
59
- // -------------------------------------------------------------------------
60
- async resolveSdk() {
61
- if (this.sdk) return this.sdk;
62
- const mod = await import("@google/adk");
63
- this.sdk = {
64
- LlmAgent: mod.LlmAgent,
65
- InMemoryRunner: mod.InMemoryRunner,
66
- isFinalResponse: mod.isFinalResponse,
67
- stringifyContent: mod.stringifyContent,
68
- Gemini: mod.Gemini
69
- };
70
- return this.sdk;
71
- }
72
- /** Resolve the `model` field for LlmAgent — a Gemini instance when an explicit
73
- * API key is supplied, otherwise the bare model id (ADK reads env keys). */
74
- resolveModel(sdk) {
75
- if (this.apiKey) {
76
- return new sdk.Gemini({ model: this.model, apiKey: this.apiKey });
77
- }
78
- return this.model;
79
- }
80
- /** Build the root LlmAgent with candidate sub-agents registered for transfer. */
81
- buildRootAgent(sdk, instruction, agents, extraTools) {
82
- const subAgents = (agents ?? []).map((a) => {
83
- const config = {
84
- name: sanitizeAgentName(a.name),
85
- description: a.description,
86
- instruction: a.prompt,
87
- model: a.model ?? this.resolveModel(sdk)
88
- };
89
- if (a.tools) config.tools = a.tools;
90
- return new sdk.LlmAgent(config);
91
- });
92
- const rootConfig = {
93
- name: sanitizeAgentName(this.rootAgentName),
94
- instruction,
95
- model: this.resolveModel(sdk)
96
- };
97
- if (subAgents.length > 0) rootConfig.subAgents = subAgents;
98
- if (extraTools && extraTools.length > 0) rootConfig.tools = extraTools;
99
- return new sdk.LlmAgent(rootConfig);
100
- }
101
- async resolveLibraryTools(libraryTools) {
102
- if (!libraryTools || libraryTools.getAll().length === 0) return [];
103
- try {
104
- return await buildAdkFunctionTools(libraryTools);
105
- } catch {
106
- return [];
107
- }
108
- }
109
- async runAgent(instruction, userMessage, agents, onProgress, libraryTools, observer, parentSpanId, agentSessionId) {
110
- if (this.guardrailHooks) {
111
- const results = this.guardrailHooks.runChecks({ command: userMessage });
112
- const blocking = getBlockingViolations(results);
113
- if (blocking.length > 0) {
114
- throw new Error(renderViolations(blocking));
115
- }
116
- }
117
- const sdk = await this.resolveSdk();
118
- const extraTools = await this.resolveLibraryTools(libraryTools);
119
- const root = this.buildRootAgent(sdk, instruction, agents, extraTools);
120
- const runner = new sdk.InMemoryRunner({ agent: root });
121
- let finalText = "";
122
- const stream = runner.runEphemeral({
123
- userId: "agent-runtime",
124
- newMessage: { role: "user", parts: [{ text: userMessage }] }
125
- });
126
- let turnNumber = 0;
127
- let currentTurnSpanId;
128
- let currentTurnStart = 0;
129
- let toolCallsInTurn = 0;
130
- let turnInputTokens = 0;
131
- let turnOutputTokens = 0;
132
- const openToolSpans = [];
133
- let totalInputTokens = 0;
134
- let totalOutputTokens = 0;
135
- let totalTokens = 0;
136
- let hasUsageData = false;
137
- const closePendingToolSpans = () => {
138
- for (const ts of openToolSpans) {
139
- emitToolExecClose(observer, ts.spanId, ts.toolName, Date.now() - ts.startMs, agentSessionId);
140
- }
141
- openToolSpans.length = 0;
142
- };
143
- const closeCurrentTurn = () => {
144
- if (currentTurnSpanId) {
145
- emitLlmTurnClose(observer, currentTurnSpanId, turnNumber, Date.now() - currentTurnStart, {
146
- inputTokens: turnInputTokens || void 0,
147
- outputTokens: turnOutputTokens || void 0,
148
- toolCallsCount: toolCallsInTurn || void 0
149
- }, agentSessionId);
150
- currentTurnSpanId = void 0;
151
- }
152
- };
153
- const captureUsage = (usageMetadata) => {
154
- const inTok = typeof usageMetadata.promptTokenCount === "number" ? usageMetadata.promptTokenCount : 0;
155
- const outTok = typeof usageMetadata.candidatesTokenCount === "number" ? usageMetadata.candidatesTokenCount : 0;
156
- if (inTok > 0 || outTok > 0) {
157
- totalInputTokens += inTok;
158
- totalOutputTokens += outTok;
159
- turnInputTokens += inTok;
160
- turnOutputTokens += outTok;
161
- hasUsageData = true;
162
- }
163
- if (typeof usageMetadata.totalTokenCount === "number") {
164
- totalTokens += usageMetadata.totalTokenCount;
165
- }
166
- };
167
- for await (const event of stream) {
168
- if (onProgress) emitProgressFromAdkEvent(event, onProgress);
169
- const ev = event;
170
- if (ev.errorCode || ev.errorMessage) {
171
- closePendingToolSpans();
172
- closeCurrentTurn();
173
- throw new Error(
174
- `Gemini API error (${ev.errorCode ?? "unknown"}): ${ev.errorMessage ?? "no details"}`
175
- );
176
- }
177
- const role = event.content?.role;
178
- const parts = event.content?.parts;
179
- if (role === "model" && parts && parts.length > 0) {
180
- closePendingToolSpans();
181
- closeCurrentTurn();
182
- turnNumber++;
183
- toolCallsInTurn = 0;
184
- turnInputTokens = 0;
185
- turnOutputTokens = 0;
186
- currentTurnStart = Date.now();
187
- currentTurnSpanId = emitLlmTurnOpen(observer, parentSpanId, turnNumber, this.model, void 0, agentSessionId);
188
- for (const part of parts) {
189
- if (part.functionCall?.name) {
190
- toolCallsInTurn++;
191
- const toolName = part.functionCall.name;
192
- const summary = truncateInputSummary(part.functionCall.args);
193
- const toolSpanId = emitToolExecOpen(observer, currentTurnSpanId, toolName, summary, turnNumber, agentSessionId);
194
- if (toolSpanId) {
195
- openToolSpans.push({ spanId: toolSpanId, toolName, startMs: Date.now() });
196
- }
197
- }
198
- }
199
- } else if (parts) {
200
- for (const part of parts) {
201
- if (part.functionResponse?.name) {
202
- if (openToolSpans.length > 0) {
203
- const ts = openToolSpans.shift();
204
- emitToolExecClose(observer, ts.spanId, ts.toolName, Date.now() - ts.startMs, agentSessionId);
205
- }
206
- }
207
- }
208
- }
209
- if (event.usageMetadata) {
210
- captureUsage(event.usageMetadata);
211
- }
212
- if (sdk.isFinalResponse(event) && event.content) {
213
- const text = sdk.stringifyContent(event) || extractEventText(event);
214
- if (text) finalText = text;
215
- closePendingToolSpans();
216
- closeCurrentTurn();
217
- }
218
- }
219
- closePendingToolSpans();
220
- closeCurrentTurn();
221
- const tokenUsage = hasUsageData ? {
222
- inputTokens: totalInputTokens,
223
- outputTokens: totalOutputTokens,
224
- totalTokens: totalTokens || totalInputTokens + totalOutputTokens
225
- } : null;
226
- return { text: finalText, tokenUsage };
227
- }
228
- nextMemoryRef() {
229
- return {
230
- id: `adk-run-${++this.runCounter}-${Date.now()}`,
231
- provider: "google-adk",
232
- compat: `google-adk@${this.model}`,
233
- created_at: (/* @__PURE__ */ new Date()).toISOString()
234
- };
235
- }
236
- // -------------------------------------------------------------------------
237
- // SdkAdapter interface
238
- // -------------------------------------------------------------------------
239
- async send(prompt, options) {
240
- this.lastMemoryRef = null;
241
- this.lastTokenUsage = null;
242
- const split = options.splitPrompt;
243
- let instruction = "";
244
- let userMessage;
245
- if (split && this.cacheConfig.enabled !== false) {
246
- instruction = split.system.join("\n\n---\n\n");
247
- userMessage = split.user;
248
- } else {
249
- userMessage = prompt;
250
- }
251
- const { text, tokenUsage } = await this.runAgent(instruction, userMessage, options.agents, options.onProgress, options.libraryTools, options.observer, options.parentSpanId, options.sessionId);
252
- this.lastMemoryRef = this.nextMemoryRef();
253
- this.lastTokenUsage = tokenUsage;
254
- return text;
255
- }
256
- async sendExecution(request) {
257
- this.lastMemoryRef = null;
258
- this.lastTokenUsage = null;
259
- const split = request.splitPrompt;
260
- let instruction = "";
261
- let userMessage;
262
- if (split && this.cacheConfig.enabled !== false) {
263
- instruction = split.system.join("\n\n---\n\n");
264
- userMessage = split.user;
265
- } else {
266
- userMessage = request.prompt;
267
- }
268
- const agents = request.options.agents ?? request.agents;
269
- const { text, tokenUsage } = await this.runAgent(instruction, userMessage, agents, request.options.onProgress, request.options.libraryTools, request.options.observer, request.options.parentSpanId, request.options.sessionId);
270
- this.lastMemoryRef = this.nextMemoryRef();
271
- this.lastTokenUsage = tokenUsage;
272
- return text;
273
- }
274
- getLastMemoryRef() {
275
- return this.lastMemoryRef;
276
- }
277
- getLastTokenUsage() {
278
- return this.lastTokenUsage;
279
- }
280
- isCompatible(compat) {
281
- return compat.startsWith("google-adk@");
282
- }
283
- // -------------------------------------------------------------------------
284
- // Test support
285
- // -------------------------------------------------------------------------
286
- /**
287
- * Inject the resolved ADK SDK surface for testing.
288
- * Bypasses the dynamic import of @google/adk and the API key requirement.
289
- */
290
- static withSdk(sdk, config) {
291
- const adapter = new _AdkSdkAdapter(config);
292
- adapter.sdk = sdk;
293
- return adapter;
294
- }
295
- };
296
- function emitProgressFromAdkEvent(event, onProgress) {
297
- const parts = event.content?.parts;
298
- if (!parts) return;
299
- for (const part of parts) {
300
- if (part.functionCall?.name) {
301
- onProgress({ type: "tool_use", tool_name: part.functionCall.name, input: part.functionCall.args });
302
- } else if (part.functionResponse?.name) {
303
- onProgress({ type: "tool_result", tool_name: part.functionResponse.name });
304
- } else if (part.text) {
305
- onProgress({ type: "text", message: part.text });
306
- }
307
- }
308
- }
309
- export {
310
- AdkSdkAdapter
311
- };
312
- //# sourceMappingURL=adk-sdk.js.map