bashirweb 0.0.0-stage → 0.1.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 +21 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/backend.d.ts +33 -0
- package/dist/backend.d.ts.map +1 -0
- package/dist/backend.js +166 -0
- package/dist/backend.js.map +1 -0
- package/dist/bashirweb.d.ts +249 -0
- package/dist/bashirweb.d.ts.map +1 -0
- package/dist/bashirweb.js +470 -0
- package/dist/bashirweb.js.map +1 -0
- package/dist/browser-console.d.ts +42 -0
- package/dist/browser-console.d.ts.map +1 -0
- package/dist/browser-console.js +51 -0
- package/dist/browser-console.js.map +1 -0
- package/dist/browser-operator.d.ts +134 -0
- package/dist/browser-operator.d.ts.map +1 -0
- package/dist/browser-operator.js +253 -0
- package/dist/browser-operator.js.map +1 -0
- package/dist/browser-tools.d.ts +24 -0
- package/dist/browser-tools.d.ts.map +1 -0
- package/dist/browser-tools.js +316 -0
- package/dist/browser-tools.js.map +1 -0
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +598 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/dashboard/assets/index-BDmtidLI.js +2 -0
- package/dist/dashboard/assets/index-n3m82N6N.css +1 -0
- package/dist/dashboard/favicon.svg +1 -0
- package/dist/dashboard/index.html +15 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/local.d.ts +61 -0
- package/dist/local.d.ts.map +1 -0
- package/dist/local.js +200 -0
- package/dist/local.js.map +1 -0
- package/dist/page-actions.d.ts +11 -0
- package/dist/page-actions.d.ts.map +1 -0
- package/dist/page-actions.js +146 -0
- package/dist/page-actions.js.map +1 -0
- package/dist/remote.d.ts +260 -0
- package/dist/remote.d.ts.map +1 -0
- package/dist/remote.js +299 -0
- package/dist/remote.js.map +1 -0
- package/dist/serve.d.ts +21 -0
- package/dist/serve.d.ts.map +1 -0
- package/dist/serve.js +79 -0
- package/dist/serve.js.map +1 -0
- package/dist/tools.d.ts +5 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +439 -0
- package/dist/tools.js.map +1 -0
- package/dist/trace-viewer.d.ts +17 -0
- package/dist/trace-viewer.d.ts.map +1 -0
- package/dist/trace-viewer.js +235 -0
- package/dist/trace-viewer.js.map +1 -0
- package/dist/workflow-host.d.ts +20 -0
- package/dist/workflow-host.d.ts.map +1 -0
- package/dist/workflow-host.js +216 -0
- package/dist/workflow-host.js.map +1 -0
- package/package.json +53 -3
- package/README.md +0 -3
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { ConfigurationError, RuntimeError, ValidationError } from '@bashirweb/core';
|
|
2
|
+
import { ToolRegistry, type ReasoningModel, type ReasoningInput, type ModelDecision, type Observation, type ProgressCallback, type StepRecord, type AgentTask, type TaskStore } from '@bashirweb/agent';
|
|
3
|
+
import type { BashirBrowser, BashirPage } from '@bashirweb/browser';
|
|
4
|
+
import { type BrowserToolContext } from './browser-tools.js';
|
|
5
|
+
import { BrowserConsole } from './browser-console.js';
|
|
6
|
+
export interface BrowserOperatorOptions {
|
|
7
|
+
/** Maximum number of tabs per session. Default 20. */
|
|
8
|
+
maxTabs?: number;
|
|
9
|
+
/** Maximum number of concurrent sessions. Default 5. */
|
|
10
|
+
maxSessions?: number;
|
|
11
|
+
/** Maximum reasoning steps. Default 25. */
|
|
12
|
+
maxSteps?: number;
|
|
13
|
+
/** Per-step timeout in ms. */
|
|
14
|
+
stepTimeoutMs?: number;
|
|
15
|
+
/** Persist tasks to a TaskStore. */
|
|
16
|
+
store?: TaskStore;
|
|
17
|
+
/** Optional approval handler for consequential actions (clicks on destructive elements, etc.). */
|
|
18
|
+
approvalHandler?: (action: string, details: Record<string, unknown>) => Promise<boolean>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A single browser session: a named group of tabs sharing a browser context.
|
|
22
|
+
*/
|
|
23
|
+
export declare class BrowserSession {
|
|
24
|
+
readonly browser: BashirBrowser;
|
|
25
|
+
readonly id: string;
|
|
26
|
+
readonly pages: Map<string, BashirPage>;
|
|
27
|
+
constructor(browser: BashirBrowser, id: string);
|
|
28
|
+
/** Opens a new tab and registers it. */
|
|
29
|
+
newTab(url?: string): Promise<BashirPage>;
|
|
30
|
+
/** Gets a registered page by id. */
|
|
31
|
+
getPage(pageId: string): BashirPage;
|
|
32
|
+
/** Lists all open tabs. */
|
|
33
|
+
listTabs(): Array<{
|
|
34
|
+
id: string;
|
|
35
|
+
url: string;
|
|
36
|
+
title: string;
|
|
37
|
+
}>;
|
|
38
|
+
/** Closes a tab. */
|
|
39
|
+
closeTab(pageId: string): Promise<void>;
|
|
40
|
+
/** Closes all tabs and the session's browser. */
|
|
41
|
+
destroy(): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Manages browser sessions for the Agent 1 operator. Each session owns a set of
|
|
45
|
+
* tabs. The session manager enforces tab/session limits and cleans up on destroy.
|
|
46
|
+
*/
|
|
47
|
+
export declare class BrowserSessionManager {
|
|
48
|
+
private readonly browser;
|
|
49
|
+
private readonly sessions;
|
|
50
|
+
private readonly maxTabs;
|
|
51
|
+
private readonly maxSessions;
|
|
52
|
+
constructor(browser: BashirBrowser, options?: {
|
|
53
|
+
maxSessions?: number;
|
|
54
|
+
tabs?: {
|
|
55
|
+
maxTabs?: number;
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
/** Creates a new session with one blank tab. */
|
|
59
|
+
newSession(url?: string): Promise<BrowserSession>;
|
|
60
|
+
/** Creates a new tab in the first session (or a new session if none). */
|
|
61
|
+
newTab(url?: string): Promise<BashirPage>;
|
|
62
|
+
/** Gets a page from any session by its id. */
|
|
63
|
+
getPage(pageId: string): BashirPage;
|
|
64
|
+
/** Lists all tabs across all sessions. */
|
|
65
|
+
listTabs(): Array<{
|
|
66
|
+
id: string;
|
|
67
|
+
url: string;
|
|
68
|
+
title: string;
|
|
69
|
+
sessionId: string;
|
|
70
|
+
}>;
|
|
71
|
+
/** Closes a tab by id. */
|
|
72
|
+
closeTab(pageId: string): Promise<void>;
|
|
73
|
+
/** Destroys all sessions. */
|
|
74
|
+
destroyAll(): Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* **Agent 1 — the AI browser operator.**
|
|
78
|
+
*
|
|
79
|
+
* An autonomous agent that drives a real browser through a continuous
|
|
80
|
+
* observe → reason → act → observe loop across **multiple tabs**. A
|
|
81
|
+
* {@link ReasoningModel} decides which browser tool to call; the
|
|
82
|
+
* {@link CollaborationOrchestrator} executes it through the tool registry, captures
|
|
83
|
+
* the observation, and feeds it back.
|
|
84
|
+
*
|
|
85
|
+
* **Provider-agnostic — no AI is hardcoded.** Any {@link ReasoningModel} implementation
|
|
86
|
+
* can drive the operator. Constructing without a model is allowed (the tool layer works
|
|
87
|
+
* standalone); calling {@link run} without a model throws a {@link ConfigurationError}.
|
|
88
|
+
*/
|
|
89
|
+
export declare class BrowserOperator {
|
|
90
|
+
private readonly browser;
|
|
91
|
+
readonly sessions: BrowserSessionManager;
|
|
92
|
+
private readonly tools;
|
|
93
|
+
private readonly orchestrator;
|
|
94
|
+
private readonly model?;
|
|
95
|
+
private readonly tasks;
|
|
96
|
+
private readonly stepHandlers;
|
|
97
|
+
private readonly controllers;
|
|
98
|
+
private readonly maxTabs;
|
|
99
|
+
private readonly maxSessions;
|
|
100
|
+
private readonly maxSteps;
|
|
101
|
+
readonly console: BrowserConsole;
|
|
102
|
+
constructor(browser: BashirBrowser, model?: ReasoningModel, options?: BrowserOperatorOptions);
|
|
103
|
+
private requireModel;
|
|
104
|
+
/** Returns the operator's tool registry. */
|
|
105
|
+
toolRegistry(): ToolRegistry;
|
|
106
|
+
/** The list of tool names available to the agent. */
|
|
107
|
+
toolNames(): string[];
|
|
108
|
+
/** Runs a goal through the browser reasoning loop. */
|
|
109
|
+
run(goal: string, options?: {
|
|
110
|
+
signal?: AbortSignal;
|
|
111
|
+
onStep?: ProgressCallback;
|
|
112
|
+
id?: string;
|
|
113
|
+
}): Promise<AgentTask>;
|
|
114
|
+
/** Resumes a paused task. */
|
|
115
|
+
resume(taskId: string, options?: {
|
|
116
|
+
signal?: AbortSignal;
|
|
117
|
+
onStep?: ProgressCallback;
|
|
118
|
+
}): Promise<AgentTask>;
|
|
119
|
+
/** Returns a task by id. */
|
|
120
|
+
task(taskId: string): AgentTask | null;
|
|
121
|
+
/** Returns step records for a task. */
|
|
122
|
+
steps(taskId: string): StepRecord[];
|
|
123
|
+
/** Stops a running task. */
|
|
124
|
+
stop(taskId: string): void;
|
|
125
|
+
/** Stops all running tasks. */
|
|
126
|
+
stopAll(): void;
|
|
127
|
+
/** Destroys all browser sessions. */
|
|
128
|
+
destroy(): Promise<void>;
|
|
129
|
+
}
|
|
130
|
+
/** Helper to build a BrowserOperator with a model. */
|
|
131
|
+
export declare function createBrowserOperator(browser: BashirBrowser, model: ReasoningModel, options?: BrowserOperatorOptions): BrowserOperator;
|
|
132
|
+
export { ConfigurationError, RuntimeError, ValidationError, type ReasoningModel, type ReasoningInput, type ModelDecision, type Observation, type ProgressCallback, type AgentTask };
|
|
133
|
+
export type { BrowserToolContext };
|
|
134
|
+
//# sourceMappingURL=browser-operator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-operator.d.ts","sourceRoot":"","sources":["../src/browser-operator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACpF,OAAO,EACL,YAAY,EAEZ,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,K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AqB,CACnC,OAAO,EAAE,aAAa,EACtB,KAAK,EAAE,cAAc,EACrB,OAAO,GAAE,sBAA2B,GACnC,eAAe,CAEjB;AAED,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,eAAe,EAAE,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,KAAK,gBAAgB,EAAE,KAAK,SAAS,EAAE,CAAC;AACpL,YAAY,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { ConfigurationError, RuntimeError, ValidationError } from '@bashirweb/core';
|
|
2
|
+
import { ToolRegistry, CollaborationOrchestrator, } from '@bashirweb/agent';
|
|
3
|
+
import { createBrowserTools } from './browser-tools.js';
|
|
4
|
+
import { BrowserConsole } from './browser-console.js';
|
|
5
|
+
/**
|
|
6
|
+
* A single browser session: a named group of tabs sharing a browser context.
|
|
7
|
+
*/
|
|
8
|
+
export class BrowserSession {
|
|
9
|
+
browser;
|
|
10
|
+
id;
|
|
11
|
+
pages = new Map();
|
|
12
|
+
constructor(browser, id) {
|
|
13
|
+
this.browser = browser;
|
|
14
|
+
this.id = id;
|
|
15
|
+
}
|
|
16
|
+
/** Opens a new tab and registers it. */
|
|
17
|
+
async newTab(url) {
|
|
18
|
+
const page = await this.browser.newPage({ context: undefined });
|
|
19
|
+
this.pages.set(page.id, page);
|
|
20
|
+
if (url)
|
|
21
|
+
await page.goto(url).catch(() => undefined);
|
|
22
|
+
return page;
|
|
23
|
+
}
|
|
24
|
+
/** Gets a registered page by id. */
|
|
25
|
+
getPage(pageId) {
|
|
26
|
+
const page = this.pages.get(pageId);
|
|
27
|
+
if (!page)
|
|
28
|
+
throw new RuntimeError(`Tab ${pageId} not found in session ${this.id}`);
|
|
29
|
+
return page;
|
|
30
|
+
}
|
|
31
|
+
/** Lists all open tabs. */
|
|
32
|
+
listTabs() {
|
|
33
|
+
return [...this.pages.values()]
|
|
34
|
+
.filter((p) => !p.isClosed)
|
|
35
|
+
.map((p) => ({ id: p.id, url: p.url(), title: '' }));
|
|
36
|
+
}
|
|
37
|
+
/** Closes a tab. */
|
|
38
|
+
async closeTab(pageId) {
|
|
39
|
+
const page = this.pages.get(pageId);
|
|
40
|
+
if (page) {
|
|
41
|
+
await page.close().catch(() => undefined);
|
|
42
|
+
this.pages.delete(pageId);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** Closes all tabs and the session's browser. */
|
|
46
|
+
async destroy() {
|
|
47
|
+
for (const page of [...this.pages.values()]) {
|
|
48
|
+
await page.close().catch(() => undefined);
|
|
49
|
+
}
|
|
50
|
+
this.pages.clear();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Manages browser sessions for the Agent 1 operator. Each session owns a set of
|
|
55
|
+
* tabs. The session manager enforces tab/session limits and cleans up on destroy.
|
|
56
|
+
*/
|
|
57
|
+
export class BrowserSessionManager {
|
|
58
|
+
browser;
|
|
59
|
+
sessions = new Map();
|
|
60
|
+
maxTabs;
|
|
61
|
+
maxSessions;
|
|
62
|
+
constructor(browser, options = {}) {
|
|
63
|
+
this.browser = browser;
|
|
64
|
+
this.maxTabs = options.tabs?.maxTabs ?? 20;
|
|
65
|
+
this.maxSessions = options.maxSessions ?? 5;
|
|
66
|
+
}
|
|
67
|
+
/** Creates a new session with one blank tab. */
|
|
68
|
+
async newSession(url) {
|
|
69
|
+
if (this.sessions.size >= this.maxSessions) {
|
|
70
|
+
throw new RuntimeError(`Maximum sessions (${this.maxSessions}) reached`);
|
|
71
|
+
}
|
|
72
|
+
const session = new BrowserSession(this.browser, `session-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`);
|
|
73
|
+
this.sessions.set(session.id, session);
|
|
74
|
+
await session.newTab(url);
|
|
75
|
+
return session;
|
|
76
|
+
}
|
|
77
|
+
/** Creates a new tab in the first session (or a new session if none). */
|
|
78
|
+
async newTab(url) {
|
|
79
|
+
let session = [...this.sessions.values()][0];
|
|
80
|
+
if (!session) {
|
|
81
|
+
session = await this.newSession(url);
|
|
82
|
+
return session.getPage([...session.pages.keys()][0]);
|
|
83
|
+
}
|
|
84
|
+
if (session.pages.size >= this.maxTabs) {
|
|
85
|
+
throw new RuntimeError(`Maximum tabs (${this.maxTabs}) reached in session ${session.id}`);
|
|
86
|
+
}
|
|
87
|
+
return session.newTab(url);
|
|
88
|
+
}
|
|
89
|
+
/** Gets a page from any session by its id. */
|
|
90
|
+
getPage(pageId) {
|
|
91
|
+
for (const session of this.sessions.values()) {
|
|
92
|
+
if (session.pages.has(pageId))
|
|
93
|
+
return session.getPage(pageId);
|
|
94
|
+
}
|
|
95
|
+
throw new RuntimeError(`Tab ${pageId} not found in any session`);
|
|
96
|
+
}
|
|
97
|
+
/** Lists all tabs across all sessions. */
|
|
98
|
+
listTabs() {
|
|
99
|
+
const tabs = [];
|
|
100
|
+
for (const session of this.sessions.values()) {
|
|
101
|
+
for (const page of session.pages.values()) {
|
|
102
|
+
if (!page.isClosed)
|
|
103
|
+
tabs.push({ id: page.id, url: page.url(), title: '', sessionId: session.id });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return tabs;
|
|
107
|
+
}
|
|
108
|
+
/** Closes a tab by id. */
|
|
109
|
+
async closeTab(pageId) {
|
|
110
|
+
for (const session of this.sessions.values()) {
|
|
111
|
+
if (session.pages.has(pageId)) {
|
|
112
|
+
await session.closeTab(pageId);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
throw new RuntimeError(`Tab ${pageId} not found`);
|
|
117
|
+
}
|
|
118
|
+
/** Destroys all sessions. */
|
|
119
|
+
async destroyAll() {
|
|
120
|
+
for (const session of [...this.sessions.values()]) {
|
|
121
|
+
await session.destroy();
|
|
122
|
+
}
|
|
123
|
+
this.sessions.clear();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* **Agent 1 — the AI browser operator.**
|
|
128
|
+
*
|
|
129
|
+
* An autonomous agent that drives a real browser through a continuous
|
|
130
|
+
* observe → reason → act → observe loop across **multiple tabs**. A
|
|
131
|
+
* {@link ReasoningModel} decides which browser tool to call; the
|
|
132
|
+
* {@link CollaborationOrchestrator} executes it through the tool registry, captures
|
|
133
|
+
* the observation, and feeds it back.
|
|
134
|
+
*
|
|
135
|
+
* **Provider-agnostic — no AI is hardcoded.** Any {@link ReasoningModel} implementation
|
|
136
|
+
* can drive the operator. Constructing without a model is allowed (the tool layer works
|
|
137
|
+
* standalone); calling {@link run} without a model throws a {@link ConfigurationError}.
|
|
138
|
+
*/
|
|
139
|
+
export class BrowserOperator {
|
|
140
|
+
browser;
|
|
141
|
+
sessions;
|
|
142
|
+
tools;
|
|
143
|
+
orchestrator;
|
|
144
|
+
model;
|
|
145
|
+
tasks = new Map();
|
|
146
|
+
stepHandlers = new Map();
|
|
147
|
+
controllers = new Map();
|
|
148
|
+
maxTabs;
|
|
149
|
+
maxSessions;
|
|
150
|
+
maxSteps;
|
|
151
|
+
console;
|
|
152
|
+
constructor(browser, model, options = {}) {
|
|
153
|
+
this.browser = browser;
|
|
154
|
+
this.maxTabs = options.maxTabs ?? 20;
|
|
155
|
+
this.maxSessions = options.maxSessions ?? 5;
|
|
156
|
+
this.maxSteps = options.maxSteps ?? 25;
|
|
157
|
+
this.model = model;
|
|
158
|
+
this.sessions = new BrowserSessionManager(browser, { maxSessions: this.maxSessions, tabs: { maxTabs: this.maxTabs } });
|
|
159
|
+
this.console = new BrowserConsole(options.approvalHandler ? undefined : undefined);
|
|
160
|
+
this.tools = createBrowserTools();
|
|
161
|
+
const lazyModel = {
|
|
162
|
+
nextAction: (input) => this.requireModel().nextAction(input),
|
|
163
|
+
};
|
|
164
|
+
this.orchestrator = new CollaborationOrchestrator(this.tools, lazyModel, {
|
|
165
|
+
maxSteps: this.maxSteps,
|
|
166
|
+
stepTimeoutMs: options.stepTimeoutMs,
|
|
167
|
+
store: options.store,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
requireModel() {
|
|
171
|
+
if (!this.model)
|
|
172
|
+
throw new ConfigurationError('BrowserOperator requires a ReasoningModel to run tasks. No default model is hardcoded.');
|
|
173
|
+
return this.model;
|
|
174
|
+
}
|
|
175
|
+
/** Returns the operator's tool registry. */
|
|
176
|
+
toolRegistry() {
|
|
177
|
+
return this.tools;
|
|
178
|
+
}
|
|
179
|
+
/** The list of tool names available to the agent. */
|
|
180
|
+
toolNames() {
|
|
181
|
+
return this.tools.list().map((t) => t.name);
|
|
182
|
+
}
|
|
183
|
+
/** Runs a goal through the browser reasoning loop. */
|
|
184
|
+
async run(goal, options = {}) {
|
|
185
|
+
const id = options.id ?? `browser-${goal.slice(0, 24).replace(/[^a-zA-Z0-9]+/g, '-').replace(/^-+|-+$/g, '') || 'goal'}-${Date.now().toString(36)}`;
|
|
186
|
+
this.console.taskEvent({ id, status: 'running', goal, steps: [], cursor: 0, createdAt: new Date().toISOString(), startedAt: new Date().toISOString(), finishedAt: null, error: null, summary: null, owner: null }, 'started');
|
|
187
|
+
if (options.onStep)
|
|
188
|
+
this.stepHandlers.set(id, options.onStep);
|
|
189
|
+
const wrappedOnStep = (step, task) => {
|
|
190
|
+
this.console.record(step.index, step.tool, step.status, step.reasoning, step.summary);
|
|
191
|
+
const handler = this.stepHandlers.get(id);
|
|
192
|
+
return handler?.(step, task);
|
|
193
|
+
};
|
|
194
|
+
try {
|
|
195
|
+
const task = await this.orchestrator.run(goal, {
|
|
196
|
+
signal: options.signal,
|
|
197
|
+
onStep: wrappedOnStep,
|
|
198
|
+
id,
|
|
199
|
+
});
|
|
200
|
+
this.tasks.set(id, task);
|
|
201
|
+
this.console.taskEvent(task, task.summary ?? 'finished');
|
|
202
|
+
return task;
|
|
203
|
+
}
|
|
204
|
+
finally {
|
|
205
|
+
this.stepHandlers.delete(id);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/** Resumes a paused task. */
|
|
209
|
+
async resume(taskId, options = {}) {
|
|
210
|
+
if (options.onStep)
|
|
211
|
+
this.stepHandlers.set(taskId, options.onStep);
|
|
212
|
+
try {
|
|
213
|
+
return await this.orchestrator.resume(taskId, {
|
|
214
|
+
signal: options.signal,
|
|
215
|
+
onStep: (step, task) => {
|
|
216
|
+
this.console.record(step.index, step.tool, step.status, step.reasoning, step.summary);
|
|
217
|
+
return this.stepHandlers.get(taskId)?.(step, task);
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
finally {
|
|
222
|
+
this.stepHandlers.delete(taskId);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/** Returns a task by id. */
|
|
226
|
+
task(taskId) {
|
|
227
|
+
return this.orchestrator.task(taskId);
|
|
228
|
+
}
|
|
229
|
+
/** Returns step records for a task. */
|
|
230
|
+
steps(taskId) {
|
|
231
|
+
return this.orchestrator.stepsFor(taskId);
|
|
232
|
+
}
|
|
233
|
+
/** Stops a running task. */
|
|
234
|
+
stop(taskId) {
|
|
235
|
+
this.orchestrator.stop(taskId);
|
|
236
|
+
}
|
|
237
|
+
/** Stops all running tasks. */
|
|
238
|
+
stopAll() {
|
|
239
|
+
this.orchestrator.stopAll();
|
|
240
|
+
void this.sessions.destroyAll();
|
|
241
|
+
}
|
|
242
|
+
/** Destroys all browser sessions. */
|
|
243
|
+
async destroy() {
|
|
244
|
+
this.stopAll();
|
|
245
|
+
await this.sessions.destroyAll();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/** Helper to build a BrowserOperator with a model. */
|
|
249
|
+
export function createBrowserOperator(browser, model, options = {}) {
|
|
250
|
+
return new BrowserOperator(browser, model, options);
|
|
251
|
+
}
|
|
252
|
+
export { ConfigurationError, RuntimeError, ValidationError };
|
|
253
|
+
//# sourceMappingURL=browser-operator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-operator.js","sourceRoot":"","sources":["../src/browser-operator.ts"],"names":[],"mappings":"AA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AI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;QAC5B,KAAK,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;IAClC,CAAC;IAED,qCAAqC;IACrC,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;IACnC,CAAC;CACF;AAED,sDAAsD;AACtD,MAAM,UAAU,qBAAqB,CACnC,OAAsB,EACtB,KAAqB,EACrB,UAAkC,EAAE;IAEpC,OAAO,IAAI,eAAe,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACtD,CAAC;AAED,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,eAAe,EAAyH,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { RuntimeError, ValidationError } from '@bashirweb/core';
|
|
2
|
+
import { ToolRegistry, type ToolContext } from '@bashirweb/agent';
|
|
3
|
+
import type { BashirPage, BashirContext, BashirBrowser } from '@bashirweb/browser';
|
|
4
|
+
import type { BrowserSessionManager } from './browser-operator.js';
|
|
5
|
+
/**
|
|
6
|
+
* Tools for the Agent 1 browser operator. Each tool operates on a specific tab
|
|
7
|
+
* (identified by `tabId`) within a session managed by the {@link BrowserSessionManager}.
|
|
8
|
+
* All tools return structured data suitable for the reasoning model to interpret.
|
|
9
|
+
*/
|
|
10
|
+
/** Context passed to each browser tool handler. */
|
|
11
|
+
export interface BrowserToolContext extends ToolContext {
|
|
12
|
+
sessions: BrowserSessionManager;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Creates the browser tool registry for Agent 1. Tools are:
|
|
16
|
+
* browser_navigate, browser_extract, browser_click, browser_fill, browser_type,
|
|
17
|
+
* browser_press, browser_screenshot, browser_tab_new, browser_tab_close,
|
|
18
|
+
* browser_tab_list, browser_tab_select, browser_evaluate, browser_wait,
|
|
19
|
+
* browser_get_text, browser_get_attribute, browser_is_visible.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createBrowserTools(): ToolRegistry;
|
|
22
|
+
export { RuntimeError, ValidationError };
|
|
23
|
+
export type { BashirPage, BashirContext, BashirBrowser };
|
|
24
|
+
//# sourceMappingURL=browser-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-tools.d.ts","sourceRoot":"","sources":["../src/browser-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAc,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAEnE;;;;GAIG;AAEH,mDAAmD;AACnD,MAAM,WAAW,kBAAmB,SAAQ,WAAW;IACrD,QAAQ,EAAE,qBAAqB,CAAC;CACjC;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,IAAI,YAAY,CA8VjD;AAED,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,CAAC;AACzC,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,CAAC"}
|