@frockbot/plugin-provider-foundation 0.0.0 → 0.1.1
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 +15 -0
- package/package.json +30 -6
- package/src/index.ts +2 -0
- package/src/manifest.ts +3 -0
- package/src/runtime.test.ts +67 -0
- package/src/runtime.ts +61 -0
- package/tsconfig.json +15 -0
- package/README.md +0 -3
package/frockbot.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 2,
|
|
3
|
+
"id": "provider-foundation",
|
|
4
|
+
"displayName": "Foundation Provider",
|
|
5
|
+
"version": "0.0.1",
|
|
6
|
+
"compatibility": {
|
|
7
|
+
"frockbot": ">=0.0.1"
|
|
8
|
+
},
|
|
9
|
+
"contributions": {
|
|
10
|
+
"runtime": {
|
|
11
|
+
"entry": "./runtime"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"permissions": []
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frockbot/plugin-provider-foundation",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./src/index.ts",
|
|
8
|
+
"./runtime": "./src/runtime.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
|
+
"test": "bun test src",
|
|
18
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@frockbot/kernel-contracts": "0.1.1",
|
|
22
|
+
"@frockbot/plugin-models": "0.1.1",
|
|
23
|
+
"cordis": "4.0.0-rc.8"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@frockbot/plugin-testkit": "0.1.1",
|
|
27
|
+
"@types/bun": "1.4.0",
|
|
28
|
+
"typescript": "^7.0.2"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
6
33
|
"repository": {
|
|
7
34
|
"type": "git",
|
|
8
35
|
"url": "git+https://github.com/timoconnellaus/frockbot.git",
|
|
9
36
|
"directory": "packages/plugin-provider-foundation"
|
|
10
|
-
},
|
|
11
|
-
"publishConfig": {
|
|
12
|
-
"access": "public"
|
|
13
37
|
}
|
|
14
38
|
}
|
package/src/index.ts
ADDED
package/src/manifest.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
type LlmStreamEvent,
|
|
4
|
+
type NormalizedModelRequest,
|
|
5
|
+
} from "@frockbot/kernel-contracts";
|
|
6
|
+
import { LlmRegistry } from "@frockbot/plugin-models";
|
|
7
|
+
import {
|
|
8
|
+
createPluginHarness,
|
|
9
|
+
verifyPluginPackage,
|
|
10
|
+
} from "@frockbot/plugin-testkit";
|
|
11
|
+
import manifest from "../frockbot.json" with { type: "json" };
|
|
12
|
+
import packageJson from "../package.json" with { type: "json" };
|
|
13
|
+
import foundationProviderPlugin, {
|
|
14
|
+
FOUNDATION_MODEL,
|
|
15
|
+
FOUNDATION_PROVIDER,
|
|
16
|
+
} from "./runtime.js";
|
|
17
|
+
|
|
18
|
+
const request: NormalizedModelRequest = {
|
|
19
|
+
requestId: "request",
|
|
20
|
+
provider: FOUNDATION_PROVIDER,
|
|
21
|
+
model: FOUNDATION_MODEL,
|
|
22
|
+
system: "",
|
|
23
|
+
messages: [{ role: "user", content: "hello" }],
|
|
24
|
+
tools: [],
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
async function collect(
|
|
28
|
+
source: AsyncIterable<LlmStreamEvent>,
|
|
29
|
+
): Promise<LlmStreamEvent[]> {
|
|
30
|
+
const events: LlmStreamEvent[] = [];
|
|
31
|
+
for await (const event of source) events.push(event);
|
|
32
|
+
return events;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
describe("foundation provider plugin", () => {
|
|
36
|
+
test("registers deterministic provider behavior for its fiber lifetime", async () => {
|
|
37
|
+
const harness = await createPluginHarness([LlmRegistry]);
|
|
38
|
+
const fiber = await harness.mount(foundationProviderPlugin);
|
|
39
|
+
|
|
40
|
+
expect(
|
|
41
|
+
await collect(
|
|
42
|
+
harness.root.llm.stream(request, new AbortController().signal),
|
|
43
|
+
),
|
|
44
|
+
).toEqual([
|
|
45
|
+
{ type: "text-delta", text: "Cordis runtime: " },
|
|
46
|
+
{ type: "text-delta", text: "hello" },
|
|
47
|
+
{ type: "finish", reason: "completed" },
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
await fiber.dispose();
|
|
51
|
+
let failure: unknown;
|
|
52
|
+
try {
|
|
53
|
+
harness.root.llm.stream(request, new AbortController().signal);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
failure = error;
|
|
56
|
+
}
|
|
57
|
+
expect(failure).toBeInstanceOf(Error);
|
|
58
|
+
await harness.dispose();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("satisfies plugin package conventions", () => {
|
|
62
|
+
expect(verifyPluginPackage({ packageJson, manifest })).toMatchObject({
|
|
63
|
+
name: "@frockbot/plugin-provider-foundation",
|
|
64
|
+
contributionKinds: ["runtime"],
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
package/src/runtime.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type LlmProvider,
|
|
3
|
+
type LlmStreamEvent,
|
|
4
|
+
} from "@frockbot/kernel-contracts";
|
|
5
|
+
import type { Plugin } from "cordis";
|
|
6
|
+
|
|
7
|
+
export const FOUNDATION_PROVIDER = "foundation";
|
|
8
|
+
export const FOUNDATION_MODEL = "deterministic-v1";
|
|
9
|
+
|
|
10
|
+
async function* foundationStream(
|
|
11
|
+
request: Parameters<LlmProvider["stream"]>[0],
|
|
12
|
+
signal: AbortSignal,
|
|
13
|
+
): AsyncGenerator<LlmStreamEvent> {
|
|
14
|
+
signal.throwIfAborted();
|
|
15
|
+
const latest = request.messages.at(-1);
|
|
16
|
+
if (latest?.role === "tool") {
|
|
17
|
+
const label = latest.name === "echo" ? "Echo" : latest.name;
|
|
18
|
+
yield { type: "text-delta", text: `${label}: ` };
|
|
19
|
+
await Promise.resolve();
|
|
20
|
+
signal.throwIfAborted();
|
|
21
|
+
yield { type: "text-delta", text: latest.content };
|
|
22
|
+
yield { type: "finish", reason: "completed" };
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const user = request.messages.findLast((message) => message.role === "user");
|
|
26
|
+
const text = user?.role === "user" ? user.content : "";
|
|
27
|
+
yield { type: "text-delta", text: "Cordis runtime: " };
|
|
28
|
+
await Promise.resolve();
|
|
29
|
+
signal.throwIfAborted();
|
|
30
|
+
yield { type: "text-delta", text };
|
|
31
|
+
yield { type: "finish", reason: "completed" };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function foundationReconciliation(
|
|
35
|
+
request: Parameters<LlmProvider["stream"]>[0],
|
|
36
|
+
signal: AbortSignal,
|
|
37
|
+
): Promise<LlmStreamEvent[]> {
|
|
38
|
+
const events: LlmStreamEvent[] = [];
|
|
39
|
+
for await (const event of foundationStream(request, signal)) {
|
|
40
|
+
events.push(event);
|
|
41
|
+
}
|
|
42
|
+
return events;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const foundationProvider: LlmProvider = {
|
|
46
|
+
id: FOUNDATION_PROVIDER,
|
|
47
|
+
stream: foundationStream,
|
|
48
|
+
reconciliation: {
|
|
49
|
+
retrieve: async (effect, signal) =>
|
|
50
|
+
({
|
|
51
|
+
status: "recovered",
|
|
52
|
+
events: await foundationReconciliation(effect.request, signal),
|
|
53
|
+
}) as const,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const foundationProviderPlugin: Plugin.Function = (ctx) =>
|
|
58
|
+
ctx.llm.register(foundationProvider);
|
|
59
|
+
foundationProviderPlugin.inject = ["llm"];
|
|
60
|
+
|
|
61
|
+
export default foundationProviderPlugin;
|
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"],
|
|
12
|
+
"types": ["bun"]
|
|
13
|
+
},
|
|
14
|
+
"include": ["src/**/*.ts"]
|
|
15
|
+
}
|
package/README.md
DELETED