Skip to content

Commit 2e128ce

Browse files
authored
Add fetchAndRun tool to omnibot (commontoolsinc#2061)
* Add `fetchAndRun` tool to omnibot * Move linkTool to just omnibot * Format pass * Fix lint errors * Fix lint
1 parent c1ce577 commit 2e128ce

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

packages/patterns/chatbot.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
wish,
1919
} from "commontools";
2020
import { type MentionableCharm } from "./backlinks-index.tsx";
21-
import { linkTool } from "./link-tool.tsx";
2221

2322
function schemaifyWish<T>(path: string) {
2423
return derive<T, T>(wish<T>(path), (i) => i);
@@ -383,11 +382,6 @@ export default recipe<ChatInput, ChatOutput>(
383382
"Remove an attachment from the attachments array by its mentionable NAME.",
384383
handler: removeAttachmentTool({ allAttachments }),
385384
},
386-
createLink: {
387-
description:
388-
"Create a link between two charm cells. Use paths like 'CharmName/result/value' or 'CharmName/input/field'. Creates a bidirectional binding where changes to the source are reflected in the target.",
389-
handler: linkTool({ mentionable }),
390-
},
391385
};
392386

393387
// Merge static and dynamic tools

packages/patterns/omnibox-fab.tsx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22
import {
33
Cell,
44
cell,
5+
compileAndRun,
56
derive,
7+
fetchProgram,
68
handler,
79
ifElse,
810
NAME,
11+
navigateTo,
912
recipe,
1013
UI,
1114
} from "commontools";
1215
import Chatbot from "./chatbot.tsx";
1316
import { calculator, readWebpage, searchWeb } from "./common-tools.tsx";
1417
import { MentionableCharm } from "./backlinks-index.tsx";
18+
import { linkTool } from "./link-tool.tsx";
1519

1620
interface OmniboxFABInput {
1721
mentionable: Cell<MentionableCharm[]>;
@@ -35,9 +39,27 @@ const dismissPeek = handler<
3539
peekDismissedIndex.set(assistantMessageCount);
3640
});
3741

42+
const fetchAndRunPattern = handler<
43+
{ url: string },
44+
{ mentionable: Cell<MentionableCharm[]> }
45+
>(({ url }, { mentionable: _mentionable }) => {
46+
const { pending: _fetchPending, result: program, error: _fetchError } =
47+
fetchProgram({ url });
48+
49+
const compileParams = derive(program, (p) => ({
50+
files: p?.files ?? [],
51+
main: p?.main ?? "",
52+
input: { value: 10 },
53+
}));
54+
const { pending: _compilePending, result, error: _compileError } =
55+
compileAndRun(compileParams);
56+
57+
return navigateTo(result);
58+
});
59+
3860
export default recipe<OmniboxFABInput>(
3961
"OmniboxFAB",
40-
({ mentionable: _mentionable }) => {
62+
({ mentionable }) => {
4163
const omnibot = Chatbot({
4264
system:
4365
"You are a polite but efficient assistant. Think Star Trek computer - helpful and professional without unnecessary conversation. Let your actions speak for themselves.\n\nTool usage priority:\n- Search this space first: listMentionable → addAttachment to access items\n- Search externally only when clearly needed: searchWeb for current events, external information, or when nothing relevant exists in the space\n\nBe matter-of-fact. Prefer action to explanation.",
@@ -52,6 +74,15 @@ export default recipe<OmniboxFABInput>(
5274
calculator: {
5375
pattern: calculator,
5476
},
77+
fetchAndRunPattern: {
78+
description: "Fetch a pattern from the URL, compile it and run it.",
79+
handler: fetchAndRunPattern({ mentionable }),
80+
},
81+
createLink: {
82+
description:
83+
"Create a link between two charm cells. Use paths like 'CharmName/result/value' or 'CharmName/input/field'. Creates a bidirectional binding where changes to the source are reflected in the target.",
84+
handler: linkTool({ mentionable }),
85+
},
5586
},
5687
});
5788

0 commit comments

Comments
 (0)