@iqai/adk 0.4.0 → 0.4.1
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 +6 -0
- package/dist/index.d.mts +34 -2
- package/dist/index.d.ts +34 -2
- package/dist/index.js +178 -3
- package/dist/index.mjs +176 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -4422,14 +4422,46 @@ declare class InMemoryMemoryService implements BaseMemoryService {
|
|
|
4422
4422
|
clear(): void;
|
|
4423
4423
|
}
|
|
4424
4424
|
|
|
4425
|
+
/**
|
|
4426
|
+
* A memory service that uses Vertex AI RAG for storage and retrieval.
|
|
4427
|
+
*/
|
|
4428
|
+
declare class VertexAiRagMemoryService implements BaseMemoryService {
|
|
4429
|
+
private _vertexRagStore;
|
|
4430
|
+
/**
|
|
4431
|
+
* Initializes a VertexAiRagMemoryService.
|
|
4432
|
+
*
|
|
4433
|
+
* @param ragCorpus The name of the Vertex AI RAG corpus to use. Format:
|
|
4434
|
+
* `projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}`
|
|
4435
|
+
* or `{rag_corpus_id}`
|
|
4436
|
+
* @param similarityTopK The number of contexts to retrieve.
|
|
4437
|
+
* @param vectorDistanceThreshold Only returns contexts with vector distance
|
|
4438
|
+
* smaller than the threshold.
|
|
4439
|
+
*/
|
|
4440
|
+
constructor(ragCorpus?: string, similarityTopK?: number, vectorDistanceThreshold?: number);
|
|
4441
|
+
/**
|
|
4442
|
+
* Adds a session to the memory service
|
|
4443
|
+
*/
|
|
4444
|
+
addSessionToMemory(session: Session): Promise<void>;
|
|
4445
|
+
/**
|
|
4446
|
+
* Searches for sessions that match the query using rag.retrieval_query
|
|
4447
|
+
*/
|
|
4448
|
+
searchMemory(options: {
|
|
4449
|
+
appName: string;
|
|
4450
|
+
userId: string;
|
|
4451
|
+
query: string;
|
|
4452
|
+
}): Promise<SearchMemoryResponse>;
|
|
4453
|
+
}
|
|
4454
|
+
|
|
4425
4455
|
/**
|
|
4426
4456
|
* Memory Services for the Agent Development Kit
|
|
4427
4457
|
*/
|
|
4428
4458
|
|
|
4429
4459
|
type index$4_InMemoryMemoryService = InMemoryMemoryService;
|
|
4430
4460
|
declare const index$4_InMemoryMemoryService: typeof InMemoryMemoryService;
|
|
4461
|
+
type index$4_VertexAiRagMemoryService = VertexAiRagMemoryService;
|
|
4462
|
+
declare const index$4_VertexAiRagMemoryService: typeof VertexAiRagMemoryService;
|
|
4431
4463
|
declare namespace index$4 {
|
|
4432
|
-
export { index$4_InMemoryMemoryService as InMemoryMemoryService };
|
|
4464
|
+
export { index$4_InMemoryMemoryService as InMemoryMemoryService, index$4_VertexAiRagMemoryService as VertexAiRagMemoryService };
|
|
4433
4465
|
}
|
|
4434
4466
|
|
|
4435
4467
|
/**
|
|
@@ -5575,4 +5607,4 @@ declare const traceLlmCall: (invocationContext: InvocationContext, eventId: stri
|
|
|
5575
5607
|
|
|
5576
5608
|
declare const VERSION = "0.1.0";
|
|
5577
5609
|
|
|
5578
|
-
export { AF_FUNCTION_CALL_ID_PREFIX, type AfterAgentCallback, type AfterModelCallback, type AfterToolCallback, LlmAgent as Agent, AgentBuilder, type AgentBuilderConfig, type AgentBuilderWithSchema, AgentEvaluator, AgentTool, type AgentToolConfig, type AgentType, index$5 as Agents, AiSdkLlm, AnthropicLlm, ApiKeyCredential, ApiKeyScheme, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, AuthTool, type AuthToolArguments, AutoFlow, BaseAgent, type BaseAgentType, BaseCodeExecutor, type BaseCodeExecutorConfig, BaseLLMConnection, BaseLlm, BaseLlmFlow, BaseLlmRequestProcessor, BaseLlmResponseProcessor, type BaseMemoryService, BasePlanner, BaseSessionService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BeforeAgentCallback, type BeforeModelCallback, type BeforeToolCallback, type BuildFunctionDeclarationOptions, type BuiltAgent, BuiltInCodeExecutor, BuiltInPlanner, CallbackContext, type CodeExecutionInput, type CodeExecutionResult, CodeExecutionUtils, CodeExecutorContext, type CreateToolConfig, type CreateToolConfigWithSchema, type CreateToolConfigWithoutSchema, DatabaseSessionService, EnhancedAuthConfig, type EnhancedRunner, type EvalCase, type EvalCaseResult, type EvalMetric, type EvalMetricResult, type EvalMetricResultPerInvocation, EvalResult, type EvalSet, type EvalSetResult, EvalStatus, type EvaluateConfig, index as Evaluation, type EvaluationResult, Evaluator, Event, EventActions, index$2 as Events, ExitLoopTool, type File, FileOperationsTool, FinalResponseMatchV2Evaluator, index$1 as Flows, type FullMessage, FunctionTool, GcsArtifactService, type GetSessionConfig, GetUserChoiceTool, GoogleLlm, GoogleSearch, HttpRequestTool, HttpScheme, InMemoryArtifactService, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, type InstructionProvider, type IntermediateData, type Interval, type Invocation, InvocationContext, type JudgeModelOptions, LLMRegistry, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionsResponse, LlmAgent, type LlmAgentConfig, LlmCallsLimitExceededError, type LlmModel, type LlmModelConfig, LlmRequest, LlmResponse, LoadArtifactsTool, LoadMemoryTool, LocalEvalService, LoopAgent, type LoopAgentConfig, McpAbi, McpAtp, McpBamm, McpCoinGecko, type McpConfig, McpDiscord, McpError, McpErrorType, McpFilesystem, McpFraxlend, McpGeneric, McpIqWiki, McpMemory, McpNearAgent, McpNearIntents, McpOdos, McpSamplingHandler, type McpSamplingRequest, type McpSamplingResponse, type McpServerConfig, McpTelegram, McpToolset, type McpTransportType, McpUpbit, index$4 as Memory, type MessagePart, type MetricInfo, type MetricValueInfo, index$6 as Models, type MultiAgentResponse, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAiLlm, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, type PerInvocationResult, PlanReActPlanner, PrebuiltMetrics, REQUEST_EUC_FUNCTION_CALL_NAME, ReadonlyContext, RougeEvaluator, RunConfig, Runner, type RunnerAskReturn, SafetyEvaluatorV1, type SamplingHandler, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionInput, type SessionOptions, index$3 as Sessions, type SingleAfterModelCallback, type SingleAfterToolCallback, type SingleAgentCallback, type SingleBeforeModelCallback, type SingleBeforeToolCallback, SingleFlow, State, StreamingMode, type TelemetryConfig, TelemetryService, type ThinkingConfig, type ToolConfig, ToolContext, type ToolUnion, index$7 as Tools, TrajectoryEvaluator, TransferToAgentTool, UserInteractionTool, VERSION, VertexAiSessionService, _findFunctionCallEventIfLastEventIsFunctionResponse, adkToMcpToolType, requestProcessor$2 as agentTransferRequestProcessor, requestProcessor$6 as basicRequestProcessor, buildFunctionDeclaration, requestProcessor as codeExecutionRequestProcessor, responseProcessor as codeExecutionResponseProcessor, requestProcessor$3 as contentRequestProcessor, convertMcpToolToBaseTool, createAuthToolArguments, createBranchContextForSubAgent, createDatabaseSessionService, createFunctionTool, createMysqlSessionService, createPostgresSessionService, createSamplingHandler, createSqliteSessionService, createTool, generateAuthEvent, generateClientFunctionCallId, getLongRunningFunctionCalls, getMcpTools, handleFunctionCallsAsync, handleFunctionCallsLive, requestProcessor$5 as identityRequestProcessor, initializeTelemetry, injectSessionState, requestProcessor$4 as instructionsRequestProcessor, isEnhancedAuthConfig, jsonSchemaToDeclaration, mcpSchemaToParameters, mergeAgentRun, mergeParallelFunctionResponseEvents, newInvocationContextId, requestProcessor$1 as nlPlanningRequestProcessor, responseProcessor$1 as nlPlanningResponseProcessor, normalizeJsonSchema, populateClientFunctionCallId, registerProviders, removeClientFunctionCallId, requestProcessor$7 as requestProcessor, shutdownTelemetry, telemetryService, traceLlmCall, traceToolCall, tracer };
|
|
5610
|
+
export { AF_FUNCTION_CALL_ID_PREFIX, type AfterAgentCallback, type AfterModelCallback, type AfterToolCallback, LlmAgent as Agent, AgentBuilder, type AgentBuilderConfig, type AgentBuilderWithSchema, AgentEvaluator, AgentTool, type AgentToolConfig, type AgentType, index$5 as Agents, AiSdkLlm, AnthropicLlm, ApiKeyCredential, ApiKeyScheme, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, AuthTool, type AuthToolArguments, AutoFlow, BaseAgent, type BaseAgentType, BaseCodeExecutor, type BaseCodeExecutorConfig, BaseLLMConnection, BaseLlm, BaseLlmFlow, BaseLlmRequestProcessor, BaseLlmResponseProcessor, type BaseMemoryService, BasePlanner, BaseSessionService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BeforeAgentCallback, type BeforeModelCallback, type BeforeToolCallback, type BuildFunctionDeclarationOptions, type BuiltAgent, BuiltInCodeExecutor, BuiltInPlanner, CallbackContext, type CodeExecutionInput, type CodeExecutionResult, CodeExecutionUtils, CodeExecutorContext, type CreateToolConfig, type CreateToolConfigWithSchema, type CreateToolConfigWithoutSchema, DatabaseSessionService, EnhancedAuthConfig, type EnhancedRunner, type EvalCase, type EvalCaseResult, type EvalMetric, type EvalMetricResult, type EvalMetricResultPerInvocation, EvalResult, type EvalSet, type EvalSetResult, EvalStatus, type EvaluateConfig, index as Evaluation, type EvaluationResult, Evaluator, Event, EventActions, index$2 as Events, ExitLoopTool, type File, FileOperationsTool, FinalResponseMatchV2Evaluator, index$1 as Flows, type FullMessage, FunctionTool, GcsArtifactService, type GetSessionConfig, GetUserChoiceTool, GoogleLlm, GoogleSearch, HttpRequestTool, HttpScheme, InMemoryArtifactService, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, type InstructionProvider, type IntermediateData, type Interval, type Invocation, InvocationContext, type JudgeModelOptions, LLMRegistry, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionsResponse, LlmAgent, type LlmAgentConfig, LlmCallsLimitExceededError, type LlmModel, type LlmModelConfig, LlmRequest, LlmResponse, LoadArtifactsTool, LoadMemoryTool, LocalEvalService, LoopAgent, type LoopAgentConfig, McpAbi, McpAtp, McpBamm, McpCoinGecko, type McpConfig, McpDiscord, McpError, McpErrorType, McpFilesystem, McpFraxlend, McpGeneric, McpIqWiki, McpMemory, McpNearAgent, McpNearIntents, McpOdos, McpSamplingHandler, type McpSamplingRequest, type McpSamplingResponse, type McpServerConfig, McpTelegram, McpToolset, type McpTransportType, McpUpbit, index$4 as Memory, type MessagePart, type MetricInfo, type MetricValueInfo, index$6 as Models, type MultiAgentResponse, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAiLlm, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, type PerInvocationResult, PlanReActPlanner, PrebuiltMetrics, REQUEST_EUC_FUNCTION_CALL_NAME, ReadonlyContext, RougeEvaluator, RunConfig, Runner, type RunnerAskReturn, SafetyEvaluatorV1, type SamplingHandler, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionInput, type SessionOptions, index$3 as Sessions, type SingleAfterModelCallback, type SingleAfterToolCallback, type SingleAgentCallback, type SingleBeforeModelCallback, type SingleBeforeToolCallback, SingleFlow, State, StreamingMode, type TelemetryConfig, TelemetryService, type ThinkingConfig, type ToolConfig, ToolContext, type ToolUnion, index$7 as Tools, TrajectoryEvaluator, TransferToAgentTool, UserInteractionTool, VERSION, VertexAiRagMemoryService, VertexAiSessionService, _findFunctionCallEventIfLastEventIsFunctionResponse, adkToMcpToolType, requestProcessor$2 as agentTransferRequestProcessor, requestProcessor$6 as basicRequestProcessor, buildFunctionDeclaration, requestProcessor as codeExecutionRequestProcessor, responseProcessor as codeExecutionResponseProcessor, requestProcessor$3 as contentRequestProcessor, convertMcpToolToBaseTool, createAuthToolArguments, createBranchContextForSubAgent, createDatabaseSessionService, createFunctionTool, createMysqlSessionService, createPostgresSessionService, createSamplingHandler, createSqliteSessionService, createTool, generateAuthEvent, generateClientFunctionCallId, getLongRunningFunctionCalls, getMcpTools, handleFunctionCallsAsync, handleFunctionCallsLive, requestProcessor$5 as identityRequestProcessor, initializeTelemetry, injectSessionState, requestProcessor$4 as instructionsRequestProcessor, isEnhancedAuthConfig, jsonSchemaToDeclaration, mcpSchemaToParameters, mergeAgentRun, mergeParallelFunctionResponseEvents, newInvocationContextId, requestProcessor$1 as nlPlanningRequestProcessor, responseProcessor$1 as nlPlanningResponseProcessor, normalizeJsonSchema, populateClientFunctionCallId, registerProviders, removeClientFunctionCallId, requestProcessor$7 as requestProcessor, shutdownTelemetry, telemetryService, traceLlmCall, traceToolCall, tracer };
|
package/dist/index.d.ts
CHANGED
|
@@ -4422,14 +4422,46 @@ declare class InMemoryMemoryService implements BaseMemoryService {
|
|
|
4422
4422
|
clear(): void;
|
|
4423
4423
|
}
|
|
4424
4424
|
|
|
4425
|
+
/**
|
|
4426
|
+
* A memory service that uses Vertex AI RAG for storage and retrieval.
|
|
4427
|
+
*/
|
|
4428
|
+
declare class VertexAiRagMemoryService implements BaseMemoryService {
|
|
4429
|
+
private _vertexRagStore;
|
|
4430
|
+
/**
|
|
4431
|
+
* Initializes a VertexAiRagMemoryService.
|
|
4432
|
+
*
|
|
4433
|
+
* @param ragCorpus The name of the Vertex AI RAG corpus to use. Format:
|
|
4434
|
+
* `projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}`
|
|
4435
|
+
* or `{rag_corpus_id}`
|
|
4436
|
+
* @param similarityTopK The number of contexts to retrieve.
|
|
4437
|
+
* @param vectorDistanceThreshold Only returns contexts with vector distance
|
|
4438
|
+
* smaller than the threshold.
|
|
4439
|
+
*/
|
|
4440
|
+
constructor(ragCorpus?: string, similarityTopK?: number, vectorDistanceThreshold?: number);
|
|
4441
|
+
/**
|
|
4442
|
+
* Adds a session to the memory service
|
|
4443
|
+
*/
|
|
4444
|
+
addSessionToMemory(session: Session): Promise<void>;
|
|
4445
|
+
/**
|
|
4446
|
+
* Searches for sessions that match the query using rag.retrieval_query
|
|
4447
|
+
*/
|
|
4448
|
+
searchMemory(options: {
|
|
4449
|
+
appName: string;
|
|
4450
|
+
userId: string;
|
|
4451
|
+
query: string;
|
|
4452
|
+
}): Promise<SearchMemoryResponse>;
|
|
4453
|
+
}
|
|
4454
|
+
|
|
4425
4455
|
/**
|
|
4426
4456
|
* Memory Services for the Agent Development Kit
|
|
4427
4457
|
*/
|
|
4428
4458
|
|
|
4429
4459
|
type index$4_InMemoryMemoryService = InMemoryMemoryService;
|
|
4430
4460
|
declare const index$4_InMemoryMemoryService: typeof InMemoryMemoryService;
|
|
4461
|
+
type index$4_VertexAiRagMemoryService = VertexAiRagMemoryService;
|
|
4462
|
+
declare const index$4_VertexAiRagMemoryService: typeof VertexAiRagMemoryService;
|
|
4431
4463
|
declare namespace index$4 {
|
|
4432
|
-
export { index$4_InMemoryMemoryService as InMemoryMemoryService };
|
|
4464
|
+
export { index$4_InMemoryMemoryService as InMemoryMemoryService, index$4_VertexAiRagMemoryService as VertexAiRagMemoryService };
|
|
4433
4465
|
}
|
|
4434
4466
|
|
|
4435
4467
|
/**
|
|
@@ -5575,4 +5607,4 @@ declare const traceLlmCall: (invocationContext: InvocationContext, eventId: stri
|
|
|
5575
5607
|
|
|
5576
5608
|
declare const VERSION = "0.1.0";
|
|
5577
5609
|
|
|
5578
|
-
export { AF_FUNCTION_CALL_ID_PREFIX, type AfterAgentCallback, type AfterModelCallback, type AfterToolCallback, LlmAgent as Agent, AgentBuilder, type AgentBuilderConfig, type AgentBuilderWithSchema, AgentEvaluator, AgentTool, type AgentToolConfig, type AgentType, index$5 as Agents, AiSdkLlm, AnthropicLlm, ApiKeyCredential, ApiKeyScheme, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, AuthTool, type AuthToolArguments, AutoFlow, BaseAgent, type BaseAgentType, BaseCodeExecutor, type BaseCodeExecutorConfig, BaseLLMConnection, BaseLlm, BaseLlmFlow, BaseLlmRequestProcessor, BaseLlmResponseProcessor, type BaseMemoryService, BasePlanner, BaseSessionService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BeforeAgentCallback, type BeforeModelCallback, type BeforeToolCallback, type BuildFunctionDeclarationOptions, type BuiltAgent, BuiltInCodeExecutor, BuiltInPlanner, CallbackContext, type CodeExecutionInput, type CodeExecutionResult, CodeExecutionUtils, CodeExecutorContext, type CreateToolConfig, type CreateToolConfigWithSchema, type CreateToolConfigWithoutSchema, DatabaseSessionService, EnhancedAuthConfig, type EnhancedRunner, type EvalCase, type EvalCaseResult, type EvalMetric, type EvalMetricResult, type EvalMetricResultPerInvocation, EvalResult, type EvalSet, type EvalSetResult, EvalStatus, type EvaluateConfig, index as Evaluation, type EvaluationResult, Evaluator, Event, EventActions, index$2 as Events, ExitLoopTool, type File, FileOperationsTool, FinalResponseMatchV2Evaluator, index$1 as Flows, type FullMessage, FunctionTool, GcsArtifactService, type GetSessionConfig, GetUserChoiceTool, GoogleLlm, GoogleSearch, HttpRequestTool, HttpScheme, InMemoryArtifactService, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, type InstructionProvider, type IntermediateData, type Interval, type Invocation, InvocationContext, type JudgeModelOptions, LLMRegistry, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionsResponse, LlmAgent, type LlmAgentConfig, LlmCallsLimitExceededError, type LlmModel, type LlmModelConfig, LlmRequest, LlmResponse, LoadArtifactsTool, LoadMemoryTool, LocalEvalService, LoopAgent, type LoopAgentConfig, McpAbi, McpAtp, McpBamm, McpCoinGecko, type McpConfig, McpDiscord, McpError, McpErrorType, McpFilesystem, McpFraxlend, McpGeneric, McpIqWiki, McpMemory, McpNearAgent, McpNearIntents, McpOdos, McpSamplingHandler, type McpSamplingRequest, type McpSamplingResponse, type McpServerConfig, McpTelegram, McpToolset, type McpTransportType, McpUpbit, index$4 as Memory, type MessagePart, type MetricInfo, type MetricValueInfo, index$6 as Models, type MultiAgentResponse, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAiLlm, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, type PerInvocationResult, PlanReActPlanner, PrebuiltMetrics, REQUEST_EUC_FUNCTION_CALL_NAME, ReadonlyContext, RougeEvaluator, RunConfig, Runner, type RunnerAskReturn, SafetyEvaluatorV1, type SamplingHandler, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionInput, type SessionOptions, index$3 as Sessions, type SingleAfterModelCallback, type SingleAfterToolCallback, type SingleAgentCallback, type SingleBeforeModelCallback, type SingleBeforeToolCallback, SingleFlow, State, StreamingMode, type TelemetryConfig, TelemetryService, type ThinkingConfig, type ToolConfig, ToolContext, type ToolUnion, index$7 as Tools, TrajectoryEvaluator, TransferToAgentTool, UserInteractionTool, VERSION, VertexAiSessionService, _findFunctionCallEventIfLastEventIsFunctionResponse, adkToMcpToolType, requestProcessor$2 as agentTransferRequestProcessor, requestProcessor$6 as basicRequestProcessor, buildFunctionDeclaration, requestProcessor as codeExecutionRequestProcessor, responseProcessor as codeExecutionResponseProcessor, requestProcessor$3 as contentRequestProcessor, convertMcpToolToBaseTool, createAuthToolArguments, createBranchContextForSubAgent, createDatabaseSessionService, createFunctionTool, createMysqlSessionService, createPostgresSessionService, createSamplingHandler, createSqliteSessionService, createTool, generateAuthEvent, generateClientFunctionCallId, getLongRunningFunctionCalls, getMcpTools, handleFunctionCallsAsync, handleFunctionCallsLive, requestProcessor$5 as identityRequestProcessor, initializeTelemetry, injectSessionState, requestProcessor$4 as instructionsRequestProcessor, isEnhancedAuthConfig, jsonSchemaToDeclaration, mcpSchemaToParameters, mergeAgentRun, mergeParallelFunctionResponseEvents, newInvocationContextId, requestProcessor$1 as nlPlanningRequestProcessor, responseProcessor$1 as nlPlanningResponseProcessor, normalizeJsonSchema, populateClientFunctionCallId, registerProviders, removeClientFunctionCallId, requestProcessor$7 as requestProcessor, shutdownTelemetry, telemetryService, traceLlmCall, traceToolCall, tracer };
|
|
5610
|
+
export { AF_FUNCTION_CALL_ID_PREFIX, type AfterAgentCallback, type AfterModelCallback, type AfterToolCallback, LlmAgent as Agent, AgentBuilder, type AgentBuilderConfig, type AgentBuilderWithSchema, AgentEvaluator, AgentTool, type AgentToolConfig, type AgentType, index$5 as Agents, AiSdkLlm, AnthropicLlm, ApiKeyCredential, ApiKeyScheme, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, AuthTool, type AuthToolArguments, AutoFlow, BaseAgent, type BaseAgentType, BaseCodeExecutor, type BaseCodeExecutorConfig, BaseLLMConnection, BaseLlm, BaseLlmFlow, BaseLlmRequestProcessor, BaseLlmResponseProcessor, type BaseMemoryService, BasePlanner, BaseSessionService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BeforeAgentCallback, type BeforeModelCallback, type BeforeToolCallback, type BuildFunctionDeclarationOptions, type BuiltAgent, BuiltInCodeExecutor, BuiltInPlanner, CallbackContext, type CodeExecutionInput, type CodeExecutionResult, CodeExecutionUtils, CodeExecutorContext, type CreateToolConfig, type CreateToolConfigWithSchema, type CreateToolConfigWithoutSchema, DatabaseSessionService, EnhancedAuthConfig, type EnhancedRunner, type EvalCase, type EvalCaseResult, type EvalMetric, type EvalMetricResult, type EvalMetricResultPerInvocation, EvalResult, type EvalSet, type EvalSetResult, EvalStatus, type EvaluateConfig, index as Evaluation, type EvaluationResult, Evaluator, Event, EventActions, index$2 as Events, ExitLoopTool, type File, FileOperationsTool, FinalResponseMatchV2Evaluator, index$1 as Flows, type FullMessage, FunctionTool, GcsArtifactService, type GetSessionConfig, GetUserChoiceTool, GoogleLlm, GoogleSearch, HttpRequestTool, HttpScheme, InMemoryArtifactService, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, type InstructionProvider, type IntermediateData, type Interval, type Invocation, InvocationContext, type JudgeModelOptions, LLMRegistry, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionsResponse, LlmAgent, type LlmAgentConfig, LlmCallsLimitExceededError, type LlmModel, type LlmModelConfig, LlmRequest, LlmResponse, LoadArtifactsTool, LoadMemoryTool, LocalEvalService, LoopAgent, type LoopAgentConfig, McpAbi, McpAtp, McpBamm, McpCoinGecko, type McpConfig, McpDiscord, McpError, McpErrorType, McpFilesystem, McpFraxlend, McpGeneric, McpIqWiki, McpMemory, McpNearAgent, McpNearIntents, McpOdos, McpSamplingHandler, type McpSamplingRequest, type McpSamplingResponse, type McpServerConfig, McpTelegram, McpToolset, type McpTransportType, McpUpbit, index$4 as Memory, type MessagePart, type MetricInfo, type MetricValueInfo, index$6 as Models, type MultiAgentResponse, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAiLlm, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, type PerInvocationResult, PlanReActPlanner, PrebuiltMetrics, REQUEST_EUC_FUNCTION_CALL_NAME, ReadonlyContext, RougeEvaluator, RunConfig, Runner, type RunnerAskReturn, SafetyEvaluatorV1, type SamplingHandler, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionInput, type SessionOptions, index$3 as Sessions, type SingleAfterModelCallback, type SingleAfterToolCallback, type SingleAgentCallback, type SingleBeforeModelCallback, type SingleBeforeToolCallback, SingleFlow, State, StreamingMode, type TelemetryConfig, TelemetryService, type ThinkingConfig, type ToolConfig, ToolContext, type ToolUnion, index$7 as Tools, TrajectoryEvaluator, TransferToAgentTool, UserInteractionTool, VERSION, VertexAiRagMemoryService, VertexAiSessionService, _findFunctionCallEventIfLastEventIsFunctionResponse, adkToMcpToolType, requestProcessor$2 as agentTransferRequestProcessor, requestProcessor$6 as basicRequestProcessor, buildFunctionDeclaration, requestProcessor as codeExecutionRequestProcessor, responseProcessor as codeExecutionResponseProcessor, requestProcessor$3 as contentRequestProcessor, convertMcpToolToBaseTool, createAuthToolArguments, createBranchContextForSubAgent, createDatabaseSessionService, createFunctionTool, createMysqlSessionService, createPostgresSessionService, createSamplingHandler, createSqliteSessionService, createTool, generateAuthEvent, generateClientFunctionCallId, getLongRunningFunctionCalls, getMcpTools, handleFunctionCallsAsync, handleFunctionCallsLive, requestProcessor$5 as identityRequestProcessor, initializeTelemetry, injectSessionState, requestProcessor$4 as instructionsRequestProcessor, isEnhancedAuthConfig, jsonSchemaToDeclaration, mcpSchemaToParameters, mergeAgentRun, mergeParallelFunctionResponseEvents, newInvocationContextId, requestProcessor$1 as nlPlanningRequestProcessor, responseProcessor$1 as nlPlanningResponseProcessor, normalizeJsonSchema, populateClientFunctionCallId, registerProviders, removeClientFunctionCallId, requestProcessor$7 as requestProcessor, shutdownTelemetry, telemetryService, traceLlmCall, traceToolCall, tracer };
|
package/dist/index.js
CHANGED
|
@@ -11295,9 +11295,183 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11295
11295
|
// src/memory/index.ts
|
|
11296
11296
|
var memory_exports = {};
|
|
11297
11297
|
__export(memory_exports, {
|
|
11298
|
-
InMemoryMemoryService: () => InMemoryMemoryService
|
|
11298
|
+
InMemoryMemoryService: () => InMemoryMemoryService,
|
|
11299
|
+
VertexAiRagMemoryService: () => VertexAiRagMemoryService
|
|
11299
11300
|
});
|
|
11300
11301
|
|
|
11302
|
+
// src/memory/vertex-ai-rag-memory-service.ts
|
|
11303
|
+
|
|
11304
|
+
var _fs = require('fs');
|
|
11305
|
+
var _os = require('os');
|
|
11306
|
+
|
|
11307
|
+
var rag = {
|
|
11308
|
+
async upload_file(options) {
|
|
11309
|
+
console.log("Mock upload_file:", options);
|
|
11310
|
+
},
|
|
11311
|
+
async retrieval_query(options) {
|
|
11312
|
+
console.log("Mock retrieval_query:", options);
|
|
11313
|
+
return { contexts: { contexts: [] } };
|
|
11314
|
+
}
|
|
11315
|
+
};
|
|
11316
|
+
function _mergeEventLists(eventLists) {
|
|
11317
|
+
const merged = [];
|
|
11318
|
+
while (eventLists.length > 0) {
|
|
11319
|
+
const current = eventLists.shift();
|
|
11320
|
+
const currentTs = new Set(current.map((event) => event.timestamp));
|
|
11321
|
+
let mergeFound = true;
|
|
11322
|
+
while (mergeFound) {
|
|
11323
|
+
mergeFound = false;
|
|
11324
|
+
const remaining = [];
|
|
11325
|
+
for (const other of eventLists) {
|
|
11326
|
+
const otherTs = new Set(other.map((event) => event.timestamp));
|
|
11327
|
+
const hasOverlap = Array.from(currentTs).some((ts) => otherTs.has(ts));
|
|
11328
|
+
if (hasOverlap) {
|
|
11329
|
+
const newEvents = other.filter((e) => !currentTs.has(e.timestamp));
|
|
11330
|
+
current.push(...newEvents);
|
|
11331
|
+
newEvents.forEach((e) => currentTs.add(e.timestamp));
|
|
11332
|
+
mergeFound = true;
|
|
11333
|
+
} else {
|
|
11334
|
+
remaining.push(other);
|
|
11335
|
+
}
|
|
11336
|
+
}
|
|
11337
|
+
eventLists.splice(0, eventLists.length, ...remaining);
|
|
11338
|
+
}
|
|
11339
|
+
merged.push(current);
|
|
11340
|
+
}
|
|
11341
|
+
return merged;
|
|
11342
|
+
}
|
|
11343
|
+
var VertexAiRagMemoryService = class {
|
|
11344
|
+
|
|
11345
|
+
/**
|
|
11346
|
+
* Initializes a VertexAiRagMemoryService.
|
|
11347
|
+
*
|
|
11348
|
+
* @param ragCorpus The name of the Vertex AI RAG corpus to use. Format:
|
|
11349
|
+
* `projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}`
|
|
11350
|
+
* or `{rag_corpus_id}`
|
|
11351
|
+
* @param similarityTopK The number of contexts to retrieve.
|
|
11352
|
+
* @param vectorDistanceThreshold Only returns contexts with vector distance
|
|
11353
|
+
* smaller than the threshold.
|
|
11354
|
+
*/
|
|
11355
|
+
constructor(ragCorpus, similarityTopK, vectorDistanceThreshold = 10) {
|
|
11356
|
+
this._vertexRagStore = {
|
|
11357
|
+
rag_resources: ragCorpus ? [{ rag_corpus: ragCorpus }] : [],
|
|
11358
|
+
similarity_top_k: similarityTopK,
|
|
11359
|
+
vector_distance_threshold: vectorDistanceThreshold
|
|
11360
|
+
};
|
|
11361
|
+
}
|
|
11362
|
+
/**
|
|
11363
|
+
* Adds a session to the memory service
|
|
11364
|
+
*/
|
|
11365
|
+
async addSessionToMemory(session) {
|
|
11366
|
+
const tempFileName = `temp_${_crypto.randomUUID.call(void 0, )}.txt`;
|
|
11367
|
+
const tempFilePath = _path.join.call(void 0, _os.tmpdir.call(void 0, ), tempFileName);
|
|
11368
|
+
try {
|
|
11369
|
+
const outputLines = [];
|
|
11370
|
+
for (const event of session.events) {
|
|
11371
|
+
if (!event.content || !event.content.parts) {
|
|
11372
|
+
continue;
|
|
11373
|
+
}
|
|
11374
|
+
const textParts = event.content.parts.filter((part) => part.text).map((part) => part.text.replace(/\n/g, " "));
|
|
11375
|
+
if (textParts.length > 0) {
|
|
11376
|
+
outputLines.push(
|
|
11377
|
+
JSON.stringify({
|
|
11378
|
+
author: event.author,
|
|
11379
|
+
timestamp: event.timestamp,
|
|
11380
|
+
text: textParts.join(".")
|
|
11381
|
+
})
|
|
11382
|
+
);
|
|
11383
|
+
}
|
|
11384
|
+
}
|
|
11385
|
+
const outputString = outputLines.join("\n");
|
|
11386
|
+
_fs.writeFileSync.call(void 0, tempFilePath, outputString, "utf8");
|
|
11387
|
+
if (!this._vertexRagStore.rag_resources || this._vertexRagStore.rag_resources.length === 0) {
|
|
11388
|
+
throw new Error("Rag resources must be set.");
|
|
11389
|
+
}
|
|
11390
|
+
for (const ragResource of this._vertexRagStore.rag_resources) {
|
|
11391
|
+
await rag.upload_file({
|
|
11392
|
+
corpus_name: ragResource.rag_corpus,
|
|
11393
|
+
path: tempFilePath,
|
|
11394
|
+
// This is the temp workaround as upload file does not support
|
|
11395
|
+
// adding metadata, thus use display_name to store the session info.
|
|
11396
|
+
display_name: `${session.appName}.${session.userId}.${session.id}`
|
|
11397
|
+
});
|
|
11398
|
+
}
|
|
11399
|
+
} finally {
|
|
11400
|
+
try {
|
|
11401
|
+
_fs.unlinkSync.call(void 0, tempFilePath);
|
|
11402
|
+
} catch (error) {
|
|
11403
|
+
console.warn("Failed to delete temporary file:", tempFilePath, error);
|
|
11404
|
+
}
|
|
11405
|
+
}
|
|
11406
|
+
}
|
|
11407
|
+
/**
|
|
11408
|
+
* Searches for sessions that match the query using rag.retrieval_query
|
|
11409
|
+
*/
|
|
11410
|
+
async searchMemory(options) {
|
|
11411
|
+
const { appName, userId, query } = options;
|
|
11412
|
+
const response = await rag.retrieval_query({
|
|
11413
|
+
text: query,
|
|
11414
|
+
rag_resources: this._vertexRagStore.rag_resources,
|
|
11415
|
+
rag_corpora: this._vertexRagStore.rag_corpora,
|
|
11416
|
+
similarity_top_k: this._vertexRagStore.similarity_top_k,
|
|
11417
|
+
vector_distance_threshold: this._vertexRagStore.vector_distance_threshold
|
|
11418
|
+
});
|
|
11419
|
+
const memoryResults = [];
|
|
11420
|
+
const sessionEventsMap = /* @__PURE__ */ new Map();
|
|
11421
|
+
for (const context4 of response.contexts.contexts) {
|
|
11422
|
+
if (!context4.source_display_name.startsWith(`${appName}.${userId}.`)) {
|
|
11423
|
+
continue;
|
|
11424
|
+
}
|
|
11425
|
+
const sessionId = context4.source_display_name.split(".").pop();
|
|
11426
|
+
const events = [];
|
|
11427
|
+
if (context4.text) {
|
|
11428
|
+
const lines = context4.text.split("\n");
|
|
11429
|
+
for (const line of lines) {
|
|
11430
|
+
const trimmedLine = line.trim();
|
|
11431
|
+
if (!trimmedLine) {
|
|
11432
|
+
continue;
|
|
11433
|
+
}
|
|
11434
|
+
try {
|
|
11435
|
+
const eventData = JSON.parse(trimmedLine);
|
|
11436
|
+
const author = eventData.author || "";
|
|
11437
|
+
const timestamp = Number.parseFloat(eventData.timestamp || "0");
|
|
11438
|
+
const text = eventData.text || "";
|
|
11439
|
+
const content = {
|
|
11440
|
+
parts: [{ text }]
|
|
11441
|
+
};
|
|
11442
|
+
const event = {
|
|
11443
|
+
author,
|
|
11444
|
+
timestamp,
|
|
11445
|
+
content
|
|
11446
|
+
};
|
|
11447
|
+
events.push(event);
|
|
11448
|
+
} catch (e7) {
|
|
11449
|
+
}
|
|
11450
|
+
}
|
|
11451
|
+
}
|
|
11452
|
+
if (sessionEventsMap.has(sessionId)) {
|
|
11453
|
+
sessionEventsMap.get(sessionId).push(events);
|
|
11454
|
+
} else {
|
|
11455
|
+
sessionEventsMap.set(sessionId, [events]);
|
|
11456
|
+
}
|
|
11457
|
+
}
|
|
11458
|
+
for (const [sessionId, eventLists] of sessionEventsMap.entries()) {
|
|
11459
|
+
const mergedEventLists = _mergeEventLists(eventLists);
|
|
11460
|
+
for (const events of mergedEventLists) {
|
|
11461
|
+
const sortedEvents = events.sort((a, b) => a.timestamp - b.timestamp).filter((event) => event.content);
|
|
11462
|
+
memoryResults.push(
|
|
11463
|
+
...sortedEvents.map((event) => ({
|
|
11464
|
+
author: event.author,
|
|
11465
|
+
content: event.content,
|
|
11466
|
+
timestamp: formatTimestamp(event.timestamp)
|
|
11467
|
+
}))
|
|
11468
|
+
);
|
|
11469
|
+
}
|
|
11470
|
+
}
|
|
11471
|
+
return { memories: memoryResults };
|
|
11472
|
+
}
|
|
11473
|
+
};
|
|
11474
|
+
|
|
11301
11475
|
// src/sessions/index.ts
|
|
11302
11476
|
var sessions_exports = {};
|
|
11303
11477
|
__export(sessions_exports, {
|
|
@@ -11703,7 +11877,7 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
11703
11877
|
if (!jsonString) return defaultValue;
|
|
11704
11878
|
try {
|
|
11705
11879
|
return JSON.parse(jsonString);
|
|
11706
|
-
} catch (
|
|
11880
|
+
} catch (e8) {
|
|
11707
11881
|
return defaultValue;
|
|
11708
11882
|
}
|
|
11709
11883
|
}
|
|
@@ -13729,4 +13903,5 @@ var VERSION = "0.1.0";
|
|
|
13729
13903
|
|
|
13730
13904
|
|
|
13731
13905
|
|
|
13732
|
-
|
|
13906
|
+
|
|
13907
|
+
exports.AF_FUNCTION_CALL_ID_PREFIX = AF_FUNCTION_CALL_ID_PREFIX; exports.Agent = LlmAgent; exports.AgentBuilder = AgentBuilder; exports.AgentEvaluator = AgentEvaluator; exports.AgentTool = AgentTool; exports.Agents = agents_exports; exports.AiSdkLlm = AiSdkLlm; exports.AnthropicLlm = AnthropicLlm; exports.ApiKeyCredential = ApiKeyCredential; exports.ApiKeyScheme = ApiKeyScheme; exports.AuthConfig = AuthConfig; exports.AuthCredential = AuthCredential; exports.AuthCredentialType = AuthCredentialType; exports.AuthHandler = AuthHandler; exports.AuthScheme = AuthScheme; exports.AuthSchemeType = AuthSchemeType; exports.AuthTool = AuthTool; exports.AutoFlow = AutoFlow; exports.BaseAgent = BaseAgent; exports.BaseCodeExecutor = BaseCodeExecutor; exports.BaseLLMConnection = BaseLLMConnection; exports.BaseLlm = BaseLlm; exports.BaseLlmFlow = BaseLlmFlow; exports.BaseLlmRequestProcessor = BaseLlmRequestProcessor; exports.BaseLlmResponseProcessor = BaseLlmResponseProcessor; exports.BasePlanner = BasePlanner; exports.BaseSessionService = BaseSessionService; exports.BaseTool = BaseTool; exports.BasicAuthCredential = BasicAuthCredential; exports.BearerTokenCredential = BearerTokenCredential; exports.BuiltInCodeExecutor = BuiltInCodeExecutor; exports.BuiltInPlanner = BuiltInPlanner; exports.CallbackContext = CallbackContext; exports.CodeExecutionUtils = CodeExecutionUtils; exports.CodeExecutorContext = CodeExecutorContext; exports.DatabaseSessionService = DatabaseSessionService; exports.EnhancedAuthConfig = EnhancedAuthConfig; exports.EvalResult = EvalResult; exports.EvalStatus = EvalStatus; exports.Evaluation = evaluation_exports; exports.Evaluator = Evaluator; exports.Event = Event; exports.EventActions = EventActions; exports.Events = events_exports; exports.ExitLoopTool = ExitLoopTool; exports.FileOperationsTool = FileOperationsTool; exports.FinalResponseMatchV2Evaluator = FinalResponseMatchV2Evaluator; exports.Flows = flows_exports; exports.FunctionTool = FunctionTool; exports.GcsArtifactService = GcsArtifactService; exports.GetUserChoiceTool = GetUserChoiceTool; exports.GoogleLlm = GoogleLlm; exports.GoogleSearch = GoogleSearch; exports.HttpRequestTool = HttpRequestTool; exports.HttpScheme = HttpScheme; exports.InMemoryArtifactService = InMemoryArtifactService; exports.InMemoryMemoryService = InMemoryMemoryService; exports.InMemoryRunner = InMemoryRunner; exports.InMemorySessionService = InMemorySessionService; exports.InvocationContext = InvocationContext; exports.LLMRegistry = LLMRegistry; exports.LangGraphAgent = LangGraphAgent; exports.LlmAgent = LlmAgent; exports.LlmCallsLimitExceededError = LlmCallsLimitExceededError; exports.LlmRequest = LlmRequest; exports.LlmResponse = LlmResponse; exports.LoadArtifactsTool = LoadArtifactsTool; exports.LoadMemoryTool = LoadMemoryTool; exports.LocalEvalService = LocalEvalService; exports.LoopAgent = LoopAgent; exports.McpAbi = McpAbi; exports.McpAtp = McpAtp; exports.McpBamm = McpBamm; exports.McpCoinGecko = McpCoinGecko; exports.McpDiscord = McpDiscord; exports.McpError = McpError; exports.McpErrorType = McpErrorType; exports.McpFilesystem = McpFilesystem; exports.McpFraxlend = McpFraxlend; exports.McpGeneric = McpGeneric; exports.McpIqWiki = McpIqWiki; exports.McpMemory = McpMemory; exports.McpNearAgent = McpNearAgent; exports.McpNearIntents = McpNearIntents; exports.McpOdos = McpOdos; exports.McpSamplingHandler = McpSamplingHandler; exports.McpTelegram = McpTelegram; exports.McpToolset = McpToolset; exports.McpUpbit = McpUpbit; exports.Memory = memory_exports; exports.Models = models_exports; exports.OAuth2Credential = OAuth2Credential; exports.OAuth2Scheme = OAuth2Scheme; exports.OpenAiLlm = OpenAiLlm; exports.OpenIdConnectScheme = OpenIdConnectScheme; exports.ParallelAgent = ParallelAgent; exports.PlanReActPlanner = PlanReActPlanner; exports.PrebuiltMetrics = PrebuiltMetrics; exports.REQUEST_EUC_FUNCTION_CALL_NAME = REQUEST_EUC_FUNCTION_CALL_NAME; exports.ReadonlyContext = ReadonlyContext; exports.RougeEvaluator = RougeEvaluator; exports.RunConfig = RunConfig; exports.Runner = Runner; exports.SafetyEvaluatorV1 = SafetyEvaluatorV1; exports.SequentialAgent = SequentialAgent; exports.Sessions = sessions_exports; exports.SingleFlow = SingleFlow; exports.State = State; exports.StreamingMode = StreamingMode; exports.TelemetryService = TelemetryService; exports.ToolContext = ToolContext; exports.Tools = tools_exports; exports.TrajectoryEvaluator = TrajectoryEvaluator; exports.TransferToAgentTool = TransferToAgentTool; exports.UserInteractionTool = UserInteractionTool; exports.VERSION = VERSION; exports.VertexAiRagMemoryService = VertexAiRagMemoryService; exports.VertexAiSessionService = VertexAiSessionService; exports._findFunctionCallEventIfLastEventIsFunctionResponse = _findFunctionCallEventIfLastEventIsFunctionResponse; exports.adkToMcpToolType = adkToMcpToolType; exports.agentTransferRequestProcessor = requestProcessor8; exports.basicRequestProcessor = requestProcessor2; exports.buildFunctionDeclaration = buildFunctionDeclaration; exports.codeExecutionRequestProcessor = requestProcessor3; exports.codeExecutionResponseProcessor = responseProcessor; exports.contentRequestProcessor = requestProcessor4; exports.convertMcpToolToBaseTool = convertMcpToolToBaseTool; exports.createAuthToolArguments = createAuthToolArguments; exports.createBranchContextForSubAgent = createBranchContextForSubAgent; exports.createDatabaseSessionService = createDatabaseSessionService; exports.createFunctionTool = createFunctionTool; exports.createMysqlSessionService = createMysqlSessionService; exports.createPostgresSessionService = createPostgresSessionService; exports.createSamplingHandler = createSamplingHandler; exports.createSqliteSessionService = createSqliteSessionService; exports.createTool = createTool; exports.generateAuthEvent = generateAuthEvent; exports.generateClientFunctionCallId = generateClientFunctionCallId; exports.getLongRunningFunctionCalls = getLongRunningFunctionCalls; exports.getMcpTools = getMcpTools; exports.handleFunctionCallsAsync = handleFunctionCallsAsync; exports.handleFunctionCallsLive = handleFunctionCallsLive; exports.identityRequestProcessor = requestProcessor5; exports.initializeTelemetry = initializeTelemetry; exports.injectSessionState = injectSessionState; exports.instructionsRequestProcessor = requestProcessor6; exports.isEnhancedAuthConfig = isEnhancedAuthConfig; exports.jsonSchemaToDeclaration = jsonSchemaToDeclaration; exports.mcpSchemaToParameters = mcpSchemaToParameters; exports.mergeAgentRun = mergeAgentRun; exports.mergeParallelFunctionResponseEvents = mergeParallelFunctionResponseEvents; exports.newInvocationContextId = newInvocationContextId; exports.nlPlanningRequestProcessor = requestProcessor7; exports.nlPlanningResponseProcessor = responseProcessor2; exports.normalizeJsonSchema = normalizeJsonSchema; exports.populateClientFunctionCallId = populateClientFunctionCallId; exports.registerProviders = registerProviders; exports.removeClientFunctionCallId = removeClientFunctionCallId; exports.requestProcessor = requestProcessor; exports.shutdownTelemetry = shutdownTelemetry; exports.telemetryService = telemetryService; exports.traceLlmCall = traceLlmCall; exports.traceToolCall = traceToolCall; exports.tracer = tracer;
|
package/dist/index.mjs
CHANGED
|
@@ -11295,9 +11295,183 @@ var AgentBuilder = class _AgentBuilder {
|
|
|
11295
11295
|
// src/memory/index.ts
|
|
11296
11296
|
var memory_exports = {};
|
|
11297
11297
|
__export(memory_exports, {
|
|
11298
|
-
InMemoryMemoryService: () => InMemoryMemoryService
|
|
11298
|
+
InMemoryMemoryService: () => InMemoryMemoryService,
|
|
11299
|
+
VertexAiRagMemoryService: () => VertexAiRagMemoryService
|
|
11299
11300
|
});
|
|
11300
11301
|
|
|
11302
|
+
// src/memory/vertex-ai-rag-memory-service.ts
|
|
11303
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
11304
|
+
import { unlinkSync, writeFileSync } from "fs";
|
|
11305
|
+
import { tmpdir } from "os";
|
|
11306
|
+
import { join } from "path";
|
|
11307
|
+
var rag = {
|
|
11308
|
+
async upload_file(options) {
|
|
11309
|
+
console.log("Mock upload_file:", options);
|
|
11310
|
+
},
|
|
11311
|
+
async retrieval_query(options) {
|
|
11312
|
+
console.log("Mock retrieval_query:", options);
|
|
11313
|
+
return { contexts: { contexts: [] } };
|
|
11314
|
+
}
|
|
11315
|
+
};
|
|
11316
|
+
function _mergeEventLists(eventLists) {
|
|
11317
|
+
const merged = [];
|
|
11318
|
+
while (eventLists.length > 0) {
|
|
11319
|
+
const current = eventLists.shift();
|
|
11320
|
+
const currentTs = new Set(current.map((event) => event.timestamp));
|
|
11321
|
+
let mergeFound = true;
|
|
11322
|
+
while (mergeFound) {
|
|
11323
|
+
mergeFound = false;
|
|
11324
|
+
const remaining = [];
|
|
11325
|
+
for (const other of eventLists) {
|
|
11326
|
+
const otherTs = new Set(other.map((event) => event.timestamp));
|
|
11327
|
+
const hasOverlap = Array.from(currentTs).some((ts) => otherTs.has(ts));
|
|
11328
|
+
if (hasOverlap) {
|
|
11329
|
+
const newEvents = other.filter((e) => !currentTs.has(e.timestamp));
|
|
11330
|
+
current.push(...newEvents);
|
|
11331
|
+
newEvents.forEach((e) => currentTs.add(e.timestamp));
|
|
11332
|
+
mergeFound = true;
|
|
11333
|
+
} else {
|
|
11334
|
+
remaining.push(other);
|
|
11335
|
+
}
|
|
11336
|
+
}
|
|
11337
|
+
eventLists.splice(0, eventLists.length, ...remaining);
|
|
11338
|
+
}
|
|
11339
|
+
merged.push(current);
|
|
11340
|
+
}
|
|
11341
|
+
return merged;
|
|
11342
|
+
}
|
|
11343
|
+
var VertexAiRagMemoryService = class {
|
|
11344
|
+
_vertexRagStore;
|
|
11345
|
+
/**
|
|
11346
|
+
* Initializes a VertexAiRagMemoryService.
|
|
11347
|
+
*
|
|
11348
|
+
* @param ragCorpus The name of the Vertex AI RAG corpus to use. Format:
|
|
11349
|
+
* `projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}`
|
|
11350
|
+
* or `{rag_corpus_id}`
|
|
11351
|
+
* @param similarityTopK The number of contexts to retrieve.
|
|
11352
|
+
* @param vectorDistanceThreshold Only returns contexts with vector distance
|
|
11353
|
+
* smaller than the threshold.
|
|
11354
|
+
*/
|
|
11355
|
+
constructor(ragCorpus, similarityTopK, vectorDistanceThreshold = 10) {
|
|
11356
|
+
this._vertexRagStore = {
|
|
11357
|
+
rag_resources: ragCorpus ? [{ rag_corpus: ragCorpus }] : [],
|
|
11358
|
+
similarity_top_k: similarityTopK,
|
|
11359
|
+
vector_distance_threshold: vectorDistanceThreshold
|
|
11360
|
+
};
|
|
11361
|
+
}
|
|
11362
|
+
/**
|
|
11363
|
+
* Adds a session to the memory service
|
|
11364
|
+
*/
|
|
11365
|
+
async addSessionToMemory(session) {
|
|
11366
|
+
const tempFileName = `temp_${randomUUID2()}.txt`;
|
|
11367
|
+
const tempFilePath = join(tmpdir(), tempFileName);
|
|
11368
|
+
try {
|
|
11369
|
+
const outputLines = [];
|
|
11370
|
+
for (const event of session.events) {
|
|
11371
|
+
if (!event.content || !event.content.parts) {
|
|
11372
|
+
continue;
|
|
11373
|
+
}
|
|
11374
|
+
const textParts = event.content.parts.filter((part) => part.text).map((part) => part.text.replace(/\n/g, " "));
|
|
11375
|
+
if (textParts.length > 0) {
|
|
11376
|
+
outputLines.push(
|
|
11377
|
+
JSON.stringify({
|
|
11378
|
+
author: event.author,
|
|
11379
|
+
timestamp: event.timestamp,
|
|
11380
|
+
text: textParts.join(".")
|
|
11381
|
+
})
|
|
11382
|
+
);
|
|
11383
|
+
}
|
|
11384
|
+
}
|
|
11385
|
+
const outputString = outputLines.join("\n");
|
|
11386
|
+
writeFileSync(tempFilePath, outputString, "utf8");
|
|
11387
|
+
if (!this._vertexRagStore.rag_resources || this._vertexRagStore.rag_resources.length === 0) {
|
|
11388
|
+
throw new Error("Rag resources must be set.");
|
|
11389
|
+
}
|
|
11390
|
+
for (const ragResource of this._vertexRagStore.rag_resources) {
|
|
11391
|
+
await rag.upload_file({
|
|
11392
|
+
corpus_name: ragResource.rag_corpus,
|
|
11393
|
+
path: tempFilePath,
|
|
11394
|
+
// This is the temp workaround as upload file does not support
|
|
11395
|
+
// adding metadata, thus use display_name to store the session info.
|
|
11396
|
+
display_name: `${session.appName}.${session.userId}.${session.id}`
|
|
11397
|
+
});
|
|
11398
|
+
}
|
|
11399
|
+
} finally {
|
|
11400
|
+
try {
|
|
11401
|
+
unlinkSync(tempFilePath);
|
|
11402
|
+
} catch (error) {
|
|
11403
|
+
console.warn("Failed to delete temporary file:", tempFilePath, error);
|
|
11404
|
+
}
|
|
11405
|
+
}
|
|
11406
|
+
}
|
|
11407
|
+
/**
|
|
11408
|
+
* Searches for sessions that match the query using rag.retrieval_query
|
|
11409
|
+
*/
|
|
11410
|
+
async searchMemory(options) {
|
|
11411
|
+
const { appName, userId, query } = options;
|
|
11412
|
+
const response = await rag.retrieval_query({
|
|
11413
|
+
text: query,
|
|
11414
|
+
rag_resources: this._vertexRagStore.rag_resources,
|
|
11415
|
+
rag_corpora: this._vertexRagStore.rag_corpora,
|
|
11416
|
+
similarity_top_k: this._vertexRagStore.similarity_top_k,
|
|
11417
|
+
vector_distance_threshold: this._vertexRagStore.vector_distance_threshold
|
|
11418
|
+
});
|
|
11419
|
+
const memoryResults = [];
|
|
11420
|
+
const sessionEventsMap = /* @__PURE__ */ new Map();
|
|
11421
|
+
for (const context4 of response.contexts.contexts) {
|
|
11422
|
+
if (!context4.source_display_name.startsWith(`${appName}.${userId}.`)) {
|
|
11423
|
+
continue;
|
|
11424
|
+
}
|
|
11425
|
+
const sessionId = context4.source_display_name.split(".").pop();
|
|
11426
|
+
const events = [];
|
|
11427
|
+
if (context4.text) {
|
|
11428
|
+
const lines = context4.text.split("\n");
|
|
11429
|
+
for (const line of lines) {
|
|
11430
|
+
const trimmedLine = line.trim();
|
|
11431
|
+
if (!trimmedLine) {
|
|
11432
|
+
continue;
|
|
11433
|
+
}
|
|
11434
|
+
try {
|
|
11435
|
+
const eventData = JSON.parse(trimmedLine);
|
|
11436
|
+
const author = eventData.author || "";
|
|
11437
|
+
const timestamp = Number.parseFloat(eventData.timestamp || "0");
|
|
11438
|
+
const text = eventData.text || "";
|
|
11439
|
+
const content = {
|
|
11440
|
+
parts: [{ text }]
|
|
11441
|
+
};
|
|
11442
|
+
const event = {
|
|
11443
|
+
author,
|
|
11444
|
+
timestamp,
|
|
11445
|
+
content
|
|
11446
|
+
};
|
|
11447
|
+
events.push(event);
|
|
11448
|
+
} catch {
|
|
11449
|
+
}
|
|
11450
|
+
}
|
|
11451
|
+
}
|
|
11452
|
+
if (sessionEventsMap.has(sessionId)) {
|
|
11453
|
+
sessionEventsMap.get(sessionId).push(events);
|
|
11454
|
+
} else {
|
|
11455
|
+
sessionEventsMap.set(sessionId, [events]);
|
|
11456
|
+
}
|
|
11457
|
+
}
|
|
11458
|
+
for (const [sessionId, eventLists] of sessionEventsMap.entries()) {
|
|
11459
|
+
const mergedEventLists = _mergeEventLists(eventLists);
|
|
11460
|
+
for (const events of mergedEventLists) {
|
|
11461
|
+
const sortedEvents = events.sort((a, b) => a.timestamp - b.timestamp).filter((event) => event.content);
|
|
11462
|
+
memoryResults.push(
|
|
11463
|
+
...sortedEvents.map((event) => ({
|
|
11464
|
+
author: event.author,
|
|
11465
|
+
content: event.content,
|
|
11466
|
+
timestamp: formatTimestamp(event.timestamp)
|
|
11467
|
+
}))
|
|
11468
|
+
);
|
|
11469
|
+
}
|
|
11470
|
+
}
|
|
11471
|
+
return { memories: memoryResults };
|
|
11472
|
+
}
|
|
11473
|
+
};
|
|
11474
|
+
|
|
11301
11475
|
// src/sessions/index.ts
|
|
11302
11476
|
var sessions_exports = {};
|
|
11303
11477
|
__export(sessions_exports, {
|
|
@@ -13682,6 +13856,7 @@ export {
|
|
|
13682
13856
|
TransferToAgentTool,
|
|
13683
13857
|
UserInteractionTool,
|
|
13684
13858
|
VERSION,
|
|
13859
|
+
VertexAiRagMemoryService,
|
|
13685
13860
|
VertexAiSessionService,
|
|
13686
13861
|
_findFunctionCallEventIfLastEventIsFunctionResponse,
|
|
13687
13862
|
adkToMcpToolType,
|