Skip to content

Commit 9ef0132

Browse files
authored
Merge pull request #119 from GleapSDK/agent-frontend-tool
Agent frontend tool
2 parents 18da8d4 + 3163a9e commit 9ef0132

17 files changed

Lines changed: 177 additions & 11 deletions

build/browser/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/browser/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/cjs/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/cjs/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/esm/index.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

build/esm/index.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/main.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,40 @@ Gleap.initialize('GnhEkS8fdwxNVjyn3BnYwKzpCkiHgKWL');
1212
// setTimeout(() => {
1313
// Gleap.startBot("6908b32c145ee7d9aa226782");
1414
// }, 1000);
15+
16+
Gleap.identify('535506', {
17+
email: 'luca@gleap.io',
18+
});
19+
20+
setTimeout(() => {
21+
// Gleap.registerAgentTool('workflow-redirect', async ({ botID }) => {
22+
// console.log('Workflow redirect', botID);
23+
// // TODO: Implement your logic.
24+
25+
// // Return a string or JSON object — the AI waits for this response.
26+
// return 'The action was completed successfully.';
27+
// });
28+
29+
Gleap.registerAgentTool('send-money', async ({ amount }) => {
30+
// TODO: Implement your logic.
31+
console.log('Send money', amount);
32+
33+
// Return a string or JSON — the AI waits for this response.
34+
return 'The action failed!';
35+
});
36+
37+
Gleap.registerAgentTool('enable-dark-mode', async () => {
38+
// TODO: Implement your logic.
39+
console.log('Enable dark mode');
40+
41+
// Return a string or JSON — the AI waits for this response.
42+
return 'The action was completed successfully.';
43+
});
44+
45+
Gleap.startAgent('6a4637d818b4a930b509fbc4', {
46+
context: {
47+
userProjectId: '68ed10f4a2ec0e4c2ff4c812',
48+
},
49+
initialMessage: 'Let me know what workflow you want to create.',
50+
});
51+
}, 2000);

index.d.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ export namespace Gleap {
6565
function startNetworkLogger(): void;
6666
function setNetworkLogsBlacklist(networkLogBlacklist: string[]): void;
6767
function setNetworkLogPropsToIgnore(filters: string[]): void;
68+
/**
69+
* @deprecated Use registerAgentTool(name, handler) with a dashboard-defined
70+
* Frontend tool instead.
71+
*/
6872
function registerAgentToolAction(
6973
callback: (toolAction: {
7074
name: string;
@@ -74,6 +78,18 @@ export namespace Gleap {
7478
toolCallId: string;
7579
}) => void
7680
): void;
81+
/**
82+
* Register the handler for a Frontend tool defined on an AI agent in the
83+
* Gleap dashboard. The agent calls the handler with the configured
84+
* parameters and waits for its return value (string or JSON — JSON is
85+
* stringified). Thrown errors are caught and reported back to the AI.
86+
*/
87+
function registerAgentTool(
88+
name: string,
89+
handler: (
90+
params: Record<string, any>
91+
) => string | object | Promise<string | object>
92+
): void;
7793
function registerCustomAction(
7894
customAction: (action: { name: string }) => void
7995
): void;
@@ -100,6 +116,10 @@ export namespace Gleap {
100116
function enableShortcuts(enabled: boolean): void;
101117
function setLanguage(language: string): void;
102118
function preFillForm(data: object): void;
119+
/**
120+
* @deprecated Define Frontend tools on your AI agent in the Gleap dashboard
121+
* and register their handlers via registerAgentTool(name, handler) instead.
122+
*/
103123
function setAiTools(tools: {
104124
name: string;
105125
description: string;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gleap",
3-
"version": "16.2.2",
3+
"version": "16.2.3",
44
"main": "build/cjs/index.js",
55
"module": "build/esm/index.mjs",
66
"exports": {

published/16.2.3/index.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)