@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/agent/ProbeAgent.cjs
CHANGED
|
@@ -16640,7 +16640,7 @@ var require_package = __commonJS({
|
|
|
16640
16640
|
module2.exports = {
|
|
16641
16641
|
name: "@aws-sdk/client-bedrock-runtime",
|
|
16642
16642
|
description: "AWS SDK for JavaScript Bedrock Runtime Client for Node.js, Browser and React Native",
|
|
16643
|
-
version: "3.
|
|
16643
|
+
version: "3.907.0",
|
|
16644
16644
|
scripts: {
|
|
16645
16645
|
build: "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
16646
16646
|
"build:cjs": "node ../../scripts/compilation/inline client-bedrock-runtime",
|
|
@@ -16659,21 +16659,21 @@ var require_package = __commonJS({
|
|
|
16659
16659
|
dependencies: {
|
|
16660
16660
|
"@aws-crypto/sha256-browser": "5.2.0",
|
|
16661
16661
|
"@aws-crypto/sha256-js": "5.2.0",
|
|
16662
|
-
"@aws-sdk/core": "3.
|
|
16663
|
-
"@aws-sdk/credential-provider-node": "3.
|
|
16662
|
+
"@aws-sdk/core": "3.907.0",
|
|
16663
|
+
"@aws-sdk/credential-provider-node": "3.907.0",
|
|
16664
16664
|
"@aws-sdk/eventstream-handler-node": "3.901.0",
|
|
16665
16665
|
"@aws-sdk/middleware-eventstream": "3.901.0",
|
|
16666
16666
|
"@aws-sdk/middleware-host-header": "3.901.0",
|
|
16667
16667
|
"@aws-sdk/middleware-logger": "3.901.0",
|
|
16668
16668
|
"@aws-sdk/middleware-recursion-detection": "3.901.0",
|
|
16669
|
-
"@aws-sdk/middleware-user-agent": "3.
|
|
16669
|
+
"@aws-sdk/middleware-user-agent": "3.907.0",
|
|
16670
16670
|
"@aws-sdk/middleware-websocket": "3.901.0",
|
|
16671
16671
|
"@aws-sdk/region-config-resolver": "3.901.0",
|
|
16672
|
-
"@aws-sdk/token-providers": "3.
|
|
16672
|
+
"@aws-sdk/token-providers": "3.907.0",
|
|
16673
16673
|
"@aws-sdk/types": "3.901.0",
|
|
16674
16674
|
"@aws-sdk/util-endpoints": "3.901.0",
|
|
16675
|
-
"@aws-sdk/util-user-agent-browser": "3.
|
|
16676
|
-
"@aws-sdk/util-user-agent-node": "3.
|
|
16675
|
+
"@aws-sdk/util-user-agent-browser": "3.907.0",
|
|
16676
|
+
"@aws-sdk/util-user-agent-node": "3.907.0",
|
|
16677
16677
|
"@smithy/config-resolver": "^4.3.0",
|
|
16678
16678
|
"@smithy/core": "^3.14.0",
|
|
16679
16679
|
"@smithy/eventstream-serde-browser": "^4.2.0",
|
|
@@ -17421,7 +17421,7 @@ var init_package = __esm({
|
|
|
17421
17421
|
"node_modules/@aws-sdk/nested-clients/package.json"() {
|
|
17422
17422
|
package_default = {
|
|
17423
17423
|
name: "@aws-sdk/nested-clients",
|
|
17424
|
-
version: "3.
|
|
17424
|
+
version: "3.907.0",
|
|
17425
17425
|
description: "Nested clients for AWS SDK packages.",
|
|
17426
17426
|
main: "./dist-cjs/index.js",
|
|
17427
17427
|
module: "./dist-es/index.js",
|
|
@@ -17450,16 +17450,16 @@ var init_package = __esm({
|
|
|
17450
17450
|
dependencies: {
|
|
17451
17451
|
"@aws-crypto/sha256-browser": "5.2.0",
|
|
17452
17452
|
"@aws-crypto/sha256-js": "5.2.0",
|
|
17453
|
-
"@aws-sdk/core": "3.
|
|
17453
|
+
"@aws-sdk/core": "3.907.0",
|
|
17454
17454
|
"@aws-sdk/middleware-host-header": "3.901.0",
|
|
17455
17455
|
"@aws-sdk/middleware-logger": "3.901.0",
|
|
17456
17456
|
"@aws-sdk/middleware-recursion-detection": "3.901.0",
|
|
17457
|
-
"@aws-sdk/middleware-user-agent": "3.
|
|
17457
|
+
"@aws-sdk/middleware-user-agent": "3.907.0",
|
|
17458
17458
|
"@aws-sdk/region-config-resolver": "3.901.0",
|
|
17459
17459
|
"@aws-sdk/types": "3.901.0",
|
|
17460
17460
|
"@aws-sdk/util-endpoints": "3.901.0",
|
|
17461
|
-
"@aws-sdk/util-user-agent-browser": "3.
|
|
17462
|
-
"@aws-sdk/util-user-agent-node": "3.
|
|
17461
|
+
"@aws-sdk/util-user-agent-browser": "3.907.0",
|
|
17462
|
+
"@aws-sdk/util-user-agent-node": "3.907.0",
|
|
17463
17463
|
"@smithy/config-resolver": "^4.3.0",
|
|
17464
17464
|
"@smithy/core": "^3.14.0",
|
|
17465
17465
|
"@smithy/fetch-http-handler": "^5.3.0",
|
|
@@ -18896,7 +18896,7 @@ var require_package2 = __commonJS({
|
|
|
18896
18896
|
module2.exports = {
|
|
18897
18897
|
name: "@aws-sdk/client-sso",
|
|
18898
18898
|
description: "AWS SDK for JavaScript Sso Client for Node.js, Browser and React Native",
|
|
18899
|
-
version: "3.
|
|
18899
|
+
version: "3.907.0",
|
|
18900
18900
|
scripts: {
|
|
18901
18901
|
build: "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
18902
18902
|
"build:cjs": "node ../../scripts/compilation/inline client-sso",
|
|
@@ -18915,16 +18915,16 @@ var require_package2 = __commonJS({
|
|
|
18915
18915
|
dependencies: {
|
|
18916
18916
|
"@aws-crypto/sha256-browser": "5.2.0",
|
|
18917
18917
|
"@aws-crypto/sha256-js": "5.2.0",
|
|
18918
|
-
"@aws-sdk/core": "3.
|
|
18918
|
+
"@aws-sdk/core": "3.907.0",
|
|
18919
18919
|
"@aws-sdk/middleware-host-header": "3.901.0",
|
|
18920
18920
|
"@aws-sdk/middleware-logger": "3.901.0",
|
|
18921
18921
|
"@aws-sdk/middleware-recursion-detection": "3.901.0",
|
|
18922
|
-
"@aws-sdk/middleware-user-agent": "3.
|
|
18922
|
+
"@aws-sdk/middleware-user-agent": "3.907.0",
|
|
18923
18923
|
"@aws-sdk/region-config-resolver": "3.901.0",
|
|
18924
18924
|
"@aws-sdk/types": "3.901.0",
|
|
18925
18925
|
"@aws-sdk/util-endpoints": "3.901.0",
|
|
18926
|
-
"@aws-sdk/util-user-agent-browser": "3.
|
|
18927
|
-
"@aws-sdk/util-user-agent-node": "3.
|
|
18926
|
+
"@aws-sdk/util-user-agent-browser": "3.907.0",
|
|
18927
|
+
"@aws-sdk/util-user-agent-node": "3.907.0",
|
|
18928
18928
|
"@smithy/config-resolver": "^4.3.0",
|
|
18929
18929
|
"@smithy/core": "^3.14.0",
|
|
18930
18930
|
"@smithy/fetch-http-handler": "^5.3.0",
|
|
@@ -26172,7 +26172,7 @@ var init_BytePairEncodingCore = __esm({
|
|
|
26172
26172
|
var chatEnabledModels;
|
|
26173
26173
|
var init_modelsChatEnabled_gen = __esm({
|
|
26174
26174
|
"node_modules/gpt-tokenizer/esm/modelsChatEnabled.gen.js"() {
|
|
26175
|
-
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"];
|
|
26175
|
+
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"];
|
|
26176
26176
|
}
|
|
26177
26177
|
});
|
|
26178
26178
|
|
|
@@ -26568,8 +26568,9 @@ var init_GptEncoding = __esm({
|
|
|
26568
26568
|
* Returns tokens assuming the 'gpt-3.5-turbo-0301' / 'gpt-4-0314' format.
|
|
26569
26569
|
* Based on OpenAI's guidelines: https://github.com/openai/openai-python/blob/main/chatml.md
|
|
26570
26570
|
* Also mentioned in section 6 of this document: https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb
|
|
26571
|
+
* @param encodeOptions Options controlling how special tokens are handled.
|
|
26571
26572
|
*/
|
|
26572
|
-
*encodeChatGenerator(chat, model = this.modelName) {
|
|
26573
|
+
*encodeChatGenerator(chat, model = this.modelName, encodeOptions) {
|
|
26573
26574
|
if (!model) {
|
|
26574
26575
|
throw new Error("Model name must be provided either during initialization or passed in to the method.");
|
|
26575
26576
|
}
|
|
@@ -26595,12 +26596,12 @@ var init_GptEncoding = __esm({
|
|
|
26595
26596
|
if (encodedRoleSeparator.length > 0) {
|
|
26596
26597
|
yield encodedRoleSeparator;
|
|
26597
26598
|
}
|
|
26598
|
-
yield* this.encodeGenerator(content);
|
|
26599
|
+
yield* this.encodeGenerator(content, encodeOptions);
|
|
26599
26600
|
yield [chatEndToken];
|
|
26600
26601
|
yield encodedMessageSeparator;
|
|
26601
26602
|
}
|
|
26602
26603
|
yield [chatStartToken];
|
|
26603
|
-
yield* this.encodeGenerator("assistant");
|
|
26604
|
+
yield* this.encodeGenerator("assistant", encodeOptions);
|
|
26604
26605
|
if (encodedRoleSeparator.length > 0) {
|
|
26605
26606
|
yield encodedRoleSeparator;
|
|
26606
26607
|
}
|
|
@@ -26611,15 +26612,20 @@ var init_GptEncoding = __esm({
|
|
|
26611
26612
|
* Returns tokens assuming the 'gpt-3.5-turbo-0301' / 'gpt-4-0314' format.
|
|
26612
26613
|
* Based on OpenAI's guidelines: https://github.com/openai/openai-python/blob/main/chatml.md
|
|
26613
26614
|
* Also mentioned in section 6 of this document: https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb
|
|
26615
|
+
* @param encodeOptions Options controlling how special tokens are handled.
|
|
26614
26616
|
*/
|
|
26615
|
-
encodeChat(chat, model = this.modelName) {
|
|
26616
|
-
return [...this.encodeChatGenerator(chat, model)].flat();
|
|
26617
|
+
encodeChat(chat, model = this.modelName, encodeOptions) {
|
|
26618
|
+
return [...this.encodeChatGenerator(chat, model, encodeOptions)].flat();
|
|
26617
26619
|
}
|
|
26618
26620
|
/**
|
|
26621
|
+
* Checks whether the provided input stays within the provided token limit.
|
|
26622
|
+
* @param input The string or chat messages to evaluate.
|
|
26623
|
+
* @param tokenLimit The maximum allowed number of tokens.
|
|
26624
|
+
* @param encodeOptions Options controlling how special tokens are handled.
|
|
26619
26625
|
* @returns {false | number} false if token limit is exceeded, otherwise the number of tokens
|
|
26620
26626
|
*/
|
|
26621
|
-
isWithinTokenLimit(input, tokenLimit) {
|
|
26622
|
-
const tokenGenerator = typeof input === "string" ? this.encodeGenerator(input) : this.encodeChatGenerator(input);
|
|
26627
|
+
isWithinTokenLimit(input, tokenLimit, encodeOptions) {
|
|
26628
|
+
const tokenGenerator = typeof input === "string" ? this.encodeGenerator(input, encodeOptions) : this.encodeChatGenerator(input, void 0, encodeOptions);
|
|
26623
26629
|
let count = 0;
|
|
26624
26630
|
for (const tokens of tokenGenerator) {
|
|
26625
26631
|
count += tokens.length;
|
|
@@ -26631,6 +26637,8 @@ var init_GptEncoding = __esm({
|
|
|
26631
26637
|
}
|
|
26632
26638
|
/**
|
|
26633
26639
|
* Counts the number of tokens in the input.
|
|
26640
|
+
* @param input The string or chat messages to evaluate.
|
|
26641
|
+
* @param encodeOptions Options controlling how special tokens are handled.
|
|
26634
26642
|
* @returns {number} The number of tokens.
|
|
26635
26643
|
*/
|
|
26636
26644
|
countTokens(input, encodeOptions) {
|
|
@@ -26644,7 +26652,7 @@ var init_GptEncoding = __esm({
|
|
|
26644
26652
|
}
|
|
26645
26653
|
return this.bytePairEncodingCoreProcessor.countNative(input, specialTokenConfig.allowedSpecial);
|
|
26646
26654
|
}
|
|
26647
|
-
const tokenGenerator = this.encodeChatGenerator(input);
|
|
26655
|
+
const tokenGenerator = this.encodeChatGenerator(input, void 0, encodeOptions);
|
|
26648
26656
|
let count = 0;
|
|
26649
26657
|
for (const tokens of tokenGenerator) {
|
|
26650
26658
|
count += tokens.length;
|
|
@@ -27082,6 +27090,226 @@ var init_tokenCounter = __esm({
|
|
|
27082
27090
|
}
|
|
27083
27091
|
});
|
|
27084
27092
|
|
|
27093
|
+
// src/agent/storage/StorageAdapter.js
|
|
27094
|
+
var StorageAdapter;
|
|
27095
|
+
var init_StorageAdapter = __esm({
|
|
27096
|
+
"src/agent/storage/StorageAdapter.js"() {
|
|
27097
|
+
"use strict";
|
|
27098
|
+
StorageAdapter = class {
|
|
27099
|
+
/**
|
|
27100
|
+
* Load conversation history for a session
|
|
27101
|
+
* @param {string} sessionId - Session identifier
|
|
27102
|
+
* @returns {Promise<Array<Object>>} Array of message objects with {role, content, ...}
|
|
27103
|
+
*/
|
|
27104
|
+
async loadHistory(sessionId) {
|
|
27105
|
+
throw new Error("StorageAdapter.loadHistory() must be implemented by subclass");
|
|
27106
|
+
}
|
|
27107
|
+
/**
|
|
27108
|
+
* Save a message to storage
|
|
27109
|
+
* @param {string} sessionId - Session identifier
|
|
27110
|
+
* @param {Object} message - Message object { role, content, ... }
|
|
27111
|
+
* @returns {Promise<void>}
|
|
27112
|
+
*/
|
|
27113
|
+
async saveMessage(sessionId, message) {
|
|
27114
|
+
throw new Error("StorageAdapter.saveMessage() must be implemented by subclass");
|
|
27115
|
+
}
|
|
27116
|
+
/**
|
|
27117
|
+
* Clear history for a session
|
|
27118
|
+
* @param {string} sessionId - Session identifier
|
|
27119
|
+
* @returns {Promise<void>}
|
|
27120
|
+
*/
|
|
27121
|
+
async clearHistory(sessionId) {
|
|
27122
|
+
throw new Error("StorageAdapter.clearHistory() must be implemented by subclass");
|
|
27123
|
+
}
|
|
27124
|
+
/**
|
|
27125
|
+
* Get session metadata (optional)
|
|
27126
|
+
* @param {string} sessionId - Session identifier
|
|
27127
|
+
* @returns {Promise<Object|null>} Session metadata or null
|
|
27128
|
+
*/
|
|
27129
|
+
async getSessionMetadata(sessionId) {
|
|
27130
|
+
return null;
|
|
27131
|
+
}
|
|
27132
|
+
/**
|
|
27133
|
+
* Update session activity timestamp (optional)
|
|
27134
|
+
* @param {string} sessionId - Session identifier
|
|
27135
|
+
* @returns {Promise<void>}
|
|
27136
|
+
*/
|
|
27137
|
+
async updateSessionActivity(sessionId) {
|
|
27138
|
+
}
|
|
27139
|
+
};
|
|
27140
|
+
}
|
|
27141
|
+
});
|
|
27142
|
+
|
|
27143
|
+
// src/agent/storage/InMemoryStorageAdapter.js
|
|
27144
|
+
var InMemoryStorageAdapter;
|
|
27145
|
+
var init_InMemoryStorageAdapter = __esm({
|
|
27146
|
+
"src/agent/storage/InMemoryStorageAdapter.js"() {
|
|
27147
|
+
"use strict";
|
|
27148
|
+
init_StorageAdapter();
|
|
27149
|
+
InMemoryStorageAdapter = class extends StorageAdapter {
|
|
27150
|
+
constructor() {
|
|
27151
|
+
super();
|
|
27152
|
+
this.sessions = /* @__PURE__ */ new Map();
|
|
27153
|
+
}
|
|
27154
|
+
async loadHistory(sessionId) {
|
|
27155
|
+
const session = this.sessions.get(sessionId);
|
|
27156
|
+
return session ? session.messages : [];
|
|
27157
|
+
}
|
|
27158
|
+
async saveMessage(sessionId, message) {
|
|
27159
|
+
if (!this.sessions.has(sessionId)) {
|
|
27160
|
+
this.sessions.set(sessionId, {
|
|
27161
|
+
messages: [],
|
|
27162
|
+
metadata: {
|
|
27163
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
27164
|
+
lastActivity: (/* @__PURE__ */ new Date()).toISOString()
|
|
27165
|
+
}
|
|
27166
|
+
});
|
|
27167
|
+
}
|
|
27168
|
+
const session = this.sessions.get(sessionId);
|
|
27169
|
+
session.messages.push(message);
|
|
27170
|
+
session.metadata.lastActivity = (/* @__PURE__ */ new Date()).toISOString();
|
|
27171
|
+
}
|
|
27172
|
+
async clearHistory(sessionId) {
|
|
27173
|
+
this.sessions.delete(sessionId);
|
|
27174
|
+
}
|
|
27175
|
+
async getSessionMetadata(sessionId) {
|
|
27176
|
+
const session = this.sessions.get(sessionId);
|
|
27177
|
+
return session ? session.metadata : null;
|
|
27178
|
+
}
|
|
27179
|
+
async updateSessionActivity(sessionId) {
|
|
27180
|
+
const session = this.sessions.get(sessionId);
|
|
27181
|
+
if (session) {
|
|
27182
|
+
session.metadata.lastActivity = (/* @__PURE__ */ new Date()).toISOString();
|
|
27183
|
+
}
|
|
27184
|
+
}
|
|
27185
|
+
};
|
|
27186
|
+
}
|
|
27187
|
+
});
|
|
27188
|
+
|
|
27189
|
+
// src/agent/hooks/HookManager.js
|
|
27190
|
+
var HookManager, HOOK_TYPES;
|
|
27191
|
+
var init_HookManager = __esm({
|
|
27192
|
+
"src/agent/hooks/HookManager.js"() {
|
|
27193
|
+
"use strict";
|
|
27194
|
+
HookManager = class {
|
|
27195
|
+
constructor() {
|
|
27196
|
+
this.hooks = /* @__PURE__ */ new Map();
|
|
27197
|
+
}
|
|
27198
|
+
/**
|
|
27199
|
+
* Register a hook callback
|
|
27200
|
+
* @param {string} hookName - Name of the hook
|
|
27201
|
+
* @param {Function} callback - Callback function
|
|
27202
|
+
* @returns {Function} Unregister function
|
|
27203
|
+
*/
|
|
27204
|
+
on(hookName, callback) {
|
|
27205
|
+
if (!this.hooks.has(hookName)) {
|
|
27206
|
+
this.hooks.set(hookName, /* @__PURE__ */ new Set());
|
|
27207
|
+
}
|
|
27208
|
+
this.hooks.get(hookName).add(callback);
|
|
27209
|
+
return () => this.off(hookName, callback);
|
|
27210
|
+
}
|
|
27211
|
+
/**
|
|
27212
|
+
* Register a one-time hook callback
|
|
27213
|
+
* @param {string} hookName - Name of the hook
|
|
27214
|
+
* @param {Function} callback - Callback function
|
|
27215
|
+
* @returns {Function} Unregister function
|
|
27216
|
+
*/
|
|
27217
|
+
once(hookName, callback) {
|
|
27218
|
+
const wrappedCallback = async (data2) => {
|
|
27219
|
+
this.off(hookName, wrappedCallback);
|
|
27220
|
+
await callback(data2);
|
|
27221
|
+
};
|
|
27222
|
+
return this.on(hookName, wrappedCallback);
|
|
27223
|
+
}
|
|
27224
|
+
/**
|
|
27225
|
+
* Unregister a hook callback
|
|
27226
|
+
* @param {string} hookName - Name of the hook
|
|
27227
|
+
* @param {Function} callback - Callback function
|
|
27228
|
+
*/
|
|
27229
|
+
off(hookName, callback) {
|
|
27230
|
+
const callbacks = this.hooks.get(hookName);
|
|
27231
|
+
if (callbacks) {
|
|
27232
|
+
callbacks.delete(callback);
|
|
27233
|
+
}
|
|
27234
|
+
}
|
|
27235
|
+
/**
|
|
27236
|
+
* Emit a hook event
|
|
27237
|
+
* @param {string} hookName - Name of the hook
|
|
27238
|
+
* @param {any} data - Data to pass to callbacks
|
|
27239
|
+
* @returns {Promise<void>}
|
|
27240
|
+
*/
|
|
27241
|
+
async emit(hookName, data2) {
|
|
27242
|
+
const callbacks = this.hooks.get(hookName);
|
|
27243
|
+
if (!callbacks || callbacks.size === 0) return;
|
|
27244
|
+
const promises = Array.from(callbacks).map((callback) => {
|
|
27245
|
+
try {
|
|
27246
|
+
return Promise.resolve(callback(data2));
|
|
27247
|
+
} catch (error2) {
|
|
27248
|
+
return Promise.reject(error2);
|
|
27249
|
+
}
|
|
27250
|
+
});
|
|
27251
|
+
const results = await Promise.allSettled(promises);
|
|
27252
|
+
results.forEach((result, index) => {
|
|
27253
|
+
if (result.status === "rejected") {
|
|
27254
|
+
console.error(`[HookManager] Error in hook "${hookName}" (callback ${index + 1}):`, result.reason);
|
|
27255
|
+
}
|
|
27256
|
+
});
|
|
27257
|
+
}
|
|
27258
|
+
/**
|
|
27259
|
+
* Clear all hooks or hooks for a specific event
|
|
27260
|
+
* @param {string} [hookName] - Optional hook name to clear
|
|
27261
|
+
*/
|
|
27262
|
+
clear(hookName) {
|
|
27263
|
+
if (hookName) {
|
|
27264
|
+
this.hooks.delete(hookName);
|
|
27265
|
+
} else {
|
|
27266
|
+
this.hooks.clear();
|
|
27267
|
+
}
|
|
27268
|
+
}
|
|
27269
|
+
/**
|
|
27270
|
+
* Get list of registered hook names
|
|
27271
|
+
* @returns {string[]} Array of hook names
|
|
27272
|
+
*/
|
|
27273
|
+
getHookNames() {
|
|
27274
|
+
return Array.from(this.hooks.keys());
|
|
27275
|
+
}
|
|
27276
|
+
/**
|
|
27277
|
+
* Get number of callbacks for a hook
|
|
27278
|
+
* @param {string} hookName - Name of the hook
|
|
27279
|
+
* @returns {number} Number of callbacks
|
|
27280
|
+
*/
|
|
27281
|
+
getCallbackCount(hookName) {
|
|
27282
|
+
const callbacks = this.hooks.get(hookName);
|
|
27283
|
+
return callbacks ? callbacks.size : 0;
|
|
27284
|
+
}
|
|
27285
|
+
};
|
|
27286
|
+
HOOK_TYPES = {
|
|
27287
|
+
// Lifecycle hooks
|
|
27288
|
+
AGENT_INITIALIZED: "agent:initialized",
|
|
27289
|
+
AGENT_CLEANUP: "agent:cleanup",
|
|
27290
|
+
// Message hooks
|
|
27291
|
+
MESSAGE_USER: "message:user",
|
|
27292
|
+
MESSAGE_ASSISTANT: "message:assistant",
|
|
27293
|
+
MESSAGE_SYSTEM: "message:system",
|
|
27294
|
+
// Tool execution hooks
|
|
27295
|
+
TOOL_START: "tool:start",
|
|
27296
|
+
TOOL_END: "tool:end",
|
|
27297
|
+
TOOL_ERROR: "tool:error",
|
|
27298
|
+
// AI streaming hooks
|
|
27299
|
+
AI_STREAM_START: "ai:stream:start",
|
|
27300
|
+
AI_STREAM_DELTA: "ai:stream:delta",
|
|
27301
|
+
AI_STREAM_END: "ai:stream:end",
|
|
27302
|
+
// Storage hooks
|
|
27303
|
+
STORAGE_LOAD: "storage:load",
|
|
27304
|
+
STORAGE_SAVE: "storage:save",
|
|
27305
|
+
STORAGE_CLEAR: "storage:clear",
|
|
27306
|
+
// Iteration hooks
|
|
27307
|
+
ITERATION_START: "iteration:start",
|
|
27308
|
+
ITERATION_END: "iteration:end"
|
|
27309
|
+
};
|
|
27310
|
+
}
|
|
27311
|
+
});
|
|
27312
|
+
|
|
27085
27313
|
// src/directory-resolver.js
|
|
27086
27314
|
async function getPackageBinDir() {
|
|
27087
27315
|
const debug = process.env.DEBUG === "1" || process.env.VERBOSE === "1";
|
|
@@ -41524,6 +41752,23 @@ var init_probeTool = __esm({
|
|
|
41524
41752
|
}
|
|
41525
41753
|
});
|
|
41526
41754
|
|
|
41755
|
+
// src/agent/storage/index.js
|
|
41756
|
+
var init_storage = __esm({
|
|
41757
|
+
"src/agent/storage/index.js"() {
|
|
41758
|
+
"use strict";
|
|
41759
|
+
init_StorageAdapter();
|
|
41760
|
+
init_InMemoryStorageAdapter();
|
|
41761
|
+
}
|
|
41762
|
+
});
|
|
41763
|
+
|
|
41764
|
+
// src/agent/hooks/index.js
|
|
41765
|
+
var init_hooks = __esm({
|
|
41766
|
+
"src/agent/hooks/index.js"() {
|
|
41767
|
+
"use strict";
|
|
41768
|
+
init_HookManager();
|
|
41769
|
+
}
|
|
41770
|
+
});
|
|
41771
|
+
|
|
41527
41772
|
// src/index.js
|
|
41528
41773
|
var init_index = __esm({
|
|
41529
41774
|
"src/index.js"() {
|
|
@@ -41543,6 +41788,8 @@ var init_index = __esm({
|
|
|
41543
41788
|
init_ProbeAgent();
|
|
41544
41789
|
init_simpleTelemetry();
|
|
41545
41790
|
init_probeTool();
|
|
41791
|
+
init_storage();
|
|
41792
|
+
init_hooks();
|
|
41546
41793
|
}
|
|
41547
41794
|
});
|
|
41548
41795
|
|
|
@@ -72657,6 +72904,8 @@ var init_ProbeAgent = __esm({
|
|
|
72657
72904
|
import_promises2 = require("fs/promises");
|
|
72658
72905
|
import_path10 = require("path");
|
|
72659
72906
|
init_tokenCounter();
|
|
72907
|
+
init_InMemoryStorageAdapter();
|
|
72908
|
+
init_HookManager();
|
|
72660
72909
|
init_tools2();
|
|
72661
72910
|
init_common2();
|
|
72662
72911
|
init_probeTool();
|
|
@@ -72689,6 +72938,8 @@ var init_ProbeAgent = __esm({
|
|
|
72689
72938
|
* @param {string} [options.mcpConfigPath] - Path to MCP configuration file
|
|
72690
72939
|
* @param {Object} [options.mcpConfig] - MCP configuration object (overrides mcpConfigPath)
|
|
72691
72940
|
* @param {Array} [options.mcpServers] - Deprecated, use mcpConfig instead
|
|
72941
|
+
* @param {Object} [options.storageAdapter] - Custom storage adapter for history management
|
|
72942
|
+
* @param {Object} [options.hooks] - Hook callbacks for events (e.g., {'tool:start': callback})
|
|
72692
72943
|
*/
|
|
72693
72944
|
constructor(options = {}) {
|
|
72694
72945
|
this.sessionId = options.sessionId || (0, import_crypto5.randomUUID)();
|
|
@@ -72702,6 +72953,13 @@ var init_ProbeAgent = __esm({
|
|
|
72702
72953
|
this.maxResponseTokens = options.maxResponseTokens || parseInt(process.env.MAX_RESPONSE_TOKENS || "0", 10) || null;
|
|
72703
72954
|
this.maxIterations = options.maxIterations || null;
|
|
72704
72955
|
this.disableMermaidValidation = !!options.disableMermaidValidation;
|
|
72956
|
+
this.storageAdapter = options.storageAdapter || new InMemoryStorageAdapter();
|
|
72957
|
+
this.hooks = new HookManager();
|
|
72958
|
+
if (options.hooks) {
|
|
72959
|
+
for (const [hookName, callback] of Object.entries(options.hooks)) {
|
|
72960
|
+
this.hooks.on(hookName, callback);
|
|
72961
|
+
}
|
|
72962
|
+
}
|
|
72705
72963
|
this.enableBash = !!options.enableBash;
|
|
72706
72964
|
this.bashConfig = options.bashConfig || {};
|
|
72707
72965
|
if (options.allowedFolders && Array.isArray(options.allowedFolders)) {
|
|
@@ -72735,9 +72993,23 @@ var init_ProbeAgent = __esm({
|
|
|
72735
72993
|
}
|
|
72736
72994
|
/**
|
|
72737
72995
|
* Initialize the agent asynchronously (must be called after constructor)
|
|
72738
|
-
* This method initializes MCP and merges MCP tools into the tool list
|
|
72996
|
+
* This method initializes MCP and merges MCP tools into the tool list, and loads history from storage
|
|
72739
72997
|
*/
|
|
72740
72998
|
async initialize() {
|
|
72999
|
+
try {
|
|
73000
|
+
const history = await this.storageAdapter.loadHistory(this.sessionId);
|
|
73001
|
+
this.history = history;
|
|
73002
|
+
if (this.debug && history.length > 0) {
|
|
73003
|
+
console.log(`[DEBUG] Loaded ${history.length} messages from storage for session ${this.sessionId}`);
|
|
73004
|
+
}
|
|
73005
|
+
await this.hooks.emit(HOOK_TYPES.STORAGE_LOAD, {
|
|
73006
|
+
sessionId: this.sessionId,
|
|
73007
|
+
messages: history
|
|
73008
|
+
});
|
|
73009
|
+
} catch (error2) {
|
|
73010
|
+
console.error(`[ERROR] Failed to load history from storage:`, error2);
|
|
73011
|
+
this.history = [];
|
|
73012
|
+
}
|
|
72741
73013
|
if (this.enableMcp && !this._mcpInitialized) {
|
|
72742
73014
|
this._mcpInitialized = true;
|
|
72743
73015
|
try {
|
|
@@ -72770,6 +73042,10 @@ var init_ProbeAgent = __esm({
|
|
|
72770
73042
|
this.mcpBridge = null;
|
|
72771
73043
|
}
|
|
72772
73044
|
}
|
|
73045
|
+
await this.hooks.emit(HOOK_TYPES.AGENT_INITIALIZED, {
|
|
73046
|
+
sessionId: this.sessionId,
|
|
73047
|
+
agent: this
|
|
73048
|
+
});
|
|
72773
73049
|
}
|
|
72774
73050
|
/**
|
|
72775
73051
|
* Initialize tools with configuration
|
|
@@ -72821,7 +73097,7 @@ var init_ProbeAgent = __esm({
|
|
|
72821
73097
|
}
|
|
72822
73098
|
const anthropicApiKey = process.env.ANTHROPIC_API_KEY;
|
|
72823
73099
|
const openaiApiKey = process.env.OPENAI_API_KEY;
|
|
72824
|
-
const googleApiKey = process.env.GOOGLE_API_KEY;
|
|
73100
|
+
const googleApiKey = process.env.GOOGLE_GENERATIVE_AI_API_KEY || process.env.GOOGLE_API_KEY;
|
|
72825
73101
|
const awsAccessKeyId = process.env.AWS_ACCESS_KEY_ID;
|
|
72826
73102
|
const awsSecretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;
|
|
72827
73103
|
const awsRegion = process.env.AWS_REGION;
|
|
@@ -72869,7 +73145,7 @@ var init_ProbeAgent = __esm({
|
|
|
72869
73145
|
} else if (awsAccessKeyId && awsSecretAccessKey && awsRegion || awsApiKey) {
|
|
72870
73146
|
this.initializeBedrockModel(awsAccessKeyId, awsSecretAccessKey, awsRegion, awsSessionToken, awsApiKey, awsBedrockBaseUrl, modelName);
|
|
72871
73147
|
} else {
|
|
72872
|
-
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.");
|
|
73148
|
+
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.");
|
|
72873
73149
|
}
|
|
72874
73150
|
}
|
|
72875
73151
|
/**
|
|
@@ -73507,6 +73783,12 @@ You are working with a repository located at: ${searchDirectory}
|
|
|
73507
73783
|
options = schemaOrOptions || {};
|
|
73508
73784
|
}
|
|
73509
73785
|
try {
|
|
73786
|
+
const oldHistoryLength = this.history.length;
|
|
73787
|
+
await this.hooks.emit(HOOK_TYPES.MESSAGE_USER, {
|
|
73788
|
+
sessionId: this.sessionId,
|
|
73789
|
+
message,
|
|
73790
|
+
images
|
|
73791
|
+
});
|
|
73510
73792
|
const systemMessage = await this.getSystemMessage();
|
|
73511
73793
|
let userMessage = { role: "user", content: message.trim() };
|
|
73512
73794
|
if (images && images.length > 0) {
|
|
@@ -73592,6 +73874,9 @@ You are working with a repository located at: ${searchDirectory}
|
|
|
73592
73874
|
});
|
|
73593
73875
|
for await (const delta of result.textStream) {
|
|
73594
73876
|
assistantResponseContent += delta;
|
|
73877
|
+
if (options.onStream) {
|
|
73878
|
+
options.onStream(delta);
|
|
73879
|
+
}
|
|
73595
73880
|
}
|
|
73596
73881
|
const usage = await result.usage;
|
|
73597
73882
|
if (usage) {
|
|
@@ -73656,6 +73941,13 @@ You are working with a repository located at: ${searchDirectory}
|
|
|
73656
73941
|
const validation = attemptCompletionSchema.safeParse(params);
|
|
73657
73942
|
if (validation.success) {
|
|
73658
73943
|
finalResult = validation.data.result;
|
|
73944
|
+
if (options.onStream && finalResult) {
|
|
73945
|
+
const chunkSize = 50;
|
|
73946
|
+
for (let i3 = 0; i3 < finalResult.length; i3 += chunkSize) {
|
|
73947
|
+
const chunk = finalResult.slice(i3, Math.min(i3 + chunkSize, finalResult.length));
|
|
73948
|
+
options.onStream(chunk);
|
|
73949
|
+
}
|
|
73950
|
+
}
|
|
73659
73951
|
if (this.debug) console.log(`[DEBUG] Task completed successfully with result: ${finalResult.substring(0, 100)}...`);
|
|
73660
73952
|
} else {
|
|
73661
73953
|
console.error(`[ERROR] Invalid attempt_completion parameters:`, validation.error);
|
|
@@ -73730,7 +74022,9 @@ ${toolResultContent}
|
|
|
73730
74022
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
73731
74023
|
name: toolName,
|
|
73732
74024
|
args: toolParams,
|
|
73733
|
-
status: "started"
|
|
74025
|
+
status: "started",
|
|
74026
|
+
pauseStream: true
|
|
74027
|
+
// Signal to pause text streaming
|
|
73734
74028
|
});
|
|
73735
74029
|
const executeToolCall = async () => {
|
|
73736
74030
|
if (toolName === "delegate") {
|
|
@@ -73914,6 +74208,18 @@ IMPORTANT: When using <attempt_complete>, this must be the ONLY content in your
|
|
|
73914
74208
|
}
|
|
73915
74209
|
}
|
|
73916
74210
|
this.tokenCounter.updateHistory(this.history);
|
|
74211
|
+
try {
|
|
74212
|
+
const messagesToSave = currentMessages.slice(oldHistoryLength);
|
|
74213
|
+
for (const message2 of messagesToSave) {
|
|
74214
|
+
await this.storageAdapter.saveMessage(this.sessionId, message2);
|
|
74215
|
+
await this.hooks.emit(HOOK_TYPES.STORAGE_SAVE, {
|
|
74216
|
+
sessionId: this.sessionId,
|
|
74217
|
+
message: message2
|
|
74218
|
+
});
|
|
74219
|
+
}
|
|
74220
|
+
} catch (error2) {
|
|
74221
|
+
console.error(`[ERROR] Failed to save messages to storage:`, error2);
|
|
74222
|
+
}
|
|
73917
74223
|
const reachedMaxIterations = currentIteration >= maxIterations && !completionAttempted;
|
|
73918
74224
|
if (options.schema && !options._schemaFormatted && !completionAttempted && !reachedMaxIterations) {
|
|
73919
74225
|
if (this.debug) {
|
|
@@ -74278,10 +74584,18 @@ Convert your previous response content into actual JSON data that follows this s
|
|
|
74278
74584
|
/**
|
|
74279
74585
|
* Clear conversation history and reset counters
|
|
74280
74586
|
*/
|
|
74281
|
-
clearHistory() {
|
|
74587
|
+
async clearHistory() {
|
|
74588
|
+
try {
|
|
74589
|
+
await this.storageAdapter.clearHistory(this.sessionId);
|
|
74590
|
+
} catch (error2) {
|
|
74591
|
+
console.error(`[ERROR] Failed to clear history in storage:`, error2);
|
|
74592
|
+
}
|
|
74282
74593
|
this.history = [];
|
|
74283
74594
|
this.tokenCounter.clear();
|
|
74284
74595
|
clearToolExecutionData(this.sessionId);
|
|
74596
|
+
await this.hooks.emit(HOOK_TYPES.STORAGE_CLEAR, {
|
|
74597
|
+
sessionId: this.sessionId
|
|
74598
|
+
});
|
|
74285
74599
|
if (this.debug) {
|
|
74286
74600
|
console.log(`[DEBUG] Cleared conversation history and reset counters for session ${this.sessionId}`);
|
|
74287
74601
|
}
|