@iqai/adk 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/dist/index.d.mts +35 -1
- package/dist/index.d.ts +35 -1
- package/dist/index.js +308 -70
- package/dist/index.mjs +242 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @iqai/adk
|
|
2
2
|
|
|
3
|
+
## 0.5.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1ec769a: fix: improve type safety across cli and adk package
|
|
8
|
+
- 9ba699c: fix: state persistence
|
|
9
|
+
- 4fbb724: Fix: state management
|
|
10
|
+
- edfe628: Add artifact parsing and rewind functionality
|
|
11
|
+
|
|
3
12
|
## 0.5.2
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -101,6 +101,10 @@ declare class EventActions {
|
|
|
101
101
|
* a compaction of events within the specified timestamp range.
|
|
102
102
|
*/
|
|
103
103
|
compaction?: EventCompaction;
|
|
104
|
+
/**
|
|
105
|
+
* The invocation id to rewind to. This is only set for rewind event.
|
|
106
|
+
*/
|
|
107
|
+
rewindBeforeInvocationId?: string;
|
|
104
108
|
/**
|
|
105
109
|
* Constructor for EventActions
|
|
106
110
|
*/
|
|
@@ -112,6 +116,7 @@ declare class EventActions {
|
|
|
112
116
|
escalate?: boolean;
|
|
113
117
|
requestedAuthConfigs?: Record<string, any>;
|
|
114
118
|
compaction?: EventCompaction;
|
|
119
|
+
rewindBeforeInvocationId?: string;
|
|
115
120
|
});
|
|
116
121
|
}
|
|
117
122
|
|
|
@@ -4142,6 +4147,11 @@ interface EnhancedRunner<T = string, M extends boolean = false> {
|
|
|
4142
4147
|
newMessage: FullMessage;
|
|
4143
4148
|
runConfig?: RunConfig;
|
|
4144
4149
|
}): AsyncIterable<Event>;
|
|
4150
|
+
rewind(params: {
|
|
4151
|
+
userId: string;
|
|
4152
|
+
sessionId: string;
|
|
4153
|
+
rewindBeforeInvocationId: string;
|
|
4154
|
+
}): any;
|
|
4145
4155
|
__outputSchema?: ZodSchema;
|
|
4146
4156
|
}
|
|
4147
4157
|
/**
|
|
@@ -4835,6 +4845,23 @@ declare namespace index$3 {
|
|
|
4835
4845
|
export { index$3_BaseSessionService as BaseSessionService, index$3_DatabaseSessionService as DatabaseSessionService, type index$3_GetSessionConfig as GetSessionConfig, index$3_InMemorySessionService as InMemorySessionService, type index$3_ListSessionsResponse as ListSessionsResponse, type index$3_Session as Session, index$3_State as State, index$3_VertexAiSessionService as VertexAiSessionService, index$3_createDatabaseSessionService as createDatabaseSessionService, index$3_createMysqlSessionService as createMysqlSessionService, index$3_createPostgresSessionService as createPostgresSessionService, index$3_createSqliteSessionService as createSqliteSessionService };
|
|
4836
4846
|
}
|
|
4837
4847
|
|
|
4848
|
+
interface ParsedArtifactUri {
|
|
4849
|
+
appName: string;
|
|
4850
|
+
userId: string;
|
|
4851
|
+
sessionId?: string;
|
|
4852
|
+
filename: string;
|
|
4853
|
+
version: number;
|
|
4854
|
+
}
|
|
4855
|
+
declare function parseArtifactUri(uri: string): ParsedArtifactUri | null;
|
|
4856
|
+
declare function getArtifactUri(args: {
|
|
4857
|
+
appName: string;
|
|
4858
|
+
userId: string;
|
|
4859
|
+
filename: string;
|
|
4860
|
+
version: number;
|
|
4861
|
+
sessionId?: string;
|
|
4862
|
+
}): string;
|
|
4863
|
+
declare function isArtifactRef(artifact: Part): boolean;
|
|
4864
|
+
|
|
4838
4865
|
declare class GcsArtifactService implements BaseArtifactService {
|
|
4839
4866
|
private readonly bucketName;
|
|
4840
4867
|
private readonly storageClient;
|
|
@@ -5709,6 +5736,13 @@ declare class Runner<T extends BaseAgent = BaseAgent> {
|
|
|
5709
5736
|
* Gets the configured summarizer or creates a default LLM-based one.
|
|
5710
5737
|
*/
|
|
5711
5738
|
private _getOrCreateSummarizer;
|
|
5739
|
+
rewind(args: {
|
|
5740
|
+
userId: string;
|
|
5741
|
+
sessionId: string;
|
|
5742
|
+
rewindBeforeInvocationId: string;
|
|
5743
|
+
}): Promise<void>;
|
|
5744
|
+
private _computeStateDeltaForRewind;
|
|
5745
|
+
private _computeArtifactDeltaForRewind;
|
|
5712
5746
|
}
|
|
5713
5747
|
/**
|
|
5714
5748
|
* An in-memory Runner for testing and development.
|
|
@@ -5798,4 +5832,4 @@ declare const traceLlmCall: (invocationContext: InvocationContext, eventId: stri
|
|
|
5798
5832
|
|
|
5799
5833
|
declare const VERSION = "0.1.0";
|
|
5800
5834
|
|
|
5801
|
-
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, type EventCompaction, index$2 as Events, type EventsCompactionConfig, type EventsSummarizer, 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, LlmEventSummarizer, type LlmModel, type LlmModelConfig, LlmRequest, LlmResponse, LoadArtifactsTool, LoadMemoryTool, LocalEvalService, LoopAgent, type LoopAgentConfig, McpAbi, McpAtp, McpBamm, McpCoinGecko, McpCoinGeckoPro, 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, runCompactionForSlidingWindow, shutdownTelemetry, telemetryService, traceLlmCall, traceToolCall, tracer };
|
|
5835
|
+
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, type EventCompaction, index$2 as Events, type EventsCompactionConfig, type EventsSummarizer, 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, LlmEventSummarizer, type LlmModel, type LlmModelConfig, LlmRequest, LlmResponse, LoadArtifactsTool, LoadMemoryTool, LocalEvalService, LoopAgent, type LoopAgentConfig, McpAbi, McpAtp, McpBamm, McpCoinGecko, McpCoinGeckoPro, 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 ParsedArtifactUri, 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, getArtifactUri, getLongRunningFunctionCalls, getMcpTools, handleFunctionCallsAsync, handleFunctionCallsLive, requestProcessor$5 as identityRequestProcessor, initializeTelemetry, injectSessionState, requestProcessor$4 as instructionsRequestProcessor, isArtifactRef, isEnhancedAuthConfig, jsonSchemaToDeclaration, mcpSchemaToParameters, mergeAgentRun, mergeParallelFunctionResponseEvents, newInvocationContextId, requestProcessor$1 as nlPlanningRequestProcessor, responseProcessor$1 as nlPlanningResponseProcessor, normalizeJsonSchema, parseArtifactUri, populateClientFunctionCallId, registerProviders, removeClientFunctionCallId, requestProcessor$7 as requestProcessor, runCompactionForSlidingWindow, shutdownTelemetry, telemetryService, traceLlmCall, traceToolCall, tracer };
|
package/dist/index.d.ts
CHANGED
|
@@ -101,6 +101,10 @@ declare class EventActions {
|
|
|
101
101
|
* a compaction of events within the specified timestamp range.
|
|
102
102
|
*/
|
|
103
103
|
compaction?: EventCompaction;
|
|
104
|
+
/**
|
|
105
|
+
* The invocation id to rewind to. This is only set for rewind event.
|
|
106
|
+
*/
|
|
107
|
+
rewindBeforeInvocationId?: string;
|
|
104
108
|
/**
|
|
105
109
|
* Constructor for EventActions
|
|
106
110
|
*/
|
|
@@ -112,6 +116,7 @@ declare class EventActions {
|
|
|
112
116
|
escalate?: boolean;
|
|
113
117
|
requestedAuthConfigs?: Record<string, any>;
|
|
114
118
|
compaction?: EventCompaction;
|
|
119
|
+
rewindBeforeInvocationId?: string;
|
|
115
120
|
});
|
|
116
121
|
}
|
|
117
122
|
|
|
@@ -4142,6 +4147,11 @@ interface EnhancedRunner<T = string, M extends boolean = false> {
|
|
|
4142
4147
|
newMessage: FullMessage;
|
|
4143
4148
|
runConfig?: RunConfig;
|
|
4144
4149
|
}): AsyncIterable<Event>;
|
|
4150
|
+
rewind(params: {
|
|
4151
|
+
userId: string;
|
|
4152
|
+
sessionId: string;
|
|
4153
|
+
rewindBeforeInvocationId: string;
|
|
4154
|
+
}): any;
|
|
4145
4155
|
__outputSchema?: ZodSchema;
|
|
4146
4156
|
}
|
|
4147
4157
|
/**
|
|
@@ -4835,6 +4845,23 @@ declare namespace index$3 {
|
|
|
4835
4845
|
export { index$3_BaseSessionService as BaseSessionService, index$3_DatabaseSessionService as DatabaseSessionService, type index$3_GetSessionConfig as GetSessionConfig, index$3_InMemorySessionService as InMemorySessionService, type index$3_ListSessionsResponse as ListSessionsResponse, type index$3_Session as Session, index$3_State as State, index$3_VertexAiSessionService as VertexAiSessionService, index$3_createDatabaseSessionService as createDatabaseSessionService, index$3_createMysqlSessionService as createMysqlSessionService, index$3_createPostgresSessionService as createPostgresSessionService, index$3_createSqliteSessionService as createSqliteSessionService };
|
|
4836
4846
|
}
|
|
4837
4847
|
|
|
4848
|
+
interface ParsedArtifactUri {
|
|
4849
|
+
appName: string;
|
|
4850
|
+
userId: string;
|
|
4851
|
+
sessionId?: string;
|
|
4852
|
+
filename: string;
|
|
4853
|
+
version: number;
|
|
4854
|
+
}
|
|
4855
|
+
declare function parseArtifactUri(uri: string): ParsedArtifactUri | null;
|
|
4856
|
+
declare function getArtifactUri(args: {
|
|
4857
|
+
appName: string;
|
|
4858
|
+
userId: string;
|
|
4859
|
+
filename: string;
|
|
4860
|
+
version: number;
|
|
4861
|
+
sessionId?: string;
|
|
4862
|
+
}): string;
|
|
4863
|
+
declare function isArtifactRef(artifact: Part): boolean;
|
|
4864
|
+
|
|
4838
4865
|
declare class GcsArtifactService implements BaseArtifactService {
|
|
4839
4866
|
private readonly bucketName;
|
|
4840
4867
|
private readonly storageClient;
|
|
@@ -5709,6 +5736,13 @@ declare class Runner<T extends BaseAgent = BaseAgent> {
|
|
|
5709
5736
|
* Gets the configured summarizer or creates a default LLM-based one.
|
|
5710
5737
|
*/
|
|
5711
5738
|
private _getOrCreateSummarizer;
|
|
5739
|
+
rewind(args: {
|
|
5740
|
+
userId: string;
|
|
5741
|
+
sessionId: string;
|
|
5742
|
+
rewindBeforeInvocationId: string;
|
|
5743
|
+
}): Promise<void>;
|
|
5744
|
+
private _computeStateDeltaForRewind;
|
|
5745
|
+
private _computeArtifactDeltaForRewind;
|
|
5712
5746
|
}
|
|
5713
5747
|
/**
|
|
5714
5748
|
* An in-memory Runner for testing and development.
|
|
@@ -5798,4 +5832,4 @@ declare const traceLlmCall: (invocationContext: InvocationContext, eventId: stri
|
|
|
5798
5832
|
|
|
5799
5833
|
declare const VERSION = "0.1.0";
|
|
5800
5834
|
|
|
5801
|
-
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, type EventCompaction, index$2 as Events, type EventsCompactionConfig, type EventsSummarizer, 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, LlmEventSummarizer, type LlmModel, type LlmModelConfig, LlmRequest, LlmResponse, LoadArtifactsTool, LoadMemoryTool, LocalEvalService, LoopAgent, type LoopAgentConfig, McpAbi, McpAtp, McpBamm, McpCoinGecko, McpCoinGeckoPro, 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, runCompactionForSlidingWindow, shutdownTelemetry, telemetryService, traceLlmCall, traceToolCall, tracer };
|
|
5835
|
+
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, type EventCompaction, index$2 as Events, type EventsCompactionConfig, type EventsSummarizer, 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, LlmEventSummarizer, type LlmModel, type LlmModelConfig, LlmRequest, LlmResponse, LoadArtifactsTool, LoadMemoryTool, LocalEvalService, LoopAgent, type LoopAgentConfig, McpAbi, McpAtp, McpBamm, McpCoinGecko, McpCoinGeckoPro, 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 ParsedArtifactUri, 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, getArtifactUri, getLongRunningFunctionCalls, getMcpTools, handleFunctionCallsAsync, handleFunctionCallsLive, requestProcessor$5 as identityRequestProcessor, initializeTelemetry, injectSessionState, requestProcessor$4 as instructionsRequestProcessor, isArtifactRef, isEnhancedAuthConfig, jsonSchemaToDeclaration, mcpSchemaToParameters, mergeAgentRun, mergeParallelFunctionResponseEvents, newInvocationContextId, requestProcessor$1 as nlPlanningRequestProcessor, responseProcessor$1 as nlPlanningResponseProcessor, normalizeJsonSchema, parseArtifactUri, populateClientFunctionCallId, registerProviders, removeClientFunctionCallId, requestProcessor$7 as requestProcessor, runCompactionForSlidingWindow, shutdownTelemetry, telemetryService, traceLlmCall, traceToolCall, tracer };
|
package/dist/index.js
CHANGED
|
@@ -3394,6 +3394,10 @@ var EventActions = (_class10 = class {
|
|
|
3394
3394
|
* a compaction of events within the specified timestamp range.
|
|
3395
3395
|
*/
|
|
3396
3396
|
|
|
3397
|
+
/**
|
|
3398
|
+
* The invocation id to rewind to. This is only set for rewind event.
|
|
3399
|
+
*/
|
|
3400
|
+
|
|
3397
3401
|
/**
|
|
3398
3402
|
* Constructor for EventActions
|
|
3399
3403
|
*/
|
|
@@ -3405,6 +3409,7 @@ var EventActions = (_class10 = class {
|
|
|
3405
3409
|
this.escalate = options.escalate;
|
|
3406
3410
|
this.requestedAuthConfigs = options.requestedAuthConfigs;
|
|
3407
3411
|
this.compaction = options.compaction;
|
|
3412
|
+
this.rewindBeforeInvocationId = options.rewindBeforeInvocationId;
|
|
3408
3413
|
}
|
|
3409
3414
|
}, _class10);
|
|
3410
3415
|
|
|
@@ -8468,8 +8473,30 @@ function rearrangeEventsForLatestFunctionResponse(events) {
|
|
|
8468
8473
|
return resultEvents;
|
|
8469
8474
|
}
|
|
8470
8475
|
function getContents(currentBranch, events, agentName = "") {
|
|
8476
|
+
const invocationIdToIndex = /* @__PURE__ */ new Map();
|
|
8477
|
+
for (let idx = 0; idx < events.length; idx++) {
|
|
8478
|
+
if (events[idx].invocationId) {
|
|
8479
|
+
invocationIdToIndex.set(events[idx].invocationId, idx);
|
|
8480
|
+
}
|
|
8481
|
+
}
|
|
8482
|
+
const rewindFilteredEvents = [];
|
|
8483
|
+
let i = events.length - 1;
|
|
8484
|
+
while (i >= 0) {
|
|
8485
|
+
const event = events[i];
|
|
8486
|
+
if (_optionalChain([event, 'access', _245 => _245.actions, 'optionalAccess', _246 => _246.rewindBeforeInvocationId])) {
|
|
8487
|
+
const rewindInvocationId = event.actions.rewindBeforeInvocationId;
|
|
8488
|
+
const rewindIndex = invocationIdToIndex.get(rewindInvocationId);
|
|
8489
|
+
if (rewindIndex !== void 0 && rewindIndex < i) {
|
|
8490
|
+
i = rewindIndex;
|
|
8491
|
+
}
|
|
8492
|
+
} else {
|
|
8493
|
+
rewindFilteredEvents.push(event);
|
|
8494
|
+
}
|
|
8495
|
+
i--;
|
|
8496
|
+
}
|
|
8497
|
+
rewindFilteredEvents.reverse();
|
|
8471
8498
|
const filteredEvents = [];
|
|
8472
|
-
for (const event of
|
|
8499
|
+
for (const event of rewindFilteredEvents) {
|
|
8473
8500
|
if (!event.content || !event.content.role || !event.content.parts || event.content.parts.length === 0) {
|
|
8474
8501
|
continue;
|
|
8475
8502
|
}
|
|
@@ -8558,7 +8585,7 @@ function mergeFunctionResponseEvents(functionResponseEvents) {
|
|
|
8558
8585
|
const partIndicesInMergedEvent = {};
|
|
8559
8586
|
for (let idx = 0; idx < partsInMergedEvent.length; idx++) {
|
|
8560
8587
|
const part = partsInMergedEvent[idx];
|
|
8561
|
-
if (_optionalChain([part, 'access',
|
|
8588
|
+
if (_optionalChain([part, 'access', _247 => _247.functionResponse, 'optionalAccess', _248 => _248.id])) {
|
|
8562
8589
|
partIndicesInMergedEvent[part.functionResponse.id] = idx;
|
|
8563
8590
|
}
|
|
8564
8591
|
}
|
|
@@ -8567,7 +8594,7 @@ function mergeFunctionResponseEvents(functionResponseEvents) {
|
|
|
8567
8594
|
throw new Error("There should be at least one function_response part.");
|
|
8568
8595
|
}
|
|
8569
8596
|
for (const part of event.content.parts) {
|
|
8570
|
-
if (_optionalChain([part, 'access',
|
|
8597
|
+
if (_optionalChain([part, 'access', _249 => _249.functionResponse, 'optionalAccess', _250 => _250.id])) {
|
|
8571
8598
|
const functionCallId = part.functionResponse.id;
|
|
8572
8599
|
if (functionCallId in partIndicesInMergedEvent) {
|
|
8573
8600
|
partsInMergedEvent[partIndicesInMergedEvent[functionCallId]] = part;
|
|
@@ -8607,7 +8634,7 @@ function processCompactionEvents(events) {
|
|
|
8607
8634
|
let lastCompactionStartTime = Number.POSITIVE_INFINITY;
|
|
8608
8635
|
for (let i = events.length - 1; i >= 0; i--) {
|
|
8609
8636
|
const event = events[i];
|
|
8610
|
-
if (_optionalChain([event, 'access',
|
|
8637
|
+
if (_optionalChain([event, 'access', _251 => _251.actions, 'optionalAccess', _252 => _252.compaction])) {
|
|
8611
8638
|
const compaction = event.actions.compaction;
|
|
8612
8639
|
const synthesizedEvent = new Event({
|
|
8613
8640
|
timestamp: compaction.endTimestamp,
|
|
@@ -8859,7 +8886,7 @@ var PlanReActPlanner = class extends BasePlanner {
|
|
|
8859
8886
|
let firstFcPartIndex = -1;
|
|
8860
8887
|
for (let i = 0; i < responseParts.length; i++) {
|
|
8861
8888
|
if (responseParts[i].functionCall) {
|
|
8862
|
-
if (!_optionalChain([responseParts, 'access',
|
|
8889
|
+
if (!_optionalChain([responseParts, 'access', _253 => _253[i], 'access', _254 => _254.functionCall, 'optionalAccess', _255 => _255.name])) {
|
|
8863
8890
|
continue;
|
|
8864
8891
|
}
|
|
8865
8892
|
preservedParts.push(responseParts[i]);
|
|
@@ -8898,7 +8925,7 @@ var PlanReActPlanner = class extends BasePlanner {
|
|
|
8898
8925
|
* Handles non-function-call parts of the response
|
|
8899
8926
|
*/
|
|
8900
8927
|
_handleNonFunctionCallParts(responsePart, preservedParts) {
|
|
8901
|
-
if (_optionalChain([responsePart, 'access',
|
|
8928
|
+
if (_optionalChain([responsePart, 'access', _256 => _256.text, 'optionalAccess', _257 => _257.includes, 'call', _258 => _258(FINAL_ANSWER_TAG)])) {
|
|
8902
8929
|
const [reasoningText, finalAnswerText] = this._splitByLastPattern(
|
|
8903
8930
|
responsePart.text,
|
|
8904
8931
|
FINAL_ANSWER_TAG
|
|
@@ -9137,7 +9164,7 @@ var OutputSchemaResponseProcessor = (_class26 = class extends BaseLlmResponsePro
|
|
|
9137
9164
|
stripCodeFences(raw) {
|
|
9138
9165
|
const fencePattern = /```(?:json)?\s*([\s\S]*?)```/i;
|
|
9139
9166
|
const fenceMatch = raw.match(fencePattern);
|
|
9140
|
-
if (_optionalChain([fenceMatch, 'optionalAccess',
|
|
9167
|
+
if (_optionalChain([fenceMatch, 'optionalAccess', _259 => _259[1]])) {
|
|
9141
9168
|
return fenceMatch[1].trim();
|
|
9142
9169
|
}
|
|
9143
9170
|
const lines = raw.split(/\r?\n/).map((l) => l.trim());
|
|
@@ -9174,7 +9201,7 @@ var SharedMemoryRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
9174
9201
|
const memoryService = invocationContext.memoryService;
|
|
9175
9202
|
if (!memoryService) return;
|
|
9176
9203
|
const lastUserEvent = invocationContext.session.events.findLast(
|
|
9177
|
-
(e) => e.author === "user" && _optionalChain([e, 'access',
|
|
9204
|
+
(e) => e.author === "user" && _optionalChain([e, 'access', _260 => _260.content, 'optionalAccess', _261 => _261.parts, 'optionalAccess', _262 => _262.length])
|
|
9178
9205
|
);
|
|
9179
9206
|
if (!lastUserEvent) return;
|
|
9180
9207
|
const query = (_nullishCoalesce(lastUserEvent.content.parts, () => ( []))).map((p) => p.text || "").join(" ");
|
|
@@ -9185,7 +9212,7 @@ var SharedMemoryRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
9185
9212
|
});
|
|
9186
9213
|
const sessionTexts = new Set(
|
|
9187
9214
|
(llmRequest.contents || []).flatMap(
|
|
9188
|
-
(c) => _optionalChain([c, 'access',
|
|
9215
|
+
(c) => _optionalChain([c, 'access', _263 => _263.parts, 'optionalAccess', _264 => _264.map, 'call', _265 => _265((p) => p.text)]) || []
|
|
9189
9216
|
)
|
|
9190
9217
|
);
|
|
9191
9218
|
for (const memory of results.memories) {
|
|
@@ -9606,7 +9633,7 @@ var LlmAgent = (_class27 = class _LlmAgent extends BaseAgent {
|
|
|
9606
9633
|
* This matches the Python implementation's _llm_flow property
|
|
9607
9634
|
*/
|
|
9608
9635
|
get llmFlow() {
|
|
9609
|
-
if (this.disallowTransferToParent && this.disallowTransferToPeers && !_optionalChain([this, 'access',
|
|
9636
|
+
if (this.disallowTransferToParent && this.disallowTransferToPeers && !_optionalChain([this, 'access', _266 => _266.subAgents, 'optionalAccess', _267 => _267.length])) {
|
|
9610
9637
|
return new SingleFlow();
|
|
9611
9638
|
}
|
|
9612
9639
|
return new AutoFlow();
|
|
@@ -9622,7 +9649,7 @@ var LlmAgent = (_class27 = class _LlmAgent extends BaseAgent {
|
|
|
9622
9649
|
);
|
|
9623
9650
|
return;
|
|
9624
9651
|
}
|
|
9625
|
-
if (this.outputKey && event.isFinalResponse() && _optionalChain([event, 'access',
|
|
9652
|
+
if (this.outputKey && event.isFinalResponse() && _optionalChain([event, 'access', _268 => _268.content, 'optionalAccess', _269 => _269.parts])) {
|
|
9626
9653
|
let result = event.content.parts.map((part) => part.text || "").join("");
|
|
9627
9654
|
if (this.outputSchema) {
|
|
9628
9655
|
if (!result.trim()) {
|
|
@@ -9842,7 +9869,7 @@ var LoopAgent = class extends BaseAgent {
|
|
|
9842
9869
|
for (const subAgent of this.subAgents) {
|
|
9843
9870
|
for await (const event of subAgent.runAsync(ctx)) {
|
|
9844
9871
|
yield event;
|
|
9845
|
-
if (_optionalChain([event, 'access',
|
|
9872
|
+
if (_optionalChain([event, 'access', _270 => _270.actions, 'optionalAccess', _271 => _271.escalate])) {
|
|
9846
9873
|
return;
|
|
9847
9874
|
}
|
|
9848
9875
|
}
|
|
@@ -10154,17 +10181,17 @@ var RunConfig = class {
|
|
|
10154
10181
|
*/
|
|
10155
10182
|
|
|
10156
10183
|
constructor(config) {
|
|
10157
|
-
this.speechConfig = _optionalChain([config, 'optionalAccess',
|
|
10158
|
-
this.responseModalities = _optionalChain([config, 'optionalAccess',
|
|
10159
|
-
this.saveInputBlobsAsArtifacts = _optionalChain([config, 'optionalAccess',
|
|
10160
|
-
this.supportCFC = _optionalChain([config, 'optionalAccess',
|
|
10161
|
-
this.streamingMode = _optionalChain([config, 'optionalAccess',
|
|
10162
|
-
this.outputAudioTranscription = _optionalChain([config, 'optionalAccess',
|
|
10163
|
-
this.inputAudioTranscription = _optionalChain([config, 'optionalAccess',
|
|
10164
|
-
this.realtimeInputConfig = _optionalChain([config, 'optionalAccess',
|
|
10165
|
-
this.enableAffectiveDialog = _optionalChain([config, 'optionalAccess',
|
|
10166
|
-
this.proactivity = _optionalChain([config, 'optionalAccess',
|
|
10167
|
-
this.maxLlmCalls = _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
10184
|
+
this.speechConfig = _optionalChain([config, 'optionalAccess', _272 => _272.speechConfig]);
|
|
10185
|
+
this.responseModalities = _optionalChain([config, 'optionalAccess', _273 => _273.responseModalities]);
|
|
10186
|
+
this.saveInputBlobsAsArtifacts = _optionalChain([config, 'optionalAccess', _274 => _274.saveInputBlobsAsArtifacts]) || false;
|
|
10187
|
+
this.supportCFC = _optionalChain([config, 'optionalAccess', _275 => _275.supportCFC]) || false;
|
|
10188
|
+
this.streamingMode = _optionalChain([config, 'optionalAccess', _276 => _276.streamingMode]) || "NONE" /* NONE */;
|
|
10189
|
+
this.outputAudioTranscription = _optionalChain([config, 'optionalAccess', _277 => _277.outputAudioTranscription]);
|
|
10190
|
+
this.inputAudioTranscription = _optionalChain([config, 'optionalAccess', _278 => _278.inputAudioTranscription]);
|
|
10191
|
+
this.realtimeInputConfig = _optionalChain([config, 'optionalAccess', _279 => _279.realtimeInputConfig]);
|
|
10192
|
+
this.enableAffectiveDialog = _optionalChain([config, 'optionalAccess', _280 => _280.enableAffectiveDialog]);
|
|
10193
|
+
this.proactivity = _optionalChain([config, 'optionalAccess', _281 => _281.proactivity]);
|
|
10194
|
+
this.maxLlmCalls = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _282 => _282.maxLlmCalls]), () => ( 500));
|
|
10168
10195
|
this.validateMaxLlmCalls();
|
|
10169
10196
|
}
|
|
10170
10197
|
/**
|
|
@@ -10184,6 +10211,48 @@ var RunConfig = class {
|
|
|
10184
10211
|
}
|
|
10185
10212
|
};
|
|
10186
10213
|
|
|
10214
|
+
// src/artifacts/artifact-util.ts
|
|
10215
|
+
var SESSION_SCOPED_ARTIFACT_URI_RE = /^artifact:\/\/apps\/([^/]+)\/users\/([^/]+)\/sessions\/([^/]+)\/artifacts\/([^/]+)\/versions\/(\d+)$/;
|
|
10216
|
+
var USER_SCOPED_ARTIFACT_URI_RE = /^artifact:\/\/apps\/([^/]+)\/users\/([^/]+)\/artifacts\/([^/]+)\/versions\/(\d+)$/;
|
|
10217
|
+
function parseArtifactUri(uri) {
|
|
10218
|
+
if (!uri || !uri.startsWith("artifact://")) {
|
|
10219
|
+
return null;
|
|
10220
|
+
}
|
|
10221
|
+
let match = SESSION_SCOPED_ARTIFACT_URI_RE.exec(uri);
|
|
10222
|
+
if (match) {
|
|
10223
|
+
return {
|
|
10224
|
+
appName: match[1],
|
|
10225
|
+
userId: match[2],
|
|
10226
|
+
sessionId: match[3],
|
|
10227
|
+
filename: match[4],
|
|
10228
|
+
version: Number.parseInt(match[5], 10)
|
|
10229
|
+
};
|
|
10230
|
+
}
|
|
10231
|
+
match = USER_SCOPED_ARTIFACT_URI_RE.exec(uri);
|
|
10232
|
+
if (match) {
|
|
10233
|
+
return {
|
|
10234
|
+
appName: match[1],
|
|
10235
|
+
userId: match[2],
|
|
10236
|
+
sessionId: void 0,
|
|
10237
|
+
filename: match[3],
|
|
10238
|
+
version: Number.parseInt(match[4], 10)
|
|
10239
|
+
};
|
|
10240
|
+
}
|
|
10241
|
+
return null;
|
|
10242
|
+
}
|
|
10243
|
+
function getArtifactUri(args) {
|
|
10244
|
+
const { appName, userId, filename, version, sessionId } = args;
|
|
10245
|
+
if (sessionId) {
|
|
10246
|
+
return `artifact://apps/${appName}/users/${userId}/sessions/${sessionId}/artifacts/${filename}/versions/${version}`;
|
|
10247
|
+
}
|
|
10248
|
+
return `artifact://apps/${appName}/users/${userId}/artifacts/${filename}/versions/${version}`;
|
|
10249
|
+
}
|
|
10250
|
+
function isArtifactRef(artifact) {
|
|
10251
|
+
return Boolean(
|
|
10252
|
+
_optionalChain([artifact, 'access', _283 => _283.fileData, 'optionalAccess', _284 => _284.fileUri]) && artifact.fileData.fileUri.startsWith("artifact://")
|
|
10253
|
+
);
|
|
10254
|
+
}
|
|
10255
|
+
|
|
10187
10256
|
// src/artifacts/in-memory-artifact-service.ts
|
|
10188
10257
|
var InMemoryArtifactService = (_class29 = class {constructor() { _class29.prototype.__init50.call(this); }
|
|
10189
10258
|
__init50() {this.artifacts = /* @__PURE__ */ new Map()}
|
|
@@ -10224,7 +10293,29 @@ var InMemoryArtifactService = (_class29 = class {constructor() { _class29.protot
|
|
|
10224
10293
|
if (targetVersion < 0 || targetVersion >= versions.length) {
|
|
10225
10294
|
return null;
|
|
10226
10295
|
}
|
|
10227
|
-
|
|
10296
|
+
const artifactEntry = versions[targetVersion];
|
|
10297
|
+
if (!artifactEntry) {
|
|
10298
|
+
return null;
|
|
10299
|
+
}
|
|
10300
|
+
if (isArtifactRef(artifactEntry)) {
|
|
10301
|
+
const parsedUri = parseArtifactUri(_optionalChain([artifactEntry, 'access', _285 => _285.fileData, 'optionalAccess', _286 => _286.fileUri]) || "");
|
|
10302
|
+
if (!parsedUri) {
|
|
10303
|
+
throw new Error(
|
|
10304
|
+
`Invalid artifact reference URI: ${_optionalChain([artifactEntry, 'access', _287 => _287.fileData, 'optionalAccess', _288 => _288.fileUri])}`
|
|
10305
|
+
);
|
|
10306
|
+
}
|
|
10307
|
+
return await this.loadArtifact({
|
|
10308
|
+
appName: parsedUri.appName,
|
|
10309
|
+
userId: parsedUri.userId,
|
|
10310
|
+
sessionId: parsedUri.sessionId || sessionId,
|
|
10311
|
+
filename: parsedUri.filename,
|
|
10312
|
+
version: parsedUri.version
|
|
10313
|
+
});
|
|
10314
|
+
}
|
|
10315
|
+
if (!artifactEntry.text && (!_optionalChain([artifactEntry, 'access', _289 => _289.inlineData, 'optionalAccess', _290 => _290.data]) || artifactEntry.inlineData.data.length === 0) && !artifactEntry.fileData) {
|
|
10316
|
+
return null;
|
|
10317
|
+
}
|
|
10318
|
+
return artifactEntry;
|
|
10228
10319
|
}
|
|
10229
10320
|
async listArtifactKeys(args) {
|
|
10230
10321
|
const { appName, userId, sessionId } = args;
|
|
@@ -10308,7 +10399,7 @@ var InMemoryMemoryService = (_class30 = class {
|
|
|
10308
10399
|
}
|
|
10309
10400
|
const userSessions = this._sessionEvents.get(userKey);
|
|
10310
10401
|
const filteredEvents = session.events.filter(
|
|
10311
|
-
(event) => _optionalChain([event, 'access',
|
|
10402
|
+
(event) => _optionalChain([event, 'access', _291 => _291.content, 'optionalAccess', _292 => _292.parts])
|
|
10312
10403
|
);
|
|
10313
10404
|
userSessions.set(session.id, filteredEvents);
|
|
10314
10405
|
}
|
|
@@ -10409,11 +10500,16 @@ var BaseSessionService = class {
|
|
|
10409
10500
|
return;
|
|
10410
10501
|
}
|
|
10411
10502
|
for (const key in event.actions.stateDelta) {
|
|
10412
|
-
if (Object.
|
|
10503
|
+
if (Object.hasOwn(event.actions.stateDelta, key)) {
|
|
10413
10504
|
if (key.startsWith("temp_")) {
|
|
10414
10505
|
continue;
|
|
10415
10506
|
}
|
|
10416
|
-
|
|
10507
|
+
const value = event.actions.stateDelta[key];
|
|
10508
|
+
if (value === null || value === void 0) {
|
|
10509
|
+
delete session.state[key];
|
|
10510
|
+
} else {
|
|
10511
|
+
session.state[key] = value;
|
|
10512
|
+
}
|
|
10417
10513
|
}
|
|
10418
10514
|
}
|
|
10419
10515
|
}
|
|
@@ -10447,7 +10543,7 @@ var InMemorySessionService = (_class31 = class extends BaseSessionService {const
|
|
|
10447
10543
|
return this.createSessionImpl(appName, userId, state, sessionId);
|
|
10448
10544
|
}
|
|
10449
10545
|
createSessionImpl(appName, userId, state, sessionId) {
|
|
10450
|
-
const finalSessionId = _optionalChain([sessionId, 'optionalAccess',
|
|
10546
|
+
const finalSessionId = _optionalChain([sessionId, 'optionalAccess', _293 => _293.trim, 'call', _294 => _294()]) || _crypto.randomUUID.call(void 0, );
|
|
10451
10547
|
const session = {
|
|
10452
10548
|
appName,
|
|
10453
10549
|
userId,
|
|
@@ -10604,7 +10700,7 @@ var InMemorySessionService = (_class31 = class extends BaseSessionService {const
|
|
|
10604
10700
|
warning(`sessionId ${sessionId} not in sessions[appName][userId]`);
|
|
10605
10701
|
return event;
|
|
10606
10702
|
}
|
|
10607
|
-
if (_optionalChain([event, 'access',
|
|
10703
|
+
if (_optionalChain([event, 'access', _295 => _295.actions, 'optionalAccess', _296 => _296.stateDelta])) {
|
|
10608
10704
|
for (const key in event.actions.stateDelta) {
|
|
10609
10705
|
const value = event.actions.stateDelta[key];
|
|
10610
10706
|
if (key.startsWith(State.APP_PREFIX)) {
|
|
@@ -10638,14 +10734,14 @@ function _findFunctionCallEventIfLastEventIsFunctionResponse(session) {
|
|
|
10638
10734
|
return null;
|
|
10639
10735
|
}
|
|
10640
10736
|
const lastEvent = events[events.length - 1];
|
|
10641
|
-
if (_optionalChain([lastEvent, 'access',
|
|
10642
|
-
const functionCallId = _optionalChain([lastEvent, 'access',
|
|
10737
|
+
if (_optionalChain([lastEvent, 'access', _297 => _297.content, 'optionalAccess', _298 => _298.parts, 'optionalAccess', _299 => _299.some, 'call', _300 => _300((part) => part.functionResponse)])) {
|
|
10738
|
+
const functionCallId = _optionalChain([lastEvent, 'access', _301 => _301.content, 'access', _302 => _302.parts, 'access', _303 => _303.find, 'call', _304 => _304(
|
|
10643
10739
|
(part) => part.functionResponse
|
|
10644
|
-
), 'optionalAccess',
|
|
10740
|
+
), 'optionalAccess', _305 => _305.functionResponse, 'optionalAccess', _306 => _306.id]);
|
|
10645
10741
|
if (!functionCallId) return null;
|
|
10646
10742
|
for (let i = events.length - 2; i >= 0; i--) {
|
|
10647
10743
|
const event = events[i];
|
|
10648
|
-
const functionCalls = _optionalChain([event, 'access',
|
|
10744
|
+
const functionCalls = _optionalChain([event, 'access', _307 => _307.getFunctionCalls, 'optionalCall', _308 => _308()]) || [];
|
|
10649
10745
|
for (const functionCall of functionCalls) {
|
|
10650
10746
|
if (functionCall.id === functionCallId) {
|
|
10651
10747
|
return event;
|
|
@@ -10858,15 +10954,15 @@ var Runner = (_class32 = class {
|
|
|
10858
10954
|
*/
|
|
10859
10955
|
_findAgentToRun(session, rootAgent) {
|
|
10860
10956
|
const event = _findFunctionCallEventIfLastEventIsFunctionResponse(session);
|
|
10861
|
-
if (_optionalChain([event, 'optionalAccess',
|
|
10957
|
+
if (_optionalChain([event, 'optionalAccess', _309 => _309.author])) {
|
|
10862
10958
|
return rootAgent.findAgent(event.author);
|
|
10863
10959
|
}
|
|
10864
|
-
const nonUserEvents = _optionalChain([session, 'access',
|
|
10960
|
+
const nonUserEvents = _optionalChain([session, 'access', _310 => _310.events, 'optionalAccess', _311 => _311.filter, 'call', _312 => _312((e) => e.author !== "user"), 'access', _313 => _313.reverse, 'call', _314 => _314()]) || [];
|
|
10865
10961
|
for (const event2 of nonUserEvents) {
|
|
10866
10962
|
if (event2.author === rootAgent.name) {
|
|
10867
10963
|
return rootAgent;
|
|
10868
10964
|
}
|
|
10869
|
-
const agent = _optionalChain([rootAgent, 'access',
|
|
10965
|
+
const agent = _optionalChain([rootAgent, 'access', _315 => _315.findSubAgent, 'optionalCall', _316 => _316(event2.author)]);
|
|
10870
10966
|
if (!agent) {
|
|
10871
10967
|
this.logger.debug(
|
|
10872
10968
|
`Event from an unknown agent: ${event2.author}, event id: ${event2.id}`
|
|
@@ -10944,7 +11040,7 @@ var Runner = (_class32 = class {
|
|
|
10944
11040
|
* Gets the configured summarizer or creates a default LLM-based one.
|
|
10945
11041
|
*/
|
|
10946
11042
|
_getOrCreateSummarizer() {
|
|
10947
|
-
if (_optionalChain([this, 'access',
|
|
11043
|
+
if (_optionalChain([this, 'access', _317 => _317.eventsCompactionConfig, 'optionalAccess', _318 => _318.summarizer])) {
|
|
10948
11044
|
return this.eventsCompactionConfig.summarizer;
|
|
10949
11045
|
}
|
|
10950
11046
|
if (this.agent instanceof LlmAgent) {
|
|
@@ -10961,6 +11057,142 @@ var Runner = (_class32 = class {
|
|
|
10961
11057
|
}
|
|
10962
11058
|
return void 0;
|
|
10963
11059
|
}
|
|
11060
|
+
async rewind(args) {
|
|
11061
|
+
const { userId, sessionId, rewindBeforeInvocationId } = args;
|
|
11062
|
+
const session = await this.sessionService.getSession(
|
|
11063
|
+
this.appName,
|
|
11064
|
+
userId,
|
|
11065
|
+
sessionId
|
|
11066
|
+
);
|
|
11067
|
+
if (!session) {
|
|
11068
|
+
throw new Error(`Session not found: ${sessionId}`);
|
|
11069
|
+
}
|
|
11070
|
+
let rewindEventIndex = -1;
|
|
11071
|
+
for (let i = 0; i < session.events.length; i++) {
|
|
11072
|
+
if (session.events[i].invocationId === rewindBeforeInvocationId) {
|
|
11073
|
+
rewindEventIndex = i;
|
|
11074
|
+
break;
|
|
11075
|
+
}
|
|
11076
|
+
}
|
|
11077
|
+
if (rewindEventIndex === -1) {
|
|
11078
|
+
throw new Error(`Invocation ID not found: ${rewindBeforeInvocationId}`);
|
|
11079
|
+
}
|
|
11080
|
+
const stateDelta = await this._computeStateDeltaForRewind(
|
|
11081
|
+
session,
|
|
11082
|
+
rewindEventIndex
|
|
11083
|
+
);
|
|
11084
|
+
const artifactDelta = await this._computeArtifactDeltaForRewind(
|
|
11085
|
+
session,
|
|
11086
|
+
rewindEventIndex
|
|
11087
|
+
);
|
|
11088
|
+
const rewindEvent = new Event({
|
|
11089
|
+
invocationId: newInvocationContextId(),
|
|
11090
|
+
author: "user",
|
|
11091
|
+
actions: new EventActions({
|
|
11092
|
+
rewindBeforeInvocationId,
|
|
11093
|
+
stateDelta,
|
|
11094
|
+
artifactDelta
|
|
11095
|
+
})
|
|
11096
|
+
});
|
|
11097
|
+
this.logger.info(
|
|
11098
|
+
"Rewinding session to invocation:",
|
|
11099
|
+
rewindBeforeInvocationId
|
|
11100
|
+
);
|
|
11101
|
+
await this.sessionService.appendEvent(session, rewindEvent);
|
|
11102
|
+
}
|
|
11103
|
+
async _computeStateDeltaForRewind(session, rewindEventIndex) {
|
|
11104
|
+
const stateAtRewindPoint = {};
|
|
11105
|
+
for (let i = 0; i < rewindEventIndex; i++) {
|
|
11106
|
+
const event = session.events[i];
|
|
11107
|
+
if (_optionalChain([event, 'access', _319 => _319.actions, 'optionalAccess', _320 => _320.stateDelta])) {
|
|
11108
|
+
for (const [k, v] of Object.entries(event.actions.stateDelta)) {
|
|
11109
|
+
if (k.startsWith("app:") || k.startsWith("user:")) {
|
|
11110
|
+
continue;
|
|
11111
|
+
}
|
|
11112
|
+
if (v === null || v === void 0) {
|
|
11113
|
+
delete stateAtRewindPoint[k];
|
|
11114
|
+
} else {
|
|
11115
|
+
stateAtRewindPoint[k] = v;
|
|
11116
|
+
}
|
|
11117
|
+
}
|
|
11118
|
+
}
|
|
11119
|
+
}
|
|
11120
|
+
const currentState = session.state;
|
|
11121
|
+
const rewindStateDelta = {};
|
|
11122
|
+
for (const [key, valueAtRewind] of Object.entries(stateAtRewindPoint)) {
|
|
11123
|
+
if (!(key in currentState) || currentState[key] !== valueAtRewind) {
|
|
11124
|
+
rewindStateDelta[key] = valueAtRewind;
|
|
11125
|
+
}
|
|
11126
|
+
}
|
|
11127
|
+
for (const key of Object.keys(currentState)) {
|
|
11128
|
+
if (key.startsWith("app:") || key.startsWith("user:")) {
|
|
11129
|
+
continue;
|
|
11130
|
+
}
|
|
11131
|
+
if (!(key in stateAtRewindPoint)) {
|
|
11132
|
+
rewindStateDelta[key] = null;
|
|
11133
|
+
}
|
|
11134
|
+
}
|
|
11135
|
+
return rewindStateDelta;
|
|
11136
|
+
}
|
|
11137
|
+
async _computeArtifactDeltaForRewind(session, rewindEventIndex) {
|
|
11138
|
+
if (!this.artifactService) {
|
|
11139
|
+
return {};
|
|
11140
|
+
}
|
|
11141
|
+
const versionsAtRewindPoint = {};
|
|
11142
|
+
for (let i = 0; i < rewindEventIndex; i++) {
|
|
11143
|
+
const event = session.events[i];
|
|
11144
|
+
if (_optionalChain([event, 'access', _321 => _321.actions, 'optionalAccess', _322 => _322.artifactDelta])) {
|
|
11145
|
+
Object.assign(versionsAtRewindPoint, event.actions.artifactDelta);
|
|
11146
|
+
}
|
|
11147
|
+
}
|
|
11148
|
+
const currentVersions = {};
|
|
11149
|
+
for (const event of session.events) {
|
|
11150
|
+
if (_optionalChain([event, 'access', _323 => _323.actions, 'optionalAccess', _324 => _324.artifactDelta])) {
|
|
11151
|
+
Object.assign(currentVersions, event.actions.artifactDelta);
|
|
11152
|
+
}
|
|
11153
|
+
}
|
|
11154
|
+
const rewindArtifactDelta = {};
|
|
11155
|
+
for (const [filename, vn] of Object.entries(currentVersions)) {
|
|
11156
|
+
if (filename.startsWith("user:")) {
|
|
11157
|
+
continue;
|
|
11158
|
+
}
|
|
11159
|
+
const vt = versionsAtRewindPoint[filename];
|
|
11160
|
+
if (vt === vn) {
|
|
11161
|
+
continue;
|
|
11162
|
+
}
|
|
11163
|
+
let artifact;
|
|
11164
|
+
if (vt === void 0 || vt === null) {
|
|
11165
|
+
artifact = {
|
|
11166
|
+
inlineData: {
|
|
11167
|
+
mimeType: "application/octet-stream",
|
|
11168
|
+
data: ""
|
|
11169
|
+
}
|
|
11170
|
+
};
|
|
11171
|
+
} else {
|
|
11172
|
+
const artifactUri = getArtifactUri({
|
|
11173
|
+
appName: this.appName,
|
|
11174
|
+
userId: session.userId,
|
|
11175
|
+
sessionId: session.id,
|
|
11176
|
+
filename,
|
|
11177
|
+
version: vt
|
|
11178
|
+
});
|
|
11179
|
+
artifact = {
|
|
11180
|
+
fileData: {
|
|
11181
|
+
fileUri: artifactUri
|
|
11182
|
+
}
|
|
11183
|
+
};
|
|
11184
|
+
}
|
|
11185
|
+
const newVersion = await this.artifactService.saveArtifact({
|
|
11186
|
+
appName: this.appName,
|
|
11187
|
+
userId: session.userId,
|
|
11188
|
+
sessionId: session.id,
|
|
11189
|
+
filename,
|
|
11190
|
+
artifact
|
|
11191
|
+
});
|
|
11192
|
+
rewindArtifactDelta[filename] = newVersion;
|
|
11193
|
+
}
|
|
11194
|
+
return rewindArtifactDelta;
|
|
11195
|
+
}
|
|
10964
11196
|
}, _class32);
|
|
10965
11197
|
var InMemoryRunner = class extends Runner {
|
|
10966
11198
|
/**
|
|
@@ -11600,7 +11832,7 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11600
11832
|
const outputSchema = this.config.outputSchema;
|
|
11601
11833
|
const agentType = this.agentType;
|
|
11602
11834
|
const isMulti = agentType === "parallel" || agentType === "sequential";
|
|
11603
|
-
const subAgentNames = _optionalChain([this, 'access',
|
|
11835
|
+
const subAgentNames = _optionalChain([this, 'access', _325 => _325.config, 'access', _326 => _326.subAgents, 'optionalAccess', _327 => _327.map, 'call', _328 => _328((a) => a.name)]) || [];
|
|
11604
11836
|
const runConfig = this.runConfig;
|
|
11605
11837
|
return {
|
|
11606
11838
|
__outputSchema: outputSchema,
|
|
@@ -11609,7 +11841,7 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11609
11841
|
let combinedResponse = "";
|
|
11610
11842
|
const perAgentBuffers = {};
|
|
11611
11843
|
const authors = /* @__PURE__ */ new Set();
|
|
11612
|
-
if (!_optionalChain([sessionOptions, 'optionalAccess',
|
|
11844
|
+
if (!_optionalChain([sessionOptions, 'optionalAccess', _329 => _329.userId])) {
|
|
11613
11845
|
throw new Error("Session configuration is required");
|
|
11614
11846
|
}
|
|
11615
11847
|
for await (const event of baseRunner.runAsync({
|
|
@@ -11618,7 +11850,7 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11618
11850
|
newMessage,
|
|
11619
11851
|
runConfig
|
|
11620
11852
|
})) {
|
|
11621
|
-
if (_optionalChain([event, 'access',
|
|
11853
|
+
if (_optionalChain([event, 'access', _330 => _330.content, 'optionalAccess', _331 => _331.parts]) && Array.isArray(event.content.parts)) {
|
|
11622
11854
|
const content = event.content.parts.map(
|
|
11623
11855
|
(part) => (part && typeof part === "object" && "text" in part ? part.text : "") || ""
|
|
11624
11856
|
).join("");
|
|
@@ -11664,6 +11896,9 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11664
11896
|
...params,
|
|
11665
11897
|
runConfig: _nullishCoalesce(params.runConfig, () => ( runConfig))
|
|
11666
11898
|
});
|
|
11899
|
+
},
|
|
11900
|
+
rewind(params) {
|
|
11901
|
+
return baseRunner.rewind(params);
|
|
11667
11902
|
}
|
|
11668
11903
|
};
|
|
11669
11904
|
}
|
|
@@ -11905,7 +12140,7 @@ var VertexAiSessionService = class extends BaseSessionService {
|
|
|
11905
12140
|
path: `operations/${operationId}`,
|
|
11906
12141
|
request_dict: {}
|
|
11907
12142
|
});
|
|
11908
|
-
if (_optionalChain([lroResponse, 'optionalAccess',
|
|
12143
|
+
if (_optionalChain([lroResponse, 'optionalAccess', _332 => _332.done])) {
|
|
11909
12144
|
break;
|
|
11910
12145
|
}
|
|
11911
12146
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
@@ -12276,12 +12511,12 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
12276
12511
|
}
|
|
12277
12512
|
async createSession(appName, userId, state, sessionId) {
|
|
12278
12513
|
await this.ensureInitialized();
|
|
12279
|
-
const id = _optionalChain([sessionId, 'optionalAccess',
|
|
12514
|
+
const id = _optionalChain([sessionId, 'optionalAccess', _333 => _333.trim, 'call', _334 => _334()]) || this.generateSessionId();
|
|
12280
12515
|
return await this.db.transaction().execute(async (trx) => {
|
|
12281
12516
|
const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", appName).executeTakeFirst();
|
|
12282
12517
|
const userState = await trx.selectFrom("user_states").selectAll().where("app_name", "=", appName).where("user_id", "=", userId).executeTakeFirst();
|
|
12283
|
-
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess',
|
|
12284
|
-
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess',
|
|
12518
|
+
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _335 => _335.state]), {});
|
|
12519
|
+
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _336 => _336.state]), {});
|
|
12285
12520
|
if (!appState) {
|
|
12286
12521
|
await trx.insertInto("app_states").values({
|
|
12287
12522
|
app_name: appName,
|
|
@@ -12340,21 +12575,21 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
12340
12575
|
return void 0;
|
|
12341
12576
|
}
|
|
12342
12577
|
let eventQuery = trx.selectFrom("events").selectAll().where("session_id", "=", sessionId).orderBy("timestamp", "desc");
|
|
12343
|
-
if (_optionalChain([config, 'optionalAccess',
|
|
12578
|
+
if (_optionalChain([config, 'optionalAccess', _337 => _337.afterTimestamp])) {
|
|
12344
12579
|
eventQuery = eventQuery.where(
|
|
12345
12580
|
"timestamp",
|
|
12346
12581
|
">=",
|
|
12347
12582
|
new Date(config.afterTimestamp * 1e3)
|
|
12348
12583
|
);
|
|
12349
12584
|
}
|
|
12350
|
-
if (_optionalChain([config, 'optionalAccess',
|
|
12585
|
+
if (_optionalChain([config, 'optionalAccess', _338 => _338.numRecentEvents])) {
|
|
12351
12586
|
eventQuery = eventQuery.limit(config.numRecentEvents);
|
|
12352
12587
|
}
|
|
12353
12588
|
const storageEvents = await eventQuery.execute();
|
|
12354
12589
|
const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", appName).executeTakeFirst();
|
|
12355
12590
|
const userState = await trx.selectFrom("user_states").selectAll().where("app_name", "=", appName).where("user_id", "=", userId).executeTakeFirst();
|
|
12356
|
-
const currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess',
|
|
12357
|
-
const currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess',
|
|
12591
|
+
const currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _339 => _339.state]), {});
|
|
12592
|
+
const currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _340 => _340.state]), {});
|
|
12358
12593
|
const sessionState = this.parseJsonSafely(storageSession.state, {});
|
|
12359
12594
|
const mergedState = this.mergeState(
|
|
12360
12595
|
currentAppState,
|
|
@@ -12412,13 +12647,13 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
12412
12647
|
}
|
|
12413
12648
|
const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", session.appName).executeTakeFirst();
|
|
12414
12649
|
const userState = await trx.selectFrom("user_states").selectAll().where("app_name", "=", session.appName).where("user_id", "=", session.userId).executeTakeFirst();
|
|
12415
|
-
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess',
|
|
12416
|
-
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess',
|
|
12650
|
+
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _341 => _341.state]), {});
|
|
12651
|
+
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _342 => _342.state]), {});
|
|
12417
12652
|
let sessionState = this.parseJsonSafely(storageSession.state, {});
|
|
12418
12653
|
let appStateDelta = {};
|
|
12419
12654
|
let userStateDelta = {};
|
|
12420
12655
|
let sessionStateDelta = {};
|
|
12421
|
-
if (_optionalChain([event, 'access',
|
|
12656
|
+
if (_optionalChain([event, 'access', _343 => _343.actions, 'optionalAccess', _344 => _344.stateDelta])) {
|
|
12422
12657
|
const deltas = this.extractStateDelta(event.actions.stateDelta);
|
|
12423
12658
|
appStateDelta = deltas.appStateDelta;
|
|
12424
12659
|
userStateDelta = deltas.userStateDelta;
|
|
@@ -12564,7 +12799,7 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
12564
12799
|
* Overrides the base class method to work with plain object state.
|
|
12565
12800
|
*/
|
|
12566
12801
|
updateSessionState(session, event) {
|
|
12567
|
-
if (!_optionalChain([event, 'access',
|
|
12802
|
+
if (!_optionalChain([event, 'access', _345 => _345.actions, 'optionalAccess', _346 => _346.stateDelta])) {
|
|
12568
12803
|
return;
|
|
12569
12804
|
}
|
|
12570
12805
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
@@ -12734,7 +12969,7 @@ var GcsArtifactService = class {
|
|
|
12734
12969
|
};
|
|
12735
12970
|
return part;
|
|
12736
12971
|
} catch (error) {
|
|
12737
|
-
if (_optionalChain([error, 'optionalAccess',
|
|
12972
|
+
if (_optionalChain([error, 'optionalAccess', _347 => _347.code]) === 404) {
|
|
12738
12973
|
return null;
|
|
12739
12974
|
}
|
|
12740
12975
|
throw error;
|
|
@@ -12985,13 +13220,13 @@ var VertexAiEvalFacade = class _VertexAiEvalFacade {
|
|
|
12985
13220
|
};
|
|
12986
13221
|
}
|
|
12987
13222
|
_getText(content) {
|
|
12988
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
13223
|
+
if (_optionalChain([content, 'optionalAccess', _348 => _348.parts])) {
|
|
12989
13224
|
return content.parts.map((p) => p.text || "").filter((text) => text.length > 0).join("\n");
|
|
12990
13225
|
}
|
|
12991
13226
|
return "";
|
|
12992
13227
|
}
|
|
12993
13228
|
_getScore(evalResult) {
|
|
12994
|
-
if (_optionalChain([evalResult, 'optionalAccess',
|
|
13229
|
+
if (_optionalChain([evalResult, 'optionalAccess', _349 => _349.summaryMetrics, 'optionalAccess', _350 => _350[0], 'optionalAccess', _351 => _351.meanScore]) !== void 0 && typeof evalResult.summaryMetrics[0].meanScore === "number" && !Number.isNaN(evalResult.summaryMetrics[0].meanScore)) {
|
|
12995
13230
|
return evalResult.summaryMetrics[0].meanScore;
|
|
12996
13231
|
}
|
|
12997
13232
|
return void 0;
|
|
@@ -13141,7 +13376,7 @@ var ResponseEvaluator = class extends Evaluator {
|
|
|
13141
13376
|
return fmeasure;
|
|
13142
13377
|
}
|
|
13143
13378
|
extractText(content) {
|
|
13144
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
13379
|
+
if (_optionalChain([content, 'optionalAccess', _352 => _352.parts])) {
|
|
13145
13380
|
return content.parts.map((p) => p.text || "").filter((text) => text.length > 0).join(" ");
|
|
13146
13381
|
}
|
|
13147
13382
|
return "";
|
|
@@ -13174,7 +13409,7 @@ var TrajectoryEvaluator = class extends Evaluator {
|
|
|
13174
13409
|
for (let i = 0; i < actualInvocations.length; i++) {
|
|
13175
13410
|
const actual = actualInvocations[i];
|
|
13176
13411
|
const expected = expectedInvocations[i];
|
|
13177
|
-
if (!_optionalChain([actual, 'access',
|
|
13412
|
+
if (!_optionalChain([actual, 'access', _353 => _353.intermediateData, 'optionalAccess', _354 => _354.toolUses]) || !_optionalChain([expected, 'access', _355 => _355.intermediateData, 'optionalAccess', _356 => _356.toolUses])) {
|
|
13178
13413
|
perInvocationResults.push({
|
|
13179
13414
|
actualInvocation: actual,
|
|
13180
13415
|
expectedInvocation: expected,
|
|
@@ -13262,7 +13497,7 @@ var SafetyEvaluatorV1 = class extends Evaluator {
|
|
|
13262
13497
|
|
|
13263
13498
|
// src/evaluation/llm-as-judge-utils.ts
|
|
13264
13499
|
function getTextFromContent(content) {
|
|
13265
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
13500
|
+
if (_optionalChain([content, 'optionalAccess', _357 => _357.parts])) {
|
|
13266
13501
|
return content.parts.map((part) => part.text).filter(Boolean).join("\n");
|
|
13267
13502
|
}
|
|
13268
13503
|
return "";
|
|
@@ -13274,9 +13509,9 @@ function getEvalStatus(score, threshold) {
|
|
|
13274
13509
|
// src/evaluation/llm-as-judge.ts
|
|
13275
13510
|
var LlmAsJudge = class {
|
|
13276
13511
|
async sampleJudge(prompt, numSamples, critiqueParser, judgeModelOptions) {
|
|
13277
|
-
const modelName = _optionalChain([judgeModelOptions, 'optionalAccess',
|
|
13512
|
+
const modelName = _optionalChain([judgeModelOptions, 'optionalAccess', _358 => _358.judgeModel]) || "gemini-2.5-flash";
|
|
13278
13513
|
const model = LLMRegistry.getModelOrCreate(modelName);
|
|
13279
|
-
const config = _optionalChain([judgeModelOptions, 'optionalAccess',
|
|
13514
|
+
const config = _optionalChain([judgeModelOptions, 'optionalAccess', _359 => _359.judgeModelConfig]) || {};
|
|
13280
13515
|
const samples = [];
|
|
13281
13516
|
for (let i = 0; i < numSamples; i++) {
|
|
13282
13517
|
try {
|
|
@@ -13342,7 +13577,7 @@ function parseCritique(response) {
|
|
|
13342
13577
|
const labelMatchIsResponseValid = response.match(
|
|
13343
13578
|
/"is_the_agent_response_valid":\s*\[*[\n\s]*"*([^"^\]^\s]*)"*[\n\s]*\]*\s*[,\n\}]/
|
|
13344
13579
|
);
|
|
13345
|
-
if (_optionalChain([labelMatchIsResponseValid, 'optionalAccess',
|
|
13580
|
+
if (_optionalChain([labelMatchIsResponseValid, 'optionalAccess', _360 => _360[1]])) {
|
|
13346
13581
|
const label = labelMatchIsResponseValid[1].toLowerCase();
|
|
13347
13582
|
return label === "valid" ? "valid" /* VALID */ : "invalid" /* INVALID */;
|
|
13348
13583
|
}
|
|
@@ -13387,7 +13622,7 @@ var FinalResponseMatchV2Evaluator = class extends Evaluator {
|
|
|
13387
13622
|
"{prompt}",
|
|
13388
13623
|
prompt
|
|
13389
13624
|
).replace("{response}", response).replace("{golden_response}", goldenResponse);
|
|
13390
|
-
const numSamples = _nullishCoalesce(_optionalChain([this, 'access',
|
|
13625
|
+
const numSamples = _nullishCoalesce(_optionalChain([this, 'access', _361 => _361.metric, 'access', _362 => _362.judgeModelOptions, 'optionalAccess', _363 => _363.numSamples]), () => ( DEFAULT_NUM_SAMPLES));
|
|
13391
13626
|
const labels = await this.llmAsJudge.sampleJudge(
|
|
13392
13627
|
formattedPrompt,
|
|
13393
13628
|
numSamples,
|
|
@@ -13427,7 +13662,7 @@ var MetricEvaluatorRegistry = (_class35 = class {constructor() { _class35.protot
|
|
|
13427
13662
|
const metricName = metricInfo.metricName;
|
|
13428
13663
|
if (this.registry.has(metricName)) {
|
|
13429
13664
|
console.info(
|
|
13430
|
-
`Updating Evaluator class for ${metricName} from ${_optionalChain([this, 'access',
|
|
13665
|
+
`Updating Evaluator class for ${metricName} from ${_optionalChain([this, 'access', _364 => _364.registry, 'access', _365 => _365.get, 'call', _366 => _366(metricName), 'optionalAccess', _367 => _367.evaluator, 'access', _368 => _368.name])} to ${evaluator.name}`
|
|
13431
13666
|
);
|
|
13432
13667
|
}
|
|
13433
13668
|
this.registry.set(metricName, {
|
|
@@ -13541,10 +13776,10 @@ var LocalEvalService = class extends BaseEvalService {
|
|
|
13541
13776
|
for (const evalMetric of evaluateConfig.evalMetrics) {
|
|
13542
13777
|
const evaluator = DEFAULT_METRIC_EVALUATOR_REGISTRY.getEvaluator(evalMetric);
|
|
13543
13778
|
const actual = results.filter(
|
|
13544
|
-
(r) => !_optionalChain([r, 'access',
|
|
13779
|
+
(r) => !_optionalChain([r, 'access', _369 => _369.invocationId, 'optionalAccess', _370 => _370.includes, 'call', _371 => _371("expected")])
|
|
13545
13780
|
);
|
|
13546
13781
|
const expected = results.filter(
|
|
13547
|
-
(r) => _optionalChain([r, 'access',
|
|
13782
|
+
(r) => _optionalChain([r, 'access', _372 => _372.invocationId, 'optionalAccess', _373 => _373.includes, 'call', _374 => _374("expected")])
|
|
13548
13783
|
);
|
|
13549
13784
|
const result = await evaluator.evaluateInvocations(actual, expected);
|
|
13550
13785
|
evalResult.evalCaseResults.push({
|
|
@@ -13936,13 +14171,13 @@ ${failures.join(
|
|
|
13936
14171
|
console.log("\n\n");
|
|
13937
14172
|
}
|
|
13938
14173
|
static _convertContentToText(content) {
|
|
13939
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
14174
|
+
if (_optionalChain([content, 'optionalAccess', _375 => _375.parts])) {
|
|
13940
14175
|
return content.parts.map((p) => p.text || "").filter((text) => text.length > 0).join("\n");
|
|
13941
14176
|
}
|
|
13942
14177
|
return "";
|
|
13943
14178
|
}
|
|
13944
14179
|
static _convertToolCallsToText(intermediateData) {
|
|
13945
|
-
if (_optionalChain([intermediateData, 'optionalAccess',
|
|
14180
|
+
if (_optionalChain([intermediateData, 'optionalAccess', _376 => _376.toolUses])) {
|
|
13946
14181
|
return intermediateData.toolUses.map((t) => JSON.stringify(t)).join("\n");
|
|
13947
14182
|
}
|
|
13948
14183
|
return "";
|
|
@@ -13997,7 +14232,7 @@ ${failures.join(
|
|
|
13997
14232
|
for (const [metricName, evalMetricResultsWithInvocations] of Object.entries(
|
|
13998
14233
|
evalMetricResults
|
|
13999
14234
|
)) {
|
|
14000
|
-
const threshold = _optionalChain([evalMetricResultsWithInvocations, 'access',
|
|
14235
|
+
const threshold = _optionalChain([evalMetricResultsWithInvocations, 'access', _377 => _377[0], 'optionalAccess', _378 => _378.evalMetricResult, 'access', _379 => _379.threshold]) || 0;
|
|
14001
14236
|
const scores = evalMetricResultsWithInvocations.map((m) => m.evalMetricResult.score).filter((s) => s !== void 0);
|
|
14002
14237
|
let overallScore;
|
|
14003
14238
|
let overallEvalStatus;
|
|
@@ -14086,7 +14321,7 @@ var RougeEvaluator = class extends Evaluator {
|
|
|
14086
14321
|
}
|
|
14087
14322
|
};
|
|
14088
14323
|
function getTextFromContent2(content) {
|
|
14089
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
14324
|
+
if (_optionalChain([content, 'optionalAccess', _380 => _380.parts])) {
|
|
14090
14325
|
return content.parts.map((part) => part.text).filter(Boolean).join("\n");
|
|
14091
14326
|
}
|
|
14092
14327
|
return "";
|
|
@@ -14284,4 +14519,7 @@ var VERSION = "0.1.0";
|
|
|
14284
14519
|
|
|
14285
14520
|
|
|
14286
14521
|
|
|
14287
|
-
|
|
14522
|
+
|
|
14523
|
+
|
|
14524
|
+
|
|
14525
|
+
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.LlmEventSummarizer = LlmEventSummarizer; 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.McpCoinGeckoPro = McpCoinGeckoPro; 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.getArtifactUri = getArtifactUri; 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.isArtifactRef = isArtifactRef; 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.parseArtifactUri = parseArtifactUri; exports.populateClientFunctionCallId = populateClientFunctionCallId; exports.registerProviders = registerProviders; exports.removeClientFunctionCallId = removeClientFunctionCallId; exports.requestProcessor = requestProcessor; exports.runCompactionForSlidingWindow = runCompactionForSlidingWindow; exports.shutdownTelemetry = shutdownTelemetry; exports.telemetryService = telemetryService; exports.traceLlmCall = traceLlmCall; exports.traceToolCall = traceToolCall; exports.tracer = tracer;
|
package/dist/index.mjs
CHANGED
|
@@ -3394,6 +3394,10 @@ var EventActions = class {
|
|
|
3394
3394
|
* a compaction of events within the specified timestamp range.
|
|
3395
3395
|
*/
|
|
3396
3396
|
compaction;
|
|
3397
|
+
/**
|
|
3398
|
+
* The invocation id to rewind to. This is only set for rewind event.
|
|
3399
|
+
*/
|
|
3400
|
+
rewindBeforeInvocationId;
|
|
3397
3401
|
/**
|
|
3398
3402
|
* Constructor for EventActions
|
|
3399
3403
|
*/
|
|
@@ -3405,6 +3409,7 @@ var EventActions = class {
|
|
|
3405
3409
|
this.escalate = options.escalate;
|
|
3406
3410
|
this.requestedAuthConfigs = options.requestedAuthConfigs;
|
|
3407
3411
|
this.compaction = options.compaction;
|
|
3412
|
+
this.rewindBeforeInvocationId = options.rewindBeforeInvocationId;
|
|
3408
3413
|
}
|
|
3409
3414
|
};
|
|
3410
3415
|
|
|
@@ -8468,8 +8473,30 @@ function rearrangeEventsForLatestFunctionResponse(events) {
|
|
|
8468
8473
|
return resultEvents;
|
|
8469
8474
|
}
|
|
8470
8475
|
function getContents(currentBranch, events, agentName = "") {
|
|
8476
|
+
const invocationIdToIndex = /* @__PURE__ */ new Map();
|
|
8477
|
+
for (let idx = 0; idx < events.length; idx++) {
|
|
8478
|
+
if (events[idx].invocationId) {
|
|
8479
|
+
invocationIdToIndex.set(events[idx].invocationId, idx);
|
|
8480
|
+
}
|
|
8481
|
+
}
|
|
8482
|
+
const rewindFilteredEvents = [];
|
|
8483
|
+
let i = events.length - 1;
|
|
8484
|
+
while (i >= 0) {
|
|
8485
|
+
const event = events[i];
|
|
8486
|
+
if (event.actions?.rewindBeforeInvocationId) {
|
|
8487
|
+
const rewindInvocationId = event.actions.rewindBeforeInvocationId;
|
|
8488
|
+
const rewindIndex = invocationIdToIndex.get(rewindInvocationId);
|
|
8489
|
+
if (rewindIndex !== void 0 && rewindIndex < i) {
|
|
8490
|
+
i = rewindIndex;
|
|
8491
|
+
}
|
|
8492
|
+
} else {
|
|
8493
|
+
rewindFilteredEvents.push(event);
|
|
8494
|
+
}
|
|
8495
|
+
i--;
|
|
8496
|
+
}
|
|
8497
|
+
rewindFilteredEvents.reverse();
|
|
8471
8498
|
const filteredEvents = [];
|
|
8472
|
-
for (const event of
|
|
8499
|
+
for (const event of rewindFilteredEvents) {
|
|
8473
8500
|
if (!event.content || !event.content.role || !event.content.parts || event.content.parts.length === 0) {
|
|
8474
8501
|
continue;
|
|
8475
8502
|
}
|
|
@@ -10184,6 +10211,48 @@ var RunConfig = class {
|
|
|
10184
10211
|
}
|
|
10185
10212
|
};
|
|
10186
10213
|
|
|
10214
|
+
// src/artifacts/artifact-util.ts
|
|
10215
|
+
var SESSION_SCOPED_ARTIFACT_URI_RE = /^artifact:\/\/apps\/([^/]+)\/users\/([^/]+)\/sessions\/([^/]+)\/artifacts\/([^/]+)\/versions\/(\d+)$/;
|
|
10216
|
+
var USER_SCOPED_ARTIFACT_URI_RE = /^artifact:\/\/apps\/([^/]+)\/users\/([^/]+)\/artifacts\/([^/]+)\/versions\/(\d+)$/;
|
|
10217
|
+
function parseArtifactUri(uri) {
|
|
10218
|
+
if (!uri || !uri.startsWith("artifact://")) {
|
|
10219
|
+
return null;
|
|
10220
|
+
}
|
|
10221
|
+
let match = SESSION_SCOPED_ARTIFACT_URI_RE.exec(uri);
|
|
10222
|
+
if (match) {
|
|
10223
|
+
return {
|
|
10224
|
+
appName: match[1],
|
|
10225
|
+
userId: match[2],
|
|
10226
|
+
sessionId: match[3],
|
|
10227
|
+
filename: match[4],
|
|
10228
|
+
version: Number.parseInt(match[5], 10)
|
|
10229
|
+
};
|
|
10230
|
+
}
|
|
10231
|
+
match = USER_SCOPED_ARTIFACT_URI_RE.exec(uri);
|
|
10232
|
+
if (match) {
|
|
10233
|
+
return {
|
|
10234
|
+
appName: match[1],
|
|
10235
|
+
userId: match[2],
|
|
10236
|
+
sessionId: void 0,
|
|
10237
|
+
filename: match[3],
|
|
10238
|
+
version: Number.parseInt(match[4], 10)
|
|
10239
|
+
};
|
|
10240
|
+
}
|
|
10241
|
+
return null;
|
|
10242
|
+
}
|
|
10243
|
+
function getArtifactUri(args) {
|
|
10244
|
+
const { appName, userId, filename, version, sessionId } = args;
|
|
10245
|
+
if (sessionId) {
|
|
10246
|
+
return `artifact://apps/${appName}/users/${userId}/sessions/${sessionId}/artifacts/${filename}/versions/${version}`;
|
|
10247
|
+
}
|
|
10248
|
+
return `artifact://apps/${appName}/users/${userId}/artifacts/${filename}/versions/${version}`;
|
|
10249
|
+
}
|
|
10250
|
+
function isArtifactRef(artifact) {
|
|
10251
|
+
return Boolean(
|
|
10252
|
+
artifact.fileData?.fileUri && artifact.fileData.fileUri.startsWith("artifact://")
|
|
10253
|
+
);
|
|
10254
|
+
}
|
|
10255
|
+
|
|
10187
10256
|
// src/artifacts/in-memory-artifact-service.ts
|
|
10188
10257
|
var InMemoryArtifactService = class {
|
|
10189
10258
|
artifacts = /* @__PURE__ */ new Map();
|
|
@@ -10224,7 +10293,29 @@ var InMemoryArtifactService = class {
|
|
|
10224
10293
|
if (targetVersion < 0 || targetVersion >= versions.length) {
|
|
10225
10294
|
return null;
|
|
10226
10295
|
}
|
|
10227
|
-
|
|
10296
|
+
const artifactEntry = versions[targetVersion];
|
|
10297
|
+
if (!artifactEntry) {
|
|
10298
|
+
return null;
|
|
10299
|
+
}
|
|
10300
|
+
if (isArtifactRef(artifactEntry)) {
|
|
10301
|
+
const parsedUri = parseArtifactUri(artifactEntry.fileData?.fileUri || "");
|
|
10302
|
+
if (!parsedUri) {
|
|
10303
|
+
throw new Error(
|
|
10304
|
+
`Invalid artifact reference URI: ${artifactEntry.fileData?.fileUri}`
|
|
10305
|
+
);
|
|
10306
|
+
}
|
|
10307
|
+
return await this.loadArtifact({
|
|
10308
|
+
appName: parsedUri.appName,
|
|
10309
|
+
userId: parsedUri.userId,
|
|
10310
|
+
sessionId: parsedUri.sessionId || sessionId,
|
|
10311
|
+
filename: parsedUri.filename,
|
|
10312
|
+
version: parsedUri.version
|
|
10313
|
+
});
|
|
10314
|
+
}
|
|
10315
|
+
if (!artifactEntry.text && (!artifactEntry.inlineData?.data || artifactEntry.inlineData.data.length === 0) && !artifactEntry.fileData) {
|
|
10316
|
+
return null;
|
|
10317
|
+
}
|
|
10318
|
+
return artifactEntry;
|
|
10228
10319
|
}
|
|
10229
10320
|
async listArtifactKeys(args) {
|
|
10230
10321
|
const { appName, userId, sessionId } = args;
|
|
@@ -10409,11 +10500,16 @@ var BaseSessionService = class {
|
|
|
10409
10500
|
return;
|
|
10410
10501
|
}
|
|
10411
10502
|
for (const key in event.actions.stateDelta) {
|
|
10412
|
-
if (Object.
|
|
10503
|
+
if (Object.hasOwn(event.actions.stateDelta, key)) {
|
|
10413
10504
|
if (key.startsWith("temp_")) {
|
|
10414
10505
|
continue;
|
|
10415
10506
|
}
|
|
10416
|
-
|
|
10507
|
+
const value = event.actions.stateDelta[key];
|
|
10508
|
+
if (value === null || value === void 0) {
|
|
10509
|
+
delete session.state[key];
|
|
10510
|
+
} else {
|
|
10511
|
+
session.state[key] = value;
|
|
10512
|
+
}
|
|
10417
10513
|
}
|
|
10418
10514
|
}
|
|
10419
10515
|
}
|
|
@@ -10961,6 +11057,142 @@ var Runner = class {
|
|
|
10961
11057
|
}
|
|
10962
11058
|
return void 0;
|
|
10963
11059
|
}
|
|
11060
|
+
async rewind(args) {
|
|
11061
|
+
const { userId, sessionId, rewindBeforeInvocationId } = args;
|
|
11062
|
+
const session = await this.sessionService.getSession(
|
|
11063
|
+
this.appName,
|
|
11064
|
+
userId,
|
|
11065
|
+
sessionId
|
|
11066
|
+
);
|
|
11067
|
+
if (!session) {
|
|
11068
|
+
throw new Error(`Session not found: ${sessionId}`);
|
|
11069
|
+
}
|
|
11070
|
+
let rewindEventIndex = -1;
|
|
11071
|
+
for (let i = 0; i < session.events.length; i++) {
|
|
11072
|
+
if (session.events[i].invocationId === rewindBeforeInvocationId) {
|
|
11073
|
+
rewindEventIndex = i;
|
|
11074
|
+
break;
|
|
11075
|
+
}
|
|
11076
|
+
}
|
|
11077
|
+
if (rewindEventIndex === -1) {
|
|
11078
|
+
throw new Error(`Invocation ID not found: ${rewindBeforeInvocationId}`);
|
|
11079
|
+
}
|
|
11080
|
+
const stateDelta = await this._computeStateDeltaForRewind(
|
|
11081
|
+
session,
|
|
11082
|
+
rewindEventIndex
|
|
11083
|
+
);
|
|
11084
|
+
const artifactDelta = await this._computeArtifactDeltaForRewind(
|
|
11085
|
+
session,
|
|
11086
|
+
rewindEventIndex
|
|
11087
|
+
);
|
|
11088
|
+
const rewindEvent = new Event({
|
|
11089
|
+
invocationId: newInvocationContextId(),
|
|
11090
|
+
author: "user",
|
|
11091
|
+
actions: new EventActions({
|
|
11092
|
+
rewindBeforeInvocationId,
|
|
11093
|
+
stateDelta,
|
|
11094
|
+
artifactDelta
|
|
11095
|
+
})
|
|
11096
|
+
});
|
|
11097
|
+
this.logger.info(
|
|
11098
|
+
"Rewinding session to invocation:",
|
|
11099
|
+
rewindBeforeInvocationId
|
|
11100
|
+
);
|
|
11101
|
+
await this.sessionService.appendEvent(session, rewindEvent);
|
|
11102
|
+
}
|
|
11103
|
+
async _computeStateDeltaForRewind(session, rewindEventIndex) {
|
|
11104
|
+
const stateAtRewindPoint = {};
|
|
11105
|
+
for (let i = 0; i < rewindEventIndex; i++) {
|
|
11106
|
+
const event = session.events[i];
|
|
11107
|
+
if (event.actions?.stateDelta) {
|
|
11108
|
+
for (const [k, v] of Object.entries(event.actions.stateDelta)) {
|
|
11109
|
+
if (k.startsWith("app:") || k.startsWith("user:")) {
|
|
11110
|
+
continue;
|
|
11111
|
+
}
|
|
11112
|
+
if (v === null || v === void 0) {
|
|
11113
|
+
delete stateAtRewindPoint[k];
|
|
11114
|
+
} else {
|
|
11115
|
+
stateAtRewindPoint[k] = v;
|
|
11116
|
+
}
|
|
11117
|
+
}
|
|
11118
|
+
}
|
|
11119
|
+
}
|
|
11120
|
+
const currentState = session.state;
|
|
11121
|
+
const rewindStateDelta = {};
|
|
11122
|
+
for (const [key, valueAtRewind] of Object.entries(stateAtRewindPoint)) {
|
|
11123
|
+
if (!(key in currentState) || currentState[key] !== valueAtRewind) {
|
|
11124
|
+
rewindStateDelta[key] = valueAtRewind;
|
|
11125
|
+
}
|
|
11126
|
+
}
|
|
11127
|
+
for (const key of Object.keys(currentState)) {
|
|
11128
|
+
if (key.startsWith("app:") || key.startsWith("user:")) {
|
|
11129
|
+
continue;
|
|
11130
|
+
}
|
|
11131
|
+
if (!(key in stateAtRewindPoint)) {
|
|
11132
|
+
rewindStateDelta[key] = null;
|
|
11133
|
+
}
|
|
11134
|
+
}
|
|
11135
|
+
return rewindStateDelta;
|
|
11136
|
+
}
|
|
11137
|
+
async _computeArtifactDeltaForRewind(session, rewindEventIndex) {
|
|
11138
|
+
if (!this.artifactService) {
|
|
11139
|
+
return {};
|
|
11140
|
+
}
|
|
11141
|
+
const versionsAtRewindPoint = {};
|
|
11142
|
+
for (let i = 0; i < rewindEventIndex; i++) {
|
|
11143
|
+
const event = session.events[i];
|
|
11144
|
+
if (event.actions?.artifactDelta) {
|
|
11145
|
+
Object.assign(versionsAtRewindPoint, event.actions.artifactDelta);
|
|
11146
|
+
}
|
|
11147
|
+
}
|
|
11148
|
+
const currentVersions = {};
|
|
11149
|
+
for (const event of session.events) {
|
|
11150
|
+
if (event.actions?.artifactDelta) {
|
|
11151
|
+
Object.assign(currentVersions, event.actions.artifactDelta);
|
|
11152
|
+
}
|
|
11153
|
+
}
|
|
11154
|
+
const rewindArtifactDelta = {};
|
|
11155
|
+
for (const [filename, vn] of Object.entries(currentVersions)) {
|
|
11156
|
+
if (filename.startsWith("user:")) {
|
|
11157
|
+
continue;
|
|
11158
|
+
}
|
|
11159
|
+
const vt = versionsAtRewindPoint[filename];
|
|
11160
|
+
if (vt === vn) {
|
|
11161
|
+
continue;
|
|
11162
|
+
}
|
|
11163
|
+
let artifact;
|
|
11164
|
+
if (vt === void 0 || vt === null) {
|
|
11165
|
+
artifact = {
|
|
11166
|
+
inlineData: {
|
|
11167
|
+
mimeType: "application/octet-stream",
|
|
11168
|
+
data: ""
|
|
11169
|
+
}
|
|
11170
|
+
};
|
|
11171
|
+
} else {
|
|
11172
|
+
const artifactUri = getArtifactUri({
|
|
11173
|
+
appName: this.appName,
|
|
11174
|
+
userId: session.userId,
|
|
11175
|
+
sessionId: session.id,
|
|
11176
|
+
filename,
|
|
11177
|
+
version: vt
|
|
11178
|
+
});
|
|
11179
|
+
artifact = {
|
|
11180
|
+
fileData: {
|
|
11181
|
+
fileUri: artifactUri
|
|
11182
|
+
}
|
|
11183
|
+
};
|
|
11184
|
+
}
|
|
11185
|
+
const newVersion = await this.artifactService.saveArtifact({
|
|
11186
|
+
appName: this.appName,
|
|
11187
|
+
userId: session.userId,
|
|
11188
|
+
sessionId: session.id,
|
|
11189
|
+
filename,
|
|
11190
|
+
artifact
|
|
11191
|
+
});
|
|
11192
|
+
rewindArtifactDelta[filename] = newVersion;
|
|
11193
|
+
}
|
|
11194
|
+
return rewindArtifactDelta;
|
|
11195
|
+
}
|
|
10964
11196
|
};
|
|
10965
11197
|
var InMemoryRunner = class extends Runner {
|
|
10966
11198
|
/**
|
|
@@ -11664,6 +11896,9 @@ var AgentBuilder = class _AgentBuilder {
|
|
|
11664
11896
|
...params,
|
|
11665
11897
|
runConfig: params.runConfig ?? runConfig
|
|
11666
11898
|
});
|
|
11899
|
+
},
|
|
11900
|
+
rewind(params) {
|
|
11901
|
+
return baseRunner.rewind(params);
|
|
11667
11902
|
}
|
|
11668
11903
|
};
|
|
11669
11904
|
}
|
|
@@ -14257,6 +14492,7 @@ export {
|
|
|
14257
14492
|
createTool,
|
|
14258
14493
|
generateAuthEvent,
|
|
14259
14494
|
generateClientFunctionCallId,
|
|
14495
|
+
getArtifactUri,
|
|
14260
14496
|
getLongRunningFunctionCalls,
|
|
14261
14497
|
getMcpTools,
|
|
14262
14498
|
handleFunctionCallsAsync,
|
|
@@ -14265,6 +14501,7 @@ export {
|
|
|
14265
14501
|
initializeTelemetry,
|
|
14266
14502
|
injectSessionState,
|
|
14267
14503
|
requestProcessor6 as instructionsRequestProcessor,
|
|
14504
|
+
isArtifactRef,
|
|
14268
14505
|
isEnhancedAuthConfig,
|
|
14269
14506
|
jsonSchemaToDeclaration,
|
|
14270
14507
|
mcpSchemaToParameters,
|
|
@@ -14274,6 +14511,7 @@ export {
|
|
|
14274
14511
|
requestProcessor7 as nlPlanningRequestProcessor,
|
|
14275
14512
|
responseProcessor2 as nlPlanningResponseProcessor,
|
|
14276
14513
|
normalizeJsonSchema,
|
|
14514
|
+
parseArtifactUri,
|
|
14277
14515
|
populateClientFunctionCallId,
|
|
14278
14516
|
registerProviders,
|
|
14279
14517
|
removeClientFunctionCallId,
|