@probelabs/probe 0.6.0-rc125 → 0.6.0-rc126
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/build/agent/ProbeAgent.js +105 -8
- package/build/agent/hooks/HookManager.js +146 -0
- package/build/agent/hooks/index.js +1 -0
- package/build/agent/index.js +328 -14
- package/build/agent/storage/InMemoryStorageAdapter.js +49 -0
- package/build/agent/storage/StorageAdapter.js +51 -0
- package/build/agent/storage/index.js +2 -0
- package/build/index.js +8 -0
- package/cjs/agent/ProbeAgent.cjs +345 -31
- package/cjs/index.cjs +353 -31
- package/index.d.ts +95 -0
- package/package.json +1 -1
- package/src/agent/ProbeAgent.js +105 -8
- package/src/agent/hooks/HookManager.js +146 -0
- package/src/agent/hooks/index.js +1 -0
- package/src/agent/storage/InMemoryStorageAdapter.js +49 -0
- package/src/agent/storage/StorageAdapter.js +51 -0
- package/src/agent/storage/index.js +2 -0
- package/src/index.js +8 -0
package/cjs/index.cjs
CHANGED
|
@@ -24340,7 +24340,7 @@ var require_package = __commonJS({
|
|
|
24340
24340
|
module2.exports = {
|
|
24341
24341
|
name: "@aws-sdk/client-bedrock-runtime",
|
|
24342
24342
|
description: "AWS SDK for JavaScript Bedrock Runtime Client for Node.js, Browser and React Native",
|
|
24343
|
-
version: "3.
|
|
24343
|
+
version: "3.907.0",
|
|
24344
24344
|
scripts: {
|
|
24345
24345
|
build: "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
24346
24346
|
"build:cjs": "node ../../scripts/compilation/inline client-bedrock-runtime",
|
|
@@ -24359,21 +24359,21 @@ var require_package = __commonJS({
|
|
|
24359
24359
|
dependencies: {
|
|
24360
24360
|
"@aws-crypto/sha256-browser": "5.2.0",
|
|
24361
24361
|
"@aws-crypto/sha256-js": "5.2.0",
|
|
24362
|
-
"@aws-sdk/core": "3.
|
|
24363
|
-
"@aws-sdk/credential-provider-node": "3.
|
|
24362
|
+
"@aws-sdk/core": "3.907.0",
|
|
24363
|
+
"@aws-sdk/credential-provider-node": "3.907.0",
|
|
24364
24364
|
"@aws-sdk/eventstream-handler-node": "3.901.0",
|
|
24365
24365
|
"@aws-sdk/middleware-eventstream": "3.901.0",
|
|
24366
24366
|
"@aws-sdk/middleware-host-header": "3.901.0",
|
|
24367
24367
|
"@aws-sdk/middleware-logger": "3.901.0",
|
|
24368
24368
|
"@aws-sdk/middleware-recursion-detection": "3.901.0",
|
|
24369
|
-
"@aws-sdk/middleware-user-agent": "3.
|
|
24369
|
+
"@aws-sdk/middleware-user-agent": "3.907.0",
|
|
24370
24370
|
"@aws-sdk/middleware-websocket": "3.901.0",
|
|
24371
24371
|
"@aws-sdk/region-config-resolver": "3.901.0",
|
|
24372
|
-
"@aws-sdk/token-providers": "3.
|
|
24372
|
+
"@aws-sdk/token-providers": "3.907.0",
|
|
24373
24373
|
"@aws-sdk/types": "3.901.0",
|
|
24374
24374
|
"@aws-sdk/util-endpoints": "3.901.0",
|
|
24375
|
-
"@aws-sdk/util-user-agent-browser": "3.
|
|
24376
|
-
"@aws-sdk/util-user-agent-node": "3.
|
|
24375
|
+
"@aws-sdk/util-user-agent-browser": "3.907.0",
|
|
24376
|
+
"@aws-sdk/util-user-agent-node": "3.907.0",
|
|
24377
24377
|
"@smithy/config-resolver": "^4.3.0",
|
|
24378
24378
|
"@smithy/core": "^3.14.0",
|
|
24379
24379
|
"@smithy/eventstream-serde-browser": "^4.2.0",
|
|
@@ -25121,7 +25121,7 @@ var init_package = __esm({
|
|
|
25121
25121
|
"node_modules/@aws-sdk/nested-clients/package.json"() {
|
|
25122
25122
|
package_default = {
|
|
25123
25123
|
name: "@aws-sdk/nested-clients",
|
|
25124
|
-
version: "3.
|
|
25124
|
+
version: "3.907.0",
|
|
25125
25125
|
description: "Nested clients for AWS SDK packages.",
|
|
25126
25126
|
main: "./dist-cjs/index.js",
|
|
25127
25127
|
module: "./dist-es/index.js",
|
|
@@ -25150,16 +25150,16 @@ var init_package = __esm({
|
|
|
25150
25150
|
dependencies: {
|
|
25151
25151
|
"@aws-crypto/sha256-browser": "5.2.0",
|
|
25152
25152
|
"@aws-crypto/sha256-js": "5.2.0",
|
|
25153
|
-
"@aws-sdk/core": "3.
|
|
25153
|
+
"@aws-sdk/core": "3.907.0",
|
|
25154
25154
|
"@aws-sdk/middleware-host-header": "3.901.0",
|
|
25155
25155
|
"@aws-sdk/middleware-logger": "3.901.0",
|
|
25156
25156
|
"@aws-sdk/middleware-recursion-detection": "3.901.0",
|
|
25157
|
-
"@aws-sdk/middleware-user-agent": "3.
|
|
25157
|
+
"@aws-sdk/middleware-user-agent": "3.907.0",
|
|
25158
25158
|
"@aws-sdk/region-config-resolver": "3.901.0",
|
|
25159
25159
|
"@aws-sdk/types": "3.901.0",
|
|
25160
25160
|
"@aws-sdk/util-endpoints": "3.901.0",
|
|
25161
|
-
"@aws-sdk/util-user-agent-browser": "3.
|
|
25162
|
-
"@aws-sdk/util-user-agent-node": "3.
|
|
25161
|
+
"@aws-sdk/util-user-agent-browser": "3.907.0",
|
|
25162
|
+
"@aws-sdk/util-user-agent-node": "3.907.0",
|
|
25163
25163
|
"@smithy/config-resolver": "^4.3.0",
|
|
25164
25164
|
"@smithy/core": "^3.14.0",
|
|
25165
25165
|
"@smithy/fetch-http-handler": "^5.3.0",
|
|
@@ -26596,7 +26596,7 @@ var require_package2 = __commonJS({
|
|
|
26596
26596
|
module2.exports = {
|
|
26597
26597
|
name: "@aws-sdk/client-sso",
|
|
26598
26598
|
description: "AWS SDK for JavaScript Sso Client for Node.js, Browser and React Native",
|
|
26599
|
-
version: "3.
|
|
26599
|
+
version: "3.907.0",
|
|
26600
26600
|
scripts: {
|
|
26601
26601
|
build: "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
26602
26602
|
"build:cjs": "node ../../scripts/compilation/inline client-sso",
|
|
@@ -26615,16 +26615,16 @@ var require_package2 = __commonJS({
|
|
|
26615
26615
|
dependencies: {
|
|
26616
26616
|
"@aws-crypto/sha256-browser": "5.2.0",
|
|
26617
26617
|
"@aws-crypto/sha256-js": "5.2.0",
|
|
26618
|
-
"@aws-sdk/core": "3.
|
|
26618
|
+
"@aws-sdk/core": "3.907.0",
|
|
26619
26619
|
"@aws-sdk/middleware-host-header": "3.901.0",
|
|
26620
26620
|
"@aws-sdk/middleware-logger": "3.901.0",
|
|
26621
26621
|
"@aws-sdk/middleware-recursion-detection": "3.901.0",
|
|
26622
|
-
"@aws-sdk/middleware-user-agent": "3.
|
|
26622
|
+
"@aws-sdk/middleware-user-agent": "3.907.0",
|
|
26623
26623
|
"@aws-sdk/region-config-resolver": "3.901.0",
|
|
26624
26624
|
"@aws-sdk/types": "3.901.0",
|
|
26625
26625
|
"@aws-sdk/util-endpoints": "3.901.0",
|
|
26626
|
-
"@aws-sdk/util-user-agent-browser": "3.
|
|
26627
|
-
"@aws-sdk/util-user-agent-node": "3.
|
|
26626
|
+
"@aws-sdk/util-user-agent-browser": "3.907.0",
|
|
26627
|
+
"@aws-sdk/util-user-agent-node": "3.907.0",
|
|
26628
26628
|
"@smithy/config-resolver": "^4.3.0",
|
|
26629
26629
|
"@smithy/core": "^3.14.0",
|
|
26630
26630
|
"@smithy/fetch-http-handler": "^5.3.0",
|
|
@@ -33872,7 +33872,7 @@ var init_BytePairEncodingCore = __esm({
|
|
|
33872
33872
|
var chatEnabledModels;
|
|
33873
33873
|
var init_modelsChatEnabled_gen = __esm({
|
|
33874
33874
|
"node_modules/gpt-tokenizer/esm/modelsChatEnabled.gen.js"() {
|
|
33875
|
-
chatEnabledModels = ["chatgpt-4o-latest", "codex-mini-latest", "computer-use-preview", "computer-use-preview-2025-03-11", "gpt-3.5", "gpt-3.5-0301", "gpt-3.5-turbo", "gpt-3.5-turbo-0125", "gpt-3.5-turbo-0613", "gpt-3.5-turbo-1106", "gpt-3.5-turbo-16k-0613", "gpt-3.5-turbo-instruct", "gpt-4", "gpt-4-0125-preview", "gpt-4-0314", "gpt-4-0613", "gpt-4-1106-preview", "gpt-4-1106-vision-preview", "gpt-4-32k", "gpt-4-turbo", "gpt-4-turbo-2024-04-09", "gpt-4-turbo-preview", "gpt-4.1", "gpt-4.1-2025-04-14", "gpt-4.1-mini", "gpt-4.1-mini-2025-04-14", "gpt-4.1-nano", "gpt-4.1-nano-2025-04-14", "gpt-4.5-preview", "gpt-4.5-preview-2025-02-27", "gpt-4o", "gpt-4o-2024-05-13", "gpt-4o-2024-08-06", "gpt-4o-2024-11-20", "gpt-4o-audio-preview", "gpt-4o-audio-preview-2024-10-01", "gpt-4o-audio-preview-2024-12-17", "gpt-4o-audio-preview-2025-06-03", "gpt-4o-mini", "gpt-4o-mini-2024-07-18", "gpt-4o-mini-audio-preview", "gpt-4o-mini-audio-preview-2024-12-17", "gpt-4o-mini-search-preview", "gpt-4o-mini-search-preview-2025-03-11", "gpt-4o-search-preview", "gpt-4o-search-preview-2025-03-11", "o1", "o1-2024-12-17", "o1-mini", "o1-mini-2024-09-12", "o1-preview", "o1-preview-2024-09-12", "o1-pro", "o1-pro-2025-03-19", "o3", "o3-2025-04-16", "o3-mini", "o3-mini-2025-01-31", "o3-pro", "o3-pro-2025-06-10", "o4-mini", "o4-mini-2025-04-16"];
|
|
33875
|
+
chatEnabledModels = ["chatgpt-4o-latest", "codex-mini-latest", "computer-use-preview", "computer-use-preview-2025-03-11", "gpt-3.5", "gpt-3.5-0301", "gpt-3.5-turbo", "gpt-3.5-turbo-0125", "gpt-3.5-turbo-0613", "gpt-3.5-turbo-1106", "gpt-3.5-turbo-16k-0613", "gpt-3.5-turbo-instruct", "gpt-4", "gpt-4-0125-preview", "gpt-4-0314", "gpt-4-0613", "gpt-4-1106-preview", "gpt-4-1106-vision-preview", "gpt-4-32k", "gpt-4-turbo", "gpt-4-turbo-2024-04-09", "gpt-4-turbo-preview", "gpt-4.1", "gpt-4.1-2025-04-14", "gpt-4.1-mini", "gpt-4.1-mini-2025-04-14", "gpt-4.1-nano", "gpt-4.1-nano-2025-04-14", "gpt-4.5-preview", "gpt-4.5-preview-2025-02-27", "gpt-4o", "gpt-4o-2024-05-13", "gpt-4o-2024-08-06", "gpt-4o-2024-11-20", "gpt-4o-audio-preview", "gpt-4o-audio-preview-2024-10-01", "gpt-4o-audio-preview-2024-12-17", "gpt-4o-audio-preview-2025-06-03", "gpt-4o-mini", "gpt-4o-mini-2024-07-18", "gpt-4o-mini-audio-preview", "gpt-4o-mini-audio-preview-2024-12-17", "gpt-4o-mini-search-preview", "gpt-4o-mini-search-preview-2025-03-11", "gpt-4o-search-preview", "gpt-4o-search-preview-2025-03-11", "gpt-5", "gpt-5-2025-08-07", "gpt-5-chat-latest", "gpt-5-codex", "gpt-5-mini", "gpt-5-mini-2025-08-07", "gpt-5-nano", "gpt-5-nano-2025-08-07", "gpt-5-pro", "gpt-5-pro-2025-10-06", "gpt-audio", "gpt-audio-2025-08-28", "gpt-audio-mini", "gpt-audio-mini-2025-10-06", "gpt-oss-120b", "gpt-oss-20b", "o1", "o1-2024-12-17", "o1-mini", "o1-mini-2024-09-12", "o1-preview", "o1-preview-2024-09-12", "o1-pro", "o1-pro-2025-03-19", "o3", "o3-2025-04-16", "o3-deep-research", "o3-deep-research-2025-06-26", "o3-mini", "o3-mini-2025-01-31", "o3-pro", "o3-pro-2025-06-10", "o4-mini", "o4-mini-2025-04-16", "o4-mini-deep-research", "o4-mini-deep-research-2025-06-26"];
|
|
33876
33876
|
}
|
|
33877
33877
|
});
|
|
33878
33878
|
|
|
@@ -34268,8 +34268,9 @@ var init_GptEncoding = __esm({
|
|
|
34268
34268
|
* Returns tokens assuming the 'gpt-3.5-turbo-0301' / 'gpt-4-0314' format.
|
|
34269
34269
|
* Based on OpenAI's guidelines: https://github.com/openai/openai-python/blob/main/chatml.md
|
|
34270
34270
|
* Also mentioned in section 6 of this document: https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb
|
|
34271
|
+
* @param encodeOptions Options controlling how special tokens are handled.
|
|
34271
34272
|
*/
|
|
34272
|
-
*encodeChatGenerator(chat, model = this.modelName) {
|
|
34273
|
+
*encodeChatGenerator(chat, model = this.modelName, encodeOptions) {
|
|
34273
34274
|
if (!model) {
|
|
34274
34275
|
throw new Error("Model name must be provided either during initialization or passed in to the method.");
|
|
34275
34276
|
}
|
|
@@ -34295,12 +34296,12 @@ var init_GptEncoding = __esm({
|
|
|
34295
34296
|
if (encodedRoleSeparator.length > 0) {
|
|
34296
34297
|
yield encodedRoleSeparator;
|
|
34297
34298
|
}
|
|
34298
|
-
yield* this.encodeGenerator(content);
|
|
34299
|
+
yield* this.encodeGenerator(content, encodeOptions);
|
|
34299
34300
|
yield [chatEndToken];
|
|
34300
34301
|
yield encodedMessageSeparator;
|
|
34301
34302
|
}
|
|
34302
34303
|
yield [chatStartToken];
|
|
34303
|
-
yield* this.encodeGenerator("assistant");
|
|
34304
|
+
yield* this.encodeGenerator("assistant", encodeOptions);
|
|
34304
34305
|
if (encodedRoleSeparator.length > 0) {
|
|
34305
34306
|
yield encodedRoleSeparator;
|
|
34306
34307
|
}
|
|
@@ -34311,15 +34312,20 @@ var init_GptEncoding = __esm({
|
|
|
34311
34312
|
* Returns tokens assuming the 'gpt-3.5-turbo-0301' / 'gpt-4-0314' format.
|
|
34312
34313
|
* Based on OpenAI's guidelines: https://github.com/openai/openai-python/blob/main/chatml.md
|
|
34313
34314
|
* Also mentioned in section 6 of this document: https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb
|
|
34315
|
+
* @param encodeOptions Options controlling how special tokens are handled.
|
|
34314
34316
|
*/
|
|
34315
|
-
encodeChat(chat, model = this.modelName) {
|
|
34316
|
-
return [...this.encodeChatGenerator(chat, model)].flat();
|
|
34317
|
+
encodeChat(chat, model = this.modelName, encodeOptions) {
|
|
34318
|
+
return [...this.encodeChatGenerator(chat, model, encodeOptions)].flat();
|
|
34317
34319
|
}
|
|
34318
34320
|
/**
|
|
34321
|
+
* Checks whether the provided input stays within the provided token limit.
|
|
34322
|
+
* @param input The string or chat messages to evaluate.
|
|
34323
|
+
* @param tokenLimit The maximum allowed number of tokens.
|
|
34324
|
+
* @param encodeOptions Options controlling how special tokens are handled.
|
|
34319
34325
|
* @returns {false | number} false if token limit is exceeded, otherwise the number of tokens
|
|
34320
34326
|
*/
|
|
34321
|
-
isWithinTokenLimit(input, tokenLimit) {
|
|
34322
|
-
const tokenGenerator = typeof input === "string" ? this.encodeGenerator(input) : this.encodeChatGenerator(input);
|
|
34327
|
+
isWithinTokenLimit(input, tokenLimit, encodeOptions) {
|
|
34328
|
+
const tokenGenerator = typeof input === "string" ? this.encodeGenerator(input, encodeOptions) : this.encodeChatGenerator(input, void 0, encodeOptions);
|
|
34323
34329
|
let count = 0;
|
|
34324
34330
|
for (const tokens of tokenGenerator) {
|
|
34325
34331
|
count += tokens.length;
|
|
@@ -34331,6 +34337,8 @@ var init_GptEncoding = __esm({
|
|
|
34331
34337
|
}
|
|
34332
34338
|
/**
|
|
34333
34339
|
* Counts the number of tokens in the input.
|
|
34340
|
+
* @param input The string or chat messages to evaluate.
|
|
34341
|
+
* @param encodeOptions Options controlling how special tokens are handled.
|
|
34334
34342
|
* @returns {number} The number of tokens.
|
|
34335
34343
|
*/
|
|
34336
34344
|
countTokens(input, encodeOptions) {
|
|
@@ -34344,7 +34352,7 @@ var init_GptEncoding = __esm({
|
|
|
34344
34352
|
}
|
|
34345
34353
|
return this.bytePairEncodingCoreProcessor.countNative(input, specialTokenConfig.allowedSpecial);
|
|
34346
34354
|
}
|
|
34347
|
-
const tokenGenerator = this.encodeChatGenerator(input);
|
|
34355
|
+
const tokenGenerator = this.encodeChatGenerator(input, void 0, encodeOptions);
|
|
34348
34356
|
let count = 0;
|
|
34349
34357
|
for (const tokens of tokenGenerator) {
|
|
34350
34358
|
count += tokens.length;
|
|
@@ -34782,6 +34790,226 @@ var init_tokenCounter = __esm({
|
|
|
34782
34790
|
}
|
|
34783
34791
|
});
|
|
34784
34792
|
|
|
34793
|
+
// src/agent/storage/StorageAdapter.js
|
|
34794
|
+
var StorageAdapter;
|
|
34795
|
+
var init_StorageAdapter = __esm({
|
|
34796
|
+
"src/agent/storage/StorageAdapter.js"() {
|
|
34797
|
+
"use strict";
|
|
34798
|
+
StorageAdapter = class {
|
|
34799
|
+
/**
|
|
34800
|
+
* Load conversation history for a session
|
|
34801
|
+
* @param {string} sessionId - Session identifier
|
|
34802
|
+
* @returns {Promise<Array<Object>>} Array of message objects with {role, content, ...}
|
|
34803
|
+
*/
|
|
34804
|
+
async loadHistory(sessionId) {
|
|
34805
|
+
throw new Error("StorageAdapter.loadHistory() must be implemented by subclass");
|
|
34806
|
+
}
|
|
34807
|
+
/**
|
|
34808
|
+
* Save a message to storage
|
|
34809
|
+
* @param {string} sessionId - Session identifier
|
|
34810
|
+
* @param {Object} message - Message object { role, content, ... }
|
|
34811
|
+
* @returns {Promise<void>}
|
|
34812
|
+
*/
|
|
34813
|
+
async saveMessage(sessionId, message) {
|
|
34814
|
+
throw new Error("StorageAdapter.saveMessage() must be implemented by subclass");
|
|
34815
|
+
}
|
|
34816
|
+
/**
|
|
34817
|
+
* Clear history for a session
|
|
34818
|
+
* @param {string} sessionId - Session identifier
|
|
34819
|
+
* @returns {Promise<void>}
|
|
34820
|
+
*/
|
|
34821
|
+
async clearHistory(sessionId) {
|
|
34822
|
+
throw new Error("StorageAdapter.clearHistory() must be implemented by subclass");
|
|
34823
|
+
}
|
|
34824
|
+
/**
|
|
34825
|
+
* Get session metadata (optional)
|
|
34826
|
+
* @param {string} sessionId - Session identifier
|
|
34827
|
+
* @returns {Promise<Object|null>} Session metadata or null
|
|
34828
|
+
*/
|
|
34829
|
+
async getSessionMetadata(sessionId) {
|
|
34830
|
+
return null;
|
|
34831
|
+
}
|
|
34832
|
+
/**
|
|
34833
|
+
* Update session activity timestamp (optional)
|
|
34834
|
+
* @param {string} sessionId - Session identifier
|
|
34835
|
+
* @returns {Promise<void>}
|
|
34836
|
+
*/
|
|
34837
|
+
async updateSessionActivity(sessionId) {
|
|
34838
|
+
}
|
|
34839
|
+
};
|
|
34840
|
+
}
|
|
34841
|
+
});
|
|
34842
|
+
|
|
34843
|
+
// src/agent/storage/InMemoryStorageAdapter.js
|
|
34844
|
+
var InMemoryStorageAdapter;
|
|
34845
|
+
var init_InMemoryStorageAdapter = __esm({
|
|
34846
|
+
"src/agent/storage/InMemoryStorageAdapter.js"() {
|
|
34847
|
+
"use strict";
|
|
34848
|
+
init_StorageAdapter();
|
|
34849
|
+
InMemoryStorageAdapter = class extends StorageAdapter {
|
|
34850
|
+
constructor() {
|
|
34851
|
+
super();
|
|
34852
|
+
this.sessions = /* @__PURE__ */ new Map();
|
|
34853
|
+
}
|
|
34854
|
+
async loadHistory(sessionId) {
|
|
34855
|
+
const session = this.sessions.get(sessionId);
|
|
34856
|
+
return session ? session.messages : [];
|
|
34857
|
+
}
|
|
34858
|
+
async saveMessage(sessionId, message) {
|
|
34859
|
+
if (!this.sessions.has(sessionId)) {
|
|
34860
|
+
this.sessions.set(sessionId, {
|
|
34861
|
+
messages: [],
|
|
34862
|
+
metadata: {
|
|
34863
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
34864
|
+
lastActivity: (/* @__PURE__ */ new Date()).toISOString()
|
|
34865
|
+
}
|
|
34866
|
+
});
|
|
34867
|
+
}
|
|
34868
|
+
const session = this.sessions.get(sessionId);
|
|
34869
|
+
session.messages.push(message);
|
|
34870
|
+
session.metadata.lastActivity = (/* @__PURE__ */ new Date()).toISOString();
|
|
34871
|
+
}
|
|
34872
|
+
async clearHistory(sessionId) {
|
|
34873
|
+
this.sessions.delete(sessionId);
|
|
34874
|
+
}
|
|
34875
|
+
async getSessionMetadata(sessionId) {
|
|
34876
|
+
const session = this.sessions.get(sessionId);
|
|
34877
|
+
return session ? session.metadata : null;
|
|
34878
|
+
}
|
|
34879
|
+
async updateSessionActivity(sessionId) {
|
|
34880
|
+
const session = this.sessions.get(sessionId);
|
|
34881
|
+
if (session) {
|
|
34882
|
+
session.metadata.lastActivity = (/* @__PURE__ */ new Date()).toISOString();
|
|
34883
|
+
}
|
|
34884
|
+
}
|
|
34885
|
+
};
|
|
34886
|
+
}
|
|
34887
|
+
});
|
|
34888
|
+
|
|
34889
|
+
// src/agent/hooks/HookManager.js
|
|
34890
|
+
var HookManager, HOOK_TYPES;
|
|
34891
|
+
var init_HookManager = __esm({
|
|
34892
|
+
"src/agent/hooks/HookManager.js"() {
|
|
34893
|
+
"use strict";
|
|
34894
|
+
HookManager = class {
|
|
34895
|
+
constructor() {
|
|
34896
|
+
this.hooks = /* @__PURE__ */ new Map();
|
|
34897
|
+
}
|
|
34898
|
+
/**
|
|
34899
|
+
* Register a hook callback
|
|
34900
|
+
* @param {string} hookName - Name of the hook
|
|
34901
|
+
* @param {Function} callback - Callback function
|
|
34902
|
+
* @returns {Function} Unregister function
|
|
34903
|
+
*/
|
|
34904
|
+
on(hookName, callback) {
|
|
34905
|
+
if (!this.hooks.has(hookName)) {
|
|
34906
|
+
this.hooks.set(hookName, /* @__PURE__ */ new Set());
|
|
34907
|
+
}
|
|
34908
|
+
this.hooks.get(hookName).add(callback);
|
|
34909
|
+
return () => this.off(hookName, callback);
|
|
34910
|
+
}
|
|
34911
|
+
/**
|
|
34912
|
+
* Register a one-time hook callback
|
|
34913
|
+
* @param {string} hookName - Name of the hook
|
|
34914
|
+
* @param {Function} callback - Callback function
|
|
34915
|
+
* @returns {Function} Unregister function
|
|
34916
|
+
*/
|
|
34917
|
+
once(hookName, callback) {
|
|
34918
|
+
const wrappedCallback = async (data2) => {
|
|
34919
|
+
this.off(hookName, wrappedCallback);
|
|
34920
|
+
await callback(data2);
|
|
34921
|
+
};
|
|
34922
|
+
return this.on(hookName, wrappedCallback);
|
|
34923
|
+
}
|
|
34924
|
+
/**
|
|
34925
|
+
* Unregister a hook callback
|
|
34926
|
+
* @param {string} hookName - Name of the hook
|
|
34927
|
+
* @param {Function} callback - Callback function
|
|
34928
|
+
*/
|
|
34929
|
+
off(hookName, callback) {
|
|
34930
|
+
const callbacks = this.hooks.get(hookName);
|
|
34931
|
+
if (callbacks) {
|
|
34932
|
+
callbacks.delete(callback);
|
|
34933
|
+
}
|
|
34934
|
+
}
|
|
34935
|
+
/**
|
|
34936
|
+
* Emit a hook event
|
|
34937
|
+
* @param {string} hookName - Name of the hook
|
|
34938
|
+
* @param {any} data - Data to pass to callbacks
|
|
34939
|
+
* @returns {Promise<void>}
|
|
34940
|
+
*/
|
|
34941
|
+
async emit(hookName, data2) {
|
|
34942
|
+
const callbacks = this.hooks.get(hookName);
|
|
34943
|
+
if (!callbacks || callbacks.size === 0) return;
|
|
34944
|
+
const promises = Array.from(callbacks).map((callback) => {
|
|
34945
|
+
try {
|
|
34946
|
+
return Promise.resolve(callback(data2));
|
|
34947
|
+
} catch (error2) {
|
|
34948
|
+
return Promise.reject(error2);
|
|
34949
|
+
}
|
|
34950
|
+
});
|
|
34951
|
+
const results = await Promise.allSettled(promises);
|
|
34952
|
+
results.forEach((result, index) => {
|
|
34953
|
+
if (result.status === "rejected") {
|
|
34954
|
+
console.error(`[HookManager] Error in hook "${hookName}" (callback ${index + 1}):`, result.reason);
|
|
34955
|
+
}
|
|
34956
|
+
});
|
|
34957
|
+
}
|
|
34958
|
+
/**
|
|
34959
|
+
* Clear all hooks or hooks for a specific event
|
|
34960
|
+
* @param {string} [hookName] - Optional hook name to clear
|
|
34961
|
+
*/
|
|
34962
|
+
clear(hookName) {
|
|
34963
|
+
if (hookName) {
|
|
34964
|
+
this.hooks.delete(hookName);
|
|
34965
|
+
} else {
|
|
34966
|
+
this.hooks.clear();
|
|
34967
|
+
}
|
|
34968
|
+
}
|
|
34969
|
+
/**
|
|
34970
|
+
* Get list of registered hook names
|
|
34971
|
+
* @returns {string[]} Array of hook names
|
|
34972
|
+
*/
|
|
34973
|
+
getHookNames() {
|
|
34974
|
+
return Array.from(this.hooks.keys());
|
|
34975
|
+
}
|
|
34976
|
+
/**
|
|
34977
|
+
* Get number of callbacks for a hook
|
|
34978
|
+
* @param {string} hookName - Name of the hook
|
|
34979
|
+
* @returns {number} Number of callbacks
|
|
34980
|
+
*/
|
|
34981
|
+
getCallbackCount(hookName) {
|
|
34982
|
+
const callbacks = this.hooks.get(hookName);
|
|
34983
|
+
return callbacks ? callbacks.size : 0;
|
|
34984
|
+
}
|
|
34985
|
+
};
|
|
34986
|
+
HOOK_TYPES = {
|
|
34987
|
+
// Lifecycle hooks
|
|
34988
|
+
AGENT_INITIALIZED: "agent:initialized",
|
|
34989
|
+
AGENT_CLEANUP: "agent:cleanup",
|
|
34990
|
+
// Message hooks
|
|
34991
|
+
MESSAGE_USER: "message:user",
|
|
34992
|
+
MESSAGE_ASSISTANT: "message:assistant",
|
|
34993
|
+
MESSAGE_SYSTEM: "message:system",
|
|
34994
|
+
// Tool execution hooks
|
|
34995
|
+
TOOL_START: "tool:start",
|
|
34996
|
+
TOOL_END: "tool:end",
|
|
34997
|
+
TOOL_ERROR: "tool:error",
|
|
34998
|
+
// AI streaming hooks
|
|
34999
|
+
AI_STREAM_START: "ai:stream:start",
|
|
35000
|
+
AI_STREAM_DELTA: "ai:stream:delta",
|
|
35001
|
+
AI_STREAM_END: "ai:stream:end",
|
|
35002
|
+
// Storage hooks
|
|
35003
|
+
STORAGE_LOAD: "storage:load",
|
|
35004
|
+
STORAGE_SAVE: "storage:save",
|
|
35005
|
+
STORAGE_CLEAR: "storage:clear",
|
|
35006
|
+
// Iteration hooks
|
|
35007
|
+
ITERATION_START: "iteration:start",
|
|
35008
|
+
ITERATION_END: "iteration:end"
|
|
35009
|
+
};
|
|
35010
|
+
}
|
|
35011
|
+
});
|
|
35012
|
+
|
|
34785
35013
|
// src/agent/xmlParsingUtils.js
|
|
34786
35014
|
function removeThinkingTags(xmlString) {
|
|
34787
35015
|
let result = xmlString;
|
|
@@ -72856,6 +73084,8 @@ var init_ProbeAgent = __esm({
|
|
|
72856
73084
|
import_promises2 = require("fs/promises");
|
|
72857
73085
|
import_path9 = require("path");
|
|
72858
73086
|
init_tokenCounter();
|
|
73087
|
+
init_InMemoryStorageAdapter();
|
|
73088
|
+
init_HookManager();
|
|
72859
73089
|
init_tools2();
|
|
72860
73090
|
init_common();
|
|
72861
73091
|
init_probeTool();
|
|
@@ -72888,6 +73118,8 @@ var init_ProbeAgent = __esm({
|
|
|
72888
73118
|
* @param {string} [options.mcpConfigPath] - Path to MCP configuration file
|
|
72889
73119
|
* @param {Object} [options.mcpConfig] - MCP configuration object (overrides mcpConfigPath)
|
|
72890
73120
|
* @param {Array} [options.mcpServers] - Deprecated, use mcpConfig instead
|
|
73121
|
+
* @param {Object} [options.storageAdapter] - Custom storage adapter for history management
|
|
73122
|
+
* @param {Object} [options.hooks] - Hook callbacks for events (e.g., {'tool:start': callback})
|
|
72891
73123
|
*/
|
|
72892
73124
|
constructor(options = {}) {
|
|
72893
73125
|
this.sessionId = options.sessionId || (0, import_crypto5.randomUUID)();
|
|
@@ -72901,6 +73133,13 @@ var init_ProbeAgent = __esm({
|
|
|
72901
73133
|
this.maxResponseTokens = options.maxResponseTokens || parseInt(process.env.MAX_RESPONSE_TOKENS || "0", 10) || null;
|
|
72902
73134
|
this.maxIterations = options.maxIterations || null;
|
|
72903
73135
|
this.disableMermaidValidation = !!options.disableMermaidValidation;
|
|
73136
|
+
this.storageAdapter = options.storageAdapter || new InMemoryStorageAdapter();
|
|
73137
|
+
this.hooks = new HookManager();
|
|
73138
|
+
if (options.hooks) {
|
|
73139
|
+
for (const [hookName, callback] of Object.entries(options.hooks)) {
|
|
73140
|
+
this.hooks.on(hookName, callback);
|
|
73141
|
+
}
|
|
73142
|
+
}
|
|
72904
73143
|
this.enableBash = !!options.enableBash;
|
|
72905
73144
|
this.bashConfig = options.bashConfig || {};
|
|
72906
73145
|
if (options.allowedFolders && Array.isArray(options.allowedFolders)) {
|
|
@@ -72934,9 +73173,23 @@ var init_ProbeAgent = __esm({
|
|
|
72934
73173
|
}
|
|
72935
73174
|
/**
|
|
72936
73175
|
* Initialize the agent asynchronously (must be called after constructor)
|
|
72937
|
-
* This method initializes MCP and merges MCP tools into the tool list
|
|
73176
|
+
* This method initializes MCP and merges MCP tools into the tool list, and loads history from storage
|
|
72938
73177
|
*/
|
|
72939
73178
|
async initialize() {
|
|
73179
|
+
try {
|
|
73180
|
+
const history = await this.storageAdapter.loadHistory(this.sessionId);
|
|
73181
|
+
this.history = history;
|
|
73182
|
+
if (this.debug && history.length > 0) {
|
|
73183
|
+
console.log(`[DEBUG] Loaded ${history.length} messages from storage for session ${this.sessionId}`);
|
|
73184
|
+
}
|
|
73185
|
+
await this.hooks.emit(HOOK_TYPES.STORAGE_LOAD, {
|
|
73186
|
+
sessionId: this.sessionId,
|
|
73187
|
+
messages: history
|
|
73188
|
+
});
|
|
73189
|
+
} catch (error2) {
|
|
73190
|
+
console.error(`[ERROR] Failed to load history from storage:`, error2);
|
|
73191
|
+
this.history = [];
|
|
73192
|
+
}
|
|
72940
73193
|
if (this.enableMcp && !this._mcpInitialized) {
|
|
72941
73194
|
this._mcpInitialized = true;
|
|
72942
73195
|
try {
|
|
@@ -72969,6 +73222,10 @@ var init_ProbeAgent = __esm({
|
|
|
72969
73222
|
this.mcpBridge = null;
|
|
72970
73223
|
}
|
|
72971
73224
|
}
|
|
73225
|
+
await this.hooks.emit(HOOK_TYPES.AGENT_INITIALIZED, {
|
|
73226
|
+
sessionId: this.sessionId,
|
|
73227
|
+
agent: this
|
|
73228
|
+
});
|
|
72972
73229
|
}
|
|
72973
73230
|
/**
|
|
72974
73231
|
* Initialize tools with configuration
|
|
@@ -73020,7 +73277,7 @@ var init_ProbeAgent = __esm({
|
|
|
73020
73277
|
}
|
|
73021
73278
|
const anthropicApiKey = process.env.ANTHROPIC_API_KEY;
|
|
73022
73279
|
const openaiApiKey = process.env.OPENAI_API_KEY;
|
|
73023
|
-
const googleApiKey = process.env.GOOGLE_API_KEY;
|
|
73280
|
+
const googleApiKey = process.env.GOOGLE_GENERATIVE_AI_API_KEY || process.env.GOOGLE_API_KEY;
|
|
73024
73281
|
const awsAccessKeyId = process.env.AWS_ACCESS_KEY_ID;
|
|
73025
73282
|
const awsSecretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;
|
|
73026
73283
|
const awsRegion = process.env.AWS_REGION;
|
|
@@ -73068,7 +73325,7 @@ var init_ProbeAgent = __esm({
|
|
|
73068
73325
|
} else if (awsAccessKeyId && awsSecretAccessKey && awsRegion || awsApiKey) {
|
|
73069
73326
|
this.initializeBedrockModel(awsAccessKeyId, awsSecretAccessKey, awsRegion, awsSessionToken, awsApiKey, awsBedrockBaseUrl, modelName);
|
|
73070
73327
|
} else {
|
|
73071
|
-
throw new Error("No API key provided. Please set ANTHROPIC_API_KEY, OPENAI_API_KEY, GOOGLE_API_KEY, AWS credentials (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION), or AWS_BEDROCK_API_KEY environment variables.");
|
|
73328
|
+
throw new Error("No API key provided. Please set ANTHROPIC_API_KEY, OPENAI_API_KEY, GOOGLE_GENERATIVE_AI_API_KEY (or GOOGLE_API_KEY), AWS credentials (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION), or AWS_BEDROCK_API_KEY environment variables.");
|
|
73072
73329
|
}
|
|
73073
73330
|
}
|
|
73074
73331
|
/**
|
|
@@ -73706,6 +73963,12 @@ You are working with a repository located at: ${searchDirectory}
|
|
|
73706
73963
|
options = schemaOrOptions || {};
|
|
73707
73964
|
}
|
|
73708
73965
|
try {
|
|
73966
|
+
const oldHistoryLength = this.history.length;
|
|
73967
|
+
await this.hooks.emit(HOOK_TYPES.MESSAGE_USER, {
|
|
73968
|
+
sessionId: this.sessionId,
|
|
73969
|
+
message,
|
|
73970
|
+
images
|
|
73971
|
+
});
|
|
73709
73972
|
const systemMessage = await this.getSystemMessage();
|
|
73710
73973
|
let userMessage = { role: "user", content: message.trim() };
|
|
73711
73974
|
if (images && images.length > 0) {
|
|
@@ -73791,6 +74054,9 @@ You are working with a repository located at: ${searchDirectory}
|
|
|
73791
74054
|
});
|
|
73792
74055
|
for await (const delta of result.textStream) {
|
|
73793
74056
|
assistantResponseContent += delta;
|
|
74057
|
+
if (options.onStream) {
|
|
74058
|
+
options.onStream(delta);
|
|
74059
|
+
}
|
|
73794
74060
|
}
|
|
73795
74061
|
const usage = await result.usage;
|
|
73796
74062
|
if (usage) {
|
|
@@ -73855,6 +74121,13 @@ You are working with a repository located at: ${searchDirectory}
|
|
|
73855
74121
|
const validation = attemptCompletionSchema.safeParse(params);
|
|
73856
74122
|
if (validation.success) {
|
|
73857
74123
|
finalResult = validation.data.result;
|
|
74124
|
+
if (options.onStream && finalResult) {
|
|
74125
|
+
const chunkSize = 50;
|
|
74126
|
+
for (let i3 = 0; i3 < finalResult.length; i3 += chunkSize) {
|
|
74127
|
+
const chunk = finalResult.slice(i3, Math.min(i3 + chunkSize, finalResult.length));
|
|
74128
|
+
options.onStream(chunk);
|
|
74129
|
+
}
|
|
74130
|
+
}
|
|
73858
74131
|
if (this.debug) console.log(`[DEBUG] Task completed successfully with result: ${finalResult.substring(0, 100)}...`);
|
|
73859
74132
|
} else {
|
|
73860
74133
|
console.error(`[ERROR] Invalid attempt_completion parameters:`, validation.error);
|
|
@@ -73929,7 +74202,9 @@ ${toolResultContent}
|
|
|
73929
74202
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
73930
74203
|
name: toolName,
|
|
73931
74204
|
args: toolParams,
|
|
73932
|
-
status: "started"
|
|
74205
|
+
status: "started",
|
|
74206
|
+
pauseStream: true
|
|
74207
|
+
// Signal to pause text streaming
|
|
73933
74208
|
});
|
|
73934
74209
|
const executeToolCall = async () => {
|
|
73935
74210
|
if (toolName === "delegate") {
|
|
@@ -74113,6 +74388,18 @@ IMPORTANT: When using <attempt_complete>, this must be the ONLY content in your
|
|
|
74113
74388
|
}
|
|
74114
74389
|
}
|
|
74115
74390
|
this.tokenCounter.updateHistory(this.history);
|
|
74391
|
+
try {
|
|
74392
|
+
const messagesToSave = currentMessages.slice(oldHistoryLength);
|
|
74393
|
+
for (const message2 of messagesToSave) {
|
|
74394
|
+
await this.storageAdapter.saveMessage(this.sessionId, message2);
|
|
74395
|
+
await this.hooks.emit(HOOK_TYPES.STORAGE_SAVE, {
|
|
74396
|
+
sessionId: this.sessionId,
|
|
74397
|
+
message: message2
|
|
74398
|
+
});
|
|
74399
|
+
}
|
|
74400
|
+
} catch (error2) {
|
|
74401
|
+
console.error(`[ERROR] Failed to save messages to storage:`, error2);
|
|
74402
|
+
}
|
|
74116
74403
|
const reachedMaxIterations = currentIteration >= maxIterations && !completionAttempted;
|
|
74117
74404
|
if (options.schema && !options._schemaFormatted && !completionAttempted && !reachedMaxIterations) {
|
|
74118
74405
|
if (this.debug) {
|
|
@@ -74477,10 +74764,18 @@ Convert your previous response content into actual JSON data that follows this s
|
|
|
74477
74764
|
/**
|
|
74478
74765
|
* Clear conversation history and reset counters
|
|
74479
74766
|
*/
|
|
74480
|
-
clearHistory() {
|
|
74767
|
+
async clearHistory() {
|
|
74768
|
+
try {
|
|
74769
|
+
await this.storageAdapter.clearHistory(this.sessionId);
|
|
74770
|
+
} catch (error2) {
|
|
74771
|
+
console.error(`[ERROR] Failed to clear history in storage:`, error2);
|
|
74772
|
+
}
|
|
74481
74773
|
this.history = [];
|
|
74482
74774
|
this.tokenCounter.clear();
|
|
74483
74775
|
clearToolExecutionData(this.sessionId);
|
|
74776
|
+
await this.hooks.emit(HOOK_TYPES.STORAGE_CLEAR, {
|
|
74777
|
+
sessionId: this.sessionId
|
|
74778
|
+
});
|
|
74484
74779
|
if (this.debug) {
|
|
74485
74780
|
console.log(`[DEBUG] Cleared conversation history and reset counters for session ${this.sessionId}`);
|
|
74486
74781
|
}
|
|
@@ -74739,13 +75034,34 @@ var init_simpleTelemetry = __esm({
|
|
|
74739
75034
|
}
|
|
74740
75035
|
});
|
|
74741
75036
|
|
|
75037
|
+
// src/agent/storage/index.js
|
|
75038
|
+
var init_storage = __esm({
|
|
75039
|
+
"src/agent/storage/index.js"() {
|
|
75040
|
+
"use strict";
|
|
75041
|
+
init_StorageAdapter();
|
|
75042
|
+
init_InMemoryStorageAdapter();
|
|
75043
|
+
}
|
|
75044
|
+
});
|
|
75045
|
+
|
|
75046
|
+
// src/agent/hooks/index.js
|
|
75047
|
+
var init_hooks = __esm({
|
|
75048
|
+
"src/agent/hooks/index.js"() {
|
|
75049
|
+
"use strict";
|
|
75050
|
+
init_HookManager();
|
|
75051
|
+
}
|
|
75052
|
+
});
|
|
75053
|
+
|
|
74742
75054
|
// src/index.js
|
|
74743
75055
|
var index_exports = {};
|
|
74744
75056
|
__export(index_exports, {
|
|
74745
75057
|
DEFAULT_SYSTEM_MESSAGE: () => DEFAULT_SYSTEM_MESSAGE,
|
|
75058
|
+
HOOK_TYPES: () => HOOK_TYPES,
|
|
75059
|
+
HookManager: () => HookManager,
|
|
75060
|
+
InMemoryStorageAdapter: () => InMemoryStorageAdapter,
|
|
74746
75061
|
ProbeAgent: () => ProbeAgent,
|
|
74747
75062
|
SimpleAppTracer: () => SimpleAppTracer,
|
|
74748
75063
|
SimpleTelemetry: () => SimpleTelemetry,
|
|
75064
|
+
StorageAdapter: () => StorageAdapter,
|
|
74749
75065
|
attemptCompletionSchema: () => attemptCompletionSchema,
|
|
74750
75066
|
attemptCompletionToolDefinition: () => attemptCompletionToolDefinition,
|
|
74751
75067
|
bashSchema: () => bashSchema,
|
|
@@ -74795,15 +75111,21 @@ var init_index = __esm({
|
|
|
74795
75111
|
init_ProbeAgent();
|
|
74796
75112
|
init_simpleTelemetry();
|
|
74797
75113
|
init_probeTool();
|
|
75114
|
+
init_storage();
|
|
75115
|
+
init_hooks();
|
|
74798
75116
|
}
|
|
74799
75117
|
});
|
|
74800
75118
|
init_index();
|
|
74801
75119
|
// Annotate the CommonJS export names for ESM import in node:
|
|
74802
75120
|
0 && (module.exports = {
|
|
74803
75121
|
DEFAULT_SYSTEM_MESSAGE,
|
|
75122
|
+
HOOK_TYPES,
|
|
75123
|
+
HookManager,
|
|
75124
|
+
InMemoryStorageAdapter,
|
|
74804
75125
|
ProbeAgent,
|
|
74805
75126
|
SimpleAppTracer,
|
|
74806
75127
|
SimpleTelemetry,
|
|
75128
|
+
StorageAdapter,
|
|
74807
75129
|
attemptCompletionSchema,
|
|
74808
75130
|
attemptCompletionToolDefinition,
|
|
74809
75131
|
bashSchema,
|