@frockbot/plugin-clock 0.0.0 → 0.1.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.
- package/frockbot.json +12 -0
- package/package.json +27 -6
- package/src/agent.ts +56 -0
- package/src/env.d.ts +10 -0
- package/src/index.ts +2 -0
- package/src/manifest.ts +3 -0
- package/tsconfig.json +15 -0
- package/README.md +0 -3
package/frockbot.json
ADDED
package/package.json
CHANGED
|
@@ -1,14 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frockbot/plugin-clock",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./src/index.ts",
|
|
8
|
+
"./agent": "./src/agent.ts",
|
|
9
|
+
"./manifest": "./src/manifest.ts",
|
|
10
|
+
"./frockbot.json": "./frockbot.json",
|
|
11
|
+
"./package.json": "./package.json"
|
|
12
|
+
},
|
|
13
|
+
"frockbot": {
|
|
14
|
+
"manifest": "./frockbot.json"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@frockbot/kernel-contracts": "0.1.0",
|
|
21
|
+
"cordis": "4.0.0-rc.8"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "26.2.0",
|
|
25
|
+
"typescript": "5.9.3"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
6
30
|
"repository": {
|
|
7
31
|
"type": "git",
|
|
8
32
|
"url": "git+https://github.com/timoconnellaus/frockbot.git",
|
|
9
33
|
"directory": "packages/plugin-clock"
|
|
10
|
-
},
|
|
11
|
-
"publishConfig": {
|
|
12
|
-
"access": "public"
|
|
13
34
|
}
|
|
14
35
|
}
|
package/src/agent.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type LlmStreamEvent,
|
|
3
|
+
type NormalizedModelRequest,
|
|
4
|
+
type ToolDefinition,
|
|
5
|
+
} from "@frockbot/kernel-contracts";
|
|
6
|
+
import type { Plugin } from "cordis";
|
|
7
|
+
|
|
8
|
+
function currentTime(): string {
|
|
9
|
+
return new Intl.DateTimeFormat(undefined, {
|
|
10
|
+
dateStyle: "medium",
|
|
11
|
+
timeStyle: "long",
|
|
12
|
+
}).format(new Date());
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const clockTool: ToolDefinition = {
|
|
16
|
+
name: "current_time",
|
|
17
|
+
description: "Return the current local date and time.",
|
|
18
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false },
|
|
19
|
+
idempotent: true,
|
|
20
|
+
validate: (input: unknown) => typeof input === "object" && input !== null,
|
|
21
|
+
execute: async () => ({ content: currentTime(), isError: false }),
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
async function* requestClockTool(
|
|
25
|
+
signal: AbortSignal,
|
|
26
|
+
): AsyncIterable<LlmStreamEvent> {
|
|
27
|
+
signal.throwIfAborted();
|
|
28
|
+
yield {
|
|
29
|
+
// pi-lens-ignore: ts:2322
|
|
30
|
+
type: "tool-call",
|
|
31
|
+
call: { id: crypto.randomUUID(), name: "current_time", input: {} },
|
|
32
|
+
};
|
|
33
|
+
yield {
|
|
34
|
+
type: "finish",
|
|
35
|
+
// pi-lens-ignore: ts:2322
|
|
36
|
+
reason: "tool-calls",
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function shouldRequestClock(request: NormalizedModelRequest): boolean {
|
|
41
|
+
if (request.messages.at(-1)?.role === "tool") return false;
|
|
42
|
+
const user = request.messages.findLast((message) => message.role === "user");
|
|
43
|
+
return user?.role === "user" && user.content.trim() === "/time";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const clockAgentPlugin: Plugin.Function = (ctx) => {
|
|
47
|
+
const tool = ctx.tools.register(clockTool);
|
|
48
|
+
const llm = ctx.on("llm/stream", (request, signal, next) => {
|
|
49
|
+
if (!shouldRequestClock(request)) return next();
|
|
50
|
+
return requestClockTool(signal);
|
|
51
|
+
});
|
|
52
|
+
return [tool, llm];
|
|
53
|
+
};
|
|
54
|
+
clockAgentPlugin.inject = ["tools", "llm"];
|
|
55
|
+
|
|
56
|
+
export default clockAgentPlugin;
|
package/src/env.d.ts
ADDED
package/src/index.ts
ADDED
package/src/manifest.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2023",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Bundler",
|
|
6
|
+
"allowImportingTsExtensions": true,
|
|
7
|
+
"resolveJsonModule": true,
|
|
8
|
+
"strict": true,
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"lib": ["ES2023", "DOM", "DOM.Iterable"],
|
|
12
|
+
"types": ["node"]
|
|
13
|
+
},
|
|
14
|
+
"include": ["src/**/*.ts"]
|
|
15
|
+
}
|
package/README.md
DELETED