@jarvis-agent/core 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/agent-llm.d.ts +2 -2
- package/dist/agent/agent-llm.d.ts.map +1 -1
- package/dist/agent/base.d.ts +2 -2
- package/dist/agent/base.d.ts.map +1 -1
- package/dist/agent/browser/build-dom-tree.d.ts.map +1 -1
- package/dist/chat/chat-agent.d.ts +2 -2
- package/dist/chat/chat-agent.d.ts.map +1 -1
- package/dist/chat/chat-llm.d.ts +3 -3
- package/dist/chat/chat-llm.d.ts.map +1 -1
- package/dist/index.cjs +87 -145
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +87 -145
- package/dist/index.esm.js.map +1 -1
- package/dist/llm/react.d.ts +6 -6
- package/dist/llm/react.d.ts.map +1 -1
- package/dist/memory/index.d.ts +2 -2
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/llm.types.d.ts +2 -2
- package/dist/types/llm.types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -39433,12 +39433,13 @@ async function callLLM(rlm, request, streamCallback, errorHandler, finishHandler
|
|
|
39433
39433
|
await errorHandler(request, e, retryNum);
|
|
39434
39434
|
}
|
|
39435
39435
|
Log.warn("callLLM abort error: ", e);
|
|
39436
|
-
|
|
39437
|
-
|
|
39438
|
-
|
|
39439
|
-
|
|
39440
|
-
|
|
39441
|
-
|
|
39436
|
+
const parts = [];
|
|
39437
|
+
if (thinkText)
|
|
39438
|
+
parts.push({ type: "reasoning", text: thinkText });
|
|
39439
|
+
if (streamText)
|
|
39440
|
+
parts.push({ type: "text", text: streamText });
|
|
39441
|
+
parts.push(...toolParts);
|
|
39442
|
+
return parts;
|
|
39442
39443
|
}
|
|
39443
39444
|
else {
|
|
39444
39445
|
if (retryNum < config$1.maxRetryNum) {
|
|
@@ -39454,30 +39455,34 @@ async function callLLM(rlm, request, streamCallback, errorHandler, finishHandler
|
|
|
39454
39455
|
finally {
|
|
39455
39456
|
reader && reader.releaseLock();
|
|
39456
39457
|
}
|
|
39457
|
-
|
|
39458
|
-
|
|
39459
|
-
|
|
39460
|
-
|
|
39461
|
-
|
|
39462
|
-
|
|
39458
|
+
const resultParts = [];
|
|
39459
|
+
if (thinkText)
|
|
39460
|
+
resultParts.push({ type: "reasoning", text: thinkText });
|
|
39461
|
+
if (streamText)
|
|
39462
|
+
resultParts.push({ type: "text", text: streamText });
|
|
39463
|
+
resultParts.push(...toolParts);
|
|
39464
|
+
return resultParts;
|
|
39463
39465
|
}
|
|
39464
39466
|
function convertAssistantContent(assistantParts) {
|
|
39465
39467
|
return assistantParts
|
|
39466
|
-
.filter((part) => part.type
|
|
39467
|
-
.map((part) =>
|
|
39468
|
-
|
|
39469
|
-
type: "text",
|
|
39470
|
-
|
|
39468
|
+
.filter((part) => part.type === "text" || part.type === "reasoning" || part.type === "tool-call")
|
|
39469
|
+
.map((part) => {
|
|
39470
|
+
if (part.type === "text") {
|
|
39471
|
+
return { type: "text", text: part.text };
|
|
39472
|
+
}
|
|
39473
|
+
if (part.type === "reasoning") {
|
|
39474
|
+
return { type: "reasoning", text: part.text };
|
|
39471
39475
|
}
|
|
39472
|
-
|
|
39476
|
+
return {
|
|
39473
39477
|
type: "tool-call",
|
|
39474
39478
|
toolCallId: part.toolCallId,
|
|
39475
39479
|
toolName: part.toolName,
|
|
39476
|
-
input: typeof part.input
|
|
39480
|
+
input: typeof part.input === "string"
|
|
39477
39481
|
? JSON.parse(part.input || "{}")
|
|
39478
39482
|
: part.input || {},
|
|
39479
39483
|
providerOptions: part.providerOptions,
|
|
39480
|
-
}
|
|
39484
|
+
};
|
|
39485
|
+
});
|
|
39481
39486
|
}
|
|
39482
39487
|
|
|
39483
39488
|
const global = {
|
|
@@ -41599,8 +41604,8 @@ class Agent {
|
|
|
41599
41604
|
if (results.length == 0) {
|
|
41600
41605
|
return null;
|
|
41601
41606
|
}
|
|
41602
|
-
if (results.every((s) => s.type
|
|
41603
|
-
return results.map((s) => s.text).join("\n\n");
|
|
41607
|
+
if (results.every((s) => s.type === "text" || s.type === "reasoning")) {
|
|
41608
|
+
return results.filter((s) => s.type === "text").map((s) => s.text).join("\n\n");
|
|
41604
41609
|
}
|
|
41605
41610
|
const toolCalls = results.filter((s) => s.type == "tool-call");
|
|
41606
41611
|
if (toolCalls.length > 1 &&
|
|
@@ -42522,30 +42527,19 @@ function run_build_dom_tree() {
|
|
|
42522
42527
|
/**
|
|
42523
42528
|
* Get clickable elements on the page
|
|
42524
42529
|
*
|
|
42525
|
-
* @param {*}
|
|
42530
|
+
* @param {*} doHighlightElements Is highlighted
|
|
42526
42531
|
* @param {*} includeAttributes [attr_names...]
|
|
42527
|
-
* @returns { element_str,
|
|
42532
|
+
* @returns { element_str, selector_map }
|
|
42528
42533
|
*/
|
|
42529
|
-
function get_clickable_elements(
|
|
42534
|
+
function get_clickable_elements(doHighlightElements = true, includeAttributes) {
|
|
42530
42535
|
window.clickable_elements = {};
|
|
42531
42536
|
computedStyleCache = new WeakMap();
|
|
42532
42537
|
document.querySelectorAll("[eko-user-highlight-id]").forEach(ele => ele.removeAttribute("eko-user-highlight-id"));
|
|
42533
|
-
let page_tree = build_dom_tree(
|
|
42538
|
+
let page_tree = build_dom_tree(doHighlightElements);
|
|
42534
42539
|
let element_tree = parse_node(page_tree);
|
|
42540
|
+
let selector_map = create_selector_map(element_tree);
|
|
42535
42541
|
let element_str = clickable_elements_to_string(element_tree, includeAttributes);
|
|
42536
|
-
|
|
42537
|
-
width: window.innerWidth || document.documentElement.clientWidth,
|
|
42538
|
-
height: window.innerHeight || document.documentElement.clientHeight,
|
|
42539
|
-
};
|
|
42540
|
-
if (markHighlightElements) {
|
|
42541
|
-
let selector_map = {};
|
|
42542
|
-
// selector_map = create_selector_map(element_tree);
|
|
42543
|
-
return { element_str, client_rect, selector_map };
|
|
42544
|
-
}
|
|
42545
|
-
else {
|
|
42546
|
-
let area_map = create_area_map(element_tree);
|
|
42547
|
-
return { element_str, client_rect, area_map };
|
|
42548
|
-
}
|
|
42542
|
+
return { element_str, selector_map };
|
|
42549
42543
|
}
|
|
42550
42544
|
function get_highlight_element(highlightIndex) {
|
|
42551
42545
|
let element = document.querySelector(`[eko-user-highlight-id="eko-highlight-${highlightIndex}"]`);
|
|
@@ -42644,13 +42638,12 @@ function run_build_dom_tree() {
|
|
|
42644
42638
|
process_node(element_tree);
|
|
42645
42639
|
return formatted_text.join('\n');
|
|
42646
42640
|
}
|
|
42647
|
-
function
|
|
42648
|
-
let
|
|
42641
|
+
function create_selector_map(element_tree) {
|
|
42642
|
+
let selector_map = {};
|
|
42649
42643
|
function process_node(node) {
|
|
42650
42644
|
if (node.tagName) {
|
|
42651
42645
|
if (node.highlightIndex != null) {
|
|
42652
|
-
|
|
42653
|
-
area_map[node.highlightIndex] = get_element_real_bounding_rect(element);
|
|
42646
|
+
selector_map[node.highlightIndex] = node;
|
|
42654
42647
|
}
|
|
42655
42648
|
for (let i = 0; i < node.children.length; i++) {
|
|
42656
42649
|
process_node(node.children[i]);
|
|
@@ -42658,38 +42651,7 @@ function run_build_dom_tree() {
|
|
|
42658
42651
|
}
|
|
42659
42652
|
}
|
|
42660
42653
|
process_node(element_tree);
|
|
42661
|
-
return
|
|
42662
|
-
}
|
|
42663
|
-
function get_element_real_bounding_rect(element) {
|
|
42664
|
-
if (!element || !(element instanceof Element)) {
|
|
42665
|
-
return { x: 0, y: 0, width: 0, height: 0 };
|
|
42666
|
-
}
|
|
42667
|
-
let rect = element.getBoundingClientRect();
|
|
42668
|
-
let x = rect.left;
|
|
42669
|
-
let y = rect.top;
|
|
42670
|
-
let width = rect.width;
|
|
42671
|
-
let height = rect.height;
|
|
42672
|
-
let win = element.ownerDocument.defaultView;
|
|
42673
|
-
let maxDepth = 10;
|
|
42674
|
-
let depth = 0;
|
|
42675
|
-
while (win && win !== win.parent && depth < maxDepth) {
|
|
42676
|
-
depth++;
|
|
42677
|
-
const frameElement = win.frameElement;
|
|
42678
|
-
if (!frameElement) {
|
|
42679
|
-
break;
|
|
42680
|
-
}
|
|
42681
|
-
const frameRect = frameElement.getBoundingClientRect();
|
|
42682
|
-
x += frameRect.left;
|
|
42683
|
-
y += frameRect.top;
|
|
42684
|
-
// Consider the border and padding of the iframe.
|
|
42685
|
-
const frameStyle = getCachedComputedStyle(frameElement);
|
|
42686
|
-
x += parseFloat(frameStyle.borderLeftWidth) || 0;
|
|
42687
|
-
y += parseFloat(frameStyle.borderTopWidth) || 0;
|
|
42688
|
-
x += parseFloat(frameStyle.paddingLeft) || 0;
|
|
42689
|
-
y += parseFloat(frameStyle.paddingTop) || 0;
|
|
42690
|
-
win = win.parent;
|
|
42691
|
-
}
|
|
42692
|
-
return { x, y, width, height };
|
|
42654
|
+
return selector_map;
|
|
42693
42655
|
}
|
|
42694
42656
|
function parse_node(node_data, parent) {
|
|
42695
42657
|
if (!node_data) {
|
|
@@ -42729,9 +42691,8 @@ function run_build_dom_tree() {
|
|
|
42729
42691
|
}
|
|
42730
42692
|
return element_node;
|
|
42731
42693
|
}
|
|
42732
|
-
function build_dom_tree(
|
|
42694
|
+
function build_dom_tree(doHighlightElements) {
|
|
42733
42695
|
let highlightIndex = 0; // Reset highlight index
|
|
42734
|
-
let duplicates = new Set();
|
|
42735
42696
|
function highlightElement(element, index, parentIframe = null) {
|
|
42736
42697
|
// Create or get highlight container
|
|
42737
42698
|
let container = document.getElementById('eko-highlight-container');
|
|
@@ -42930,36 +42891,13 @@ function run_build_dom_tree() {
|
|
|
42930
42891
|
interactiveRoles.has(ariaRole) ||
|
|
42931
42892
|
(tabIndex !== null && tabIndex !== '-1') ||
|
|
42932
42893
|
element.getAttribute('data-action') === 'a-dropdown-select' ||
|
|
42933
|
-
element.getAttribute('data-action') === 'a-dropdown-button'
|
|
42934
|
-
element.getAttribute('contenteditable') === 'true';
|
|
42894
|
+
element.getAttribute('data-action') === 'a-dropdown-button';
|
|
42935
42895
|
if (hasInteractiveRole)
|
|
42936
42896
|
return true;
|
|
42937
|
-
//
|
|
42938
|
-
|
|
42939
|
-
//
|
|
42940
|
-
|
|
42941
|
-
// 'touchstart',
|
|
42942
|
-
// 'touchend',
|
|
42943
|
-
// 'keydown',
|
|
42944
|
-
// 'keyup',
|
|
42945
|
-
// 'focus',
|
|
42946
|
-
// 'blur',
|
|
42947
|
-
// ];
|
|
42948
|
-
const clickEventTypes = [
|
|
42949
|
-
'click',
|
|
42950
|
-
'mousedown',
|
|
42951
|
-
'mouseup',
|
|
42952
|
-
'touchstart',
|
|
42953
|
-
'touchend',
|
|
42954
|
-
];
|
|
42955
|
-
// Filter elements that have no real event listeners at all
|
|
42956
|
-
if (window.getEventListeners) {
|
|
42957
|
-
const listeners = window.getEventListeners(element);
|
|
42958
|
-
const hasRealClickListeners = clickEventTypes.some((type) => listeners[type]?.length > 0);
|
|
42959
|
-
if (!hasRealClickListeners) {
|
|
42960
|
-
return false;
|
|
42961
|
-
}
|
|
42962
|
-
}
|
|
42897
|
+
// Get computed style
|
|
42898
|
+
const style = getCachedComputedStyle(element);
|
|
42899
|
+
// Check if element has click-like styling
|
|
42900
|
+
const hasClickStyling = style.cursor === 'pointer' || element.style.cursor === 'pointer';
|
|
42963
42901
|
// Check for event listeners
|
|
42964
42902
|
const hasClickHandler = element.onclick !== null ||
|
|
42965
42903
|
element.getAttribute('onclick') !== null ||
|
|
@@ -42967,10 +42905,24 @@ function run_build_dom_tree() {
|
|
|
42967
42905
|
element.hasAttribute('@click') ||
|
|
42968
42906
|
element.hasAttribute('v-on:click');
|
|
42969
42907
|
// Helper function to safely get event listeners
|
|
42970
|
-
function
|
|
42908
|
+
function getEventListeners(el) {
|
|
42909
|
+
// if (window.getEventListeners) {
|
|
42910
|
+
// return window.getEventListeners?.(el) || {};
|
|
42911
|
+
// }
|
|
42971
42912
|
// List of common event types to check
|
|
42972
42913
|
const listeners = {};
|
|
42973
|
-
|
|
42914
|
+
const eventTypes = [
|
|
42915
|
+
'click',
|
|
42916
|
+
'mousedown',
|
|
42917
|
+
'mouseup',
|
|
42918
|
+
'touchstart',
|
|
42919
|
+
'touchend',
|
|
42920
|
+
'keydown',
|
|
42921
|
+
'keyup',
|
|
42922
|
+
'focus',
|
|
42923
|
+
'blur',
|
|
42924
|
+
];
|
|
42925
|
+
for (const type of eventTypes) {
|
|
42974
42926
|
const handler = el[`on${type}`];
|
|
42975
42927
|
if (handler) {
|
|
42976
42928
|
listeners[type] = [
|
|
@@ -42984,34 +42936,30 @@ function run_build_dom_tree() {
|
|
|
42984
42936
|
return listeners;
|
|
42985
42937
|
}
|
|
42986
42938
|
// Check for click-related events on the element itself
|
|
42987
|
-
const listeners =
|
|
42988
|
-
const hasClickListeners =
|
|
42939
|
+
const listeners = getEventListeners(element);
|
|
42940
|
+
const hasClickListeners = listeners &&
|
|
42941
|
+
(listeners.click?.length > 0 ||
|
|
42942
|
+
listeners.mousedown?.length > 0 ||
|
|
42943
|
+
listeners.mouseup?.length > 0 ||
|
|
42944
|
+
listeners.touchstart?.length > 0 ||
|
|
42945
|
+
listeners.touchend?.length > 0);
|
|
42989
42946
|
// Check for ARIA properties that suggest interactivity
|
|
42990
42947
|
const hasAriaProps = element.hasAttribute('aria-expanded') ||
|
|
42991
42948
|
element.hasAttribute('aria-pressed') ||
|
|
42992
42949
|
element.hasAttribute('aria-selected') ||
|
|
42993
42950
|
element.hasAttribute('aria-checked');
|
|
42951
|
+
// Check for form-related functionality
|
|
42952
|
+
element.form !== undefined ||
|
|
42953
|
+
element.hasAttribute('contenteditable') ||
|
|
42954
|
+
(style && style.userSelect !== 'none');
|
|
42994
42955
|
// Check if element is draggable
|
|
42995
42956
|
const isDraggable = element.draggable || element.getAttribute('draggable') === 'true';
|
|
42996
|
-
|
|
42997
|
-
|
|
42998
|
-
|
|
42999
|
-
|
|
43000
|
-
|
|
43001
|
-
|
|
43002
|
-
let count = 0;
|
|
43003
|
-
let current = element.parentElement;
|
|
43004
|
-
while (current && current !== document.documentElement) {
|
|
43005
|
-
hasClickStyling = current.style.cursor === 'pointer' || getCachedComputedStyle(current).cursor === 'pointer';
|
|
43006
|
-
if (hasClickStyling)
|
|
43007
|
-
return false;
|
|
43008
|
-
current = current.parentElement;
|
|
43009
|
-
if (++count > 10)
|
|
43010
|
-
break;
|
|
43011
|
-
}
|
|
43012
|
-
return true;
|
|
43013
|
-
}
|
|
43014
|
-
return false;
|
|
42957
|
+
return (hasAriaProps ||
|
|
42958
|
+
hasClickStyling ||
|
|
42959
|
+
hasClickHandler ||
|
|
42960
|
+
hasClickListeners ||
|
|
42961
|
+
// isFormRelated ||
|
|
42962
|
+
isDraggable);
|
|
43015
42963
|
}
|
|
43016
42964
|
// Helper function to check if element is visible
|
|
43017
42965
|
function isElementVisible(element) {
|
|
@@ -43041,14 +42989,11 @@ function run_build_dom_tree() {
|
|
|
43041
42989
|
if (!topEl)
|
|
43042
42990
|
return false;
|
|
43043
42991
|
// Check if the element or any of its parents match our target element
|
|
43044
|
-
let count = 0;
|
|
43045
42992
|
let current = topEl;
|
|
43046
42993
|
while (current && current !== shadowRoot) {
|
|
43047
42994
|
if (current === element)
|
|
43048
42995
|
return true;
|
|
43049
42996
|
current = current.parentElement;
|
|
43050
|
-
if (++count > 15)
|
|
43051
|
-
break;
|
|
43052
42997
|
}
|
|
43053
42998
|
return false;
|
|
43054
42999
|
}
|
|
@@ -43063,14 +43008,11 @@ function run_build_dom_tree() {
|
|
|
43063
43008
|
const topEl = document.elementFromPoint(point.x, point.y);
|
|
43064
43009
|
if (!topEl)
|
|
43065
43010
|
return false;
|
|
43066
|
-
let count = 0;
|
|
43067
43011
|
let current = topEl;
|
|
43068
43012
|
while (current && current !== document.documentElement) {
|
|
43069
43013
|
if (current === element)
|
|
43070
43014
|
return true;
|
|
43071
43015
|
current = current.parentElement;
|
|
43072
|
-
if (++count > 15)
|
|
43073
|
-
break;
|
|
43074
43016
|
}
|
|
43075
43017
|
return false;
|
|
43076
43018
|
}
|
|
@@ -43094,10 +43036,8 @@ function run_build_dom_tree() {
|
|
|
43094
43036
|
}
|
|
43095
43037
|
// Function to traverse the DOM and create nested JSON
|
|
43096
43038
|
function buildDomTree(node, parentIframe = null) {
|
|
43097
|
-
if (!node
|
|
43039
|
+
if (!node)
|
|
43098
43040
|
return null;
|
|
43099
|
-
}
|
|
43100
|
-
duplicates.add(node);
|
|
43101
43041
|
// Special case for text nodes
|
|
43102
43042
|
if (node.nodeType === Node.TEXT_NODE) {
|
|
43103
43043
|
const textContent = node.textContent.trim();
|
|
@@ -43142,7 +43082,7 @@ function run_build_dom_tree() {
|
|
|
43142
43082
|
if (shouldHighlight) {
|
|
43143
43083
|
nodeData.highlightIndex = highlightIndex++;
|
|
43144
43084
|
window.clickable_elements[nodeData.highlightIndex] = node;
|
|
43145
|
-
if (
|
|
43085
|
+
if (doHighlightElements) {
|
|
43146
43086
|
highlightElement(node, nodeData.highlightIndex, parentIframe);
|
|
43147
43087
|
}
|
|
43148
43088
|
}
|
|
@@ -43157,7 +43097,7 @@ function run_build_dom_tree() {
|
|
|
43157
43097
|
}
|
|
43158
43098
|
// Handle shadow DOM
|
|
43159
43099
|
if (node.shadowRoot) {
|
|
43160
|
-
const shadowChildren = Array.from(node.shadowRoot.
|
|
43100
|
+
const shadowChildren = Array.from(node.shadowRoot.childNodes).map((child) => buildDomTree(child, parentIframe));
|
|
43161
43101
|
nodeData.children.push(...shadowChildren);
|
|
43162
43102
|
}
|
|
43163
43103
|
// Handle iframes
|
|
@@ -43165,7 +43105,7 @@ function run_build_dom_tree() {
|
|
|
43165
43105
|
try {
|
|
43166
43106
|
const iframeDoc = node.contentDocument || node.contentWindow.document;
|
|
43167
43107
|
if (iframeDoc) {
|
|
43168
|
-
const iframeChildren = Array.from(iframeDoc.body.
|
|
43108
|
+
const iframeChildren = Array.from(iframeDoc.body.childNodes).map((child) => buildDomTree(child, node));
|
|
43169
43109
|
nodeData.children.push(...iframeChildren);
|
|
43170
43110
|
}
|
|
43171
43111
|
}
|
|
@@ -43174,9 +43114,8 @@ function run_build_dom_tree() {
|
|
|
43174
43114
|
}
|
|
43175
43115
|
}
|
|
43176
43116
|
else {
|
|
43177
|
-
|
|
43178
|
-
|
|
43179
|
-
const children = Array.from(node.children).map((child) => buildDomTree(child, parentIframe)).filter(child => child !== null);
|
|
43117
|
+
if (nodeData.isVisible != false) {
|
|
43118
|
+
const children = Array.from(node.childNodes).map((child) => buildDomTree(child, parentIframe));
|
|
43180
43119
|
nodeData.children.push(...children);
|
|
43181
43120
|
}
|
|
43182
43121
|
}
|
|
@@ -45222,7 +45161,7 @@ async function callChatLLM(chatId, messageId, rlm, messages, tools, toolChoice,
|
|
|
45222
45161
|
});
|
|
45223
45162
|
}
|
|
45224
45163
|
function convertAssistantToolResults(results) {
|
|
45225
|
-
return results.map((part) => {
|
|
45164
|
+
return results.filter((part) => part.type !== "reasoning").map((part) => {
|
|
45226
45165
|
if (part.type == "text") {
|
|
45227
45166
|
return {
|
|
45228
45167
|
type: "text",
|
|
@@ -45972,10 +45911,13 @@ class ChatAgent {
|
|
|
45972
45911
|
}
|
|
45973
45912
|
for (let i = 0; i < results.length; i++) {
|
|
45974
45913
|
const result = results[i];
|
|
45975
|
-
if (result.type
|
|
45914
|
+
if (result.type === "text") {
|
|
45976
45915
|
text = result.text;
|
|
45977
45916
|
continue;
|
|
45978
45917
|
}
|
|
45918
|
+
if (result.type === "reasoning") {
|
|
45919
|
+
continue;
|
|
45920
|
+
}
|
|
45979
45921
|
let toolResult;
|
|
45980
45922
|
try {
|
|
45981
45923
|
const args = typeof result.input == "string"
|