@iqai/adk 0.0.7 → 0.0.9
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 +13 -0
- package/dist/index.d.mts +43 -7
- package/dist/index.d.ts +43 -7
- package/dist/index.js +307 -163
- package/dist/index.mjs +168 -24
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17; var _class18; var _class19; var _class20; var _class21; var _class22; var _class23; var _class24; var _class25; var _class26; var _class27; var _class28; var _class29;var __defProp = Object.defineProperty;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17; var _class18; var _class19; var _class20; var _class21; var _class22; var _class23; var _class24; var _class25; var _class26; var _class27; var _class28; var _class29; var _class30;var __defProp = Object.defineProperty;
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
@@ -2947,6 +2947,13 @@ var _ssejs = require('@modelcontextprotocol/sdk/client/sse.js');
|
|
|
2947
2947
|
var _stdiojs = require('@modelcontextprotocol/sdk/client/stdio.js');
|
|
2948
2948
|
var _typesjs = require('@modelcontextprotocol/sdk/types.js');
|
|
2949
2949
|
|
|
2950
|
+
// src/tools/mcp/sampling-handler.ts
|
|
2951
|
+
init_logger();
|
|
2952
|
+
|
|
2953
|
+
|
|
2954
|
+
|
|
2955
|
+
|
|
2956
|
+
|
|
2950
2957
|
// src/tools/mcp/types.ts
|
|
2951
2958
|
var McpErrorType = /* @__PURE__ */ ((McpErrorType2) => {
|
|
2952
2959
|
McpErrorType2["CONNECTION_ERROR"] = "connection_error";
|
|
@@ -2969,6 +2976,154 @@ var McpError = class extends Error {
|
|
|
2969
2976
|
}
|
|
2970
2977
|
};
|
|
2971
2978
|
|
|
2979
|
+
// src/tools/mcp/sampling-handler.ts
|
|
2980
|
+
var McpSamplingHandler = (_class17 = class {
|
|
2981
|
+
__init20() {this.logger = new Logger({ name: "McpSamplingHandler" })}
|
|
2982
|
+
|
|
2983
|
+
constructor(adkHandler) {;_class17.prototype.__init20.call(this);
|
|
2984
|
+
this.adkHandler = adkHandler;
|
|
2985
|
+
}
|
|
2986
|
+
/**
|
|
2987
|
+
* Handle MCP sampling request and convert between formats
|
|
2988
|
+
*/
|
|
2989
|
+
async handleSamplingRequest(request) {
|
|
2990
|
+
try {
|
|
2991
|
+
const validationResult = _typesjs.CreateMessageRequestSchema.safeParse(request);
|
|
2992
|
+
if (!validationResult.success) {
|
|
2993
|
+
this.logger.error(
|
|
2994
|
+
"Invalid MCP sampling request:",
|
|
2995
|
+
validationResult.error
|
|
2996
|
+
);
|
|
2997
|
+
throw new McpError(
|
|
2998
|
+
`Invalid sampling request: ${validationResult.error.message}`,
|
|
2999
|
+
"INVALID_REQUEST_ERROR" /* INVALID_REQUEST_ERROR */
|
|
3000
|
+
);
|
|
3001
|
+
}
|
|
3002
|
+
const mcpParams = request.params;
|
|
3003
|
+
if (!mcpParams.messages || !Array.isArray(mcpParams.messages)) {
|
|
3004
|
+
throw new McpError(
|
|
3005
|
+
"Invalid sampling request: messages array is required",
|
|
3006
|
+
"INVALID_REQUEST_ERROR" /* INVALID_REQUEST_ERROR */
|
|
3007
|
+
);
|
|
3008
|
+
}
|
|
3009
|
+
if (!mcpParams.maxTokens || mcpParams.maxTokens <= 0) {
|
|
3010
|
+
throw new McpError(
|
|
3011
|
+
"Invalid sampling request: maxTokens must be a positive number",
|
|
3012
|
+
"INVALID_REQUEST_ERROR" /* INVALID_REQUEST_ERROR */
|
|
3013
|
+
);
|
|
3014
|
+
}
|
|
3015
|
+
this.logger.debug("Converting MCP request to ADK format");
|
|
3016
|
+
const adkMessages = this.convertMcpMessagesToADK(mcpParams.messages);
|
|
3017
|
+
const adkRequest = {
|
|
3018
|
+
messages: adkMessages,
|
|
3019
|
+
systemPrompt: mcpParams.systemPrompt,
|
|
3020
|
+
modelPreferences: mcpParams.modelPreferences,
|
|
3021
|
+
includeContext: mcpParams.includeContext,
|
|
3022
|
+
temperature: mcpParams.temperature,
|
|
3023
|
+
maxTokens: mcpParams.maxTokens,
|
|
3024
|
+
stopSequences: mcpParams.stopSequences,
|
|
3025
|
+
metadata: mcpParams.metadata
|
|
3026
|
+
};
|
|
3027
|
+
this.logger.debug("Calling ADK sampling handler");
|
|
3028
|
+
const adkResponse = await this.adkHandler(adkRequest);
|
|
3029
|
+
this.logger.debug("Converting ADK response to MCP format");
|
|
3030
|
+
const mcpResponse = this.convertADKResponseToMcp(adkResponse);
|
|
3031
|
+
const responseValidation = _typesjs.CreateMessageResultSchema.safeParse(mcpResponse);
|
|
3032
|
+
if (!responseValidation.success) {
|
|
3033
|
+
this.logger.error(
|
|
3034
|
+
"Invalid MCP response generated:",
|
|
3035
|
+
responseValidation.error
|
|
3036
|
+
);
|
|
3037
|
+
throw new McpError(
|
|
3038
|
+
`Invalid response generated: ${responseValidation.error.message}`,
|
|
3039
|
+
"SAMPLING_ERROR" /* SAMPLING_ERROR */
|
|
3040
|
+
);
|
|
3041
|
+
}
|
|
3042
|
+
return mcpResponse;
|
|
3043
|
+
} catch (error) {
|
|
3044
|
+
this.logger.error("Error handling sampling request:", error);
|
|
3045
|
+
if (error instanceof McpError) {
|
|
3046
|
+
throw error;
|
|
3047
|
+
}
|
|
3048
|
+
throw new McpError(
|
|
3049
|
+
`Sampling request failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
3050
|
+
"SAMPLING_ERROR" /* SAMPLING_ERROR */,
|
|
3051
|
+
error instanceof Error ? error : void 0
|
|
3052
|
+
);
|
|
3053
|
+
}
|
|
3054
|
+
}
|
|
3055
|
+
/**
|
|
3056
|
+
* Convert MCP messages to ADK message format
|
|
3057
|
+
*/
|
|
3058
|
+
convertMcpMessagesToADK(mcpMessages) {
|
|
3059
|
+
return mcpMessages.map((mcpMessage) => {
|
|
3060
|
+
const adkRole = mcpMessage.role === "assistant" ? "assistant" : "user";
|
|
3061
|
+
let adkContent;
|
|
3062
|
+
if (mcpMessage.content.type === "text") {
|
|
3063
|
+
adkContent = mcpMessage.content.text || "";
|
|
3064
|
+
} else if (mcpMessage.content.type === "image") {
|
|
3065
|
+
const contentParts = [];
|
|
3066
|
+
if (mcpMessage.content.text) {
|
|
3067
|
+
contentParts.push({
|
|
3068
|
+
type: "text",
|
|
3069
|
+
text: mcpMessage.content.text
|
|
3070
|
+
});
|
|
3071
|
+
}
|
|
3072
|
+
if (mcpMessage.content.data) {
|
|
3073
|
+
const mimeType = mcpMessage.content.mimeType || "image/jpeg";
|
|
3074
|
+
const dataUrl = `data:${mimeType};base64,${mcpMessage.content.data}`;
|
|
3075
|
+
contentParts.push({
|
|
3076
|
+
type: "image",
|
|
3077
|
+
image_url: {
|
|
3078
|
+
url: dataUrl
|
|
3079
|
+
}
|
|
3080
|
+
});
|
|
3081
|
+
}
|
|
3082
|
+
adkContent = contentParts.length > 0 ? contentParts : "";
|
|
3083
|
+
} else {
|
|
3084
|
+
this.logger.warn(
|
|
3085
|
+
`Unknown MCP content type: ${mcpMessage.content.type}`
|
|
3086
|
+
);
|
|
3087
|
+
adkContent = mcpMessage.content.data || "";
|
|
3088
|
+
}
|
|
3089
|
+
const adkMessage = {
|
|
3090
|
+
role: adkRole,
|
|
3091
|
+
content: adkContent
|
|
3092
|
+
};
|
|
3093
|
+
this.logger.debug(
|
|
3094
|
+
`Converted MCP message - role: ${mcpMessage.role} -> ${adkRole}, content type: ${mcpMessage.content.type}`
|
|
3095
|
+
);
|
|
3096
|
+
return adkMessage;
|
|
3097
|
+
});
|
|
3098
|
+
}
|
|
3099
|
+
/**
|
|
3100
|
+
* Convert ADK response to MCP response format
|
|
3101
|
+
*/
|
|
3102
|
+
convertADKResponseToMcp(adkResponse) {
|
|
3103
|
+
const mcpResponse = {
|
|
3104
|
+
model: adkResponse.model,
|
|
3105
|
+
stopReason: adkResponse.stopReason,
|
|
3106
|
+
role: "assistant",
|
|
3107
|
+
// ADK responses are always from assistant
|
|
3108
|
+
content: {
|
|
3109
|
+
type: "text",
|
|
3110
|
+
text: adkResponse.content || ""
|
|
3111
|
+
}
|
|
3112
|
+
};
|
|
3113
|
+
this.logger.debug(
|
|
3114
|
+
`Converted ADK response - model: ${adkResponse.model}, content length: ${_optionalChain([adkResponse, 'access', _39 => _39.content, 'optionalAccess', _40 => _40.length]) || 0}`
|
|
3115
|
+
);
|
|
3116
|
+
return mcpResponse;
|
|
3117
|
+
}
|
|
3118
|
+
/**
|
|
3119
|
+
* Update the ADK handler
|
|
3120
|
+
*/
|
|
3121
|
+
updateHandler(handler) {
|
|
3122
|
+
this.adkHandler = handler;
|
|
3123
|
+
this.logger.debug("ADK sampling handler updated");
|
|
3124
|
+
}
|
|
3125
|
+
}, _class17);
|
|
3126
|
+
|
|
2972
3127
|
// src/tools/mcp/utils.ts
|
|
2973
3128
|
function withRetry(fn, instance, reinitMethod, maxRetries = 1) {
|
|
2974
3129
|
return async (...args) => {
|
|
@@ -2998,16 +3153,15 @@ function withRetry(fn, instance, reinitMethod, maxRetries = 1) {
|
|
|
2998
3153
|
}
|
|
2999
3154
|
|
|
3000
3155
|
// src/tools/mcp/client.ts
|
|
3001
|
-
var McpClientService = (
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
constructor(config) {;
|
|
3156
|
+
var McpClientService = (_class18 = class {
|
|
3157
|
+
|
|
3158
|
+
__init21() {this.client = null}
|
|
3159
|
+
__init22() {this.transport = null}
|
|
3160
|
+
__init23() {this.isClosing = false}
|
|
3161
|
+
__init24() {this.mcpSamplingHandler = null}
|
|
3162
|
+
__init25() {this.logger = new Logger({ name: "McpClientService" })}
|
|
3163
|
+
constructor(config) {;_class18.prototype.__init21.call(this);_class18.prototype.__init22.call(this);_class18.prototype.__init23.call(this);_class18.prototype.__init24.call(this);_class18.prototype.__init25.call(this);
|
|
3009
3164
|
this.config = config;
|
|
3010
|
-
this.samplingHandler = config.samplingHandler || null;
|
|
3011
3165
|
}
|
|
3012
3166
|
/**
|
|
3013
3167
|
* Initializes and returns an MCP client based on configuration.
|
|
@@ -3177,7 +3331,7 @@ var McpClientService = (_class17 = class {
|
|
|
3177
3331
|
},
|
|
3178
3332
|
this,
|
|
3179
3333
|
async (instance) => await instance.reinitialize(),
|
|
3180
|
-
_optionalChain([this, 'access',
|
|
3334
|
+
_optionalChain([this, 'access', _41 => _41.config, 'access', _42 => _42.retryOptions, 'optionalAccess', _43 => _43.maxRetries]) || 2
|
|
3181
3335
|
);
|
|
3182
3336
|
return await wrappedCall();
|
|
3183
3337
|
} catch (error) {
|
|
@@ -3209,7 +3363,7 @@ var McpClientService = (_class17 = class {
|
|
|
3209
3363
|
return !!this.client && !this.isClosing;
|
|
3210
3364
|
}
|
|
3211
3365
|
async setupSamplingHandler(client) {
|
|
3212
|
-
if (!this.
|
|
3366
|
+
if (!this.mcpSamplingHandler) {
|
|
3213
3367
|
if (this.config.debug) {
|
|
3214
3368
|
console.log(
|
|
3215
3369
|
"\u26A0\uFE0F No sampling handler provided - sampling requests will be rejected"
|
|
@@ -3220,23 +3374,7 @@ var McpClientService = (_class17 = class {
|
|
|
3220
3374
|
client.setRequestHandler(_typesjs.CreateMessageRequestSchema, async (request) => {
|
|
3221
3375
|
try {
|
|
3222
3376
|
this.logger.debug("Received sampling request:", request);
|
|
3223
|
-
const
|
|
3224
|
-
if (!samplingRequest.messages || !Array.isArray(samplingRequest.messages)) {
|
|
3225
|
-
throw new McpError(
|
|
3226
|
-
"Invalid sampling request: messages array is required",
|
|
3227
|
-
"INVALID_REQUEST_ERROR" /* INVALID_REQUEST_ERROR */
|
|
3228
|
-
);
|
|
3229
|
-
}
|
|
3230
|
-
if (!samplingRequest.maxTokens || samplingRequest.maxTokens <= 0) {
|
|
3231
|
-
throw new McpError(
|
|
3232
|
-
"Invalid sampling request: maxTokens must be a positive number",
|
|
3233
|
-
"INVALID_REQUEST_ERROR" /* INVALID_REQUEST_ERROR */
|
|
3234
|
-
);
|
|
3235
|
-
}
|
|
3236
|
-
const response = await this.samplingHandler({
|
|
3237
|
-
method: request.method,
|
|
3238
|
-
params: request.params
|
|
3239
|
-
});
|
|
3377
|
+
const response = await this.mcpSamplingHandler.handleSamplingRequest(request);
|
|
3240
3378
|
if (this.config.debug) {
|
|
3241
3379
|
console.log("\u2705 Sampling request completed successfully");
|
|
3242
3380
|
}
|
|
@@ -3257,25 +3395,31 @@ var McpClientService = (_class17 = class {
|
|
|
3257
3395
|
console.log("\u{1F3AF} Sampling handler registered successfully");
|
|
3258
3396
|
}
|
|
3259
3397
|
}
|
|
3398
|
+
/**
|
|
3399
|
+
* Set an ADK sampling handler
|
|
3400
|
+
*/
|
|
3260
3401
|
setSamplingHandler(handler) {
|
|
3261
|
-
this.
|
|
3402
|
+
this.mcpSamplingHandler = new McpSamplingHandler(handler);
|
|
3262
3403
|
if (this.client) {
|
|
3263
3404
|
this.setupSamplingHandler(this.client).catch((error) => {
|
|
3264
3405
|
console.error("Failed to update sampling handler:", error);
|
|
3265
3406
|
});
|
|
3266
3407
|
}
|
|
3267
3408
|
}
|
|
3409
|
+
/**
|
|
3410
|
+
* Remove the sampling handler
|
|
3411
|
+
*/
|
|
3268
3412
|
removeSamplingHandler() {
|
|
3269
|
-
this.
|
|
3413
|
+
this.mcpSamplingHandler = null;
|
|
3270
3414
|
if (this.client) {
|
|
3271
3415
|
try {
|
|
3272
|
-
_optionalChain([this, 'access',
|
|
3416
|
+
_optionalChain([this, 'access', _44 => _44.client, 'access', _45 => _45.removeRequestHandler, 'optionalCall', _46 => _46("sampling/createMessage")]);
|
|
3273
3417
|
} catch (error) {
|
|
3274
3418
|
console.error("Failed to remove sampling handler:", error);
|
|
3275
3419
|
}
|
|
3276
3420
|
}
|
|
3277
3421
|
}
|
|
3278
|
-
},
|
|
3422
|
+
}, _class18);
|
|
3279
3423
|
|
|
3280
3424
|
// src/tools/mcp/create-tool.ts
|
|
3281
3425
|
init_logger();
|
|
@@ -3477,11 +3621,11 @@ async function createTool(mcpTool, client) {
|
|
|
3477
3621
|
throw error;
|
|
3478
3622
|
}
|
|
3479
3623
|
}
|
|
3480
|
-
var McpToolAdapter = (
|
|
3624
|
+
var McpToolAdapter = (_class19 = class extends BaseTool {
|
|
3481
3625
|
|
|
3482
3626
|
|
|
3483
|
-
|
|
3484
|
-
|
|
3627
|
+
__init26() {this.clientService = null}
|
|
3628
|
+
__init27() {this.logger = new Logger({ name: "McpToolAdapter" })}
|
|
3485
3629
|
constructor(mcpTool, client) {
|
|
3486
3630
|
const metadata = mcpTool.metadata || {};
|
|
3487
3631
|
super({
|
|
@@ -3490,7 +3634,7 @@ var McpToolAdapter = (_class18 = class extends BaseTool {
|
|
|
3490
3634
|
isLongRunning: _nullishCoalesce(metadata.isLongRunning, () => ( false)),
|
|
3491
3635
|
shouldRetryOnFailure: _nullishCoalesce(metadata.shouldRetryOnFailure, () => ( false)),
|
|
3492
3636
|
maxRetryAttempts: _nullishCoalesce(metadata.maxRetryAttempts, () => ( 3))
|
|
3493
|
-
});
|
|
3637
|
+
});_class19.prototype.__init26.call(this);_class19.prototype.__init27.call(this);;
|
|
3494
3638
|
this.mcpTool = mcpTool;
|
|
3495
3639
|
this.client = client;
|
|
3496
3640
|
if (client.reinitialize && typeof client.reinitialize === "function") {
|
|
@@ -3563,16 +3707,16 @@ var McpToolAdapter = (_class18 = class extends BaseTool {
|
|
|
3563
3707
|
throw error;
|
|
3564
3708
|
}
|
|
3565
3709
|
}
|
|
3566
|
-
},
|
|
3710
|
+
}, _class19);
|
|
3567
3711
|
|
|
3568
3712
|
// src/tools/mcp/index.ts
|
|
3569
|
-
var McpToolset = (
|
|
3713
|
+
var McpToolset = (_class20 = class {
|
|
3570
3714
|
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
constructor(config, toolFilter = null) {;
|
|
3715
|
+
__init28() {this.clientService = null}
|
|
3716
|
+
__init29() {this.toolFilter = null}
|
|
3717
|
+
__init30() {this.tools = []}
|
|
3718
|
+
__init31() {this.isClosing = false}
|
|
3719
|
+
constructor(config, toolFilter = null) {;_class20.prototype.__init28.call(this);_class20.prototype.__init29.call(this);_class20.prototype.__init30.call(this);_class20.prototype.__init31.call(this);
|
|
3576
3720
|
this.config = config;
|
|
3577
3721
|
this.toolFilter = toolFilter;
|
|
3578
3722
|
this.clientService = new McpClientService(config);
|
|
@@ -3621,7 +3765,7 @@ var McpToolset = (_class19 = class {
|
|
|
3621
3765
|
"resource_closed_error" /* RESOURCE_CLOSED_ERROR */
|
|
3622
3766
|
);
|
|
3623
3767
|
}
|
|
3624
|
-
if (this.tools.length > 0 && !_optionalChain([this, 'access',
|
|
3768
|
+
if (this.tools.length > 0 && !_optionalChain([this, 'access', _47 => _47.config, 'access', _48 => _48.cacheConfig, 'optionalAccess', _49 => _49.enabled]) === false) {
|
|
3625
3769
|
return this.tools;
|
|
3626
3770
|
}
|
|
3627
3771
|
if (!this.clientService) {
|
|
@@ -3647,7 +3791,7 @@ var McpToolset = (_class19 = class {
|
|
|
3647
3791
|
}
|
|
3648
3792
|
}
|
|
3649
3793
|
}
|
|
3650
|
-
if (_optionalChain([this, 'access',
|
|
3794
|
+
if (_optionalChain([this, 'access', _50 => _50.config, 'access', _51 => _51.cacheConfig, 'optionalAccess', _52 => _52.enabled]) !== false) {
|
|
3651
3795
|
this.tools = tools;
|
|
3652
3796
|
}
|
|
3653
3797
|
return tools;
|
|
@@ -3707,7 +3851,7 @@ var McpToolset = (_class19 = class {
|
|
|
3707
3851
|
async dispose() {
|
|
3708
3852
|
await this.close();
|
|
3709
3853
|
}
|
|
3710
|
-
},
|
|
3854
|
+
}, _class20);
|
|
3711
3855
|
async function getMcpTools(config, toolFilter) {
|
|
3712
3856
|
const toolset = new McpToolset(config, toolFilter);
|
|
3713
3857
|
try {
|
|
@@ -3814,11 +3958,11 @@ var BaseLLM = class {
|
|
|
3814
3958
|
};
|
|
3815
3959
|
|
|
3816
3960
|
// src/models/base-llm-connection.ts
|
|
3817
|
-
var BaseLLMConnection = (
|
|
3961
|
+
var BaseLLMConnection = (_class21 = class {constructor() { _class21.prototype.__init32.call(this); }
|
|
3818
3962
|
/**
|
|
3819
3963
|
* Whether the connection is active
|
|
3820
3964
|
*/
|
|
3821
|
-
|
|
3965
|
+
__init32() {this._isActive = true}
|
|
3822
3966
|
/**
|
|
3823
3967
|
* Gets whether the connection is active
|
|
3824
3968
|
*/
|
|
@@ -3831,7 +3975,7 @@ var BaseLLMConnection = (_class20 = class {constructor() { _class20.prototype.__
|
|
|
3831
3975
|
close() {
|
|
3832
3976
|
this._isActive = false;
|
|
3833
3977
|
}
|
|
3834
|
-
},
|
|
3978
|
+
}, _class21);
|
|
3835
3979
|
|
|
3836
3980
|
// src/models/anthropic-llm.ts
|
|
3837
3981
|
init_logger();
|
|
@@ -3839,7 +3983,7 @@ var _axios = require('axios'); var _axios2 = _interopRequireDefault(_axios);
|
|
|
3839
3983
|
|
|
3840
3984
|
// src/models/anthropic-llm-connection.ts
|
|
3841
3985
|
init_logger();
|
|
3842
|
-
var AnthropicLLMConnection = (
|
|
3986
|
+
var AnthropicLLMConnection = (_class22 = class extends BaseLLMConnection {
|
|
3843
3987
|
/**
|
|
3844
3988
|
* Axios instance for API calls
|
|
3845
3989
|
*/
|
|
@@ -3866,12 +4010,12 @@ var AnthropicLLMConnection = (_class21 = class extends BaseLLMConnection {
|
|
|
3866
4010
|
|
|
3867
4011
|
|
|
3868
4012
|
|
|
3869
|
-
|
|
4013
|
+
__init33() {this.logger = new Logger({ name: "AnthropicLlmConnection" })}
|
|
3870
4014
|
/**
|
|
3871
4015
|
* Constructor
|
|
3872
4016
|
*/
|
|
3873
4017
|
constructor(client, model, initialRequest, defaultParams) {
|
|
3874
|
-
super();
|
|
4018
|
+
super();_class22.prototype.__init33.call(this);;
|
|
3875
4019
|
this.client = client;
|
|
3876
4020
|
this.model = model;
|
|
3877
4021
|
this.defaultParams = defaultParams;
|
|
@@ -3951,7 +4095,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
3951
4095
|
* Convert Anthropic tool calls to ADK tool calls
|
|
3952
4096
|
*/
|
|
3953
4097
|
convertToolCalls(toolUses) {
|
|
3954
|
-
if (!_optionalChain([toolUses, 'optionalAccess',
|
|
4098
|
+
if (!_optionalChain([toolUses, 'optionalAccess', _53 => _53.length])) {
|
|
3955
4099
|
return void 0;
|
|
3956
4100
|
}
|
|
3957
4101
|
return toolUses.map((toolUse) => ({
|
|
@@ -3966,7 +4110,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
3966
4110
|
* Extract tool uses from response content
|
|
3967
4111
|
*/
|
|
3968
4112
|
extractToolUses(content) {
|
|
3969
|
-
if (!_optionalChain([content, 'optionalAccess',
|
|
4113
|
+
if (!_optionalChain([content, 'optionalAccess', _54 => _54.length])) return [];
|
|
3970
4114
|
const toolUses = [];
|
|
3971
4115
|
for (const block of content) {
|
|
3972
4116
|
this.logger.debug(`Processing content block of type: ${block.type}`);
|
|
@@ -4082,17 +4226,17 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4082
4226
|
const toolUses = this.extractToolUses(apiResponse.content);
|
|
4083
4227
|
const toolCalls = this.convertToolCalls(toolUses);
|
|
4084
4228
|
this.logger.debug(
|
|
4085
|
-
`- Extracted ${toolUses.length} tool uses in content and converted ${_optionalChain([toolCalls, 'optionalAccess',
|
|
4229
|
+
`- Extracted ${toolUses.length} tool uses in content and converted ${_optionalChain([toolCalls, 'optionalAccess', _55 => _55.length]) || 0} tool calls`
|
|
4086
4230
|
);
|
|
4087
4231
|
const llmResponse = new LLMResponse({
|
|
4088
4232
|
role: "assistant",
|
|
4089
4233
|
content,
|
|
4090
|
-
tool_calls: _optionalChain([toolCalls, 'optionalAccess',
|
|
4234
|
+
tool_calls: _optionalChain([toolCalls, 'optionalAccess', _56 => _56.length]) ? toolCalls : void 0,
|
|
4091
4235
|
raw_response: apiResponse
|
|
4092
4236
|
});
|
|
4093
4237
|
const logObject = {
|
|
4094
4238
|
role: llmResponse.role,
|
|
4095
|
-
content: _optionalChain([llmResponse, 'access',
|
|
4239
|
+
content: _optionalChain([llmResponse, 'access', _57 => _57.content, 'optionalAccess', _58 => _58.substring, 'call', _59 => _59(0, 50)]) + (llmResponse.content && llmResponse.content.length > 50 ? "..." : ""),
|
|
4096
4240
|
tool_calls: llmResponse.tool_calls ? `[${llmResponse.tool_calls.length} calls]` : "undefined"
|
|
4097
4241
|
};
|
|
4098
4242
|
this.logger.debug(
|
|
@@ -4105,10 +4249,10 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4105
4249
|
throw error;
|
|
4106
4250
|
}
|
|
4107
4251
|
}
|
|
4108
|
-
},
|
|
4252
|
+
}, _class22);
|
|
4109
4253
|
|
|
4110
4254
|
// src/models/anthropic-llm.ts
|
|
4111
|
-
var AnthropicLLM = (
|
|
4255
|
+
var AnthropicLLM = (_class23 = class extends BaseLLM {
|
|
4112
4256
|
/**
|
|
4113
4257
|
* Anthropic API key
|
|
4114
4258
|
*/
|
|
@@ -4121,23 +4265,23 @@ var AnthropicLLM = (_class22 = class extends BaseLLM {
|
|
|
4121
4265
|
* Default parameters for requests
|
|
4122
4266
|
*/
|
|
4123
4267
|
|
|
4124
|
-
|
|
4268
|
+
__init34() {this.logger = new Logger({ name: "AnthropicLLM" })}
|
|
4125
4269
|
/**
|
|
4126
4270
|
* Constructor for AnthropicLLM
|
|
4127
4271
|
*/
|
|
4128
4272
|
constructor(model, config) {
|
|
4129
|
-
super(model);
|
|
4130
|
-
this.apiKey = _optionalChain([config, 'optionalAccess',
|
|
4131
|
-
this.baseURL = _optionalChain([config, 'optionalAccess',
|
|
4273
|
+
super(model);_class23.prototype.__init34.call(this);;
|
|
4274
|
+
this.apiKey = _optionalChain([config, 'optionalAccess', _60 => _60.apiKey]) || process.env.ANTHROPIC_API_KEY || "";
|
|
4275
|
+
this.baseURL = _optionalChain([config, 'optionalAccess', _61 => _61.baseURL]) || "https://api.anthropic.com/v1";
|
|
4132
4276
|
if (!this.apiKey) {
|
|
4133
4277
|
throw new Error(
|
|
4134
4278
|
"Anthropic API key is required. Provide it in config or set ANTHROPIC_API_KEY environment variable."
|
|
4135
4279
|
);
|
|
4136
4280
|
}
|
|
4137
4281
|
this.defaultParams = {
|
|
4138
|
-
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4139
|
-
top_p: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4140
|
-
max_tokens: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4282
|
+
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _62 => _62.defaultParams, 'optionalAccess', _63 => _63.temperature]), () => ( 0.7)),
|
|
4283
|
+
top_p: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _64 => _64.defaultParams, 'optionalAccess', _65 => _65.top_p]), () => ( 1)),
|
|
4284
|
+
max_tokens: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _66 => _66.defaultParams, 'optionalAccess', _67 => _67.max_tokens]), () => ( 1024))
|
|
4141
4285
|
};
|
|
4142
4286
|
}
|
|
4143
4287
|
/**
|
|
@@ -4223,7 +4367,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4223
4367
|
* Convert ADK function declarations to Anthropic tool format
|
|
4224
4368
|
*/
|
|
4225
4369
|
convertFunctionsToTools(functions) {
|
|
4226
|
-
if (!_optionalChain([functions, 'optionalAccess',
|
|
4370
|
+
if (!_optionalChain([functions, 'optionalAccess', _68 => _68.length])) {
|
|
4227
4371
|
return [];
|
|
4228
4372
|
}
|
|
4229
4373
|
return functions.map((func) => ({
|
|
@@ -4236,7 +4380,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4236
4380
|
* Convert Anthropic tool calls to ADK tool calls
|
|
4237
4381
|
*/
|
|
4238
4382
|
convertToolUses(toolUses) {
|
|
4239
|
-
if (!_optionalChain([toolUses, 'optionalAccess',
|
|
4383
|
+
if (!_optionalChain([toolUses, 'optionalAccess', _69 => _69.length])) {
|
|
4240
4384
|
return [];
|
|
4241
4385
|
}
|
|
4242
4386
|
return toolUses.map((toolUse) => ({
|
|
@@ -4251,7 +4395,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4251
4395
|
* Extract tool uses from response content
|
|
4252
4396
|
*/
|
|
4253
4397
|
extractToolUses(content) {
|
|
4254
|
-
if (!_optionalChain([content, 'optionalAccess',
|
|
4398
|
+
if (!_optionalChain([content, 'optionalAccess', _70 => _70.length])) return [];
|
|
4255
4399
|
const toolUses = [];
|
|
4256
4400
|
for (const block of content) {
|
|
4257
4401
|
this.logger.debug(`Processing content block of type: ${block.type}`);
|
|
@@ -4322,7 +4466,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4322
4466
|
temperature: _nullishCoalesce(llmRequest.config.temperature, () => ( this.defaultParams.temperature)),
|
|
4323
4467
|
max_tokens: _nullishCoalesce(llmRequest.config.max_tokens, () => ( this.defaultParams.max_tokens)),
|
|
4324
4468
|
top_p: _nullishCoalesce(llmRequest.config.top_p, () => ( this.defaultParams.top_p)),
|
|
4325
|
-
tools: _optionalChain([tools, 'optionalAccess',
|
|
4469
|
+
tools: _optionalChain([tools, 'optionalAccess', _71 => _71.length]) ? tools : void 0
|
|
4326
4470
|
};
|
|
4327
4471
|
this.logger.debug("API Request:", {
|
|
4328
4472
|
model: params.model,
|
|
@@ -4353,7 +4497,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4353
4497
|
});
|
|
4354
4498
|
const logObject = {
|
|
4355
4499
|
role: llmResponse.role,
|
|
4356
|
-
content: _optionalChain([llmResponse, 'access',
|
|
4500
|
+
content: _optionalChain([llmResponse, 'access', _72 => _72.content, 'optionalAccess', _73 => _73.substring, 'call', _74 => _74(0, 50)]) + (llmResponse.content && llmResponse.content.length > 50 ? "..." : ""),
|
|
4357
4501
|
tool_calls: llmResponse.tool_calls ? `[${llmResponse.tool_calls.length} calls]` : "undefined"
|
|
4358
4502
|
};
|
|
4359
4503
|
this.logger.debug(
|
|
@@ -4385,7 +4529,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4385
4529
|
this.defaultParams
|
|
4386
4530
|
);
|
|
4387
4531
|
}
|
|
4388
|
-
},
|
|
4532
|
+
}, _class23);
|
|
4389
4533
|
|
|
4390
4534
|
// src/models/google-llm.ts
|
|
4391
4535
|
|
|
@@ -4406,9 +4550,9 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4406
4550
|
constructor(model, config) {
|
|
4407
4551
|
super(model);
|
|
4408
4552
|
const apiKey = process.env.GOOGLE_API_KEY;
|
|
4409
|
-
const projectId = _optionalChain([config, 'optionalAccess',
|
|
4410
|
-
const location = _optionalChain([config, 'optionalAccess',
|
|
4411
|
-
const useVertexAI = _optionalChain([process, 'access',
|
|
4553
|
+
const projectId = _optionalChain([config, 'optionalAccess', _75 => _75.projectId]) || process.env.GOOGLE_CLOUD_PROJECT;
|
|
4554
|
+
const location = _optionalChain([config, 'optionalAccess', _76 => _76.location]) || process.env.GOOGLE_CLOUD_LOCATION;
|
|
4555
|
+
const useVertexAI = _optionalChain([process, 'access', _77 => _77.env, 'access', _78 => _78.USE_VERTEX_AI, 'optionalAccess', _79 => _79.toLowerCase, 'call', _80 => _80()]) === "true";
|
|
4412
4556
|
if (!useVertexAI && !apiKey) {
|
|
4413
4557
|
throw new Error(
|
|
4414
4558
|
"Google API Key is required. Provide via config or GOOGLE_API_KEY env var."
|
|
@@ -4433,9 +4577,9 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4433
4577
|
}
|
|
4434
4578
|
this.ai = new (0, _genai.GoogleGenAI)(options);
|
|
4435
4579
|
this.defaultParams = {
|
|
4436
|
-
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4437
|
-
topP: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4438
|
-
maxOutputTokens: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4580
|
+
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _81 => _81.defaultParams, 'optionalAccess', _82 => _82.temperature]), () => ( 0.7)),
|
|
4581
|
+
topP: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _83 => _83.defaultParams, 'optionalAccess', _84 => _84.top_p]), () => ( 1)),
|
|
4582
|
+
maxOutputTokens: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _85 => _85.defaultParams, 'optionalAccess', _86 => _86.maxOutputTokens]), () => ( 1024))
|
|
4439
4583
|
};
|
|
4440
4584
|
}
|
|
4441
4585
|
/**
|
|
@@ -4573,7 +4717,7 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4573
4717
|
);
|
|
4574
4718
|
parts.push({ text: "" });
|
|
4575
4719
|
}
|
|
4576
|
-
if (googleRole === "function" && (parts.length !== 1 || !_optionalChain([parts, 'access',
|
|
4720
|
+
if (googleRole === "function" && (parts.length !== 1 || !_optionalChain([parts, 'access', _87 => _87[0], 'optionalAccess', _88 => _88.functionResponse]))) {
|
|
4577
4721
|
console.error(
|
|
4578
4722
|
`[GoogleLLM] convertMessage - Invalid parts for 'function' role. Expected 1 functionResponse part. Got:`,
|
|
4579
4723
|
JSON.stringify(parts),
|
|
@@ -4681,13 +4825,13 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4681
4825
|
role: "assistant",
|
|
4682
4826
|
content: null
|
|
4683
4827
|
});
|
|
4684
|
-
if (typeof _optionalChain([response, 'optionalAccess',
|
|
4828
|
+
if (typeof _optionalChain([response, 'optionalAccess', _89 => _89.candidates, 'optionalAccess', _90 => _90[0], 'optionalAccess', _91 => _91.content, 'optionalAccess', _92 => _92.parts, 'optionalAccess', _93 => _93[0], 'optionalAccess', _94 => _94.text]) === "string") {
|
|
4685
4829
|
result.content = response.candidates[0].content.parts[0].text;
|
|
4686
4830
|
}
|
|
4687
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
4831
|
+
if (_optionalChain([response, 'optionalAccess', _95 => _95.candidates, 'optionalAccess', _96 => _96[0], 'optionalAccess', _97 => _97.content, 'optionalAccess', _98 => _98.parts, 'optionalAccess', _99 => _99[0], 'optionalAccess', _100 => _100.text])) {
|
|
4688
4832
|
result.content = response.candidates[0].content.parts[0].text;
|
|
4689
4833
|
}
|
|
4690
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
4834
|
+
if (_optionalChain([response, 'optionalAccess', _101 => _101.candidates, 'optionalAccess', _102 => _102[0], 'optionalAccess', _103 => _103.content, 'optionalAccess', _104 => _104.parts, 'optionalAccess', _105 => _105[0], 'optionalAccess', _106 => _106.functionCall])) {
|
|
4691
4835
|
const functionCall = response.candidates[0].content.parts[0].functionCall;
|
|
4692
4836
|
result.function_call = {
|
|
4693
4837
|
name: functionCall.name,
|
|
@@ -4734,10 +4878,10 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4734
4878
|
if (stream) {
|
|
4735
4879
|
const streamingResult = await this.ai.models.generateContentStream(requestOptions);
|
|
4736
4880
|
for await (const chunk of streamingResult) {
|
|
4737
|
-
if (!_optionalChain([chunk, 'access',
|
|
4881
|
+
if (!_optionalChain([chunk, 'access', _107 => _107.candidates, 'optionalAccess', _108 => _108[0], 'optionalAccess', _109 => _109.content, 'optionalAccess', _110 => _110.parts, 'optionalAccess', _111 => _111[0], 'optionalAccess', _112 => _112.text])) {
|
|
4738
4882
|
continue;
|
|
4739
4883
|
}
|
|
4740
|
-
const partialText = _optionalChain([chunk, 'access',
|
|
4884
|
+
const partialText = _optionalChain([chunk, 'access', _113 => _113.candidates, 'access', _114 => _114[0], 'optionalAccess', _115 => _115.content, 'optionalAccess', _116 => _116.parts, 'access', _117 => _117[0], 'optionalAccess', _118 => _118.text]) || "";
|
|
4741
4885
|
const partialResponse = new LLMResponse({
|
|
4742
4886
|
content: partialText,
|
|
4743
4887
|
role: "assistant",
|
|
@@ -4761,7 +4905,7 @@ init_logger();
|
|
|
4761
4905
|
var _openai = require('openai'); var _openai2 = _interopRequireDefault(_openai);
|
|
4762
4906
|
|
|
4763
4907
|
// src/models/openai-llm-connection.ts
|
|
4764
|
-
var OpenAILLMConnection = (
|
|
4908
|
+
var OpenAILLMConnection = (_class24 = class extends BaseLLMConnection {
|
|
4765
4909
|
/**
|
|
4766
4910
|
* OpenAI client
|
|
4767
4911
|
*/
|
|
@@ -4793,12 +4937,12 @@ var OpenAILLMConnection = (_class23 = class extends BaseLLMConnection {
|
|
|
4793
4937
|
/**
|
|
4794
4938
|
* Ongoing chat history
|
|
4795
4939
|
*/
|
|
4796
|
-
|
|
4940
|
+
__init35() {this.messages = []}
|
|
4797
4941
|
/**
|
|
4798
4942
|
* Constructor for OpenAILLMConnection
|
|
4799
4943
|
*/
|
|
4800
4944
|
constructor(client, model, initialRequest, defaultParams) {
|
|
4801
|
-
super();
|
|
4945
|
+
super();_class24.prototype.__init35.call(this);;
|
|
4802
4946
|
this.client = client;
|
|
4803
4947
|
this.model = model;
|
|
4804
4948
|
this.initialRequest = initialRequest;
|
|
@@ -4878,10 +5022,10 @@ var OpenAILLMConnection = (_class23 = class extends BaseLLMConnection {
|
|
|
4878
5022
|
for await (const chunk of stream) {
|
|
4879
5023
|
if (chunk.choices.length === 0) continue;
|
|
4880
5024
|
const delta = chunk.choices[0].delta;
|
|
4881
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
5025
|
+
if (_optionalChain([delta, 'optionalAccess', _119 => _119.content])) {
|
|
4882
5026
|
responseContent += delta.content;
|
|
4883
5027
|
}
|
|
4884
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
5028
|
+
if (_optionalChain([delta, 'optionalAccess', _120 => _120.function_call])) {
|
|
4885
5029
|
if (!functionCall) {
|
|
4886
5030
|
functionCall = {
|
|
4887
5031
|
name: delta.function_call.name || "",
|
|
@@ -4892,7 +5036,7 @@ var OpenAILLMConnection = (_class23 = class extends BaseLLMConnection {
|
|
|
4892
5036
|
functionCall.arguments += delta.function_call.arguments || "";
|
|
4893
5037
|
}
|
|
4894
5038
|
}
|
|
4895
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
5039
|
+
if (_optionalChain([delta, 'optionalAccess', _121 => _121.tool_calls])) {
|
|
4896
5040
|
for (const toolDelta of delta.tool_calls) {
|
|
4897
5041
|
const id = toolDelta.id || "";
|
|
4898
5042
|
let tool = toolCalls.find((t) => t.id === id);
|
|
@@ -4900,20 +5044,20 @@ var OpenAILLMConnection = (_class23 = class extends BaseLLMConnection {
|
|
|
4900
5044
|
tool = {
|
|
4901
5045
|
id,
|
|
4902
5046
|
function: {
|
|
4903
|
-
name: _optionalChain([toolDelta, 'access',
|
|
4904
|
-
arguments: _optionalChain([toolDelta, 'access',
|
|
5047
|
+
name: _optionalChain([toolDelta, 'access', _122 => _122.function, 'optionalAccess', _123 => _123.name]) || "",
|
|
5048
|
+
arguments: _optionalChain([toolDelta, 'access', _124 => _124.function, 'optionalAccess', _125 => _125.arguments]) || ""
|
|
4905
5049
|
}
|
|
4906
5050
|
};
|
|
4907
5051
|
toolCalls.push(tool);
|
|
4908
5052
|
} else {
|
|
4909
|
-
tool.function.name += _optionalChain([toolDelta, 'access',
|
|
4910
|
-
tool.function.arguments += _optionalChain([toolDelta, 'access',
|
|
5053
|
+
tool.function.name += _optionalChain([toolDelta, 'access', _126 => _126.function, 'optionalAccess', _127 => _127.name]) || "";
|
|
5054
|
+
tool.function.arguments += _optionalChain([toolDelta, 'access', _128 => _128.function, 'optionalAccess', _129 => _129.arguments]) || "";
|
|
4911
5055
|
}
|
|
4912
5056
|
}
|
|
4913
5057
|
}
|
|
4914
5058
|
if (this.responseCallback) {
|
|
4915
5059
|
const response = new LLMResponse({
|
|
4916
|
-
content: _optionalChain([delta, 'optionalAccess',
|
|
5060
|
+
content: _optionalChain([delta, 'optionalAccess', _130 => _130.content]) || null,
|
|
4917
5061
|
role: "assistant",
|
|
4918
5062
|
function_call: functionCall,
|
|
4919
5063
|
tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
@@ -5005,10 +5149,10 @@ var OpenAILLMConnection = (_class23 = class extends BaseLLMConnection {
|
|
|
5005
5149
|
onEnd(callback) {
|
|
5006
5150
|
this.endCallback = callback;
|
|
5007
5151
|
}
|
|
5008
|
-
},
|
|
5152
|
+
}, _class24);
|
|
5009
5153
|
|
|
5010
5154
|
// src/models/openai-llm.ts
|
|
5011
|
-
var OpenAILLM = (
|
|
5155
|
+
var OpenAILLM = (_class25 = class extends BaseLLM {
|
|
5012
5156
|
/**
|
|
5013
5157
|
* OpenAI client instance
|
|
5014
5158
|
*/
|
|
@@ -5017,23 +5161,23 @@ var OpenAILLM = (_class24 = class extends BaseLLM {
|
|
|
5017
5161
|
* Default parameters for requests
|
|
5018
5162
|
*/
|
|
5019
5163
|
|
|
5020
|
-
|
|
5164
|
+
__init36() {this.logger = new Logger({ name: "OpenAILLM" })}
|
|
5021
5165
|
/**
|
|
5022
5166
|
* Constructor for OpenAILLM
|
|
5023
5167
|
*/
|
|
5024
5168
|
constructor(model, config) {
|
|
5025
|
-
super(model);
|
|
5169
|
+
super(model);_class25.prototype.__init36.call(this);;
|
|
5026
5170
|
this.client = new (0, _openai2.default)({
|
|
5027
|
-
apiKey: _optionalChain([config, 'optionalAccess',
|
|
5028
|
-
baseURL: _optionalChain([config, 'optionalAccess',
|
|
5029
|
-
organization: _optionalChain([config, 'optionalAccess',
|
|
5171
|
+
apiKey: _optionalChain([config, 'optionalAccess', _131 => _131.apiKey]) || process.env.OPENAI_API_KEY,
|
|
5172
|
+
baseURL: _optionalChain([config, 'optionalAccess', _132 => _132.baseURL]),
|
|
5173
|
+
organization: _optionalChain([config, 'optionalAccess', _133 => _133.organization])
|
|
5030
5174
|
});
|
|
5031
5175
|
this.defaultParams = {
|
|
5032
|
-
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
5033
|
-
top_p: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
5034
|
-
max_tokens: _optionalChain([config, 'optionalAccess',
|
|
5035
|
-
frequency_penalty: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
5036
|
-
presence_penalty: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
5176
|
+
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _134 => _134.defaultParams, 'optionalAccess', _135 => _135.temperature]), () => ( 0.7)),
|
|
5177
|
+
top_p: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _136 => _136.defaultParams, 'optionalAccess', _137 => _137.top_p]), () => ( 1)),
|
|
5178
|
+
max_tokens: _optionalChain([config, 'optionalAccess', _138 => _138.defaultParams, 'optionalAccess', _139 => _139.max_tokens]),
|
|
5179
|
+
frequency_penalty: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _140 => _140.defaultParams, 'optionalAccess', _141 => _141.frequency_penalty]), () => ( 0)),
|
|
5180
|
+
presence_penalty: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _142 => _142.defaultParams, 'optionalAccess', _143 => _143.presence_penalty]), () => ( 0))
|
|
5037
5181
|
};
|
|
5038
5182
|
}
|
|
5039
5183
|
/**
|
|
@@ -5143,16 +5287,16 @@ var OpenAILLM = (_class24 = class extends BaseLLM {
|
|
|
5143
5287
|
*/
|
|
5144
5288
|
convertResponse(response) {
|
|
5145
5289
|
const result = new LLMResponse({
|
|
5146
|
-
content: _optionalChain([response, 'access',
|
|
5147
|
-
role: _optionalChain([response, 'access',
|
|
5290
|
+
content: _optionalChain([response, 'access', _144 => _144.message, 'optionalAccess', _145 => _145.content]) || null,
|
|
5291
|
+
role: _optionalChain([response, 'access', _146 => _146.message, 'optionalAccess', _147 => _147.role]) || "assistant"
|
|
5148
5292
|
});
|
|
5149
|
-
if (_optionalChain([response, 'access',
|
|
5293
|
+
if (_optionalChain([response, 'access', _148 => _148.message, 'optionalAccess', _149 => _149.function_call])) {
|
|
5150
5294
|
result.function_call = {
|
|
5151
5295
|
name: response.message.function_call.name,
|
|
5152
5296
|
arguments: response.message.function_call.arguments
|
|
5153
5297
|
};
|
|
5154
5298
|
}
|
|
5155
|
-
if (_optionalChain([response, 'access',
|
|
5299
|
+
if (_optionalChain([response, 'access', _150 => _150.message, 'optionalAccess', _151 => _151.tool_calls])) {
|
|
5156
5300
|
result.tool_calls = response.message.tool_calls.map((tool) => ({
|
|
5157
5301
|
id: tool.id,
|
|
5158
5302
|
function: {
|
|
@@ -5170,24 +5314,24 @@ var OpenAILLM = (_class24 = class extends BaseLLM {
|
|
|
5170
5314
|
this.logger.debug(
|
|
5171
5315
|
`Converting chunk - delta: ${JSON.stringify(chunk.delta || {})}`
|
|
5172
5316
|
);
|
|
5173
|
-
const content = _optionalChain([chunk, 'access',
|
|
5317
|
+
const content = _optionalChain([chunk, 'access', _152 => _152.delta, 'optionalAccess', _153 => _153.content]);
|
|
5174
5318
|
const result = new LLMResponse({
|
|
5175
5319
|
content: content !== void 0 ? content : null,
|
|
5176
|
-
role: _optionalChain([chunk, 'access',
|
|
5320
|
+
role: _optionalChain([chunk, 'access', _154 => _154.delta, 'optionalAccess', _155 => _155.role]) || "assistant",
|
|
5177
5321
|
is_partial: true
|
|
5178
5322
|
});
|
|
5179
|
-
if (_optionalChain([chunk, 'access',
|
|
5323
|
+
if (_optionalChain([chunk, 'access', _156 => _156.delta, 'optionalAccess', _157 => _157.function_call])) {
|
|
5180
5324
|
result.function_call = {
|
|
5181
5325
|
name: chunk.delta.function_call.name || "",
|
|
5182
5326
|
arguments: chunk.delta.function_call.arguments || ""
|
|
5183
5327
|
};
|
|
5184
5328
|
}
|
|
5185
|
-
if (_optionalChain([chunk, 'access',
|
|
5329
|
+
if (_optionalChain([chunk, 'access', _158 => _158.delta, 'optionalAccess', _159 => _159.tool_calls])) {
|
|
5186
5330
|
result.tool_calls = chunk.delta.tool_calls.map((tool) => ({
|
|
5187
5331
|
id: tool.id || "",
|
|
5188
5332
|
function: {
|
|
5189
|
-
name: _optionalChain([tool, 'access',
|
|
5190
|
-
arguments: _optionalChain([tool, 'access',
|
|
5333
|
+
name: _optionalChain([tool, 'access', _160 => _160.function, 'optionalAccess', _161 => _161.name]) || "",
|
|
5334
|
+
arguments: _optionalChain([tool, 'access', _162 => _162.function, 'optionalAccess', _163 => _163.arguments]) || ""
|
|
5191
5335
|
}
|
|
5192
5336
|
}));
|
|
5193
5337
|
}
|
|
@@ -5236,7 +5380,7 @@ var OpenAILLM = (_class24 = class extends BaseLLM {
|
|
|
5236
5380
|
accumulatedContent += responseChunk.content;
|
|
5237
5381
|
}
|
|
5238
5382
|
this.logger.debug(
|
|
5239
|
-
`Chunk received - delta: "${_optionalChain([choice, 'access',
|
|
5383
|
+
`Chunk received - delta: "${_optionalChain([choice, 'access', _164 => _164.delta, 'optionalAccess', _165 => _165.content]) || ""}"`,
|
|
5240
5384
|
`responseChunk content: "${responseChunk.content || ""}"`,
|
|
5241
5385
|
`is_partial: ${responseChunk.is_partial}`,
|
|
5242
5386
|
`accumulated: "${accumulatedContent.substring(0, 30)}${accumulatedContent.length > 30 ? "..." : ""}"`
|
|
@@ -5304,7 +5448,7 @@ var OpenAILLM = (_class24 = class extends BaseLLM {
|
|
|
5304
5448
|
this.defaultParams
|
|
5305
5449
|
);
|
|
5306
5450
|
}
|
|
5307
|
-
},
|
|
5451
|
+
}, _class25);
|
|
5308
5452
|
|
|
5309
5453
|
// src/models/registry.ts
|
|
5310
5454
|
function registerProviders() {
|
|
@@ -5502,7 +5646,7 @@ var OAuth2Credential = class extends AuthCredential {
|
|
|
5502
5646
|
"Cannot refresh token: no refresh token or refresh function"
|
|
5503
5647
|
);
|
|
5504
5648
|
}
|
|
5505
|
-
const result = await _optionalChain([this, 'access',
|
|
5649
|
+
const result = await _optionalChain([this, 'access', _166 => _166.refreshFunction, 'optionalCall', _167 => _167(this.refreshToken)]);
|
|
5506
5650
|
if (!result) {
|
|
5507
5651
|
throw new Error("Failed to refresh token");
|
|
5508
5652
|
}
|
|
@@ -5556,7 +5700,7 @@ var AuthHandler = class {
|
|
|
5556
5700
|
* Gets the authentication token
|
|
5557
5701
|
*/
|
|
5558
5702
|
getToken() {
|
|
5559
|
-
return _optionalChain([this, 'access',
|
|
5703
|
+
return _optionalChain([this, 'access', _168 => _168.credential, 'optionalAccess', _169 => _169.getToken, 'call', _170 => _170()]);
|
|
5560
5704
|
}
|
|
5561
5705
|
/**
|
|
5562
5706
|
* Gets headers for HTTP requests
|
|
@@ -5571,7 +5715,7 @@ var AuthHandler = class {
|
|
|
5571
5715
|
* Refreshes the token if necessary
|
|
5572
5716
|
*/
|
|
5573
5717
|
async refreshToken() {
|
|
5574
|
-
if (_optionalChain([this, 'access',
|
|
5718
|
+
if (_optionalChain([this, 'access', _171 => _171.credential, 'optionalAccess', _172 => _172.canRefresh, 'call', _173 => _173()])) {
|
|
5575
5719
|
await this.credential.refresh();
|
|
5576
5720
|
}
|
|
5577
5721
|
}
|
|
@@ -5797,7 +5941,7 @@ var InMemoryMemoryService = class {
|
|
|
5797
5941
|
};
|
|
5798
5942
|
const normalizedQuery = query.toLowerCase().trim();
|
|
5799
5943
|
const queryTerms = normalizedQuery.split(/\s+/);
|
|
5800
|
-
const sessionsToSearch = _optionalChain([options, 'optionalAccess',
|
|
5944
|
+
const sessionsToSearch = _optionalChain([options, 'optionalAccess', _174 => _174.sessionId]) ? this.sessions.has(options.sessionId) ? [this.sessions.get(options.sessionId)] : [] : Array.from(this.sessions.values());
|
|
5801
5945
|
for (const session of sessionsToSearch) {
|
|
5802
5946
|
const matchedEvents = [];
|
|
5803
5947
|
const scores = [];
|
|
@@ -5823,7 +5967,7 @@ var InMemoryMemoryService = class {
|
|
|
5823
5967
|
}
|
|
5824
5968
|
}
|
|
5825
5969
|
const score = queryTerms.length > 0 ? termMatches / queryTerms.length : 0;
|
|
5826
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
5970
|
+
if (_optionalChain([options, 'optionalAccess', _175 => _175.threshold]) !== void 0 && score < options.threshold) {
|
|
5827
5971
|
continue;
|
|
5828
5972
|
}
|
|
5829
5973
|
if (score > 0) {
|
|
@@ -5843,7 +5987,7 @@ var InMemoryMemoryService = class {
|
|
|
5843
5987
|
response.memories.sort(
|
|
5844
5988
|
(a, b) => (_nullishCoalesce(b.relevanceScore, () => ( 0))) - (_nullishCoalesce(a.relevanceScore, () => ( 0)))
|
|
5845
5989
|
);
|
|
5846
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
5990
|
+
if (_optionalChain([options, 'optionalAccess', _176 => _176.limit]) !== void 0 && options.limit > 0) {
|
|
5847
5991
|
response.memories = response.memories.slice(0, options.limit);
|
|
5848
5992
|
}
|
|
5849
5993
|
return response;
|
|
@@ -5875,7 +6019,7 @@ var InMemoryMemoryService = class {
|
|
|
5875
6019
|
init_logger();
|
|
5876
6020
|
var _fs = require('fs'); var fs3 = _interopRequireWildcard(_fs);
|
|
5877
6021
|
|
|
5878
|
-
var PersistentMemoryService = (
|
|
6022
|
+
var PersistentMemoryService = (_class26 = class {
|
|
5879
6023
|
/**
|
|
5880
6024
|
* In-memory service used for search operations
|
|
5881
6025
|
*/
|
|
@@ -5888,11 +6032,11 @@ var PersistentMemoryService = (_class25 = class {
|
|
|
5888
6032
|
* File prefix for memory files
|
|
5889
6033
|
*/
|
|
5890
6034
|
|
|
5891
|
-
|
|
6035
|
+
__init37() {this.logger = new Logger({ name: "PersistentMemoryService" })}
|
|
5892
6036
|
/**
|
|
5893
6037
|
* Constructor for PersistentMemoryService
|
|
5894
6038
|
*/
|
|
5895
|
-
constructor(config) {;
|
|
6039
|
+
constructor(config) {;_class26.prototype.__init37.call(this);
|
|
5896
6040
|
this.inMemoryService = new InMemoryMemoryService();
|
|
5897
6041
|
this.storageDir = config.storageDir;
|
|
5898
6042
|
this.filePrefix = config.filePrefix || "memory";
|
|
@@ -6034,7 +6178,7 @@ var PersistentMemoryService = (_class25 = class {
|
|
|
6034
6178
|
);
|
|
6035
6179
|
}
|
|
6036
6180
|
}
|
|
6037
|
-
},
|
|
6181
|
+
}, _class26);
|
|
6038
6182
|
|
|
6039
6183
|
// src/sessions/index.ts
|
|
6040
6184
|
var sessions_exports = {};
|
|
@@ -6109,17 +6253,17 @@ var InMemorySessionService = class {
|
|
|
6109
6253
|
let sessions = Array.from(this.sessions.values()).filter(
|
|
6110
6254
|
(session) => session.userId === userId
|
|
6111
6255
|
);
|
|
6112
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6256
|
+
if (_optionalChain([options, 'optionalAccess', _177 => _177.createdAfter])) {
|
|
6113
6257
|
sessions = sessions.filter(
|
|
6114
6258
|
(session) => session.createdAt >= options.createdAfter
|
|
6115
6259
|
);
|
|
6116
6260
|
}
|
|
6117
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6261
|
+
if (_optionalChain([options, 'optionalAccess', _178 => _178.updatedAfter])) {
|
|
6118
6262
|
sessions = sessions.filter(
|
|
6119
6263
|
(session) => session.updatedAt >= options.updatedAfter
|
|
6120
6264
|
);
|
|
6121
6265
|
}
|
|
6122
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6266
|
+
if (_optionalChain([options, 'optionalAccess', _179 => _179.metadataFilter])) {
|
|
6123
6267
|
sessions = sessions.filter((session) => {
|
|
6124
6268
|
for (const [key, value] of Object.entries(options.metadataFilter)) {
|
|
6125
6269
|
if (session.metadata[key] !== value) {
|
|
@@ -6130,7 +6274,7 @@ var InMemorySessionService = class {
|
|
|
6130
6274
|
});
|
|
6131
6275
|
}
|
|
6132
6276
|
sessions.sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime());
|
|
6133
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6277
|
+
if (_optionalChain([options, 'optionalAccess', _180 => _180.limit]) !== void 0 && options.limit > 0) {
|
|
6134
6278
|
sessions = sessions.slice(0, options.limit);
|
|
6135
6279
|
}
|
|
6136
6280
|
return sessions;
|
|
@@ -6165,7 +6309,7 @@ var InMemorySessionService = class {
|
|
|
6165
6309
|
if (event.is_partial) {
|
|
6166
6310
|
return event;
|
|
6167
6311
|
}
|
|
6168
|
-
if (_optionalChain([event, 'access',
|
|
6312
|
+
if (_optionalChain([event, 'access', _181 => _181.actions, 'optionalAccess', _182 => _182.stateDelta])) {
|
|
6169
6313
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
6170
6314
|
if (key.startsWith("_temp_")) {
|
|
6171
6315
|
continue;
|
|
@@ -6271,7 +6415,7 @@ var PostgresSessionService = class {
|
|
|
6271
6415
|
}
|
|
6272
6416
|
async listSessions(userId, options) {
|
|
6273
6417
|
let query = this.db.select().from(this.sessionsTable).where(_drizzleorm.eq.call(void 0, this.sessionsTable.userId, userId));
|
|
6274
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6418
|
+
if (_optionalChain([options, 'optionalAccess', _183 => _183.limit]) !== void 0 && options.limit > 0) {
|
|
6275
6419
|
query = query.limit(options.limit);
|
|
6276
6420
|
}
|
|
6277
6421
|
const results = await query;
|
|
@@ -6298,12 +6442,12 @@ var PostgresSessionService = class {
|
|
|
6298
6442
|
if (event.is_partial) {
|
|
6299
6443
|
return event;
|
|
6300
6444
|
}
|
|
6301
|
-
if (_optionalChain([event, 'access',
|
|
6445
|
+
if (_optionalChain([event, 'access', _184 => _184.actions, 'optionalAccess', _185 => _185.stateDelta])) {
|
|
6302
6446
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
6303
6447
|
if (key.startsWith("_temp_")) {
|
|
6304
6448
|
continue;
|
|
6305
6449
|
}
|
|
6306
|
-
_optionalChain([session, 'access',
|
|
6450
|
+
_optionalChain([session, 'access', _186 => _186.state, 'optionalAccess', _187 => _187.set, 'call', _188 => _188(key, value)]);
|
|
6307
6451
|
}
|
|
6308
6452
|
}
|
|
6309
6453
|
if (!session.events) {
|
|
@@ -6334,11 +6478,11 @@ var sessionsSchema2 = _pgcore.pgTable.call(void 0, "sessions", {
|
|
|
6334
6478
|
updatedAt: _pgcore.timestamp.call(void 0, "updated_at", { withTimezone: true }).defaultNow().notNull(),
|
|
6335
6479
|
state: _pgcore.jsonb.call(void 0, "state").default("{}").$type()
|
|
6336
6480
|
});
|
|
6337
|
-
var PgLiteSessionService = (
|
|
6481
|
+
var PgLiteSessionService = (_class27 = class {
|
|
6338
6482
|
|
|
6339
6483
|
|
|
6340
|
-
|
|
6341
|
-
constructor(config) {;
|
|
6484
|
+
__init38() {this.initialized = false}
|
|
6485
|
+
constructor(config) {;_class27.prototype.__init38.call(this);
|
|
6342
6486
|
this.db = _pglite.drizzle.call(void 0, config.pglite, {
|
|
6343
6487
|
schema: { sessions: sessionsSchema2 }
|
|
6344
6488
|
});
|
|
@@ -6447,7 +6591,7 @@ var PgLiteSessionService = (_class26 = class {
|
|
|
6447
6591
|
async listSessions(userId, options) {
|
|
6448
6592
|
await this.ensureInitialized();
|
|
6449
6593
|
let query = this.db.select().from(this.sessionsTable).where(_drizzleorm.eq.call(void 0, this.sessionsTable.userId, userId));
|
|
6450
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6594
|
+
if (_optionalChain([options, 'optionalAccess', _189 => _189.limit]) !== void 0 && options.limit > 0) {
|
|
6451
6595
|
query = query.limit(options.limit);
|
|
6452
6596
|
}
|
|
6453
6597
|
const results = await query;
|
|
@@ -6470,12 +6614,12 @@ var PgLiteSessionService = (_class26 = class {
|
|
|
6470
6614
|
if (event.is_partial) {
|
|
6471
6615
|
return event;
|
|
6472
6616
|
}
|
|
6473
|
-
if (_optionalChain([event, 'access',
|
|
6617
|
+
if (_optionalChain([event, 'access', _190 => _190.actions, 'optionalAccess', _191 => _191.stateDelta])) {
|
|
6474
6618
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
6475
6619
|
if (key.startsWith("_temp_")) {
|
|
6476
6620
|
continue;
|
|
6477
6621
|
}
|
|
6478
|
-
_optionalChain([session, 'access',
|
|
6622
|
+
_optionalChain([session, 'access', _192 => _192.state, 'optionalAccess', _193 => _193.set, 'call', _194 => _194(key, value)]);
|
|
6479
6623
|
}
|
|
6480
6624
|
}
|
|
6481
6625
|
if (!session.events) {
|
|
@@ -6486,7 +6630,7 @@ var PgLiteSessionService = (_class26 = class {
|
|
|
6486
6630
|
await this.updateSession(session);
|
|
6487
6631
|
return event;
|
|
6488
6632
|
}
|
|
6489
|
-
},
|
|
6633
|
+
}, _class27);
|
|
6490
6634
|
|
|
6491
6635
|
// src/sessions/sqlite-session-service.ts
|
|
6492
6636
|
|
|
@@ -6506,12 +6650,12 @@ var sessionsSchema3 = _sqlitecore.sqliteTable.call(void 0, "sessions", {
|
|
|
6506
6650
|
updatedAt: _sqlitecore.integer.call(void 0, "updated_at", { mode: "timestamp" }).notNull(),
|
|
6507
6651
|
state: _sqlitecore.text.call(void 0, "state", { mode: "json" }).default("{}").$type()
|
|
6508
6652
|
});
|
|
6509
|
-
var SqliteSessionService = (
|
|
6653
|
+
var SqliteSessionService = (_class28 = class {
|
|
6510
6654
|
|
|
6511
6655
|
|
|
6512
|
-
|
|
6656
|
+
__init39() {this.initialized = false}
|
|
6513
6657
|
|
|
6514
|
-
constructor(config) {;
|
|
6658
|
+
constructor(config) {;_class28.prototype.__init39.call(this);
|
|
6515
6659
|
this.sqliteInstance = config.sqlite;
|
|
6516
6660
|
const dbPath = this.sqliteInstance.name;
|
|
6517
6661
|
if (dbPath && dbPath !== ":memory:") {
|
|
@@ -6632,7 +6776,7 @@ var SqliteSessionService = (_class27 = class {
|
|
|
6632
6776
|
async listSessions(userId, options) {
|
|
6633
6777
|
await this.ensureInitialized();
|
|
6634
6778
|
let query = this.db.select().from(this.sessionsTable).where(_drizzleorm.eq.call(void 0, this.sessionsTable.userId, userId));
|
|
6635
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6779
|
+
if (_optionalChain([options, 'optionalAccess', _195 => _195.limit]) !== void 0 && options.limit > 0) {
|
|
6636
6780
|
query = query.limit(options.limit);
|
|
6637
6781
|
}
|
|
6638
6782
|
const results = await query;
|
|
@@ -6655,12 +6799,12 @@ var SqliteSessionService = (_class27 = class {
|
|
|
6655
6799
|
if (event.is_partial) {
|
|
6656
6800
|
return event;
|
|
6657
6801
|
}
|
|
6658
|
-
if (_optionalChain([event, 'access',
|
|
6802
|
+
if (_optionalChain([event, 'access', _196 => _196.actions, 'optionalAccess', _197 => _197.stateDelta])) {
|
|
6659
6803
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
6660
6804
|
if (key.startsWith("_temp_")) {
|
|
6661
6805
|
continue;
|
|
6662
6806
|
}
|
|
6663
|
-
_optionalChain([session, 'access',
|
|
6807
|
+
_optionalChain([session, 'access', _198 => _198.state, 'optionalAccess', _199 => _199.set, 'call', _200 => _200(key, value)]);
|
|
6664
6808
|
}
|
|
6665
6809
|
}
|
|
6666
6810
|
if (!session.events) {
|
|
@@ -6671,7 +6815,7 @@ var SqliteSessionService = (_class27 = class {
|
|
|
6671
6815
|
await this.updateSession(session);
|
|
6672
6816
|
return event;
|
|
6673
6817
|
}
|
|
6674
|
-
},
|
|
6818
|
+
}, _class28);
|
|
6675
6819
|
|
|
6676
6820
|
// src/sessions/session-util.ts
|
|
6677
6821
|
function generateSessionId() {
|
|
@@ -6707,7 +6851,7 @@ function cloneSession(session) {
|
|
|
6707
6851
|
var _uuid = require('uuid');
|
|
6708
6852
|
|
|
6709
6853
|
// src/events/event-actions.ts
|
|
6710
|
-
var EventActions = (
|
|
6854
|
+
var EventActions = (_class29 = class {
|
|
6711
6855
|
/**
|
|
6712
6856
|
* If true, it won't call model to summarize function response.
|
|
6713
6857
|
* Only used for function_response event.
|
|
@@ -6716,12 +6860,12 @@ var EventActions = (_class28 = class {
|
|
|
6716
6860
|
/**
|
|
6717
6861
|
* Indicates that the event is updating the state with the given delta.
|
|
6718
6862
|
*/
|
|
6719
|
-
|
|
6863
|
+
__init40() {this.stateDelta = {}}
|
|
6720
6864
|
/**
|
|
6721
6865
|
* Indicates that the event is updating an artifact. key is the filename,
|
|
6722
6866
|
* value is the version.
|
|
6723
6867
|
*/
|
|
6724
|
-
|
|
6868
|
+
__init41() {this.artifactDelta = {}}
|
|
6725
6869
|
/**
|
|
6726
6870
|
* If set, the event transfers to the specified agent.
|
|
6727
6871
|
*/
|
|
@@ -6733,21 +6877,21 @@ var EventActions = (_class28 = class {
|
|
|
6733
6877
|
/**
|
|
6734
6878
|
* Constructor for EventActions
|
|
6735
6879
|
*/
|
|
6736
|
-
constructor(options = {}) {;
|
|
6880
|
+
constructor(options = {}) {;_class29.prototype.__init40.call(this);_class29.prototype.__init41.call(this);
|
|
6737
6881
|
this.skipSummarization = options.skipSummarization;
|
|
6738
6882
|
this.stateDelta = options.stateDelta || {};
|
|
6739
6883
|
this.artifactDelta = options.artifactDelta || {};
|
|
6740
6884
|
this.transferToAgent = options.transferToAgent;
|
|
6741
6885
|
this.escalate = options.escalate;
|
|
6742
6886
|
}
|
|
6743
|
-
},
|
|
6887
|
+
}, _class29);
|
|
6744
6888
|
|
|
6745
6889
|
// src/events/event.ts
|
|
6746
|
-
var Event = (
|
|
6890
|
+
var Event = (_class30 = class _Event extends LLMResponse {
|
|
6747
6891
|
/**
|
|
6748
6892
|
* The invocation ID of the event.
|
|
6749
6893
|
*/
|
|
6750
|
-
|
|
6894
|
+
__init42() {this.invocationId = ""}
|
|
6751
6895
|
/**
|
|
6752
6896
|
* 'user' or the name of the agent, indicating who appended the event to the session.
|
|
6753
6897
|
*/
|
|
@@ -6755,7 +6899,7 @@ var Event = (_class29 = class _Event extends LLMResponse {
|
|
|
6755
6899
|
/**
|
|
6756
6900
|
* The actions taken by the agent.
|
|
6757
6901
|
*/
|
|
6758
|
-
|
|
6902
|
+
__init43() {this.actions = new EventActions()}
|
|
6759
6903
|
/**
|
|
6760
6904
|
* Set of ids of the long running function calls.
|
|
6761
6905
|
* Agent client will know from this field about which function call is long running.
|
|
@@ -6773,7 +6917,7 @@ var Event = (_class29 = class _Event extends LLMResponse {
|
|
|
6773
6917
|
/**
|
|
6774
6918
|
* The unique identifier of the event.
|
|
6775
6919
|
*/
|
|
6776
|
-
|
|
6920
|
+
__init44() {this.id = ""}
|
|
6777
6921
|
/**
|
|
6778
6922
|
* The timestamp of the event.
|
|
6779
6923
|
*/
|
|
@@ -6803,7 +6947,7 @@ var Event = (_class29 = class _Event extends LLMResponse {
|
|
|
6803
6947
|
role,
|
|
6804
6948
|
is_partial: partial,
|
|
6805
6949
|
raw_response
|
|
6806
|
-
});
|
|
6950
|
+
});_class30.prototype.__init42.call(this);_class30.prototype.__init43.call(this);_class30.prototype.__init44.call(this);;
|
|
6807
6951
|
this.invocationId = invocationId;
|
|
6808
6952
|
this.author = author;
|
|
6809
6953
|
this.actions = actions;
|
|
@@ -6837,7 +6981,7 @@ var Event = (_class29 = class _Event extends LLMResponse {
|
|
|
6837
6981
|
static newId() {
|
|
6838
6982
|
return _uuid.v4.call(void 0, ).substring(0, 8);
|
|
6839
6983
|
}
|
|
6840
|
-
},
|
|
6984
|
+
}, _class30);
|
|
6841
6985
|
|
|
6842
6986
|
// src/runners.ts
|
|
6843
6987
|
var Runner = class {
|