melchizedek-agents 0.18.0 → 0.20.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/.env.example +12 -0
- package/CHANGELOG.md +1001 -0
- package/DOCUMENTATION.md +252 -65
- package/QUICKSTART.md +9 -6
- package/README.md +42 -4
- package/config/agents/examples/harness.yaml +3 -1
- package/config/agents/examples/model_zoo.yaml +10 -9
- package/config/agents/syndicateSchema.yaml +53 -16
- package/config/agents/templates/account_memory.yaml +2 -6
- package/config/agents/templates/case_desk.yaml +3 -9
- package/config/agents/templates/draft_review.yaml +3 -9
- package/config/agents/templates/intake_extractor.yaml +1 -3
- package/config/agents/templates/research_brief.yaml +3 -9
- package/config/agents/templates/research_desk.yaml +3 -9
- package/config/agents/templates/review_panel.yaml +4 -12
- package/config/agents/templates/support_triage.yaml +4 -12
- package/config/agents/templates/systems_operator.yaml +2 -6
- package/db/hardening.sql +7 -1
- package/db/migrations/0013_tool_credentials.sql +260 -0
- package/dist/lib/a2a/app.d.ts +70 -6
- package/dist/lib/a2a/app.js +107 -2
- package/dist/lib/a2a/executor.d.ts +20 -3
- package/dist/lib/a2a/executor.js +66 -7
- package/dist/lib/a2a/remoteAgent.d.ts +24 -9
- package/dist/lib/a2a/remoteAgent.js +31 -14
- package/dist/lib/adkPeer.d.ts +63 -0
- package/dist/lib/adkPeer.js +240 -0
- package/dist/lib/compile.d.ts +159 -30
- package/dist/lib/compile.js +215 -134
- package/dist/lib/compileAdk.d.ts +32 -0
- package/dist/lib/compileAdk.js +142 -0
- package/dist/lib/compileNative.d.ts +111 -0
- package/dist/lib/compileNative.js +278 -0
- package/dist/lib/config.d.ts +6 -5
- package/dist/lib/config.js +6 -5
- package/dist/lib/doctor.d.ts +28 -1
- package/dist/lib/doctor.js +64 -2
- package/dist/lib/index.d.ts +6 -1
- package/dist/lib/index.js +7 -1
- package/dist/lib/loadSyndicate.d.ts +18 -0
- package/dist/lib/memory/erase.d.ts +5 -3
- package/dist/lib/memory/erase.js +5 -2
- package/dist/lib/memory/namespace.d.ts +8 -1
- package/dist/lib/memory/namespace.js +12 -6
- package/dist/lib/memory/providers.js +2 -1
- package/dist/lib/memory/supabaseMemoryService.d.ts +37 -3
- package/dist/lib/memory/supabaseMemoryService.js +42 -2
- package/dist/lib/model.d.ts +47 -0
- package/dist/lib/model.js +37 -0
- package/dist/lib/models/adapterResolver.d.ts +115 -0
- package/dist/lib/models/adapterResolver.js +137 -0
- package/dist/lib/models/adkGeminiAdapter.d.ts +90 -0
- package/dist/lib/models/adkGeminiAdapter.js +369 -0
- package/dist/lib/models/adkShim.d.ts +111 -0
- package/dist/lib/models/adkShim.js +136 -0
- package/dist/lib/models/capabilities.d.ts +3 -0
- package/dist/lib/models/capabilities.js +33 -23
- package/dist/lib/models/chatCompletionsAdapter.d.ts +279 -0
- package/dist/lib/models/chatCompletionsAdapter.js +854 -0
- package/dist/lib/models/circuitBreaker.d.ts +42 -0
- package/dist/lib/models/circuitBreaker.js +70 -0
- package/dist/lib/models/claudeAdapter.d.ts +103 -0
- package/dist/lib/models/claudeAdapter.js +669 -0
- package/dist/lib/models/claudeLlm.d.ts +39 -62
- package/dist/lib/models/claudeLlm.js +45 -350
- package/dist/lib/models/claudeModels.d.ts +127 -0
- package/dist/lib/models/claudeModels.js +237 -0
- package/dist/lib/models/contract.d.ts +395 -0
- package/dist/lib/models/contract.js +39 -0
- package/dist/lib/models/endpoints.js +2 -1
- package/dist/lib/models/errorResponse.d.ts +50 -0
- package/dist/lib/models/errorResponse.js +48 -0
- package/dist/lib/models/fallback.d.ts +18 -11
- package/dist/lib/models/fallback.js +54 -43
- package/dist/lib/models/fallbackAdapter.d.ts +55 -0
- package/dist/lib/models/fallbackAdapter.js +62 -0
- package/dist/lib/models/gateway.js +2 -1
- package/dist/lib/models/gatewayAdapter.d.ts +51 -0
- package/dist/lib/models/gatewayAdapter.js +81 -0
- package/dist/lib/models/gatewayLlm.d.ts +12 -33
- package/dist/lib/models/gatewayLlm.js +16 -77
- package/dist/lib/models/geminiAdapter.d.ts +125 -0
- package/dist/lib/models/geminiAdapter.js +854 -0
- package/dist/lib/models/geminiState.d.ts +46 -0
- package/dist/lib/models/geminiState.js +51 -0
- package/dist/lib/models/genaiMapping.d.ts +283 -0
- package/dist/lib/models/genaiMapping.js +965 -0
- package/dist/lib/models/gptAdapter.d.ts +240 -0
- package/dist/lib/models/gptAdapter.js +804 -0
- package/dist/lib/models/gptLlm.d.ts +63 -123
- package/dist/lib/models/gptLlm.js +89 -603
- package/dist/lib/models/grokAdapter.d.ts +86 -0
- package/dist/lib/models/grokAdapter.js +142 -0
- package/dist/lib/models/grokLlm.d.ts +22 -45
- package/dist/lib/models/grokLlm.js +24 -69
- package/dist/lib/models/kimiAdapter.d.ts +157 -0
- package/dist/lib/models/kimiAdapter.js +203 -0
- package/dist/lib/models/kimiLlm.d.ts +15 -107
- package/dist/lib/models/kimiLlm.js +19 -155
- package/dist/lib/models/ollamaAdapter.d.ts +125 -0
- package/dist/lib/models/ollamaAdapter.js +155 -0
- package/dist/lib/models/ollamaLlm.d.ts +11 -107
- package/dist/lib/models/ollamaLlm.js +15 -153
- package/dist/lib/models/openAiCompatibleLlm.d.ts +73 -216
- package/dist/lib/models/openAiCompatibleLlm.js +109 -671
- package/dist/lib/models/providerState.d.ts +63 -0
- package/dist/lib/models/providerState.js +61 -0
- package/dist/lib/models/reasoning.d.ts +26 -0
- package/dist/lib/models/reasoning.js +59 -0
- package/dist/lib/models/registry.d.ts +62 -35
- package/dist/lib/models/registry.js +100 -124
- package/dist/lib/models/retry.d.ts +2 -1
- package/dist/lib/models/retry.js +3 -2
- package/dist/lib/models/schemaNormalize.d.ts +98 -0
- package/dist/lib/models/schemaNormalize.js +321 -1
- package/dist/lib/models/tracedGemini.d.ts +41 -0
- package/dist/lib/models/tracedGemini.js +98 -0
- package/dist/lib/models/urls.d.ts +11 -0
- package/dist/lib/models/urls.js +16 -0
- package/dist/lib/net/redirects.d.ts +21 -2
- package/dist/lib/net/redirects.js +11 -34
- package/dist/lib/observability/audit.d.ts +5 -1
- package/dist/lib/observability/lineage.d.ts +14 -0
- package/dist/lib/observability/lineage.js +33 -0
- package/dist/lib/observability/supabaseSpanExporter.d.ts +10 -4
- package/dist/lib/observability/supabaseSpanExporter.js +17 -9
- package/dist/lib/observability/tracer.d.ts +26 -8
- package/dist/lib/observability/tracer.js +43 -18
- package/dist/lib/runtime/adkMemoryBridge.d.ts +46 -0
- package/dist/lib/runtime/adkMemoryBridge.js +68 -0
- package/dist/lib/runtime/adkSessionBridge.d.ts +78 -0
- package/dist/lib/runtime/adkSessionBridge.js +176 -0
- package/dist/lib/runtime/approvals.d.ts +5 -0
- package/dist/lib/runtime/approvals.js +39 -8
- package/dist/lib/runtime/credentials.d.ts +61 -0
- package/dist/lib/runtime/credentials.js +67 -0
- package/dist/lib/runtime/events.d.ts +229 -0
- package/dist/lib/runtime/events.js +274 -0
- package/dist/lib/runtime/logging.d.ts +32 -0
- package/dist/lib/runtime/logging.js +55 -0
- package/dist/lib/runtime/memoryService.d.ts +72 -0
- package/dist/lib/runtime/memoryService.js +25 -0
- package/dist/lib/runtime/native/agentLoop.d.ts +209 -0
- package/dist/lib/runtime/native/agentLoop.js +705 -0
- package/dist/lib/runtime/native/compaction.d.ts +103 -0
- package/dist/lib/runtime/native/compaction.js +191 -0
- package/dist/lib/runtime/native/delegate.d.ts +151 -0
- package/dist/lib/runtime/native/delegate.js +256 -0
- package/dist/lib/runtime/native/history.d.ts +83 -0
- package/dist/lib/runtime/native/history.js +312 -0
- package/dist/lib/runtime/native/interrupts.d.ts +129 -0
- package/dist/lib/runtime/native/interrupts.js +310 -0
- package/dist/lib/runtime/native/request.d.ts +215 -0
- package/dist/lib/runtime/native/request.js +585 -0
- package/dist/lib/runtime/native/selfCorrection.d.ts +164 -0
- package/dist/lib/runtime/native/selfCorrection.js +327 -0
- package/dist/lib/runtime/native/step.d.ts +156 -0
- package/dist/lib/runtime/native/step.js +263 -0
- package/dist/lib/runtime/native/taskMode.d.ts +64 -0
- package/dist/lib/runtime/native/taskMode.js +126 -0
- package/dist/lib/runtime/native/telemetry.d.ts +75 -0
- package/dist/lib/runtime/native/telemetry.js +299 -0
- package/dist/lib/runtime/native/tempState.d.ts +31 -0
- package/dist/lib/runtime/native/tempState.js +56 -0
- package/dist/lib/runtime/nativeTurn.d.ts +86 -0
- package/dist/lib/runtime/nativeTurn.js +107 -0
- package/dist/lib/runtime/questions.d.ts +29 -7
- package/dist/lib/runtime/questions.js +47 -32
- package/dist/lib/runtime/runtimeFlag.d.ts +38 -0
- package/dist/lib/runtime/runtimeFlag.js +58 -0
- package/dist/lib/runtime/sessions.d.ts +166 -0
- package/dist/lib/runtime/sessions.js +201 -0
- package/dist/lib/runtime/syndicateTurn.d.ts +46 -5
- package/dist/lib/runtime/syndicateTurn.js +233 -36
- package/dist/lib/runtime/valueDepth.d.ts +23 -0
- package/dist/lib/runtime/valueDepth.js +41 -0
- package/dist/lib/session/supabaseSessionService.d.ts +65 -18
- package/dist/lib/session/supabaseSessionService.js +148 -105
- package/dist/lib/session/transcript.d.ts +69 -23
- package/dist/lib/session/transcript.js +105 -29
- package/dist/lib/skills.js +33 -7
- package/dist/lib/storage/postgres/credentialStore.d.ts +20 -0
- package/dist/lib/storage/postgres/credentialStore.js +82 -0
- package/dist/lib/storage/postgres/index.d.ts +12 -0
- package/dist/lib/storage/postgres/index.js +6 -1
- package/dist/lib/storage/postgres/sessionService.d.ts +44 -16
- package/dist/lib/storage/postgres/sessionService.js +128 -66
- package/dist/lib/syndicateSchema.d.ts +49 -0
- package/dist/lib/syndicateSchema.js +99 -9
- package/dist/lib/toolRegistry.d.ts +26 -2
- package/dist/lib/toolRegistry.js +73 -17
- package/dist/lib/tools/adkTool.d.ts +81 -0
- package/dist/lib/tools/adkTool.js +268 -0
- package/dist/lib/tools/auth.d.ts +118 -0
- package/dist/lib/tools/auth.js +89 -0
- package/dist/lib/tools/collectionsSearchTool.d.ts +8 -7
- package/dist/lib/tools/collectionsSearchTool.js +12 -27
- package/dist/lib/tools/credentialCipher.d.ts +58 -0
- package/dist/lib/tools/credentialCipher.js +116 -0
- package/dist/lib/tools/credentialStore.d.ts +77 -0
- package/dist/lib/tools/credentialStore.js +246 -0
- package/dist/lib/tools/examples.d.ts +43 -0
- package/dist/lib/tools/examples.js +62 -0
- package/dist/lib/tools/generateImageTool.d.ts +15 -6
- package/dist/lib/tools/generateImageTool.js +19 -29
- package/dist/lib/tools/inspectImageTool.d.ts +9 -6
- package/dist/lib/tools/inspectImageTool.js +13 -17
- package/dist/lib/tools/mcpToolFactory.d.ts +42 -1
- package/dist/lib/tools/mcpToolFactory.js +46 -47
- package/dist/lib/tools/memoryTools.d.ts +61 -0
- package/dist/lib/tools/memoryTools.js +119 -0
- package/dist/lib/tools/nativeTools.d.ts +38 -0
- package/dist/lib/tools/nativeTools.js +43 -0
- package/dist/lib/tools/oauthConsent.d.ts +181 -0
- package/dist/lib/tools/oauthConsent.js +330 -0
- package/dist/lib/tools/openapi/call.d.ts +108 -0
- package/dist/lib/tools/openapi/call.js +295 -0
- package/dist/lib/tools/openapi/parse.d.ts +147 -0
- package/dist/lib/tools/openapi/parse.js +570 -0
- package/dist/lib/tools/openapiTools.d.ts +25 -17
- package/dist/lib/tools/openapiTools.js +124 -121
- package/dist/lib/tools/scienceTools.d.ts +14 -14
- package/dist/lib/tools/skillToolset.d.ts +58 -87
- package/dist/lib/tools/skillToolset.js +61 -142
- package/dist/lib/tools/skills/env.d.ts +58 -0
- package/dist/lib/tools/skills/env.js +165 -0
- package/dist/lib/tools/skills/executor.d.ts +114 -0
- package/dist/lib/tools/skills/executor.js +331 -0
- package/dist/lib/tools/skills/frontmatter.d.ts +79 -0
- package/dist/lib/tools/skills/frontmatter.js +215 -0
- package/dist/lib/tools/skills/loader.d.ts +91 -0
- package/dist/lib/tools/skills/loader.js +257 -0
- package/dist/lib/tools/skills/tools.d.ts +187 -0
- package/dist/lib/tools/skills/tools.js +386 -0
- package/dist/lib/tools/taskTools.d.ts +15 -15
- package/dist/lib/tools/tool.d.ts +354 -0
- package/dist/lib/tools/tool.js +304 -0
- package/dist/lib/tools/toolContract.d.ts +89 -33
- package/dist/lib/tools/toolContract.js +104 -82
- package/dist/lib/tools/urlContextTool.d.ts +4 -1
- package/dist/lib/tools/urlContextTool.js +6 -2
- package/dist/lib/tools/webExtractTool.d.ts +3 -3
- package/dist/lib/tools/webExtractTool.js +2 -1
- package/dist/lib/tools/webSearchTool.d.ts +7 -10
- package/dist/lib/tools/webSearchTool.js +15 -60
- package/dist/lib/tools/wikiTools.d.ts +19 -19
- package/dist/lib/tools/wikiTools.js +13 -9
- package/dist/lib/tools/xApiSearchTool.d.ts +3 -3
- package/dist/lib/tools/xApiSearchTool.js +2 -1
- package/dist/lib/tools/xSearchTool.d.ts +8 -10
- package/dist/lib/tools/xSearchTool.js +12 -63
- package/dist/lib/tools/xaiSearchParams.d.ts +41 -0
- package/dist/lib/tools/xaiSearchParams.js +126 -0
- package/dist/lib/wiki/agentRun.d.ts +12 -0
- package/dist/lib/wiki/agentRun.js +74 -35
- package/dist/lib/wiki/entities.d.ts +12 -0
- package/dist/lib/wiki/entities.js +45 -3
- package/dist/lib/workflow/agentNode.d.ts +153 -0
- package/dist/lib/workflow/agentNode.js +365 -0
- package/dist/lib/workflow/graph.d.ts +178 -0
- package/dist/lib/workflow/graph.js +468 -0
- package/dist/lib/workflow/nodeEvents.d.ts +50 -0
- package/dist/lib/workflow/nodeEvents.js +101 -0
- package/dist/lib/workflow/pause.d.ts +122 -0
- package/dist/lib/workflow/pause.js +180 -0
- package/dist/lib/workflow/resume.d.ts +166 -0
- package/dist/lib/workflow/resume.js +441 -0
- package/dist/lib/workflow/route.d.ts +58 -0
- package/dist/lib/workflow/route.js +69 -0
- package/dist/lib/workflow/scheduler.d.ts +418 -0
- package/dist/lib/workflow/scheduler.js +756 -0
- package/dist/lib/workflow/toolNode.d.ts +127 -0
- package/dist/lib/workflow/toolNode.js +236 -0
- package/dist/lib/workflow/turn.d.ts +118 -0
- package/dist/lib/workflow/turn.js +216 -0
- package/dist/lib/workflow.d.ts +33 -11
- package/dist/lib/workflow.js +49 -27
- package/dist/lib/workflowConfig.d.ts +7 -2
- package/dist/lib/workflowConfig.js +7 -12
- package/dist/scripts/a2a_server.js +4 -3
- package/dist/scripts/assistant_worker.d.ts +2 -1
- package/dist/scripts/assistant_worker.js +9 -4
- package/dist/scripts/doctor.d.ts +3 -1
- package/dist/scripts/doctor.js +4 -2
- package/dist/scripts/syndicate_chat.js +19 -10
- package/package.json +9 -3
- package/skills/briefs/melchizedek-author.md +3 -2
- package/skills/briefs/melchizedek-models.md +13 -9
- package/skills/briefs/melchizedek.md +3 -3
- package/skills/melchizedek/SKILL.md +2 -1
- package/skills/melchizedek-author/SKILL.md +2 -1
- package/skills/melchizedek-author/assets/minimal.yaml +2 -0
- package/skills/melchizedek-models/SKILL.md +23 -6
package/dist/lib/a2a/executor.js
CHANGED
|
@@ -8,6 +8,12 @@
|
|
|
8
8
|
* cancellation, the per-server concurrency cap, and memory ingestion after
|
|
9
9
|
* the reply. Every turn semantic — dispatch, delegation, relay fallback,
|
|
10
10
|
* guards, the step cap — is the runtime's.
|
|
11
|
+
*
|
|
12
|
+
* Its stores are the engine's (ADR 0080): it takes a session store and a
|
|
13
|
+
* memory service with either face, the engine's or ADK's, reads a session
|
|
14
|
+
* through the engine's SessionService, and hands the turn runner the faces
|
|
15
|
+
* its fixed signature names through the bridges
|
|
16
|
+
* (lib/runtime/adkSessionBridge.ts, lib/runtime/adkMemoryBridge.ts).
|
|
11
17
|
*/
|
|
12
18
|
import { createHash, randomUUID } from 'node:crypto';
|
|
13
19
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
@@ -17,9 +23,12 @@ import { nestedLoader } from '../loadSyndicate.js';
|
|
|
17
23
|
import { configDigest } from '../observability/lineage.js';
|
|
18
24
|
import { turnLockKey } from './turnLock.js';
|
|
19
25
|
import { ingestTurnMemory, runSyndicateTurn } from '../runtime/syndicateTurn.js';
|
|
26
|
+
import { asAdkSessionService, asSessionService } from '../runtime/adkSessionBridge.js';
|
|
27
|
+
import { asAdkMemoryService } from '../runtime/adkMemoryBridge.js';
|
|
20
28
|
import { approvalResponsePart, describeApproval, pendingApproval } from '../runtime/approvals.js';
|
|
21
29
|
import { declaresApprovals } from '../compile.js';
|
|
22
30
|
import { describeInput } from '../runtime/syndicateTurn.js';
|
|
31
|
+
import { describeConsent } from '../runtime/credentials.js';
|
|
23
32
|
export const requestContextStorage = new AsyncLocalStorage();
|
|
24
33
|
/** The app name every A2A session and memory silo is stored under. */
|
|
25
34
|
export const A2A_APP_NAME = 'melchizedek-a2a';
|
|
@@ -303,6 +312,39 @@ function publishApprovalRequest(eventBus, taskId, contextId, pending) {
|
|
|
303
312
|
metadata: undefined,
|
|
304
313
|
}));
|
|
305
314
|
}
|
|
315
|
+
/**
|
|
316
|
+
* A call waits for an OAuth grant (ADR 0085): the task ends input-required,
|
|
317
|
+
* naming the provider, with a data part carrying the authorization URL and
|
|
318
|
+
* its state nonce. The person opens the URL; the server's callback stores
|
|
319
|
+
* the grant; the next message on the conversation resumes the call. The
|
|
320
|
+
* part carries no token, code or verifier.
|
|
321
|
+
*/
|
|
322
|
+
function publishConsentRequest(eventBus, taskId, contextId, pending) {
|
|
323
|
+
const message = statusMessage(taskId, contextId, `Authorization needed: ${describeConsent(pending)}. Open ${pending.authUri} to authorize, then send any message on this conversation to continue.`);
|
|
324
|
+
message.parts.push({
|
|
325
|
+
content: {
|
|
326
|
+
$case: 'data',
|
|
327
|
+
value: {
|
|
328
|
+
type: 'consent_request',
|
|
329
|
+
consent_id: pending.id,
|
|
330
|
+
agent: pending.agent,
|
|
331
|
+
provider: pending.provider,
|
|
332
|
+
authorization_url: pending.authUri,
|
|
333
|
+
state: pending.state,
|
|
334
|
+
scopes: pending.scopes,
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
metadata: undefined,
|
|
338
|
+
filename: '',
|
|
339
|
+
mediaType: 'application/json',
|
|
340
|
+
});
|
|
341
|
+
eventBus.publish(AgentEvent.statusUpdate({
|
|
342
|
+
taskId,
|
|
343
|
+
contextId,
|
|
344
|
+
status: { state: TaskState.TASK_STATE_INPUT_REQUIRED, message, timestamp: new Date().toISOString() },
|
|
345
|
+
metadata: undefined,
|
|
346
|
+
}));
|
|
347
|
+
}
|
|
306
348
|
/**
|
|
307
349
|
* The caller's answer to the open approval, from the raw A2A parts: a data
|
|
308
350
|
* part `{ approval: { id, approved } }` naming that request, or the text
|
|
@@ -375,8 +417,16 @@ export function answerStream(eventBus, taskId, contextId) {
|
|
|
375
417
|
export class SyndicateExecutor {
|
|
376
418
|
opts;
|
|
377
419
|
configHash;
|
|
420
|
+
/** The store as the engine reads it. */
|
|
421
|
+
sessions;
|
|
422
|
+
/** The faces the turn runner's fixed signature names (ADR 0045 item 4). */
|
|
423
|
+
turnSessions;
|
|
424
|
+
turnMemory;
|
|
378
425
|
constructor(opts) {
|
|
379
426
|
this.opts = opts;
|
|
427
|
+
this.sessions = asSessionService(opts.sessionService);
|
|
428
|
+
this.turnSessions = asAdkSessionService(opts.sessionService);
|
|
429
|
+
this.turnMemory = opts.memoryService ? asAdkMemoryService(opts.memoryService) : undefined;
|
|
380
430
|
}
|
|
381
431
|
/** Provenance stamp for every turn this executor serves (lineage.ts). */
|
|
382
432
|
configHashFor() {
|
|
@@ -531,8 +581,10 @@ export class SyndicateExecutor {
|
|
|
531
581
|
// Approvals (ADR 0028): while a gated call waits, a message is its
|
|
532
582
|
// answer, or the request is repeated without spending a model call.
|
|
533
583
|
if (declaresApprovals(config)) {
|
|
534
|
-
const session = await this.
|
|
535
|
-
|
|
584
|
+
const session = await this.sessions.get({ appName, userId, sessionId: contextId });
|
|
585
|
+
// The stored Event JSON either way (ADR 0052): pendingApproval still
|
|
586
|
+
// names ADK's Event, which a TurnEvent reaches only through a cast.
|
|
587
|
+
const pending = pendingApproval((session?.events ?? []));
|
|
536
588
|
if (pending) {
|
|
537
589
|
const answer = approvalAnswer(rawParts, pending);
|
|
538
590
|
if (!answer) {
|
|
@@ -551,11 +603,12 @@ export class SyndicateExecutor {
|
|
|
551
603
|
appName,
|
|
552
604
|
userId,
|
|
553
605
|
sessionId: contextId,
|
|
554
|
-
sessionService: this.
|
|
555
|
-
memoryService: this.
|
|
606
|
+
sessionService: this.turnSessions,
|
|
607
|
+
memoryService: this.turnMemory,
|
|
556
608
|
compile: this.opts.compileFor(ctx),
|
|
557
609
|
signal: slot.signal,
|
|
558
610
|
deadlineMs: this.opts.taskTimeoutMs,
|
|
611
|
+
...(this.opts.toolCredentials ? { toolCredentials: this.opts.toolCredentials } : {}),
|
|
559
612
|
streaming: !!stream,
|
|
560
613
|
trace: {
|
|
561
614
|
taskId,
|
|
@@ -591,6 +644,12 @@ export class SyndicateExecutor {
|
|
|
591
644
|
await report(ctx, 'input-required', 'approval', u);
|
|
592
645
|
return;
|
|
593
646
|
}
|
|
647
|
+
if (result.status === 'input-required' && result.consent) {
|
|
648
|
+
log(`⏸ Task ${short} waiting for ${result.consent.provider} authorization after ${spent}`);
|
|
649
|
+
publishConsentRequest(eventBus, taskId, contextId, result.consent);
|
|
650
|
+
await report(ctx, 'input-required', 'consent', u);
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
594
653
|
if (result.status === 'input-required' && result.input) {
|
|
595
654
|
log(`⏸ Task ${short} waiting for input from ${result.input.node} after ${spent}`);
|
|
596
655
|
publishInputRequest(eventBus, taskId, contextId, result.input);
|
|
@@ -609,11 +668,11 @@ export class SyndicateExecutor {
|
|
|
609
668
|
// Long-term memory: there is no "session end" on a server, so ingest
|
|
610
669
|
// after every completed task. Runs AFTER the final publish, so it never
|
|
611
670
|
// delays the reply, and a failure here never fails the task.
|
|
612
|
-
if (this.
|
|
671
|
+
if (this.turnMemory) {
|
|
613
672
|
try {
|
|
614
673
|
await ingestTurnMemory({
|
|
615
|
-
memoryService: this.
|
|
616
|
-
sessionService: this.
|
|
674
|
+
memoryService: this.turnMemory,
|
|
675
|
+
sessionService: this.turnSessions,
|
|
617
676
|
appName,
|
|
618
677
|
userId,
|
|
619
678
|
sessionId: contextId,
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
*
|
|
13
13
|
* Built on the official A2A SDK client with its v0.3 compatibility layer on,
|
|
14
14
|
* so a remote agent may speak A2A 1.0 (e.g. Microsoft Foundry) or 0.3 (most
|
|
15
|
-
* other platforms today); the card decides.
|
|
15
|
+
* other platforms today); the card decides. The client does not depend on
|
|
16
|
+
* ADK, and the tool is the engine's own (remoteAgentOwnTool); the ADK
|
|
17
|
+
* runtime receives it through toFunctionTool (remoteAgentTool).
|
|
16
18
|
*
|
|
17
19
|
* Security:
|
|
18
20
|
* - Every URL — the card and the endpoint the card names — passes the
|
|
@@ -27,7 +29,8 @@
|
|
|
27
29
|
*/
|
|
28
30
|
import type { AgentCard, Message, Task } from '@a2a-js/sdk';
|
|
29
31
|
import type { Client } from '@a2a-js/sdk/client';
|
|
30
|
-
import { FunctionTool } from '@google/adk';
|
|
32
|
+
import type { FunctionTool } from '@google/adk';
|
|
33
|
+
import type { Tool } from '../tools/tool.ts';
|
|
31
34
|
export interface RemoteAnswer {
|
|
32
35
|
state: string;
|
|
33
36
|
text: string;
|
|
@@ -79,13 +82,25 @@ export declare class RemoteA2AAgent {
|
|
|
79
82
|
export declare function remoteContextId(localSessionId: string | undefined, subagentName: string): string | undefined;
|
|
80
83
|
/** Render a remote result as the tool output the orchestrator reads. */
|
|
81
84
|
export declare function remoteToolOutput(name: string, answer: RemoteAnswer): string;
|
|
82
|
-
/**
|
|
83
|
-
|
|
84
|
-
* an orchestrator delegates to it exactly as to a local subagent. Failures
|
|
85
|
-
* come back as readable text, never as a throw into the runner.
|
|
86
|
-
*/
|
|
87
|
-
export declare function remoteAgentTool(params: {
|
|
85
|
+
/** What a remote agent tool is built from: the subagent's name and description, and where it is served. */
|
|
86
|
+
export interface RemoteAgentToolParams {
|
|
88
87
|
name: string;
|
|
89
88
|
description: string;
|
|
90
89
|
url: string;
|
|
91
|
-
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The subagent as an own Tool (lib/tools/tool.ts, ADR 0062) with AgentTool's
|
|
93
|
+
* contract (one `request` string), so an orchestrator delegates to it
|
|
94
|
+
* exactly as to a local subagent, on either runtime. The remote
|
|
95
|
+
* conversation is keyed by the local session (`ctx.sessionId`), and the call
|
|
96
|
+
* aborts with the turn (`ctx.signal`). Failures come back as readable text,
|
|
97
|
+
* never as a throw into the runner.
|
|
98
|
+
*/
|
|
99
|
+
export declare function remoteAgentOwnTool(params: RemoteAgentToolParams): Tool;
|
|
100
|
+
/**
|
|
101
|
+
* The remote agent tool as the ADK runtime runs it: the FunctionTool
|
|
102
|
+
* toFunctionTool (lib/tools/adkTool.ts) makes of remoteAgentOwnTool, which
|
|
103
|
+
* declares the same parameters the hand-built FunctionTool declared and
|
|
104
|
+
* carries the own Tool for toolOf().
|
|
105
|
+
*/
|
|
106
|
+
export declare function remoteAgentTool(params: RemoteAgentToolParams): FunctionTool;
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
*
|
|
13
13
|
* Built on the official A2A SDK client with its v0.3 compatibility layer on,
|
|
14
14
|
* so a remote agent may speak A2A 1.0 (e.g. Microsoft Foundry) or 0.3 (most
|
|
15
|
-
* other platforms today); the card decides.
|
|
15
|
+
* other platforms today); the card decides. The client does not depend on
|
|
16
|
+
* ADK, and the tool is the engine's own (remoteAgentOwnTool); the ADK
|
|
17
|
+
* runtime receives it through toFunctionTool (remoteAgentTool).
|
|
16
18
|
*
|
|
17
19
|
* Security:
|
|
18
20
|
* - Every URL — the card and the endpoint the card names — passes the
|
|
@@ -28,9 +30,9 @@
|
|
|
28
30
|
import { createHash, randomUUID } from 'node:crypto';
|
|
29
31
|
import { Role, TaskState } from '@a2a-js/sdk';
|
|
30
32
|
import { ClientFactory, DefaultAgentCardResolver, JsonRpcTransportFactory, RestTransportFactory } from '@a2a-js/sdk/client';
|
|
31
|
-
import { FunctionTool } from '@google/adk';
|
|
32
33
|
import { checkHost } from '../net/addressGuard.js';
|
|
33
34
|
import { currentTurnSignal } from '../runtime/turnControl.js';
|
|
35
|
+
import { toFunctionTool } from '../tools/adkTool.js';
|
|
34
36
|
const FETCH_TIMEOUT_MS = 30_000;
|
|
35
37
|
const POLL_INTERVAL_MS = 1_500;
|
|
36
38
|
const DEFAULT_TASK_TIMEOUT_MS = 10 * 60 * 1000;
|
|
@@ -234,29 +236,35 @@ export function remoteToolOutput(name, answer) {
|
|
|
234
236
|
return `Error: remote agent ${name} ended in state '${answer.state}'${answer.text ? ` — ${answer.text}` : ''}.`;
|
|
235
237
|
}
|
|
236
238
|
/**
|
|
237
|
-
* The subagent as
|
|
238
|
-
* an orchestrator delegates to it
|
|
239
|
-
*
|
|
239
|
+
* The subagent as an own Tool (lib/tools/tool.ts, ADR 0062) with AgentTool's
|
|
240
|
+
* contract (one `request` string), so an orchestrator delegates to it
|
|
241
|
+
* exactly as to a local subagent, on either runtime. The remote
|
|
242
|
+
* conversation is keyed by the local session (`ctx.sessionId`), and the call
|
|
243
|
+
* aborts with the turn (`ctx.signal`). Failures come back as readable text,
|
|
244
|
+
* never as a throw into the runner.
|
|
240
245
|
*/
|
|
241
|
-
export function
|
|
246
|
+
export function remoteAgentOwnTool(params) {
|
|
242
247
|
const client = new RemoteA2AAgent(params.url);
|
|
243
|
-
|
|
248
|
+
const declaration = {
|
|
244
249
|
name: params.name,
|
|
245
250
|
description: params.description || `Remote agent ${params.name}`,
|
|
246
251
|
parameters: {
|
|
247
|
-
type: '
|
|
248
|
-
properties: { request: { type: '
|
|
252
|
+
type: 'object',
|
|
253
|
+
properties: { request: { type: 'string', description: `What to ask ${params.name}.` } },
|
|
249
254
|
required: ['request'],
|
|
250
255
|
},
|
|
251
|
-
|
|
252
|
-
|
|
256
|
+
};
|
|
257
|
+
return {
|
|
258
|
+
name: params.name,
|
|
259
|
+
declaration: () => declaration,
|
|
260
|
+
execute: async (args, ctx) => {
|
|
253
261
|
const request = String(args?.request ?? '').trim();
|
|
254
262
|
if (!request)
|
|
255
263
|
return `Error: ${params.name} needs a request.`;
|
|
256
264
|
try {
|
|
257
265
|
const answer = await client.send(request, {
|
|
258
|
-
contextId: remoteContextId(
|
|
259
|
-
signal: currentTurnSignal(),
|
|
266
|
+
contextId: remoteContextId(ctx?.sessionId, params.name),
|
|
267
|
+
signal: ctx?.signal ?? currentTurnSignal(),
|
|
260
268
|
});
|
|
261
269
|
return remoteToolOutput(params.name, answer);
|
|
262
270
|
}
|
|
@@ -264,5 +272,14 @@ export function remoteAgentTool(params) {
|
|
|
264
272
|
return `Error: remote agent ${params.name} could not be reached (${err instanceof Error ? err.message : String(err)}).`;
|
|
265
273
|
}
|
|
266
274
|
},
|
|
267
|
-
}
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* The remote agent tool as the ADK runtime runs it: the FunctionTool
|
|
279
|
+
* toFunctionTool (lib/tools/adkTool.ts) makes of remoteAgentOwnTool, which
|
|
280
|
+
* declares the same parameters the hand-built FunctionTool declared and
|
|
281
|
+
* carries the own Tool for toolOf().
|
|
282
|
+
*/
|
|
283
|
+
export function remoteAgentTool(params) {
|
|
284
|
+
return toFunctionTool(remoteAgentOwnTool(params));
|
|
268
285
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lib/adkPeer.ts — @google/adk as an optional peer (ADR 0102).
|
|
3
|
+
*
|
|
4
|
+
* WHY this file exists:
|
|
5
|
+
* From 0.20.0 the native runtime is the default, and @google/adk is needed
|
|
6
|
+
* only for MELCHIZEDEK_RUNTIME=adk and the features only ADK runs. Until
|
|
7
|
+
* 1.0.0 removes ADK (ADR 0045), the engine's objects still carry an ADK
|
|
8
|
+
* face: the tool registry holds FunctionTools that carry their own Tool,
|
|
9
|
+
* the model shims are BaseLlm classes that carry their contract adapter,
|
|
10
|
+
* and the durable session stores are ADK BaseSessionServices as well as
|
|
11
|
+
* the engine's SessionService. Those classes extend ADK's at load time.
|
|
12
|
+
*
|
|
13
|
+
* This module is the one place the package loads ADK. It tries once, when
|
|
14
|
+
* it is first imported, and every other module takes ADK's values from
|
|
15
|
+
* here, never from '@google/adk' directly (a type-only import is fine):
|
|
16
|
+
* - When ADK is installed, each export below IS ADK's own value, so the
|
|
17
|
+
* ADK runtime, `instanceof` and ADK's registry behave exactly as before.
|
|
18
|
+
* - When it is not, the base classes are stand-ins: they construct as
|
|
19
|
+
* ADK's do (a tool's name, a model's id, a toolset's filter) and carry
|
|
20
|
+
* ADK's own Symbol.for marks, so the engine reads them as it reads ADK's,
|
|
21
|
+
* and every method only ADK calls throws AdkNotInstalledError, which
|
|
22
|
+
* names the package. Everything else (`Runner`, `LlmAgent`, the plugins)
|
|
23
|
+
* is reached through requireAdk(feature), which throws the same error.
|
|
24
|
+
*
|
|
25
|
+
* A package that is installed but fails to load for another reason (a
|
|
26
|
+
* missing dependency of its own, a syntax error) is not "absent": that
|
|
27
|
+
* error is rethrown, so nothing hides a broken install.
|
|
28
|
+
*
|
|
29
|
+
* The load is a top-level await of a dynamic import: an ES module cannot
|
|
30
|
+
* load another synchronously, and the exported classes must exist before
|
|
31
|
+
* any subclass is defined.
|
|
32
|
+
*/
|
|
33
|
+
import type * as AdkModule from '@google/adk';
|
|
34
|
+
/** The package this module loads. */
|
|
35
|
+
export declare const ADK_PACKAGE = "@google/adk";
|
|
36
|
+
/** @google/adk's module namespace, as its types describe it. */
|
|
37
|
+
export type Adk = typeof AdkModule;
|
|
38
|
+
/** ADK's module when it is installed, else undefined. */
|
|
39
|
+
export declare const adk: Adk | undefined;
|
|
40
|
+
/** Whether @google/adk is installed and loaded. */
|
|
41
|
+
export declare function adkInstalled(): boolean;
|
|
42
|
+
/** The installed @google/adk version, read from its package.json, or undefined when it is not installed. */
|
|
43
|
+
export declare function adkVersion(): Promise<string | undefined>;
|
|
44
|
+
/** A feature only ADK runs was used without @google/adk installed. */
|
|
45
|
+
export declare class AdkNotInstalledError extends Error {
|
|
46
|
+
readonly feature: string;
|
|
47
|
+
constructor(feature: string);
|
|
48
|
+
}
|
|
49
|
+
/** ADK's module, or AdkNotInstalledError naming `feature` when it is not installed. */
|
|
50
|
+
export declare function requireAdk(feature: string): Adk;
|
|
51
|
+
export declare const BaseTool: Adk['BaseTool'];
|
|
52
|
+
export type BaseTool = AdkModule.BaseTool;
|
|
53
|
+
export declare const FunctionTool: Adk['FunctionTool'];
|
|
54
|
+
export type FunctionTool<TParameters extends AdkModule.ToolInputParameters = undefined> = AdkModule.FunctionTool<TParameters>;
|
|
55
|
+
export declare const BaseToolset: Adk['BaseToolset'];
|
|
56
|
+
export type BaseToolset = AdkModule.BaseToolset;
|
|
57
|
+
export declare const BaseLlm: Adk['BaseLlm'];
|
|
58
|
+
export type BaseLlm = AdkModule.BaseLlm;
|
|
59
|
+
export declare const Gemini: Adk['Gemini'];
|
|
60
|
+
export type Gemini = AdkModule.Gemini;
|
|
61
|
+
export declare const BaseSessionService: Adk['BaseSessionService'];
|
|
62
|
+
export type BaseSessionService = AdkModule.BaseSessionService;
|
|
63
|
+
export declare const GOOGLE_SEARCH: Adk['GOOGLE_SEARCH'];
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lib/adkPeer.ts — @google/adk as an optional peer (ADR 0102).
|
|
3
|
+
*
|
|
4
|
+
* WHY this file exists:
|
|
5
|
+
* From 0.20.0 the native runtime is the default, and @google/adk is needed
|
|
6
|
+
* only for MELCHIZEDEK_RUNTIME=adk and the features only ADK runs. Until
|
|
7
|
+
* 1.0.0 removes ADK (ADR 0045), the engine's objects still carry an ADK
|
|
8
|
+
* face: the tool registry holds FunctionTools that carry their own Tool,
|
|
9
|
+
* the model shims are BaseLlm classes that carry their contract adapter,
|
|
10
|
+
* and the durable session stores are ADK BaseSessionServices as well as
|
|
11
|
+
* the engine's SessionService. Those classes extend ADK's at load time.
|
|
12
|
+
*
|
|
13
|
+
* This module is the one place the package loads ADK. It tries once, when
|
|
14
|
+
* it is first imported, and every other module takes ADK's values from
|
|
15
|
+
* here, never from '@google/adk' directly (a type-only import is fine):
|
|
16
|
+
* - When ADK is installed, each export below IS ADK's own value, so the
|
|
17
|
+
* ADK runtime, `instanceof` and ADK's registry behave exactly as before.
|
|
18
|
+
* - When it is not, the base classes are stand-ins: they construct as
|
|
19
|
+
* ADK's do (a tool's name, a model's id, a toolset's filter) and carry
|
|
20
|
+
* ADK's own Symbol.for marks, so the engine reads them as it reads ADK's,
|
|
21
|
+
* and every method only ADK calls throws AdkNotInstalledError, which
|
|
22
|
+
* names the package. Everything else (`Runner`, `LlmAgent`, the plugins)
|
|
23
|
+
* is reached through requireAdk(feature), which throws the same error.
|
|
24
|
+
*
|
|
25
|
+
* A package that is installed but fails to load for another reason (a
|
|
26
|
+
* missing dependency of its own, a syntax error) is not "absent": that
|
|
27
|
+
* error is rethrown, so nothing hides a broken install.
|
|
28
|
+
*
|
|
29
|
+
* The load is a top-level await of a dynamic import: an ES module cannot
|
|
30
|
+
* load another synchronously, and the exported classes must exist before
|
|
31
|
+
* any subclass is defined.
|
|
32
|
+
*/
|
|
33
|
+
/** The package this module loads. */
|
|
34
|
+
export const ADK_PACKAGE = '@google/adk';
|
|
35
|
+
/** Whether `err` says the package itself could not be found (and not a module it imports). */
|
|
36
|
+
function isMissingPackage(err) {
|
|
37
|
+
const e = err;
|
|
38
|
+
if (!e || typeof e !== 'object')
|
|
39
|
+
return false;
|
|
40
|
+
if (e.code !== 'ERR_MODULE_NOT_FOUND' && e.code !== 'MODULE_NOT_FOUND')
|
|
41
|
+
return false;
|
|
42
|
+
return typeof e.message === 'string' && e.message.includes(`'${ADK_PACKAGE}'`);
|
|
43
|
+
}
|
|
44
|
+
let loaded;
|
|
45
|
+
try {
|
|
46
|
+
loaded = await import('@google/adk');
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
if (!isMissingPackage(err))
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
/** ADK's module when it is installed, else undefined. */
|
|
53
|
+
export const adk = loaded;
|
|
54
|
+
/** Whether @google/adk is installed and loaded. */
|
|
55
|
+
export function adkInstalled() {
|
|
56
|
+
return loaded !== undefined;
|
|
57
|
+
}
|
|
58
|
+
/** The installed @google/adk version, read from its package.json, or undefined when it is not installed. */
|
|
59
|
+
export async function adkVersion() {
|
|
60
|
+
if (!loaded)
|
|
61
|
+
return undefined;
|
|
62
|
+
try {
|
|
63
|
+
const { createRequire } = await import('node:module');
|
|
64
|
+
const require = createRequire(import.meta.url);
|
|
65
|
+
const fs = await import('node:fs');
|
|
66
|
+
const path = await import('node:path');
|
|
67
|
+
// The package's exports map hides package.json, so walk up from its entry.
|
|
68
|
+
let dir = path.dirname(require.resolve(ADK_PACKAGE));
|
|
69
|
+
for (let i = 0; i < 6; i++) {
|
|
70
|
+
const file = path.join(dir, 'package.json');
|
|
71
|
+
if (fs.existsSync(file)) {
|
|
72
|
+
const pkg = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
73
|
+
if (pkg.name === ADK_PACKAGE)
|
|
74
|
+
return pkg.version;
|
|
75
|
+
}
|
|
76
|
+
dir = path.dirname(dir);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
// Unreadable: the version is unknown, not the package absent.
|
|
81
|
+
}
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
/** A feature only ADK runs was used without @google/adk installed. */
|
|
85
|
+
export class AdkNotInstalledError extends Error {
|
|
86
|
+
feature;
|
|
87
|
+
constructor(feature) {
|
|
88
|
+
super(`${feature} needs ${ADK_PACKAGE}, which is not installed. ` +
|
|
89
|
+
`Install it beside melchizedek-agents (npm install ${ADK_PACKAGE}@~2.2.0), ` +
|
|
90
|
+
`or run on the native runtime (the default; unset MELCHIZEDEK_RUNTIME or set it to native).`);
|
|
91
|
+
this.name = 'AdkNotInstalledError';
|
|
92
|
+
this.feature = feature;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** ADK's module, or AdkNotInstalledError naming `feature` when it is not installed. */
|
|
96
|
+
export function requireAdk(feature) {
|
|
97
|
+
if (!loaded)
|
|
98
|
+
throw new AdkNotInstalledError(feature);
|
|
99
|
+
return loaded;
|
|
100
|
+
}
|
|
101
|
+
// ── Stand-ins for ADK's base classes ─────────────────────────────────────────
|
|
102
|
+
//
|
|
103
|
+
// Each matches the ADK constructor's effect on the instance and ADK's
|
|
104
|
+
// Symbol.for mark, nothing more. They exist only when ADK is not installed.
|
|
105
|
+
const BASE_TOOL = Symbol.for('google.adk.baseTool');
|
|
106
|
+
const IN_MODEL_TOOL = Symbol.for('google.adk.inModelTool');
|
|
107
|
+
const FUNCTION_TOOL = Symbol.for('google.adk.functionTool');
|
|
108
|
+
const BASE_TOOLSET = Symbol.for('google.adk.baseToolset');
|
|
109
|
+
const BASE_MODEL = Symbol.for('google.adk.baseModel');
|
|
110
|
+
const GEMINI_MODEL = Symbol.for('google.adk.geminiModel');
|
|
111
|
+
function adkOnly(what) {
|
|
112
|
+
throw new AdkNotInstalledError(what);
|
|
113
|
+
}
|
|
114
|
+
class MissingBaseTool {
|
|
115
|
+
[BASE_TOOL] = true;
|
|
116
|
+
name;
|
|
117
|
+
description;
|
|
118
|
+
isLongRunning;
|
|
119
|
+
constructor(params) {
|
|
120
|
+
this.name = params.name;
|
|
121
|
+
this.description = params.description;
|
|
122
|
+
this.isLongRunning = params.isLongRunning ?? false;
|
|
123
|
+
}
|
|
124
|
+
_getDeclaration() {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
async checkRequireConfirmation() {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
async processLlmRequest(_request) {
|
|
131
|
+
adkOnly(`The ADK face of the tool '${this.name}'`);
|
|
132
|
+
}
|
|
133
|
+
async runAsync(_request) {
|
|
134
|
+
return adkOnly(`The ADK face of the tool '${this.name}'`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
class MissingFunctionTool extends MissingBaseTool {
|
|
138
|
+
[FUNCTION_TOOL] = true;
|
|
139
|
+
execute;
|
|
140
|
+
parameters;
|
|
141
|
+
requireConfirmation;
|
|
142
|
+
constructor(options) {
|
|
143
|
+
const name = options.name ?? options.execute.name;
|
|
144
|
+
if (!name)
|
|
145
|
+
throw new Error('Tool name cannot be empty. Either name the `execute` function or provide a `name`.');
|
|
146
|
+
super({ name, description: options.description, isLongRunning: options.isLongRunning });
|
|
147
|
+
this.execute = options.execute;
|
|
148
|
+
this.parameters = options.parameters;
|
|
149
|
+
this.requireConfirmation = options.requireConfirmation ?? false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
class MissingBaseToolset {
|
|
153
|
+
[BASE_TOOLSET] = true;
|
|
154
|
+
toolFilter;
|
|
155
|
+
prefix;
|
|
156
|
+
constructor(toolFilter, prefix) {
|
|
157
|
+
this.toolFilter = toolFilter;
|
|
158
|
+
this.prefix = prefix;
|
|
159
|
+
}
|
|
160
|
+
async getTools() {
|
|
161
|
+
return adkOnly('An ADK toolset');
|
|
162
|
+
}
|
|
163
|
+
async close() { }
|
|
164
|
+
}
|
|
165
|
+
class MissingBaseLlm {
|
|
166
|
+
[BASE_MODEL] = true;
|
|
167
|
+
model;
|
|
168
|
+
static supportedModels = [];
|
|
169
|
+
constructor({ model }) {
|
|
170
|
+
this.model = model;
|
|
171
|
+
}
|
|
172
|
+
generateContentAsync() {
|
|
173
|
+
return adkOnly(`The ADK face of the model '${this.model}'`);
|
|
174
|
+
}
|
|
175
|
+
async connect() {
|
|
176
|
+
return adkOnly(`The ADK face of the model '${this.model}'`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* ADK's Gemini, absent: it holds what a caller gave it (the model, a key,
|
|
181
|
+
* Vertex AI's settings), as ADK's does, so the native runtime reads it as it
|
|
182
|
+
* reads TracedGemini (lib/compileNative.ts). Calling it throws.
|
|
183
|
+
*/
|
|
184
|
+
class MissingGemini extends MissingBaseLlm {
|
|
185
|
+
[GEMINI_MODEL] = true;
|
|
186
|
+
apiKey;
|
|
187
|
+
vertexai;
|
|
188
|
+
project;
|
|
189
|
+
location;
|
|
190
|
+
headers;
|
|
191
|
+
constructor(params) {
|
|
192
|
+
super({ model: params.model ?? 'gemini-2.5-flash' });
|
|
193
|
+
if (params.apiKey !== undefined)
|
|
194
|
+
this.apiKey = params.apiKey;
|
|
195
|
+
if (params.vertexai !== undefined)
|
|
196
|
+
this.vertexai = params.vertexai;
|
|
197
|
+
if (params.project !== undefined)
|
|
198
|
+
this.project = params.project;
|
|
199
|
+
if (params.location !== undefined)
|
|
200
|
+
this.location = params.location;
|
|
201
|
+
if (params.headers !== undefined)
|
|
202
|
+
this.headers = params.headers;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* ADK's session service base, absent. A store that extends it is still the
|
|
207
|
+
* engine's SessionService; only the ADK face (the base's appendEvent, which
|
|
208
|
+
* ADK's Runner reaches) needs ADK.
|
|
209
|
+
*/
|
|
210
|
+
class MissingBaseSessionService {
|
|
211
|
+
async appendEvent(_request) {
|
|
212
|
+
return adkOnly('The ADK face of a session store');
|
|
213
|
+
}
|
|
214
|
+
/** ADK's own: the session when it exists, else a new one, through the store's methods. */
|
|
215
|
+
async getOrCreateSession(request) {
|
|
216
|
+
const self = this;
|
|
217
|
+
if (!request.sessionId)
|
|
218
|
+
return self.createSession(request);
|
|
219
|
+
const session = await self.getSession({ appName: request.appName, userId: request.userId, sessionId: request.sessionId });
|
|
220
|
+
return session ?? self.createSession(request);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/** ADK's GOOGLE_SEARCH, absent: an in-model tool named google_search, which the engine reads by ADK's mark. */
|
|
224
|
+
class MissingGoogleSearchTool extends MissingBaseTool {
|
|
225
|
+
[IN_MODEL_TOOL] = true;
|
|
226
|
+
constructor() {
|
|
227
|
+
super({ name: 'google_search', description: 'Google Search Tool' });
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
// ── The values every other module imports ────────────────────────────────────
|
|
231
|
+
//
|
|
232
|
+
// A type of the same name sits beside each value, so `import { BaseTool }`
|
|
233
|
+
// from here serves as both, as it did from '@google/adk'.
|
|
234
|
+
export const BaseTool = loaded?.BaseTool ?? MissingBaseTool;
|
|
235
|
+
export const FunctionTool = loaded?.FunctionTool ?? MissingFunctionTool;
|
|
236
|
+
export const BaseToolset = loaded?.BaseToolset ?? MissingBaseToolset;
|
|
237
|
+
export const BaseLlm = loaded?.BaseLlm ?? MissingBaseLlm;
|
|
238
|
+
export const Gemini = loaded?.Gemini ?? MissingGemini;
|
|
239
|
+
export const BaseSessionService = loaded?.BaseSessionService ?? MissingBaseSessionService;
|
|
240
|
+
export const GOOGLE_SEARCH = loaded?.GOOGLE_SEARCH ?? new MissingGoogleSearchTool();
|