web-agent-bridge 3.12.0 → 3.13.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,66 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Anthropic Claude tool-use example agent that uses the WAB system prompt
5
+ * and WABLiveTool to safely interact with a third-party site.
6
+ *
7
+ * Prerequisites:
8
+ * npm install @anthropic-ai/sdk web-agent-bridge
9
+ * export ANTHROPIC_API_KEY=sk-ant-...
10
+ *
11
+ * Run:
12
+ * node examples/anthropic-tools-agent.js "Place an order on shop.example.com"
13
+ */
14
+
15
+ const Anthropic = require('@anthropic-ai/sdk');
16
+ const { systemPrompt, WABLiveTool } = require('web-agent-bridge');
17
+
18
+ const client = new Anthropic();
19
+ const tool = new WABLiveTool({ agentName: 'wab-anthropic-demo/1' });
20
+
21
+ const CLAUDE_TOOL_SCHEMA = [{
22
+ name: tool.name,
23
+ description: tool.description,
24
+ input_schema: tool.schema
25
+ }];
26
+
27
+ async function run(userTask) {
28
+ const messages = [{ role: 'user', content: userTask }];
29
+ const system = systemPrompt({ agentName: 'wab-anthropic-demo', agentVersion: '1.0' });
30
+
31
+ for (let step = 0; step < 6; step++) {
32
+ const reply = await client.messages.create({
33
+ model: 'claude-3-5-sonnet-latest',
34
+ max_tokens: 1024,
35
+ system,
36
+ tools: CLAUDE_TOOL_SCHEMA,
37
+ messages
38
+ });
39
+
40
+ messages.push({ role: 'assistant', content: reply.content });
41
+
42
+ if (reply.stop_reason !== 'tool_use') {
43
+ const text = reply.content.filter(b => b.type === 'text').map(b => b.text).join('\n');
44
+ console.log('\n=== Final answer ===\n' + text);
45
+ return text;
46
+ }
47
+
48
+ const toolUses = reply.content.filter(b => b.type === 'tool_use');
49
+ const results = [];
50
+ for (const tu of toolUses) {
51
+ console.log(`→ tool call: ${tu.name} ${JSON.stringify(tu.input)}`);
52
+ const out = await (tool.invoke ? tool.invoke(tu.input) : tool._call(tu.input));
53
+ console.log('← tool result:', String(out).slice(0, 280));
54
+ results.push({ type: 'tool_result', tool_use_id: tu.id, content: typeof out === 'string' ? out : JSON.stringify(out) });
55
+ }
56
+ messages.push({ role: 'user', content: results });
57
+ }
58
+ console.warn('Max steps reached without a final answer.');
59
+ }
60
+
61
+ if (require.main === module) {
62
+ const task = process.argv.slice(2).join(' ') || 'Search shop.example.com for olive oil';
63
+ run(task).catch((e) => { console.error(e); process.exit(1); });
64
+ }
65
+
66
+ module.exports = { run };
@@ -0,0 +1,69 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * OpenAI tool-calling example agent that uses the WAB system prompt
5
+ * and WABLiveTool to safely interact with a third-party site.
6
+ *
7
+ * Prerequisites:
8
+ * npm install openai web-agent-bridge
9
+ * export OPENAI_API_KEY=sk-...
10
+ *
11
+ * Run:
12
+ * node examples/openai-tools-agent.js "Search shop.example.com for olive oil"
13
+ */
14
+
15
+ const OpenAI = require('openai');
16
+ const { systemPrompt, WABLiveTool } = require('web-agent-bridge');
17
+
18
+ const client = new OpenAI();
19
+ const tool = new WABLiveTool({ agentName: 'wab-openai-demo/1' });
20
+
21
+ const OPENAI_TOOL_SCHEMA = [{
22
+ type: 'function',
23
+ function: {
24
+ name: tool.name,
25
+ description: tool.description,
26
+ parameters: tool.schema
27
+ }
28
+ }];
29
+
30
+ async function run(userTask) {
31
+ const messages = [
32
+ { role: 'system', content: systemPrompt({ agentName: 'wab-openai-demo', agentVersion: '1.0' }) },
33
+ { role: 'user', content: userTask }
34
+ ];
35
+
36
+ for (let step = 0; step < 6; step++) {
37
+ const reply = await client.chat.completions.create({
38
+ model: 'gpt-4o-mini',
39
+ messages,
40
+ tools: OPENAI_TOOL_SCHEMA,
41
+ tool_choice: 'auto'
42
+ });
43
+
44
+ const msg = reply.choices[0].message;
45
+ messages.push(msg);
46
+
47
+ if (!msg.tool_calls || msg.tool_calls.length === 0) {
48
+ console.log('\n=== Final answer ===\n' + msg.content);
49
+ return msg.content;
50
+ }
51
+
52
+ for (const tc of msg.tool_calls) {
53
+ let args = {};
54
+ try { args = JSON.parse(tc.function.arguments || '{}'); } catch (_) { /* ignore */ }
55
+ console.log(`→ tool call: ${tc.function.name} ${JSON.stringify(args)}`);
56
+ const out = await (tool.invoke ? tool.invoke(args) : tool._call(args));
57
+ console.log('← tool result:', String(out).slice(0, 280));
58
+ messages.push({ role: 'tool', tool_call_id: tc.id, content: typeof out === 'string' ? out : JSON.stringify(out) });
59
+ }
60
+ }
61
+ console.warn('Max steps reached without a final answer.');
62
+ }
63
+
64
+ if (require.main === module) {
65
+ const task = process.argv.slice(2).join(' ') || 'Search shop.example.com for olive oil';
66
+ run(task).catch((e) => { console.error(e); process.exit(1); });
67
+ }
68
+
69
+ module.exports = { run };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-agent-bridge",
3
- "version": "3.12.0",
3
+ "version": "3.13.0",
4
4
  "description": "Agent Transaction Bridge — the trust + transaction layer for agentic commerce. Signed intent contracts, idempotent transactions, Ed25519-verifiable receipts, explicit compensation. Plus the original WAB stack: sovereign browser, ShieldQR, SSL health, DNS discovery, agent mesh, and unified gateway for safe AI–website interaction.",
5
5
  "author": "Web Agent Bridge <dev@webagentbridge.com>",
6
6
  "main": "server/index.js",