melchizedek-agents 1.0.0 → 1.0.2
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/CHANGELOG.md +53 -0
- package/DOCUMENTATION.md +11 -9
- package/config/agents/examples/critic.yaml +12 -7
- package/config/agents/examples/image_production.yaml +2 -2
- package/config/agents/examples/librarian.yaml +1 -1
- package/config/agents/examples/pipeline.yaml +1 -1
- package/config/agents/examples/research.yaml +3 -2
- package/config/agents/examples/scribe.yaml +5 -4
- package/config/agents/examples/weather.yaml +2 -1
- package/config/agents/syndicateSchema.yaml +18 -15
- package/dist/lib/dispatch.d.ts +4 -4
- package/dist/lib/dispatch.js +4 -4
- package/dist/lib/syndicateSchema.js +6 -6
- package/package.json +2 -2
- package/skills/briefs/melchizedek-author.md +1 -1
- package/skills/melchizedek-author/SKILL.md +1 -1
- package/skills/melchizedek-author/assets/minimal.yaml +1 -1
- package/dist/lib/adkPeer.d.ts +0 -63
- package/dist/lib/adkPeer.js +0 -240
- package/dist/lib/compileAdk.d.ts +0 -32
- package/dist/lib/compileAdk.js +0 -142
- package/dist/lib/models/adkGeminiAdapter.d.ts +0 -90
- package/dist/lib/models/adkGeminiAdapter.js +0 -369
- package/dist/lib/models/adkShim.d.ts +0 -111
- package/dist/lib/models/adkShim.js +0 -136
- package/dist/lib/models/claudeLlm.d.ts +0 -79
- package/dist/lib/models/claudeLlm.js +0 -87
- package/dist/lib/models/fallback.d.ts +0 -48
- package/dist/lib/models/fallback.js +0 -116
- package/dist/lib/models/gatewayLlm.d.ts +0 -36
- package/dist/lib/models/gatewayLlm.js +0 -44
- package/dist/lib/models/gptLlm.d.ts +0 -99
- package/dist/lib/models/gptLlm.js +0 -129
- package/dist/lib/models/grokLlm.d.ts +0 -50
- package/dist/lib/models/grokLlm.js +0 -56
- package/dist/lib/models/kimiLlm.d.ts +0 -31
- package/dist/lib/models/kimiLlm.js +0 -35
- package/dist/lib/models/ollamaLlm.d.ts +0 -37
- package/dist/lib/models/ollamaLlm.js +0 -42
- package/dist/lib/models/openAiCompatibleLlm.d.ts +0 -96
- package/dist/lib/models/openAiCompatibleLlm.js +0 -156
- package/dist/lib/models/tracedGemini.d.ts +0 -41
- package/dist/lib/models/tracedGemini.js +0 -98
- package/dist/lib/runtime/adkMemoryBridge.d.ts +0 -46
- package/dist/lib/runtime/adkMemoryBridge.js +0 -68
- package/dist/lib/runtime/adkSessionBridge.d.ts +0 -78
- package/dist/lib/runtime/adkSessionBridge.js +0 -176
- package/dist/lib/tools/adkTool.d.ts +0 -81
- package/dist/lib/tools/adkTool.js +0 -268
- package/dist/lib/tools/collectionsSearchTool.d.ts +0 -56
- package/dist/lib/tools/collectionsSearchTool.js +0 -71
- package/dist/lib/tools/urlContextTool.d.ts +0 -32
- package/dist/lib/tools/urlContextTool.js +0 -43
- package/dist/lib/tools/webSearchTool.d.ts +0 -51
- package/dist/lib/tools/webSearchTool.js +0 -82
- package/dist/lib/tools/xSearchTool.d.ts +0 -59
- package/dist/lib/tools/xSearchTool.js +0 -74
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* lib/runtime/adkMemoryBridge.ts — one memory service, either runtime
|
|
3
|
-
* (ADR 0059, ADR 0080).
|
|
4
|
-
*
|
|
5
|
-
* WHY this file exists:
|
|
6
|
-
* Until ADK leaves at 1.0, the ADK runtime and ingestTurnMemory call ADK's
|
|
7
|
-
* BaseMemoryService methods (searchMemory, addSessionToMemory), and the
|
|
8
|
-
* native runtime the engine's MemoryService (lib/runtime/memoryService.ts:
|
|
9
|
-
* search, ingest). The engine's service implements both (ADR 0059 item 1),
|
|
10
|
-
* so it passes through here unchanged, and so does a consumer's ADK
|
|
11
|
-
* service. A service that implements only the engine's interface gets
|
|
12
|
-
* ADK's face from MemoryServiceForAdk: ADK's two methods hand their
|
|
13
|
-
* arguments to the engine's, as the engine's own service does.
|
|
14
|
-
*
|
|
15
|
-
* The bridge is applied at the seam, where a surface hands its service to
|
|
16
|
-
* the turn runner; the A2A server keeps the service it was given for its
|
|
17
|
-
* by-name checks (verifyEmbeddingDimensions, pruneExpired,
|
|
18
|
-
* deleteUserMemory), and the bridge forwards those too.
|
|
19
|
-
*
|
|
20
|
-
* This module imports ADK's types only, and loads nothing at run time.
|
|
21
|
-
*/
|
|
22
|
-
import type { BaseMemoryService, SearchMemoryRequest, SearchMemoryResponse, Session as AdkSession } from '@google/adk';
|
|
23
|
-
import type { MemoryService } from './memoryService.ts';
|
|
24
|
-
/** ADK's memory service, named here so a surface never imports ADK for the type. */
|
|
25
|
-
export type AdkMemoryService = BaseMemoryService;
|
|
26
|
-
/** A memory service with either face: what a surface takes from its caller. */
|
|
27
|
-
export type EitherMemoryService = MemoryService | BaseMemoryService;
|
|
28
|
-
/** The engine's two methods. */
|
|
29
|
-
export declare function isMemoryService(value: unknown): value is MemoryService;
|
|
30
|
-
/** ADK's two methods. A duck check, so a service built against another copy of ADK still counts. */
|
|
31
|
-
export declare function isAdkMemoryService(value: unknown): value is BaseMemoryService;
|
|
32
|
-
/** ADK's BaseMemoryService over an engine MemoryService. */
|
|
33
|
-
export declare class MemoryServiceForAdk implements BaseMemoryService {
|
|
34
|
-
readonly service: MemoryService;
|
|
35
|
-
readonly deleteUserMemory?: (userKey: string) => Promise<number>;
|
|
36
|
-
readonly pruneExpired?: (namespace: string, days: number) => Promise<number | null>;
|
|
37
|
-
readonly verifyEmbeddingDimensions?: () => Promise<void>;
|
|
38
|
-
constructor(service: MemoryService);
|
|
39
|
-
/** The extraction rules and model ingestTurnMemory passes, as the engine's service takes them. */
|
|
40
|
-
addSessionToMemory(session: AdkSession, extractionRules?: string, options?: {
|
|
41
|
-
extractionModel?: string;
|
|
42
|
-
}): Promise<void>;
|
|
43
|
-
searchMemory(request: SearchMemoryRequest): Promise<SearchMemoryResponse>;
|
|
44
|
-
}
|
|
45
|
-
/** The service as the ADK runtime takes it: itself when it already has ADK's face. */
|
|
46
|
-
export declare function asAdkMemoryService(service: EitherMemoryService): BaseMemoryService;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* lib/runtime/adkMemoryBridge.ts — one memory service, either runtime
|
|
3
|
-
* (ADR 0059, ADR 0080).
|
|
4
|
-
*
|
|
5
|
-
* WHY this file exists:
|
|
6
|
-
* Until ADK leaves at 1.0, the ADK runtime and ingestTurnMemory call ADK's
|
|
7
|
-
* BaseMemoryService methods (searchMemory, addSessionToMemory), and the
|
|
8
|
-
* native runtime the engine's MemoryService (lib/runtime/memoryService.ts:
|
|
9
|
-
* search, ingest). The engine's service implements both (ADR 0059 item 1),
|
|
10
|
-
* so it passes through here unchanged, and so does a consumer's ADK
|
|
11
|
-
* service. A service that implements only the engine's interface gets
|
|
12
|
-
* ADK's face from MemoryServiceForAdk: ADK's two methods hand their
|
|
13
|
-
* arguments to the engine's, as the engine's own service does.
|
|
14
|
-
*
|
|
15
|
-
* The bridge is applied at the seam, where a surface hands its service to
|
|
16
|
-
* the turn runner; the A2A server keeps the service it was given for its
|
|
17
|
-
* by-name checks (verifyEmbeddingDimensions, pruneExpired,
|
|
18
|
-
* deleteUserMemory), and the bridge forwards those too.
|
|
19
|
-
*
|
|
20
|
-
* This module imports ADK's types only, and loads nothing at run time.
|
|
21
|
-
*/
|
|
22
|
-
/** The engine's two methods. */
|
|
23
|
-
export function isMemoryService(value) {
|
|
24
|
-
const v = value;
|
|
25
|
-
return typeof v === 'object' && v !== null && typeof v.ingest === 'function' && typeof v.search === 'function';
|
|
26
|
-
}
|
|
27
|
-
/** ADK's two methods. A duck check, so a service built against another copy of ADK still counts. */
|
|
28
|
-
export function isAdkMemoryService(value) {
|
|
29
|
-
const v = value;
|
|
30
|
-
return (typeof v === 'object' && v !== null &&
|
|
31
|
-
typeof v.addSessionToMemory === 'function' && typeof v.searchMemory === 'function');
|
|
32
|
-
}
|
|
33
|
-
/** ADK's BaseMemoryService over an engine MemoryService. */
|
|
34
|
-
export class MemoryServiceForAdk {
|
|
35
|
-
service;
|
|
36
|
-
deleteUserMemory;
|
|
37
|
-
pruneExpired;
|
|
38
|
-
verifyEmbeddingDimensions;
|
|
39
|
-
constructor(service) {
|
|
40
|
-
this.service = service;
|
|
41
|
-
// The optional extras, only when the service has them: the A2A server
|
|
42
|
-
// checks for each by name.
|
|
43
|
-
if (service.deleteUserMemory)
|
|
44
|
-
this.deleteUserMemory = (userKey) => service.deleteUserMemory(userKey);
|
|
45
|
-
if (service.pruneExpired)
|
|
46
|
-
this.pruneExpired = (namespace, days) => service.pruneExpired(namespace, days);
|
|
47
|
-
if (service.verifyEmbeddingDimensions)
|
|
48
|
-
this.verifyEmbeddingDimensions = () => service.verifyEmbeddingDimensions();
|
|
49
|
-
}
|
|
50
|
-
/** The extraction rules and model ingestTurnMemory passes, as the engine's service takes them. */
|
|
51
|
-
async addSessionToMemory(session, extractionRules, options) {
|
|
52
|
-
await this.service.ingest(session, {
|
|
53
|
-
...(extractionRules !== undefined ? { extractionRules } : {}),
|
|
54
|
-
...(options?.extractionModel !== undefined ? { extractionModel: options.extractionModel } : {}),
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
async searchMemory(request) {
|
|
58
|
-
return (await this.service.search({ appName: request.appName, userId: request.userId, query: request.query }));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
/** The service as the ADK runtime takes it: itself when it already has ADK's face. */
|
|
62
|
-
export function asAdkMemoryService(service) {
|
|
63
|
-
if (isAdkMemoryService(service))
|
|
64
|
-
return service;
|
|
65
|
-
if (isMemoryService(service))
|
|
66
|
-
return new MemoryServiceForAdk(service);
|
|
67
|
-
throw new TypeError('Not a memory service: it implements neither MemoryService nor ADK\'s BaseMemoryService.');
|
|
68
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* lib/runtime/adkSessionBridge.ts — one session store, either runtime
|
|
3
|
-
* (ADR 0045, ADR 0052, ADR 0058).
|
|
4
|
-
*
|
|
5
|
-
* WHY this file exists:
|
|
6
|
-
* Until ADK leaves at 1.0, the ADK runtime asks for ADK's
|
|
7
|
-
* BaseSessionService and the native runtime for the engine's
|
|
8
|
-
* SessionService (lib/runtime/sessions.ts). The durable stores and the
|
|
9
|
-
* transcript projection implement both, so they need no bridge. A store
|
|
10
|
-
* that implements only one of them gets the other here:
|
|
11
|
-
* - SessionServiceForAdk: the ADK runtime on an engine store, such as
|
|
12
|
-
* InProcessSessionService.
|
|
13
|
-
* - AdkSessionServiceForEngine: the engine's interface on an ADK store,
|
|
14
|
-
* such as ADK's InMemorySessionService, with the interface's meaning
|
|
15
|
-
* where ADK's store has another (sessions.ts, "ONE MEANING ACROSS
|
|
16
|
-
* STORES").
|
|
17
|
-
* asAdkSessionService and asSessionService hand a store back as it is
|
|
18
|
-
* when it already implements the face asked for, and a bridge back as the
|
|
19
|
-
* store it wraps, so a store bridged one way and then back is itself.
|
|
20
|
-
* A surface that takes a store from its caller (the A2A executor and app,
|
|
21
|
-
* the REPL) types it as EitherSessionService and asks for the face it
|
|
22
|
-
* needs here (ADR 0080).
|
|
23
|
-
*
|
|
24
|
-
* APPEND: each face keeps its own runtime's rules for the caller's session.
|
|
25
|
-
* The ADK face applies an event to the runner's session through ADK's
|
|
26
|
-
* base service, write-order check and all, exactly as the durable stores
|
|
27
|
-
* do, and the store records it on a copy. The engine face applies it
|
|
28
|
-
* through applyEvent, which never changes the caller's event, and hands
|
|
29
|
-
* ADK's store a copy.
|
|
30
|
-
*
|
|
31
|
-
* This module loads ADK at run time, so it is not one of the engine's leaf
|
|
32
|
-
* modules (tests/events.test.ts names those).
|
|
33
|
-
*/
|
|
34
|
-
import { BaseSessionService } from '../adkPeer.ts';
|
|
35
|
-
import type { CreateSessionRequest as AdkCreateSessionRequest, DeleteSessionRequest as AdkDeleteSessionRequest, Event as AdkEvent, GetSessionRequest as AdkGetSessionRequest, ListSessionsRequest as AdkListSessionsRequest, ListSessionsResponse as AdkListSessionsResponse, Session as AdkSession } from '@google/adk';
|
|
36
|
-
import type { TurnEvent } from './events.ts';
|
|
37
|
-
import type { CreateSessionRequest, GetSessionOptions, ListSessionsRequest, ListSessionsResult, Session, SessionKey, SessionService } from './sessions.ts';
|
|
38
|
-
/** ADK's session service, named here so a surface never imports ADK for the type (ADR 0080). */
|
|
39
|
-
export type AdkSessionService = BaseSessionService;
|
|
40
|
-
/** A session store with either face: what a surface takes from its caller. */
|
|
41
|
-
export type EitherSessionService = SessionService | BaseSessionService;
|
|
42
|
-
/** Every method the engine's interface names. */
|
|
43
|
-
export declare function isSessionService(value: unknown): value is SessionService;
|
|
44
|
-
/**
|
|
45
|
-
* Every method ADK's runner and services call. A duck check rather than
|
|
46
|
-
* instanceof, so a store built against another copy of ADK still counts.
|
|
47
|
-
*/
|
|
48
|
-
export declare function isAdkSessionService(value: unknown): value is BaseSessionService;
|
|
49
|
-
/** ADK's BaseSessionService over an engine SessionService. */
|
|
50
|
-
export declare class SessionServiceForAdk extends BaseSessionService {
|
|
51
|
-
readonly service: SessionService;
|
|
52
|
-
constructor(service: SessionService);
|
|
53
|
-
createSession(request: AdkCreateSessionRequest): Promise<AdkSession>;
|
|
54
|
-
getSession(request: AdkGetSessionRequest): Promise<AdkSession | undefined>;
|
|
55
|
-
listSessions(request: AdkListSessionsRequest): Promise<AdkListSessionsResponse>;
|
|
56
|
-
deleteSession(request: AdkDeleteSessionRequest): Promise<void>;
|
|
57
|
-
appendEvent({ session, event }: {
|
|
58
|
-
session: AdkSession;
|
|
59
|
-
event: AdkEvent;
|
|
60
|
-
}): Promise<AdkEvent>;
|
|
61
|
-
}
|
|
62
|
-
/** The engine's SessionService over an ADK BaseSessionService. */
|
|
63
|
-
export declare class AdkSessionServiceForEngine implements SessionService {
|
|
64
|
-
readonly service: BaseSessionService;
|
|
65
|
-
constructor(service: BaseSessionService);
|
|
66
|
-
/** A session that exists comes back unchanged: ADK's own store would reset it. */
|
|
67
|
-
create(request: CreateSessionRequest): Promise<Session>;
|
|
68
|
-
/** Reads the whole session and filters it here, so `options` mean what the interface says. */
|
|
69
|
-
get(key: SessionKey, options?: GetSessionOptions): Promise<Session | undefined>;
|
|
70
|
-
/** The window goes to ADK's store as an offset; the paging figures are the interface's. */
|
|
71
|
-
list(request: ListSessionsRequest): Promise<ListSessionsResult>;
|
|
72
|
-
delete(key: SessionKey): Promise<void>;
|
|
73
|
-
append(session: Session, event: TurnEvent): Promise<TurnEvent>;
|
|
74
|
-
}
|
|
75
|
-
/** The store as the ADK runtime takes it: itself when it already is one. */
|
|
76
|
-
export declare function asAdkSessionService(service: EitherSessionService): BaseSessionService;
|
|
77
|
-
/** The store as the engine's interface: itself when it already is one. */
|
|
78
|
-
export declare function asSessionService(service: EitherSessionService): SessionService;
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* lib/runtime/adkSessionBridge.ts — one session store, either runtime
|
|
3
|
-
* (ADR 0045, ADR 0052, ADR 0058).
|
|
4
|
-
*
|
|
5
|
-
* WHY this file exists:
|
|
6
|
-
* Until ADK leaves at 1.0, the ADK runtime asks for ADK's
|
|
7
|
-
* BaseSessionService and the native runtime for the engine's
|
|
8
|
-
* SessionService (lib/runtime/sessions.ts). The durable stores and the
|
|
9
|
-
* transcript projection implement both, so they need no bridge. A store
|
|
10
|
-
* that implements only one of them gets the other here:
|
|
11
|
-
* - SessionServiceForAdk: the ADK runtime on an engine store, such as
|
|
12
|
-
* InProcessSessionService.
|
|
13
|
-
* - AdkSessionServiceForEngine: the engine's interface on an ADK store,
|
|
14
|
-
* such as ADK's InMemorySessionService, with the interface's meaning
|
|
15
|
-
* where ADK's store has another (sessions.ts, "ONE MEANING ACROSS
|
|
16
|
-
* STORES").
|
|
17
|
-
* asAdkSessionService and asSessionService hand a store back as it is
|
|
18
|
-
* when it already implements the face asked for, and a bridge back as the
|
|
19
|
-
* store it wraps, so a store bridged one way and then back is itself.
|
|
20
|
-
* A surface that takes a store from its caller (the A2A executor and app,
|
|
21
|
-
* the REPL) types it as EitherSessionService and asks for the face it
|
|
22
|
-
* needs here (ADR 0080).
|
|
23
|
-
*
|
|
24
|
-
* APPEND: each face keeps its own runtime's rules for the caller's session.
|
|
25
|
-
* The ADK face applies an event to the runner's session through ADK's
|
|
26
|
-
* base service, write-order check and all, exactly as the durable stores
|
|
27
|
-
* do, and the store records it on a copy. The engine face applies it
|
|
28
|
-
* through applyEvent, which never changes the caller's event, and hands
|
|
29
|
-
* ADK's store a copy.
|
|
30
|
-
*
|
|
31
|
-
* This module loads ADK at run time, so it is not one of the engine's leaf
|
|
32
|
-
* modules (tests/events.test.ts names those).
|
|
33
|
-
*/
|
|
34
|
-
import { BaseSessionService } from '../adkPeer.js';
|
|
35
|
-
import { applyEvent, listPage, listWindow, selectEvents, withoutTempKeys } from './sessions.js';
|
|
36
|
-
/** Every method the engine's interface names. */
|
|
37
|
-
export function isSessionService(value) {
|
|
38
|
-
const v = value;
|
|
39
|
-
return (typeof v === 'object' && v !== null &&
|
|
40
|
-
typeof v.create === 'function' && typeof v.get === 'function' && typeof v.list === 'function' &&
|
|
41
|
-
typeof v.delete === 'function' && typeof v.append === 'function');
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Every method ADK's runner and services call. A duck check rather than
|
|
45
|
-
* instanceof, so a store built against another copy of ADK still counts.
|
|
46
|
-
*/
|
|
47
|
-
export function isAdkSessionService(value) {
|
|
48
|
-
const v = value;
|
|
49
|
-
return (typeof v === 'object' && v !== null &&
|
|
50
|
-
typeof v.createSession === 'function' && typeof v.getSession === 'function' &&
|
|
51
|
-
typeof v.listSessions === 'function' && typeof v.deleteSession === 'function' &&
|
|
52
|
-
typeof v.appendEvent === 'function');
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* A copy a store may apply an event to without touching the caller's
|
|
56
|
-
* session: applyEvent and ADK's base service change only `state`'s keys,
|
|
57
|
-
* the `events` array and `lastUpdateTime`.
|
|
58
|
-
*/
|
|
59
|
-
function shadowOf(session) {
|
|
60
|
-
return { ...session, state: { ...session.state }, events: [...session.events] };
|
|
61
|
-
}
|
|
62
|
-
/** The key fields only: a request object can carry more. */
|
|
63
|
-
function keyOf(request) {
|
|
64
|
-
return { appName: request.appName, userId: request.userId, sessionId: request.sessionId };
|
|
65
|
-
}
|
|
66
|
-
// ── The ADK runtime on an engine store ───────────────────────────────────────
|
|
67
|
-
/** ADK's BaseSessionService over an engine SessionService. */
|
|
68
|
-
export class SessionServiceForAdk extends BaseSessionService {
|
|
69
|
-
service;
|
|
70
|
-
constructor(service) {
|
|
71
|
-
super();
|
|
72
|
-
this.service = service;
|
|
73
|
-
}
|
|
74
|
-
async createSession(request) {
|
|
75
|
-
return (await this.service.create(request));
|
|
76
|
-
}
|
|
77
|
-
async getSession(request) {
|
|
78
|
-
return (await this.service.get(keyOf(request), request.config));
|
|
79
|
-
}
|
|
80
|
-
async listSessions(request) {
|
|
81
|
-
return (await this.service.list(request));
|
|
82
|
-
}
|
|
83
|
-
async deleteSession(request) {
|
|
84
|
-
await this.service.delete(keyOf(request));
|
|
85
|
-
}
|
|
86
|
-
async appendEvent({ session, event }) {
|
|
87
|
-
if (event.partial)
|
|
88
|
-
return event;
|
|
89
|
-
// The store applies the event once, to the session as it stood.
|
|
90
|
-
const before = shadowOf(session);
|
|
91
|
-
await super.appendEvent({ session, event });
|
|
92
|
-
session.lastUpdateTime = event.timestamp;
|
|
93
|
-
await this.service.append(before, event);
|
|
94
|
-
return event;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
// ── The engine's interface on an ADK store ───────────────────────────────────
|
|
98
|
-
/** The engine's SessionService over an ADK BaseSessionService. */
|
|
99
|
-
export class AdkSessionServiceForEngine {
|
|
100
|
-
service;
|
|
101
|
-
constructor(service) {
|
|
102
|
-
this.service = service;
|
|
103
|
-
}
|
|
104
|
-
/** A session that exists comes back unchanged: ADK's own store would reset it. */
|
|
105
|
-
async create(request) {
|
|
106
|
-
if (request.sessionId) {
|
|
107
|
-
const existing = await this.get({ appName: request.appName, userId: request.userId, sessionId: request.sessionId });
|
|
108
|
-
if (existing)
|
|
109
|
-
return existing;
|
|
110
|
-
}
|
|
111
|
-
const created = await this.service.createSession({
|
|
112
|
-
appName: request.appName,
|
|
113
|
-
userId: request.userId,
|
|
114
|
-
sessionId: request.sessionId,
|
|
115
|
-
state: withoutTempKeys(request.state ?? {}),
|
|
116
|
-
});
|
|
117
|
-
return created;
|
|
118
|
-
}
|
|
119
|
-
/** Reads the whole session and filters it here, so `options` mean what the interface says. */
|
|
120
|
-
async get(key, options) {
|
|
121
|
-
const held = (await this.service.getSession(keyOf(key)));
|
|
122
|
-
if (!held)
|
|
123
|
-
return undefined;
|
|
124
|
-
return { ...held, events: selectEvents(held.events, options) };
|
|
125
|
-
}
|
|
126
|
-
/** The window goes to ADK's store as an offset; the paging figures are the interface's. */
|
|
127
|
-
async list(request) {
|
|
128
|
-
const { offset, limit } = listWindow(request);
|
|
129
|
-
const listed = await this.service.listSessions({
|
|
130
|
-
appName: request.appName,
|
|
131
|
-
userId: request.userId,
|
|
132
|
-
order: request.order,
|
|
133
|
-
offset,
|
|
134
|
-
limit,
|
|
135
|
-
});
|
|
136
|
-
return {
|
|
137
|
-
sessions: listed.sessions.map((s) => ({ ...s, events: [] })),
|
|
138
|
-
...listPage(listed.totalItems, request),
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
async delete(key) {
|
|
142
|
-
await this.service.deleteSession(keyOf(key));
|
|
143
|
-
}
|
|
144
|
-
async append(session, event) {
|
|
145
|
-
if (event.partial)
|
|
146
|
-
return event;
|
|
147
|
-
// ADK's base service applies an event to the session it is given and
|
|
148
|
-
// rewrites the event's delta in place, so ADK's store gets copies of
|
|
149
|
-
// both, and the session as it stood.
|
|
150
|
-
const before = shadowOf(session);
|
|
151
|
-
const stored = applyEvent(session, event);
|
|
152
|
-
await this.service.appendEvent({ session: before, event: structuredClone(stored) });
|
|
153
|
-
return stored;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
// ── Either face of a store ───────────────────────────────────────────────────
|
|
157
|
-
/** The store as the ADK runtime takes it: itself when it already is one. */
|
|
158
|
-
export function asAdkSessionService(service) {
|
|
159
|
-
if (service instanceof AdkSessionServiceForEngine)
|
|
160
|
-
return service.service;
|
|
161
|
-
if (isAdkSessionService(service))
|
|
162
|
-
return service;
|
|
163
|
-
if (isSessionService(service))
|
|
164
|
-
return new SessionServiceForAdk(service);
|
|
165
|
-
throw new TypeError('Not a session service: it implements neither SessionService nor ADK\'s BaseSessionService.');
|
|
166
|
-
}
|
|
167
|
-
/** The store as the engine's interface: itself when it already is one. */
|
|
168
|
-
export function asSessionService(service) {
|
|
169
|
-
if (service instanceof SessionServiceForAdk)
|
|
170
|
-
return service.service;
|
|
171
|
-
if (isSessionService(service))
|
|
172
|
-
return service;
|
|
173
|
-
if (isAdkSessionService(service))
|
|
174
|
-
return new AdkSessionServiceForEngine(service);
|
|
175
|
-
throw new TypeError('Not a session service: it implements neither SessionService nor ADK\'s BaseSessionService.');
|
|
176
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* lib/tools/adkTool.ts — the boundary where an own Tool becomes an ADK tool.
|
|
3
|
-
*
|
|
4
|
-
* WHY this file exists:
|
|
5
|
-
* Tools are the engine's own (lib/tools/tool.ts, ADR 0051): a name, the
|
|
6
|
-
* declaration the model receives, and `execute(args, ctx)`. Until 1.0.0
|
|
7
|
-
* removes ADK (ADR 0045) the ADK runtime runs the same tools, and this
|
|
8
|
-
* module is the one place that turns a Tool into what ADK consumes: a
|
|
9
|
-
* FunctionTool whose Gemini-dialect parameters come from the Tool's
|
|
10
|
-
* declaration, and whose execute hands the Tool a ToolContext read from
|
|
11
|
-
* ADK's own Context. Nothing else in lib/tools builds an ADK tool from an
|
|
12
|
-
* own Tool, and tool.ts and toolContract.ts import nothing from ADK.
|
|
13
|
-
*
|
|
14
|
-
* The ADK runtime behaves as it did when every tool was a FunctionTool:
|
|
15
|
-
* - the declaration ADK sends is the Tool's, in Gemini's dialect
|
|
16
|
-
* (toGeminiSchema), so contractToolDeclaration reads the same
|
|
17
|
-
* parameters through either path;
|
|
18
|
-
* - a long-running Tool is a long-running FunctionTool, and its pending
|
|
19
|
-
* (undefined) result is the null response ADK waits on;
|
|
20
|
-
* - a Tool that requires approval sets FunctionTool's own gate, which
|
|
21
|
-
* raises `adk_request_confirmation` as lib/compile.ts's gate does;
|
|
22
|
-
* - a Tool that throws becomes ADK's `Error in tool '<name>': …` response;
|
|
23
|
-
* - a Tool's `instruction`, and an InstructionTool's, are appended to the
|
|
24
|
-
* request's system instruction in the tool's processLlmRequest, joined
|
|
25
|
-
* as ADK's own appendInstructions joins them, at the tool's place in the
|
|
26
|
-
* agent's list: where ADK's load_memory and preload_memory wrote theirs
|
|
27
|
-
* (ADR 0059);
|
|
28
|
-
* - the context reaches the run's memory through ADK's own
|
|
29
|
-
* `Context.searchMemory`, so a search reads the silo ADK's tools read;
|
|
30
|
-
* - a NativeToolMarker is the shared sentinel the ADK runtime always ran
|
|
31
|
-
* for that server-side tool, which carries the same marker (ADR 0062);
|
|
32
|
-
* - a Tool's `contents` hook adds to the request's history in the tool's
|
|
33
|
-
* processLlmRequest, where ADK's load_skill_resource added a binary
|
|
34
|
-
* file (ADR 0083);
|
|
35
|
-
* - an own Toolset (the skills harness) is a BaseToolset whose getTools
|
|
36
|
-
* lists the Toolset's tools for ADK's ReadonlyContext, each through
|
|
37
|
-
* toAdkTool (ADR 0083).
|
|
38
|
-
*
|
|
39
|
-
* toAdkTool takes any of these and picks the wrapper.
|
|
40
|
-
*/
|
|
41
|
-
import { BaseTool, BaseToolset, FunctionTool } from '../adkPeer.ts';
|
|
42
|
-
import type { InstructionTool, NativeToolMarker, Tool, ToolContext, Toolset } from './tool.ts';
|
|
43
|
-
import type { ToolContract } from './toolContract.ts';
|
|
44
|
-
/** The ToolContext for one ADK call; a standalone one outside a run. */
|
|
45
|
-
export declare function adkToolContext(adkContext: unknown): ToolContext;
|
|
46
|
-
/**
|
|
47
|
-
* ADK surface: a FunctionTool that runs `tool`. Its Gemini-dialect
|
|
48
|
-
* parameters derive from the Tool's declaration (for a defineTool contract,
|
|
49
|
-
* from the zod schema), and its execute runs the Tool, which validates its
|
|
50
|
-
* own arguments. Non-Gemini providers keep receiving the schema through
|
|
51
|
-
* schemaNormalize.toLowercaseJsonSchema() at request-build time.
|
|
52
|
-
*
|
|
53
|
-
* Takes a Tool, or a hand-built contract object, which defineTool makes a
|
|
54
|
-
* Tool first. The FunctionTool carries the Tool (toolOf in lib/tools/tool.ts
|
|
55
|
-
* reads it back), so a runtime that resolves names through the registry can
|
|
56
|
-
* run the Tool itself.
|
|
57
|
-
*/
|
|
58
|
-
export declare function toFunctionTool(tool: ToolContract<any>): FunctionTool;
|
|
59
|
-
export declare function toFunctionTool(tool: Tool): FunctionTool;
|
|
60
|
-
/**
|
|
61
|
-
* ADK surface for an InstructionTool: a BaseTool that declares no function,
|
|
62
|
-
* so it never enters the request's tools, and appends the InstructionTool's
|
|
63
|
-
* text in processLlmRequest, where ADK's PreloadMemoryTool appended its own.
|
|
64
|
-
* instructionToolOf (lib/tools/tool.ts) reads the InstructionTool back.
|
|
65
|
-
*/
|
|
66
|
-
export declare function toAdkInstructionTool(tool: InstructionTool): BaseTool;
|
|
67
|
-
/**
|
|
68
|
-
* ADK surface for a NativeToolMarker: the shared sentinel the ADK runtime
|
|
69
|
-
* has always run for it, which during processLlmRequest leaves itself in
|
|
70
|
-
* the request for the adapter (or adds Gemini's own tool object).
|
|
71
|
-
*/
|
|
72
|
-
export declare function toAdkNativeTool(marker: NativeToolMarker): BaseTool;
|
|
73
|
-
/** ADK surface for an own Toolset: a BaseToolset carrying it. */
|
|
74
|
-
export declare function toAdkToolset(toolset: Toolset): BaseToolset;
|
|
75
|
-
/**
|
|
76
|
-
* What the engine holds as a tool, as the ADK runtime consumes it: a Tool
|
|
77
|
-
* or a defineTool contract through toFunctionTool, an InstructionTool
|
|
78
|
-
* through toAdkInstructionTool, a NativeToolMarker through toAdkNativeTool.
|
|
79
|
-
* An ADK tool (one with runAsync) passes through as it is.
|
|
80
|
-
*/
|
|
81
|
-
export declare function toAdkTool(tool: Tool | ToolContract<any> | InstructionTool | NativeToolMarker | BaseTool): BaseTool;
|