-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcounter.js
More file actions
55 lines (51 loc) · 1.41 KB
/
Copy pathcounter.js
File metadata and controls
55 lines (51 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
export function setupCounter(element) {
let counter = 0
const setCounter = (count) => {
counter = count
element.innerHTML = `count is ${counter}`
}
element.addEventListener('click', () => setCounter(counter + 1))
setCounter(0)
const registration = navigator.modelContext.registerTool({
name: "get_page_title",
description: "Get current page title",
inputSchema: { type: "object", properties: {} },
async execute() {
return {
content: [{ type: "text", text: document.title }]
};
}
});
navigator.modelContext.registerTool({
name: 'get_counter',
description: 'This will return the current value of the counter, call this before setting the counter',
inputSchema: {
type: 'object',
properties: {}
},
async execute(args) {
return {
content:
[{type: 'text', text: `the current counter value is ${counter}`}]
}
}
});
navigator.modelContext.registerTool({
name: 'set_counter',
description: 'This will set the counter to the desired value',
inputSchema: {
type: 'object',
properties: {
newCounterValue: { type: 'number', description: 'The number you want to set the counter to' }
},
required: ['newCounterValue']
},
async execute(args) {
const newValue = args.newCounterValue
setCounter(newValue)
return {
content: [{ type: 'text', text: 'counter is now ' + args.newCounterValue }]
};
}
})
}