sentience-ts 0.10.5 → 0.11.0
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/LICENSE.md +43 -0
- package/README.md +211 -7
- package/dist/agent.d.ts +145 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +374 -0
- package/dist/agent.js.map +1 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +225 -2
- package/dist/browser.js.map +1 -1
- package/dist/conversational-agent.d.ts +123 -0
- package/dist/conversational-agent.d.ts.map +1 -0
- package/dist/conversational-agent.js +327 -0
- package/dist/conversational-agent.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/llm-provider.d.ts +60 -0
- package/dist/llm-provider.d.ts.map +1 -0
- package/dist/llm-provider.js +106 -0
- package/dist/llm-provider.js.map +1 -0
- package/dist/snapshot.d.ts +2 -0
- package/dist/snapshot.d.ts.map +1 -1
- package/dist/snapshot.js +86 -1
- package/dist/snapshot.js.map +1 -1
- package/package.json +10 -1
package/LICENSE.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Elastic License
|
|
2
|
+
## Acceptance
|
|
3
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
4
|
+
|
|
5
|
+
## Copyright License
|
|
6
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below.
|
|
7
|
+
|
|
8
|
+
## Limitations
|
|
9
|
+
You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
|
|
10
|
+
|
|
11
|
+
You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
|
|
12
|
+
|
|
13
|
+
You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
|
|
14
|
+
|
|
15
|
+
## Patents
|
|
16
|
+
The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
17
|
+
|
|
18
|
+
## Notices
|
|
19
|
+
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
|
|
20
|
+
|
|
21
|
+
If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
|
|
22
|
+
|
|
23
|
+
## No Other Rights
|
|
24
|
+
These terms do not imply any licenses other than those expressly granted in these terms.
|
|
25
|
+
|
|
26
|
+
## Termination
|
|
27
|
+
If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
|
|
28
|
+
|
|
29
|
+
## No Liability
|
|
30
|
+
As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
|
|
31
|
+
|
|
32
|
+
## Definitions
|
|
33
|
+
The **licensor** is the entity offering these terms, and the **software** is the software the licensor makes available under these terms, including any portion of it.
|
|
34
|
+
|
|
35
|
+
you refers to the individual or entity agreeing to these terms.
|
|
36
|
+
|
|
37
|
+
**your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. control means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
38
|
+
|
|
39
|
+
**your licenses** are all the licenses granted to you for the software under these terms.
|
|
40
|
+
|
|
41
|
+
**use** means anything you do with the software requiring one of your licenses.
|
|
42
|
+
|
|
43
|
+
**trademark** means trademarks, service marks, and similar rights.
|
package/README.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# Sentience TypeScript SDK
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
TypeScript/JavaScript SDK for Sentience AI Agent Browser Automation. Build intelligent web automation agents that can see, understand, and interact with web pages like humans do.
|
|
3
|
+
The SDK is open under ELv2; the core semantic geometry and reliability logic runs in Sentience-hosted services.
|
|
6
4
|
|
|
7
5
|
## Installation
|
|
8
6
|
|
|
@@ -14,7 +12,194 @@ npm run build
|
|
|
14
12
|
npx playwright install chromium
|
|
15
13
|
```
|
|
16
14
|
|
|
17
|
-
## Quick Start
|
|
15
|
+
## Quick Start: Choose Your Abstraction Level
|
|
16
|
+
|
|
17
|
+
Sentience SDK offers **4 levels of abstraction** - choose based on your needs:
|
|
18
|
+
|
|
19
|
+
### 💬 Level 4: Conversational Agent (Highest Abstraction) - **NEW in v0.3.0**
|
|
20
|
+
|
|
21
|
+
Complete automation with natural conversation. Just describe what you want, and the agent plans and executes everything:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { SentienceBrowser, ConversationalAgent, OpenAIProvider } from 'sentience-ts';
|
|
25
|
+
|
|
26
|
+
const browser = await SentienceBrowser.create({ apiKey: process.env.SENTIENCE_API_KEY });
|
|
27
|
+
const llm = new OpenAIProvider(process.env.OPENAI_API_KEY!, 'gpt-4o');
|
|
28
|
+
const agent = new ConversationalAgent({ llmProvider: llm, browser });
|
|
29
|
+
|
|
30
|
+
// Navigate to starting page
|
|
31
|
+
await browser.getPage().goto('https://amazon.com');
|
|
32
|
+
|
|
33
|
+
// ONE command does it all - automatic planning and execution!
|
|
34
|
+
const response = await agent.execute(
|
|
35
|
+
"Search for 'wireless mouse' and tell me the price of the top result"
|
|
36
|
+
);
|
|
37
|
+
console.log(response); // "I found the top result for wireless mouse on Amazon. It's priced at $24.99..."
|
|
38
|
+
|
|
39
|
+
// Follow-up questions maintain context
|
|
40
|
+
const followUp = await agent.chat("Add it to cart");
|
|
41
|
+
console.log(followUp);
|
|
42
|
+
|
|
43
|
+
await browser.close();
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**When to use:** Complex multi-step tasks, conversational interfaces, maximum convenience
|
|
47
|
+
**Code reduction:** 99% less code - describe goals in natural language
|
|
48
|
+
**Requirements:** OpenAI or Anthropic API key
|
|
49
|
+
|
|
50
|
+
### 🤖 Level 3: Agent (Natural Language Commands) - **Recommended for Most Users**
|
|
51
|
+
|
|
52
|
+
Zero coding knowledge needed. Just write what you want in plain English:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { SentienceBrowser, SentienceAgent, OpenAIProvider } from 'sentience-ts';
|
|
56
|
+
|
|
57
|
+
const browser = await SentienceBrowser.create({ apiKey: process.env.SENTIENCE_API_KEY });
|
|
58
|
+
const llm = new OpenAIProvider(process.env.OPENAI_API_KEY!, 'gpt-4o-mini');
|
|
59
|
+
const agent = new SentienceAgent(browser, llm);
|
|
60
|
+
|
|
61
|
+
await browser.getPage().goto('https://www.amazon.com');
|
|
62
|
+
|
|
63
|
+
// Just natural language commands - agent handles everything!
|
|
64
|
+
await agent.act('Click the search box');
|
|
65
|
+
await agent.act("Type 'wireless mouse' into the search field");
|
|
66
|
+
await agent.act('Press Enter key');
|
|
67
|
+
await agent.act('Click the first product result');
|
|
68
|
+
|
|
69
|
+
// Automatic token tracking
|
|
70
|
+
console.log(`Tokens used: ${agent.getTokenStats().totalTokens}`);
|
|
71
|
+
await browser.close();
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**When to use:** Quick automation, non-technical users, rapid prototyping
|
|
75
|
+
**Code reduction:** 95-98% less code vs manual approach
|
|
76
|
+
**Requirements:** OpenAI API key (or Anthropic for Claude)
|
|
77
|
+
|
|
78
|
+
### 🔧 Level 2: Direct SDK (Technical Control)
|
|
79
|
+
|
|
80
|
+
Full control with semantic selectors. For technical users who want precision:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { SentienceBrowser, snapshot, find, click, typeText, press } from 'sentience-ts';
|
|
84
|
+
|
|
85
|
+
const browser = await SentienceBrowser.create({ apiKey: process.env.SENTIENCE_API_KEY });
|
|
86
|
+
await browser.getPage().goto('https://www.amazon.com');
|
|
87
|
+
|
|
88
|
+
// Get semantic snapshot
|
|
89
|
+
const snap = await snapshot(browser);
|
|
90
|
+
|
|
91
|
+
// Find elements using query DSL
|
|
92
|
+
const searchBox = find(snap, 'role=textbox text~"search"');
|
|
93
|
+
await click(browser, searchBox!.id);
|
|
94
|
+
|
|
95
|
+
// Type and submit
|
|
96
|
+
await typeText(browser, searchBox!.id, 'wireless mouse');
|
|
97
|
+
await press(browser, 'Enter');
|
|
98
|
+
|
|
99
|
+
await browser.close();
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**When to use:** Need precise control, debugging, custom workflows
|
|
103
|
+
**Code reduction:** Still 80% less code vs raw Playwright
|
|
104
|
+
**Requirements:** Only Sentience API key
|
|
105
|
+
|
|
106
|
+
### ⚙️ Level 1: Raw Playwright (Maximum Control)
|
|
107
|
+
|
|
108
|
+
For when you need complete low-level control (rare):
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import { chromium } from 'playwright';
|
|
112
|
+
|
|
113
|
+
const browser = await chromium.launch();
|
|
114
|
+
const page = await browser.newPage();
|
|
115
|
+
await page.goto('https://www.amazon.com');
|
|
116
|
+
await page.fill('#twotabsearchtextbox', 'wireless mouse');
|
|
117
|
+
await page.press('#twotabsearchtextbox', 'Enter');
|
|
118
|
+
await browser.close();
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**When to use:** Very specific edge cases, custom browser configs
|
|
122
|
+
**Tradeoffs:** No semantic intelligence, brittle selectors, more code
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Agent Layer Examples
|
|
127
|
+
|
|
128
|
+
### Google Search (6 lines of code)
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import { SentienceBrowser, SentienceAgent, OpenAIProvider } from 'sentience-ts';
|
|
132
|
+
|
|
133
|
+
const browser = await SentienceBrowser.create({ apiKey: apiKey });
|
|
134
|
+
const llm = new OpenAIProvider(openaiKey, 'gpt-4o-mini');
|
|
135
|
+
const agent = new SentienceAgent(browser, llm);
|
|
136
|
+
|
|
137
|
+
await browser.getPage().goto('https://www.google.com');
|
|
138
|
+
await agent.act('Click the search box');
|
|
139
|
+
await agent.act("Type 'mechanical keyboards' into the search field");
|
|
140
|
+
await agent.act('Press Enter key');
|
|
141
|
+
await agent.act('Click the first non-ad search result');
|
|
142
|
+
|
|
143
|
+
await browser.close();
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**See full example:** [examples/agent-google-search.ts](examples/agent-google-search.ts)
|
|
147
|
+
|
|
148
|
+
### Using Anthropic Claude Instead of GPT
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
import { SentienceAgent, AnthropicProvider } from 'sentience-ts';
|
|
152
|
+
|
|
153
|
+
// Swap OpenAI for Anthropic - same API!
|
|
154
|
+
const llm = new AnthropicProvider(
|
|
155
|
+
process.env.ANTHROPIC_API_KEY!,
|
|
156
|
+
'claude-3-5-sonnet-20241022'
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
const agent = new SentienceAgent(browser, llm);
|
|
160
|
+
await agent.act('Click the search button'); // Works exactly the same
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**BYOB (Bring Your Own Brain):** OpenAI, Anthropic, or implement `LLMProvider` for any model.
|
|
164
|
+
|
|
165
|
+
**See full example:** [examples/agent-with-anthropic.ts](examples/agent-with-anthropic.ts)
|
|
166
|
+
|
|
167
|
+
### Amazon Shopping (98% code reduction)
|
|
168
|
+
|
|
169
|
+
**Before (manual approach):** 350 lines
|
|
170
|
+
**After (agent layer):** 6 lines
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
await agent.act('Click the search box');
|
|
174
|
+
await agent.act("Type 'wireless mouse' into the search field");
|
|
175
|
+
await agent.act('Press Enter key');
|
|
176
|
+
await agent.act('Click the first visible product in the search results');
|
|
177
|
+
await agent.act("Click the 'Add to Cart' button");
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
**See full example:** [examples/agent-amazon-shopping.ts](examples/agent-amazon-shopping.ts)
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Installation for Agent Layer
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
# Install core SDK
|
|
188
|
+
npm install sentience-ts
|
|
189
|
+
|
|
190
|
+
# Install LLM provider (choose one or both)
|
|
191
|
+
npm install openai # For GPT-4, GPT-4o, GPT-4o-mini
|
|
192
|
+
npm install @anthropic-ai/sdk # For Claude 3.5 Sonnet
|
|
193
|
+
|
|
194
|
+
# Set API keys
|
|
195
|
+
export SENTIENCE_API_KEY="your-sentience-key"
|
|
196
|
+
export OPENAI_API_KEY="your-openai-key" # OR
|
|
197
|
+
export ANTHROPIC_API_KEY="your-anthropic-key"
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## Direct SDK Quick Start
|
|
18
203
|
|
|
19
204
|
```typescript
|
|
20
205
|
import { SentienceBrowser, snapshot, find, click } from './src';
|
|
@@ -351,6 +536,12 @@ element.z_index // CSS stacking order
|
|
|
351
536
|
|
|
352
537
|
See the `examples/` directory for complete working examples:
|
|
353
538
|
|
|
539
|
+
### Agent Layer (Level 3 - Natural Language)
|
|
540
|
+
- **`agent-google-search.ts`** - Google search automation with natural language commands
|
|
541
|
+
- **`agent-amazon-shopping.ts`** - Amazon shopping bot (6 lines vs 350 lines manual code)
|
|
542
|
+
- **`agent-with-anthropic.ts`** - Using Anthropic Claude instead of OpenAI GPT
|
|
543
|
+
|
|
544
|
+
### Direct SDK (Level 2 - Technical Control)
|
|
354
545
|
- **`hello.ts`** - Extension bridge verification
|
|
355
546
|
- **`basic-agent.ts`** - Basic snapshot and element inspection
|
|
356
547
|
- **`query-demo.ts`** - Query engine demonstrations
|
|
@@ -492,8 +683,21 @@ npm run example:hello
|
|
|
492
683
|
|
|
493
684
|
## License
|
|
494
685
|
|
|
495
|
-
|
|
686
|
+
📜 **License**
|
|
687
|
+
|
|
688
|
+
This SDK is licensed under the **Elastic License 2.0 (ELv2)**.
|
|
689
|
+
|
|
690
|
+
The Elastic License 2.0 allows you to use, modify, and distribute this SDK for internal, research, and non-competitive purposes. It **does not permit offering this SDK or a derivative as a hosted or managed service**, nor using it to build a competing product or service.
|
|
691
|
+
|
|
692
|
+
### Important Notes
|
|
693
|
+
|
|
694
|
+
- This SDK is a **client-side library** that communicates with proprietary Sentience services and browser components.
|
|
695
|
+
|
|
696
|
+
- The Sentience backend services (including semantic geometry grounding, ranking, visual cues, and trace processing) are **not open source** and are governed by Sentience’s Terms of Service.
|
|
697
|
+
|
|
698
|
+
- Use of this SDK does **not** grant rights to operate, replicate, or reimplement Sentience’s hosted services.
|
|
699
|
+
|
|
700
|
+
For commercial usage, hosted offerings, or enterprise deployments, please contact Sentience to obtain a commercial license.
|
|
496
701
|
|
|
497
|
-
|
|
702
|
+
See the full license text in [`LICENSE`](./LICENSE.md).
|
|
498
703
|
|
|
499
|
-
Note: The SDK communicates with proprietary Sentience services and browser components that are not open source. Access to those components is governed by Sentience's Terms of Service.
|
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentience Agent: High-level automation agent using LLM + SDK
|
|
3
|
+
* Implements observe-think-act loop for natural language commands
|
|
4
|
+
*/
|
|
5
|
+
import { SentienceBrowser } from './browser';
|
|
6
|
+
import { SnapshotOptions } from './snapshot';
|
|
7
|
+
import { LLMProvider } from './llm-provider';
|
|
8
|
+
/**
|
|
9
|
+
* Execution result from agent.act()
|
|
10
|
+
*/
|
|
11
|
+
export interface AgentActResult {
|
|
12
|
+
success: boolean;
|
|
13
|
+
action?: string;
|
|
14
|
+
elementId?: number;
|
|
15
|
+
text?: string;
|
|
16
|
+
key?: string;
|
|
17
|
+
outcome?: string;
|
|
18
|
+
urlChanged?: boolean;
|
|
19
|
+
durationMs: number;
|
|
20
|
+
attempt: number;
|
|
21
|
+
goal: string;
|
|
22
|
+
error?: string;
|
|
23
|
+
message?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* History entry for executed action
|
|
27
|
+
*/
|
|
28
|
+
export interface HistoryEntry {
|
|
29
|
+
goal: string;
|
|
30
|
+
action: string;
|
|
31
|
+
result: AgentActResult;
|
|
32
|
+
success: boolean;
|
|
33
|
+
attempt: number;
|
|
34
|
+
durationMs: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Token usage statistics
|
|
38
|
+
*/
|
|
39
|
+
export interface TokenStats {
|
|
40
|
+
totalPromptTokens: number;
|
|
41
|
+
totalCompletionTokens: number;
|
|
42
|
+
totalTokens: number;
|
|
43
|
+
byAction: Array<{
|
|
44
|
+
goal: string;
|
|
45
|
+
promptTokens?: number;
|
|
46
|
+
completionTokens?: number;
|
|
47
|
+
totalTokens?: number;
|
|
48
|
+
model?: string;
|
|
49
|
+
}>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* High-level agent that combines Sentience SDK with any LLM provider.
|
|
53
|
+
*
|
|
54
|
+
* Uses observe-think-act loop to execute natural language commands:
|
|
55
|
+
* 1. OBSERVE: Get snapshot of current page state
|
|
56
|
+
* 2. THINK: Query LLM to decide next action
|
|
57
|
+
* 3. ACT: Execute action using SDK
|
|
58
|
+
*
|
|
59
|
+
* Example:
|
|
60
|
+
* ```typescript
|
|
61
|
+
* import { SentienceBrowser, SentienceAgent, OpenAIProvider } from 'sentience-ts';
|
|
62
|
+
*
|
|
63
|
+
* const browser = await SentienceBrowser.create({ apiKey: 'sentience_key' });
|
|
64
|
+
* const llm = new OpenAIProvider('openai_key', 'gpt-4o');
|
|
65
|
+
* const agent = new SentienceAgent(browser, llm);
|
|
66
|
+
*
|
|
67
|
+
* await browser.getPage().goto('https://google.com');
|
|
68
|
+
* await agent.act('Click the search box');
|
|
69
|
+
* await agent.act("Type 'magic mouse' into the search field");
|
|
70
|
+
* await agent.act('Press Enter key');
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare class SentienceAgent {
|
|
74
|
+
private browser;
|
|
75
|
+
private llm;
|
|
76
|
+
private snapshotLimit;
|
|
77
|
+
private verbose;
|
|
78
|
+
private history;
|
|
79
|
+
private tokenUsage;
|
|
80
|
+
/**
|
|
81
|
+
* Initialize Sentience Agent
|
|
82
|
+
* @param browser - SentienceBrowser instance
|
|
83
|
+
* @param llm - LLM provider (OpenAIProvider, AnthropicProvider, etc.)
|
|
84
|
+
* @param snapshotLimit - Maximum elements to include in context (default: 50)
|
|
85
|
+
* @param verbose - Print execution logs (default: true)
|
|
86
|
+
*/
|
|
87
|
+
constructor(browser: SentienceBrowser, llm: LLMProvider, snapshotLimit?: number, verbose?: boolean);
|
|
88
|
+
/**
|
|
89
|
+
* Execute a high-level goal using observe → think → act loop
|
|
90
|
+
* @param goal - Natural language instruction (e.g., "Click the Sign In button")
|
|
91
|
+
* @param maxRetries - Number of retries on failure (default: 2)
|
|
92
|
+
* @param snapshotOptions - Optional snapshot parameters (limit, filter, etc.)
|
|
93
|
+
* @returns Result dict with status, action_taken, reasoning, and execution data
|
|
94
|
+
*
|
|
95
|
+
* Example:
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const result = await agent.act('Click the search box');
|
|
98
|
+
* console.log(result);
|
|
99
|
+
* // { success: true, action: 'click', elementId: 42, ... }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
act(goal: string, maxRetries?: number, snapshotOptions?: SnapshotOptions): Promise<AgentActResult>;
|
|
103
|
+
/**
|
|
104
|
+
* Filter elements from snapshot based on goal context.
|
|
105
|
+
* Applies goal-based keyword matching to boost relevant elements and filters out irrelevant ones.
|
|
106
|
+
*/
|
|
107
|
+
private filterElements;
|
|
108
|
+
/**
|
|
109
|
+
* Extract meaningful keywords from goal text
|
|
110
|
+
*/
|
|
111
|
+
private extractKeywords;
|
|
112
|
+
/**
|
|
113
|
+
* Convert snapshot elements to token-efficient prompt string
|
|
114
|
+
* Format: [ID] <role> "text" {cues} @ (x,y) (Imp:score)
|
|
115
|
+
* Note: elements are already filtered by filterElements() in act()
|
|
116
|
+
*/
|
|
117
|
+
private buildContext;
|
|
118
|
+
/**
|
|
119
|
+
* Query LLM with standardized prompt template
|
|
120
|
+
*/
|
|
121
|
+
private queryLLM;
|
|
122
|
+
/**
|
|
123
|
+
* Parse action string and execute SDK call
|
|
124
|
+
*/
|
|
125
|
+
private executeAction;
|
|
126
|
+
/**
|
|
127
|
+
* Track token usage for analytics
|
|
128
|
+
*/
|
|
129
|
+
private trackTokens;
|
|
130
|
+
/**
|
|
131
|
+
* Get token usage statistics
|
|
132
|
+
* @returns Dictionary with token usage breakdown
|
|
133
|
+
*/
|
|
134
|
+
getTokenStats(): TokenStats;
|
|
135
|
+
/**
|
|
136
|
+
* Get execution history
|
|
137
|
+
* @returns List of all actions taken with results
|
|
138
|
+
*/
|
|
139
|
+
getHistory(): HistoryEntry[];
|
|
140
|
+
/**
|
|
141
|
+
* Clear execution history and reset token counters
|
|
142
|
+
*/
|
|
143
|
+
clearHistory(): void;
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAY,eAAe,EAAE,MAAM,YAAY,CAAC;AAGvD,OAAO,EAAE,WAAW,EAAe,MAAM,gBAAgB,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7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