Skip to content

Commit 617754d

Browse files
fix: remove KV store implementation and repository dispatch handling, clean up related references
1 parent 54225cf commit 617754d

18 files changed

Lines changed: 18 additions & 507 deletions

‎.github/knip.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { KnipConfig } from "knip";
22

33
const config: KnipConfig = {
4-
entry: ["src/kernel.ts", "src/adapters/cloudflare-worker.ts", "deploy/setup-kv-namespace.ts", "src/index.ts"],
4+
entry: ["src/kernel.ts", "src/adapters/cloudflare-worker.ts", "src/index.ts"],
55
project: ["src/**/*.ts"],
66
ignore: ["jest.config.ts"],
77
ignoreBinaries: ["i"],

‎.github/workflows/worker-deploy.yml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ jobs:
1919

2020
- uses: oven-sh/setup-bun@v2
2121

22-
- name: Run setup script
22+
- name: Install dependencies
2323
run: |
2424
bun install
25-
bun setup-kv
2625
env:
2726
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
2827
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

‎README.md‎

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,7 @@ bun dev
7171
- If not done already, create a Cloudflare account.
7272
- Run `npx wrangler login` to log in.
7373

74-
4. **Create a KV Namespace:**
75-
76-
- Generate a KV namespace using `npx wrangler kv:namespace create PLUGIN_CHAIN_STATE`.
77-
- Copy the generated ID and paste it under `[env.dev]` in `wrangler.toml`.
78-
79-
5. **Manage Secrets:**
74+
4. **Manage Secrets:**
8075

8176
- Add (env) secrets using `npx wrangler secret put <KEY> --env dev`.
8277
- For the private key, execute the following (replace `YOUR_APP_PRIVATE_KEY.PEM` with the actual PEM file path):
@@ -85,10 +80,10 @@ bun dev
8580
echo $(openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in YOUR_APP_PRIVATE_KEY.PEM) | npx wrangler secret put APP_PRIVATE_KEY --env dev
8681
```
8782

88-
6. **Deploy the Kernel:**
83+
5. **Deploy the Kernel:**
8984
- Execute `bun run deploy-dev` to deploy the kernel.
9085

91-
7. **Setup database (optional)**
86+
6. **Setup database (optional)**
9287
- You can set up your local database by going through [this repository](https://github.com/ubiquity-os/database) and following the instructions.
9388

9489
### Plugin-Kernel Input/Output Interface
@@ -99,7 +94,7 @@ Inputs are received within the workflow, triggered by the `workflow_dispatch` ev
9994

10095
```typescript
10196
interface PluginInput {
102-
stateId: string; // An identifier used to track the state of plugin chain execution in Cloudflare KV
97+
stateId: string; // Identifier used to trace a plugin invocation
10398
eventName: string; // The complete name of the event (e.g., `issue_comment.created`)
10499
eventPayload: any; // The payload associated with the event
105100
settings: string; // A string containing JSON with settings specific to your plugin
@@ -123,28 +118,6 @@ const input: PluginInput = {
123118
};
124119
```
125120
126-
#### Output
127-
128-
Data is returned using the `repository_dispatch` event on the plugin's repository, and the output is structured within the `client_payload`.
129-
130-
The `event_type` must be set to `return-data-to-ubiquity-os-kernel`.
131-
132-
```typescript
133-
interface PluginOutput {
134-
state_id: string; // The state ID passed in the inputs must be included here
135-
output: string; // A string containing JSON with custom output, defined by the plugin itself
136-
}
137-
```
138-
139-
Example usage:
140-
141-
```typescript
142-
const output: PluginOutput = {
143-
state_id: "abc123",
144-
output: '{ "result": "success", "message": "Plugin executed successfully" }',
145-
};
146-
```
147-
148121
## Plugin Quick Start
149122
150123
The kernel supports 2 types of plugins:

‎package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"knip-ci": "knip --no-exit-code --reporter json --config .github/knip.ts",
3232
"jest:test": "jest --coverage",
3333
"plugin:hello-world": "tsx tests/__mocks__/hello-world-plugin.ts",
34-
"setup-kv": "bun --env-file=.dev.vars scripts/setup-kv-namespace.ts",
3534
"setup": "tsx ./scripts/setup.ts",
3635
"start:azure": "run-p proxy build:watch start",
3736
"start:bun": "run-p proxy start",

‎scripts/deploy.ts‎

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,17 @@
11
import { confirm, input, select } from "@inquirer/prompts";
2-
import { exec, execSync, spawn } from "child_process";
2+
import { exec, spawn } from "child_process";
3+
import { parse } from "dotenv";
34
import { readFileSync, unlinkSync, writeFileSync } from "fs";
45
import ora from "ora";
56
import path from "path";
6-
import { parse } from "dotenv";
77
import toml from "toml";
8-
// @ts-expect-error No typings exist for this package
9-
import * as tomlify from "tomlify-j0.4";
108

119
interface WranglerConfiguration {
12-
name: string;
13-
env: {
14-
[env: string]: {
15-
kv_namespaces?: {
16-
id: string;
17-
binding: string;
18-
}[];
19-
};
20-
};
21-
kv_namespaces: {
22-
id: string;
23-
binding: string;
24-
}[];
10+
env?: Record<string, unknown>;
2511
}
2612

2713
const WRANGLER_PATH = path.resolve(__dirname, "..", "node_modules/.bin/wrangler");
2814
const WRANGLER_TOML_PATH = path.resolve(__dirname, "..", "wrangler.toml");
29-
const BINDING_NAME = "PLUGIN_CHAIN_STATE";
3015

3116
function checkIfWranglerInstalled() {
3217
return new Promise((resolve) => {
@@ -101,23 +86,6 @@ function wranglerDeploy(env: string | null) {
10186
});
10287
}
10388

104-
function wranglerKvNamespace(projectName: string, namespace: string) {
105-
const kvList = JSON.parse(execSync(`${WRANGLER_PATH} kv namespace list`).toString()) as { id: string; title: string }[];
106-
const existingNamespace = kvList.find((o) => o.title === namespace || o.title === `${projectName}-${namespace}`);
107-
if (existingNamespace) {
108-
return existingNamespace.id;
109-
}
110-
111-
const res = execSync(`${WRANGLER_PATH} kv namespace create ${namespace}`).toString();
112-
113-
const newId = res.match(/id = \s*"([^"]+)"/)?.[1];
114-
if (!newId) {
115-
console.log(res);
116-
throw new Error(`The new ID could not be found.`);
117-
}
118-
return newId;
119-
}
120-
12189
void (async () => {
12290
const spinner = ora("Checking if Wrangler is installed").start();
12391
const wranglerInstalled = await checkIfWranglerInstalled();
@@ -185,40 +153,6 @@ void (async () => {
185153
}
186154
}
187155

188-
spinner.start("Setting up KV namespace");
189-
try {
190-
const kvNamespace = selectedEnv ? `${selectedEnv}-plugin-chain-state` : `plugin-chain-state`;
191-
const namespaceId = wranglerKvNamespace(wranglerToml.name, kvNamespace);
192-
if (selectedEnv) {
193-
const existingBinding = wranglerToml.env[selectedEnv]?.kv_namespaces?.find((o) => o.binding === BINDING_NAME);
194-
if (!existingBinding) {
195-
wranglerToml.env[selectedEnv] = wranglerToml.env[selectedEnv] ?? {};
196-
wranglerToml.env[selectedEnv].kv_namespaces = wranglerToml.env[selectedEnv].kv_namespaces ?? [];
197-
wranglerToml.env[selectedEnv].kv_namespaces?.push({
198-
id: namespaceId,
199-
binding: BINDING_NAME,
200-
});
201-
} else {
202-
existingBinding.id = namespaceId;
203-
}
204-
} else {
205-
const existingBinding = wranglerToml.kv_namespaces.find((o) => o.binding === BINDING_NAME);
206-
if (!existingBinding) {
207-
wranglerToml.kv_namespaces.push({
208-
id: namespaceId,
209-
binding: BINDING_NAME,
210-
});
211-
} else {
212-
existingBinding.id = namespaceId;
213-
}
214-
}
215-
writeFileSync(WRANGLER_TOML_PATH, tomlify.toToml(wranglerToml));
216-
spinner.succeed(`Using KV namespace ${kvNamespace} with ID: ${namespaceId}`);
217-
} catch (err) {
218-
spinner.fail(`Error setting up KV namespace: ${err}`);
219-
process.exit(1);
220-
}
221-
222156
spinner.start("Deploying to Cloudflare Workers").stopAndPersist();
223157
try {
224158
await wranglerDeploy(selectedEnv);

‎scripts/setup-kv-namespace.ts‎

Lines changed: 0 additions & 106 deletions
This file was deleted.

‎scripts/setup.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import http from "http";
1+
import { confirm, input } from "@inquirer/prompts";
2+
import { Octokit } from "@octokit/core";
23
import fs from "fs";
3-
import path from "path";
4+
import http from "http";
5+
import NodeRSA from "node-rsa";
46
import open from "open";
57
import ora, { Ora } from "ora";
6-
import NodeRSA from "node-rsa";
7-
import { Octokit } from "@octokit/core";
8-
import { confirm, input } from "@inquirer/prompts";
8+
import path from "path";
99

1010
const PORT = 3000;
1111
const DEV_ENV_FILE = ".dev.vars";
@@ -24,7 +24,7 @@ const manifestTemplate = {
2424
contents: "write",
2525
members: "read",
2626
},
27-
default_events: ["issues", "issue_comment", "label", "pull_request", "push", "repository", "repository_dispatch"],
27+
default_events: ["issues", "issue_comment", "label", "pull_request", "push", "repository"],
2828
};
2929

3030
class GithubAppSetup {

‎src/github/github-event-handler.ts‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@ import { logger } from "../logger/logger";
66

77
import { customOctokit } from "./github-client";
88
import { GitHubContext, SimplifiedContext } from "./github-context";
9-
import { PluginChainState } from "./types/plugin";
10-
import { KvStore } from "./utils/kv-store";
11-
129
export type Options = {
1310
environment: "production" | "development";
1411
webhookSecret: string;
1512
appId: string | number;
1613
privateKey: string;
17-
pluginChainState: KvStore<PluginChainState>;
1814
llmClient: OpenAI;
1915
llm: string;
2016
logger?: typeof logger;
@@ -25,7 +21,6 @@ export class GitHubEventHandler {
2521
public on: Webhooks<SimplifiedContext>["on"];
2622
public onAny: Webhooks<SimplifiedContext>["onAny"];
2723
public onError: Webhooks<SimplifiedContext>["onError"];
28-
public pluginChainState: KvStore<PluginChainState>;
2924

3025
readonly environment: "production" | "development";
3126
private readonly _webhookSecret: string;
@@ -40,7 +35,6 @@ export class GitHubEventHandler {
4035
this._privateKey = options.privateKey;
4136
this._appId = Number(options.appId);
4237
this._webhookSecret = options.webhookSecret;
43-
this.pluginChainState = options.pluginChainState;
4438
this._llmClient = options.llmClient;
4539
this.llm = options.llm;
4640

0 commit comments

Comments
 (0)