augure 0.8.0 → 0.9.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.
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env node
2
+
3
+ // ../core/dist/mcp-server.js
4
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
5
+ import { ListToolsRequestSchema, CallToolRequestSchema, ListResourcesRequestSchema, ReadResourceRequestSchema, ListPromptsRequestSchema, GetPromptRequestSchema } from "@modelcontextprotocol/sdk/types.js";
6
+ function validateMemoryPath(path) {
7
+ if (path.includes("..") || path.startsWith("/")) {
8
+ throw new Error(`Invalid memory path: ${path}`);
9
+ }
10
+ }
11
+ function createMcpServer(config) {
12
+ const server = new Server({ name: "augure", version: config.version ?? "0.0.0" }, { capabilities: { tools: {}, resources: {}, prompts: {} } });
13
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
14
+ tools: config.tools.list().map((t) => ({
15
+ name: t.name,
16
+ description: t.description,
17
+ inputSchema: t.parameters
18
+ }))
19
+ }));
20
+ server.setRequestHandler(CallToolRequestSchema, async (req) => {
21
+ const result = await config.tools.execute(req.params.name, req.params.arguments ?? {});
22
+ return {
23
+ content: [{ type: "text", text: result.output }],
24
+ isError: !result.success
25
+ };
26
+ });
27
+ server.setRequestHandler(ListResourcesRequestSchema, async () => {
28
+ const memFiles = await config.memory.list();
29
+ const jobs = config.scheduler.listJobs();
30
+ return {
31
+ resources: [
32
+ ...memFiles.map((f) => ({
33
+ uri: `memory://${f}`,
34
+ name: f,
35
+ mimeType: "text/markdown"
36
+ })),
37
+ {
38
+ uri: "jobs://list",
39
+ name: "Scheduled Jobs",
40
+ mimeType: "application/json"
41
+ },
42
+ ...jobs.map((j) => ({
43
+ uri: `jobs://${j.id}`,
44
+ name: `Job: ${j.id}`,
45
+ mimeType: "application/json"
46
+ }))
47
+ ]
48
+ };
49
+ });
50
+ server.setRequestHandler(ReadResourceRequestSchema, async (req) => {
51
+ const uri = req.params.uri;
52
+ if (uri.startsWith("memory://")) {
53
+ const path = uri.slice("memory://".length);
54
+ validateMemoryPath(path);
55
+ let content;
56
+ try {
57
+ content = await config.memory.read(path);
58
+ } catch {
59
+ throw new Error(`Memory file not found: ${path}`);
60
+ }
61
+ return {
62
+ contents: [{ uri, text: content, mimeType: "text/markdown" }]
63
+ };
64
+ }
65
+ if (uri === "jobs://list") {
66
+ return {
67
+ contents: [{
68
+ uri,
69
+ text: JSON.stringify(config.scheduler.listJobs(), null, 2),
70
+ mimeType: "application/json"
71
+ }]
72
+ };
73
+ }
74
+ if (uri.startsWith("jobs://")) {
75
+ const jobId = uri.slice("jobs://".length);
76
+ const job = config.scheduler.listJobs().find((j) => j.id === jobId);
77
+ if (!job) {
78
+ throw new Error(`Job not found: ${jobId}`);
79
+ }
80
+ return {
81
+ contents: [{
82
+ uri,
83
+ text: JSON.stringify(job, null, 2),
84
+ mimeType: "application/json"
85
+ }]
86
+ };
87
+ }
88
+ throw new Error(`Unknown resource: ${uri}`);
89
+ });
90
+ server.setRequestHandler(ListPromptsRequestSchema, async () => {
91
+ if (!config.personaResolver)
92
+ return { prompts: [] };
93
+ const personas = config.personaResolver.listAll();
94
+ return {
95
+ prompts: personas.map((p) => ({
96
+ name: p.meta.id,
97
+ description: `Persona: ${p.meta.name}`,
98
+ arguments: [
99
+ { name: "message", description: "User message for context", required: false }
100
+ ]
101
+ }))
102
+ };
103
+ });
104
+ server.setRequestHandler(GetPromptRequestSchema, async (req) => {
105
+ if (!config.personaResolver)
106
+ throw new Error("No personas configured");
107
+ const message = req.params.arguments?.message ?? "";
108
+ const personaText = config.personaResolver.resolve(String(message));
109
+ return {
110
+ messages: [
111
+ { role: "user", content: { type: "text", text: personaText } }
112
+ ]
113
+ };
114
+ });
115
+ return server;
116
+ }
117
+
118
+ export {
119
+ createMcpServer
120
+ };
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+
28
+ export {
29
+ __commonJS,
30
+ __toESM
31
+ };
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ noopLogger
4
+ } from "./chunk-62OPINAX.js";
5
+
6
+ // ../browser/dist/session-manager.js
7
+ import { Stagehand } from "@browserbasehq/stagehand";
8
+
9
+ // ../browser/dist/provider.js
10
+ var PROVIDER_BASE_URLS = {
11
+ openrouter: "https://openrouter.ai/api/v1",
12
+ anthropic: "https://api.anthropic.com/v1",
13
+ openai: "https://api.openai.com/v1"
14
+ };
15
+ function createStagehandConfig(config, llm) {
16
+ const baseURL = PROVIDER_BASE_URLS[llm.provider];
17
+ return {
18
+ env: config.provider === "local" ? "LOCAL" : "BROWSERBASE",
19
+ apiKey: config.browserbase?.apiKey,
20
+ projectId: config.browserbase?.projectId,
21
+ model: {
22
+ modelName: llm.model,
23
+ apiKey: llm.apiKey,
24
+ ...baseURL ? { baseURL } : {}
25
+ },
26
+ localBrowserLaunchOptions: config.provider === "local" ? {
27
+ headless: config.defaults?.headless ?? true,
28
+ viewport: config.defaults?.viewport ?? { width: 1280, height: 720 }
29
+ } : void 0,
30
+ domSettleTimeout: (config.defaults?.timeout ?? 30) * 1e3,
31
+ verbose: 0,
32
+ disablePino: true
33
+ };
34
+ }
35
+
36
+ // ../browser/dist/session-manager.js
37
+ var BrowserSessionManager = class {
38
+ sessions = /* @__PURE__ */ new Map();
39
+ config;
40
+ llm;
41
+ ttlMs;
42
+ log;
43
+ counter = 0;
44
+ constructor(opts) {
45
+ this.config = opts.config;
46
+ this.llm = opts.llm;
47
+ this.ttlMs = opts.ttlMs ?? 12e4;
48
+ this.log = opts.logger ?? noopLogger;
49
+ }
50
+ async open(url) {
51
+ const id = `s_${Date.now()}_${++this.counter}`;
52
+ const stagehandConfig = createStagehandConfig(this.config, this.llm);
53
+ const stagehand = new Stagehand(stagehandConfig);
54
+ await stagehand.init();
55
+ if (url) {
56
+ const page = stagehand.context.activePage();
57
+ if (!page)
58
+ throw new Error(`No active page after init for session ${id}`);
59
+ await page.goto(url, { waitUntil: "domcontentloaded" });
60
+ }
61
+ const timer = setTimeout(() => {
62
+ this.log.warn(`Browser session ${id} expired (TTL ${this.ttlMs}ms)`);
63
+ this.close(id).catch(() => {
64
+ });
65
+ }, this.ttlMs);
66
+ this.sessions.set(id, { stagehand, timer });
67
+ this.log.info(`Browser session ${id} opened`);
68
+ return id;
69
+ }
70
+ async navigate(sessionId, url) {
71
+ const entry = this.getSession(sessionId);
72
+ this.resetTtl(sessionId, entry);
73
+ const page = entry.stagehand.context.activePage();
74
+ if (!page)
75
+ throw new Error(`No active page for session ${sessionId}`);
76
+ await page.goto(url, { waitUntil: "domcontentloaded" });
77
+ }
78
+ async act(sessionId, instruction, variables) {
79
+ const entry = this.getSession(sessionId);
80
+ this.resetTtl(sessionId, entry);
81
+ const result = await entry.stagehand.act(instruction, variables ? { variables } : void 0);
82
+ return { success: result.success, message: result.message ?? result.actionDescription ?? "" };
83
+ }
84
+ async extract(sessionId, instruction, schema) {
85
+ const entry = this.getSession(sessionId);
86
+ this.resetTtl(sessionId, entry);
87
+ if (schema) {
88
+ return entry.stagehand.extract(instruction, schema);
89
+ }
90
+ return entry.stagehand.extract(instruction);
91
+ }
92
+ async observe(sessionId, instruction) {
93
+ const entry = this.getSession(sessionId);
94
+ this.resetTtl(sessionId, entry);
95
+ const actions = await entry.stagehand.observe(instruction);
96
+ return actions.map((a) => ({
97
+ description: a.description ?? "",
98
+ selector: a.selector ?? ""
99
+ }));
100
+ }
101
+ async screenshot(sessionId) {
102
+ const entry = this.getSession(sessionId);
103
+ this.resetTtl(sessionId, entry);
104
+ const page = entry.stagehand.context.activePage();
105
+ if (!page)
106
+ throw new Error(`No active page for session ${sessionId}`);
107
+ const buffer = await page.screenshot();
108
+ return Buffer.from(buffer).toString("base64");
109
+ }
110
+ async close(sessionId) {
111
+ const entry = this.sessions.get(sessionId);
112
+ if (!entry)
113
+ return;
114
+ clearTimeout(entry.timer);
115
+ this.sessions.delete(sessionId);
116
+ try {
117
+ await entry.stagehand.close();
118
+ } catch {
119
+ }
120
+ this.log.info(`Browser session ${sessionId} closed`);
121
+ }
122
+ async closeAll() {
123
+ const ids = [...this.sessions.keys()];
124
+ await Promise.all(ids.map((id) => this.close(id)));
125
+ }
126
+ getSession(sessionId) {
127
+ const entry = this.sessions.get(sessionId);
128
+ if (!entry)
129
+ throw new Error(`Unknown or expired: no browser session ${sessionId}`);
130
+ return entry;
131
+ }
132
+ resetTtl(sessionId, entry) {
133
+ clearTimeout(entry.timer);
134
+ entry.timer = setTimeout(() => {
135
+ this.log.warn(`Browser session ${sessionId} expired (TTL ${this.ttlMs}ms)`);
136
+ this.close(sessionId).catch(() => {
137
+ });
138
+ }, this.ttlMs);
139
+ }
140
+ };
141
+
142
+ export {
143
+ createStagehandConfig,
144
+ BrowserSessionManager
145
+ };