@omem-ai/plugin-sdk 0.0.0-stage → 0.0.2
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/README.md +153 -2
- package/dist/agent-login.d.ts +69 -0
- package/dist/blocks.d.ts +208 -0
- package/dist/blocks.js +352 -0
- package/dist/charts.d.ts +125 -0
- package/dist/charts.js +686 -0
- package/dist/client.d.ts +105 -0
- package/dist/client.js +73 -0
- package/dist/credential.d.ts +181 -0
- package/dist/hook.d.ts +50 -0
- package/dist/objects.d.ts +85 -0
- package/dist/server.d.ts +355 -0
- package/dist/server.js +1 -0
- package/dist/slots.d.ts +58 -0
- package/package.json +27 -4
- package/service.mjs +117 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The plugin page's side of the bridge (docs/v2/plugins.md). The page runs in a sandboxed
|
|
3
|
+
* iframe without omem's origin: it cannot read the owner's token or call /api itself. It asks
|
|
4
|
+
* the shell (web/src/views/Plugin.vue) by postMessage, and the shell forwards only paths under
|
|
5
|
+
* /api/plugins/<this plugin>/. The shell also sends the theme and the server events of this plugin.
|
|
6
|
+
*/
|
|
7
|
+
export type OmemEvent = {
|
|
8
|
+
type: "plugin";
|
|
9
|
+
plugin: string;
|
|
10
|
+
conversationId: string;
|
|
11
|
+
blockId?: string;
|
|
12
|
+
settings?: boolean;
|
|
13
|
+
} | {
|
|
14
|
+
type: "run";
|
|
15
|
+
runId: string;
|
|
16
|
+
status: string;
|
|
17
|
+
};
|
|
18
|
+
export { renderBlock, renderView, GENERIC_KINDS, type BlockView, type ViewComponent, type UiField } from "./blocks";
|
|
19
|
+
export type { PluginSlot, PluginSlotApi, PluginSlotContext, PluginSlotPlace, PluginSlotWhen } from "./slots";
|
|
20
|
+
import type { ViewComponent as SlotComponentAll } from "./blocks";
|
|
21
|
+
import type { PluginObjectContext as SlotPluginContext } from "./objects";
|
|
22
|
+
import type { PluginSlotBlock as SlotBlockOf, PluginSlotView as SlotViewOf } from "./slots";
|
|
23
|
+
/** What a slot's block draws on omem's pages: display components, no interactive `page`. */
|
|
24
|
+
export type PluginSlotView = SlotViewOf<Exclude<SlotComponentAll, {
|
|
25
|
+
type: "page";
|
|
26
|
+
}>>;
|
|
27
|
+
/** A slot's block: `load` as the person looking (in the item's space), `view` to display components. */
|
|
28
|
+
export type PluginSlotBlock<T> = SlotBlockOf<T, SlotPluginContext, Exclude<SlotComponentAll, {
|
|
29
|
+
type: "page";
|
|
30
|
+
}>>;
|
|
31
|
+
export type * from "./server";
|
|
32
|
+
export type { PluginObject, PluginObjectAction, PluginObjectState, PluginObjectContext, PluginObjectApi, PluginConnection, PluginSignal, PluginHook, PluginHookRequest, PluginHookResult } from "./objects";
|
|
33
|
+
export type * from "./hook.ts";
|
|
34
|
+
export type { AgentLoginApi, AgentLoginContext, AgentLoginDef, AgentLoginResult } from "./agent-login";
|
|
35
|
+
export type { CommandJudgeCall, CommandVerdict, CredentialApi, CredentialCommand, CredentialContext, CredentialDef, CredentialOutcome } from "./credential";
|
|
36
|
+
export type Omem = {
|
|
37
|
+
plugin: string;
|
|
38
|
+
/** The query of the shell's route (#/plugin/<id>?session=…): a link can open a given session. */
|
|
39
|
+
params: Record<string, string>;
|
|
40
|
+
/** Paths are relative to /api/plugins/<id>/ (e.g. "sessions"). */
|
|
41
|
+
get<T = any>(path: string): Promise<T>;
|
|
42
|
+
post<T = any>(path: string, body?: unknown): Promise<T>;
|
|
43
|
+
on(fn: (e: OmemEvent) => void): () => void;
|
|
44
|
+
/** Open an omem page in the shell (e.g. "/learn"). */
|
|
45
|
+
navigate(to: string): void;
|
|
46
|
+
/** Open the shell's settings dialog for this plugin; a saved change arrives as a plugin event with settings: true. */
|
|
47
|
+
openSettings(): void;
|
|
48
|
+
/**
|
|
49
|
+
* A WebSocket to one of the plugin's streams (its service, started if needed), opened by the shell
|
|
50
|
+
* as the owner and relayed here. Binary messages arrive as ArrayBuffer.
|
|
51
|
+
*/
|
|
52
|
+
stream(name: string): OmemStream;
|
|
53
|
+
/**
|
|
54
|
+
* A voice conversation (the manifest says `voice: true`). The shell takes the microphone and talks to
|
|
55
|
+
* the voice model of Settings → 后端与模型 → 语音 with `instructions` and no tools; this page gets the
|
|
56
|
+
* transcript as it grows and the whole of it at the end, never the audio. Call it from a click: the
|
|
57
|
+
* shell refuses a start the person did not just ask for (the promise rejects, `code: "gesture"`).
|
|
58
|
+
*/
|
|
59
|
+
voice(o: {
|
|
60
|
+
instructions: string;
|
|
61
|
+
onTurns?: (turns: VoiceTurn[]) => void;
|
|
62
|
+
onState?: (state: VoiceState, detail?: string) => void;
|
|
63
|
+
}): Promise<OmemVoice>;
|
|
64
|
+
/** Whether voice can be used now, and why not (not declared, no voice model yet: `detail` says where to set it up). */
|
|
65
|
+
voiceStatus(): Promise<VoiceStatus>;
|
|
66
|
+
};
|
|
67
|
+
export type VoiceTurn = {
|
|
68
|
+
role: "user" | "assistant";
|
|
69
|
+
text: string;
|
|
70
|
+
final: boolean;
|
|
71
|
+
};
|
|
72
|
+
export type VoiceState = "connecting" | "live" | "ended" | "failed";
|
|
73
|
+
export type VoiceStatus = {
|
|
74
|
+
allowed: boolean;
|
|
75
|
+
ready: boolean;
|
|
76
|
+
detail: string;
|
|
77
|
+
api: "live" | "realtime" | null;
|
|
78
|
+
model: string | null;
|
|
79
|
+
};
|
|
80
|
+
/** What a finished conversation leaves: both sides as text, when it ran, on which model. */
|
|
81
|
+
export type VoiceRecord = {
|
|
82
|
+
transcript: {
|
|
83
|
+
role: "user" | "assistant";
|
|
84
|
+
text: string;
|
|
85
|
+
}[];
|
|
86
|
+
startedAt: string;
|
|
87
|
+
endedAt: string;
|
|
88
|
+
api: string;
|
|
89
|
+
model: string;
|
|
90
|
+
};
|
|
91
|
+
export type OmemVoice = {
|
|
92
|
+
/** End it (or take what is left after the other side ended it). */
|
|
93
|
+
stop(): Promise<VoiceRecord>;
|
|
94
|
+
mute(on: boolean): void;
|
|
95
|
+
/** Resolves when the conversation ends, by stop(), by the shell's own “结束” button, or by a dropped connection. */
|
|
96
|
+
ended: Promise<VoiceRecord>;
|
|
97
|
+
};
|
|
98
|
+
export type OmemStream = {
|
|
99
|
+
send(data: string | ArrayBuffer): void;
|
|
100
|
+
close(): void;
|
|
101
|
+
onopen?: () => void;
|
|
102
|
+
onmessage?: (data: string | ArrayBuffer) => void;
|
|
103
|
+
onclose?: (reason: string) => void;
|
|
104
|
+
};
|
|
105
|
+
export declare function connect(): Promise<Omem>;
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { GENERIC_KINDS as M, renderBlock as h, renderView as k } from "./blocks.js";
|
|
2
|
+
let f = 0;
|
|
3
|
+
const g = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Set(), v = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), r = (d) => window.parent.postMessage({ omem: 1, ...d }, "*");
|
|
4
|
+
function E(d, c) {
|
|
5
|
+
const e = document.documentElement;
|
|
6
|
+
for (const [t, a] of Object.entries(d)) e.style.setProperty(t, a);
|
|
7
|
+
e.style.colorScheme = c, e.dataset.theme = c;
|
|
8
|
+
}
|
|
9
|
+
let w = null;
|
|
10
|
+
function T() {
|
|
11
|
+
return w ??= new Promise((d) => {
|
|
12
|
+
window.addEventListener("message", (c) => {
|
|
13
|
+
if (c.source !== window.parent) return;
|
|
14
|
+
const e = c.data;
|
|
15
|
+
if (!(!e || e.omem !== 1)) {
|
|
16
|
+
if ((e.type === "init" || e.type === "theme") && E(e.vars, String(e.scheme)), e.type === "init") {
|
|
17
|
+
const t = String(e.plugin), a = (n, s, i) => new Promise((o, p) => {
|
|
18
|
+
const l = ++f;
|
|
19
|
+
g.set(l, { resolve: o, reject: p }), r({ type: "request", id: l, method: n, path: s, body: i });
|
|
20
|
+
});
|
|
21
|
+
d({
|
|
22
|
+
plugin: t,
|
|
23
|
+
params: e.params ?? {},
|
|
24
|
+
get: (n) => a("GET", n),
|
|
25
|
+
post: (n, s) => a("POST", n, s ?? {}),
|
|
26
|
+
on: (n) => (y.add(n), () => y.delete(n)),
|
|
27
|
+
navigate: (n) => r({ type: "navigate", to: n }),
|
|
28
|
+
openSettings: () => r({ type: "settings" }),
|
|
29
|
+
stream: (n) => {
|
|
30
|
+
const s = ++f, i = {
|
|
31
|
+
send: (o) => typeof o == "string" ? r({ type: "stream-send", sid: s, data: o }) : window.parent.postMessage({ omem: 1, type: "stream-send", sid: s, data: o }, "*", [o]),
|
|
32
|
+
close: () => {
|
|
33
|
+
v.delete(s), r({ type: "stream-close", sid: s });
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
return v.set(s, i), r({ type: "stream-open", sid: s, name: n }), i;
|
|
37
|
+
},
|
|
38
|
+
voiceStatus: () => a("GET", "voice"),
|
|
39
|
+
voice: (n) => new Promise((s, i) => {
|
|
40
|
+
const o = ++f;
|
|
41
|
+
let p;
|
|
42
|
+
const l = new Promise((u) => p = u), S = {
|
|
43
|
+
stop: () => (r({ type: "voice-stop", vid: o }), l),
|
|
44
|
+
mute: (u) => r({ type: "voice-mute", vid: o, on: u }),
|
|
45
|
+
ended: l
|
|
46
|
+
};
|
|
47
|
+
m.set(o, { started: { resolve: s, reject: i }, ended: p, onTurns: n.onTurns, onState: n.onState, voice: S }), r({ type: "voice-start", vid: o, instructions: n.instructions });
|
|
48
|
+
})
|
|
49
|
+
});
|
|
50
|
+
} else if (e.type === "response") {
|
|
51
|
+
const t = g.get(e.id);
|
|
52
|
+
if (!t) return;
|
|
53
|
+
g.delete(e.id), e.ok ? t.resolve(e.data) : t.reject(new Error(String(e.error ?? "请求失败")));
|
|
54
|
+
} else if (e.type === "event") for (const t of y) t(e.event);
|
|
55
|
+
else if (e.type === "voice-event") {
|
|
56
|
+
const t = m.get(e.vid);
|
|
57
|
+
if (!t) return;
|
|
58
|
+
e.event === "turns" ? t.onTurns?.(e.turns) : e.event === "state" ? t.onState?.(e.state, e.detail ? String(e.detail) : void 0) : e.event === "started" ? (t.started?.resolve(t.voice), t.started = null) : e.event === "error" ? (t.started?.reject(Object.assign(new Error(String(e.error ?? "语音没有连上")), { code: e.code ? String(e.code) : void 0 })), m.delete(e.vid)) : e.event === "ended" && (t.ended(e.record), m.delete(e.vid));
|
|
59
|
+
} else if (e.type === "stream-event") {
|
|
60
|
+
const t = v.get(e.sid);
|
|
61
|
+
if (!t) return;
|
|
62
|
+
e.event === "open" ? t.onopen?.() : e.event === "message" ? t.onmessage?.(e.data) : e.event === "close" && (v.delete(e.sid), t.onclose?.(String(e.reason ?? "")));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}), r({ type: "ready" });
|
|
66
|
+
}), w;
|
|
67
|
+
}
|
|
68
|
+
export {
|
|
69
|
+
M as GENERIC_KINDS,
|
|
70
|
+
T as connect,
|
|
71
|
+
h as renderBlock,
|
|
72
|
+
k as renderView
|
|
73
|
+
};
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credentials (docs/v2/credentials.md, phase 1): one authorization per person that provides several
|
|
3
|
+
* AI backends and command-line tools. Declared in `register(api)`:
|
|
4
|
+
*
|
|
5
|
+
* api.credential({
|
|
6
|
+
* id: "corp",
|
|
7
|
+
* name: "公司账号",
|
|
8
|
+
* required: true,
|
|
9
|
+
* async login(ctx, show) {
|
|
10
|
+
* const device = await startDeviceFlow(ctx.signal);
|
|
11
|
+
* show({ url: device.url, code: device.code });
|
|
12
|
+
* const token = await waitForToken(device, ctx.signal);
|
|
13
|
+
* await ctx.secret.set(token.refresh);
|
|
14
|
+
* await writeCredentials(ctx.home, token);
|
|
15
|
+
* return { user: token.user, expiresAt: token.expiresAt };
|
|
16
|
+
* },
|
|
17
|
+
* async refresh(ctx) { … return { expiresAt } or null },
|
|
18
|
+
* async check(ctx) { … return { state: "ok" | "expired" | "missing", … } },
|
|
19
|
+
* async logout(ctx) { await revoke(await ctx.secret.get()); },
|
|
20
|
+
* async provide(ctx) { await writeCredentials(ctx.home, await exchange(await ctx.secret.get())); },
|
|
21
|
+
* provides: { backends: ["somebackend"], commands: [{ name: "acme", install: ["~/.local/share/acme"], state: [".local/share/acme/data"] }] },
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* The manifest declares `permissions.credential: true`; omem calls it only once the owner trusts the
|
|
25
|
+
* plugin and runs it inside omem. No imports here, so omem's own type checks can compare these with
|
|
26
|
+
* the host's (src/agents/credentials.ts).
|
|
27
|
+
*/
|
|
28
|
+
export type CredentialContext = {
|
|
29
|
+
userId: string;
|
|
30
|
+
/** This person's account folder (HOME inside the sandbox their runs start in); for the owner, this machine's HOME. */
|
|
31
|
+
home: string;
|
|
32
|
+
/** `HOME` for this person. */
|
|
33
|
+
env: Record<string, string>;
|
|
34
|
+
/** One secret omem keeps for the plugin per person and credential (in its vault, never in the account folder). */
|
|
35
|
+
secret: {
|
|
36
|
+
get(): Promise<string | null>;
|
|
37
|
+
set(value: string | null): Promise<void>;
|
|
38
|
+
};
|
|
39
|
+
/** The plugin's own settings (the owner's values from 设置 → 插件, defaults filled in). */
|
|
40
|
+
settings: Record<string, string | number | boolean | string[]>;
|
|
41
|
+
/** Aborted when the login times out (11 minutes) or the person cancels or logs out. */
|
|
42
|
+
signal: AbortSignal;
|
|
43
|
+
};
|
|
44
|
+
export type CredentialOutcome = {
|
|
45
|
+
json: string;
|
|
46
|
+
equals: unknown;
|
|
47
|
+
};
|
|
48
|
+
type CommandMatch = {
|
|
49
|
+
subcommand?: string[];
|
|
50
|
+
/** Exact argument vector, including flags. */
|
|
51
|
+
args?: string[];
|
|
52
|
+
/** Named options, e.g. { instance: "sample", verbose: true }. False requires absence. */
|
|
53
|
+
options?: Record<string, string | boolean>;
|
|
54
|
+
};
|
|
55
|
+
export type CommandJudgeCall = {
|
|
56
|
+
command: string;
|
|
57
|
+
argv: readonly string[];
|
|
58
|
+
cwd: string;
|
|
59
|
+
member: string;
|
|
60
|
+
runId: string | null;
|
|
61
|
+
};
|
|
62
|
+
export type CommandVerdict = {
|
|
63
|
+
action: "allow" | "approve" | "deny" | "log";
|
|
64
|
+
title?: string;
|
|
65
|
+
reason?: string;
|
|
66
|
+
approver?: "caller" | "owner";
|
|
67
|
+
key?: string;
|
|
68
|
+
};
|
|
69
|
+
/** One command-line tool the credential provides. */
|
|
70
|
+
export type CredentialCommand = {
|
|
71
|
+
name: string;
|
|
72
|
+
/**
|
|
73
|
+
* Optional: only invocations whose subcommand starts with these words belong to this credential
|
|
74
|
+
* (after global options, as in readOnly matches). Two credentials can then share one executable —
|
|
75
|
+
* `bytedcli meego …` for one login, the rest of `bytedcli` for another; the longest prefix wins.
|
|
76
|
+
*/
|
|
77
|
+
subcommand?: string[];
|
|
78
|
+
/** Install directories mounted read-only into members' sandboxes (`~` is this machine's HOME). */
|
|
79
|
+
install?: string[];
|
|
80
|
+
/** State directories it writes, relative to HOME. */
|
|
81
|
+
state?: string[];
|
|
82
|
+
/** Command login variable names (e.g. ACME_TOKEN) to restore for this invocation in the executor. */
|
|
83
|
+
loginEnv?: string[];
|
|
84
|
+
/** Called after enabled operation rules, with the caller's read-only credential context. */
|
|
85
|
+
judge?(call: CommandJudgeCall, ctx: CredentialContext): Promise<CommandVerdict | null> | CommandVerdict | null;
|
|
86
|
+
readOnly?: CommandMatch[];
|
|
87
|
+
resource?: {
|
|
88
|
+
match: CommandMatch;
|
|
89
|
+
key: string;
|
|
90
|
+
}[];
|
|
91
|
+
outcomes?: {
|
|
92
|
+
unauthenticated?: CredentialOutcome[];
|
|
93
|
+
expired?: CredentialOutcome[];
|
|
94
|
+
denied?: CredentialOutcome[];
|
|
95
|
+
applyUrl?: string;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
export type CredentialDef = {
|
|
99
|
+
/** Unique within the plugin; the full name is `<plugin>:<id>`. */
|
|
100
|
+
id: string;
|
|
101
|
+
name: string;
|
|
102
|
+
describe?: string;
|
|
103
|
+
/** Shown as required in the onboarding list. */
|
|
104
|
+
required?: boolean;
|
|
105
|
+
/** Call `show` with the link (and code) the person opens; omem puts it on their page and in their Feishu private chat. */
|
|
106
|
+
login(ctx: CredentialContext, show: (link: {
|
|
107
|
+
url: string;
|
|
108
|
+
code?: string;
|
|
109
|
+
}) => void): Promise<{
|
|
110
|
+
user: string;
|
|
111
|
+
expiresAt?: number;
|
|
112
|
+
}>;
|
|
113
|
+
/**
|
|
114
|
+
* Optional: the owner's own login on this machine, through the tool's official flow (ctx.home is this
|
|
115
|
+
* machine's HOME; ctx.secret cannot be written). Call `show` with the official link, resolve when it is
|
|
116
|
+
* done. Without it, the owner logs in on the machine themselves and omem only checks.
|
|
117
|
+
*/
|
|
118
|
+
ownerLogin?(ctx: CredentialContext, show: (link: {
|
|
119
|
+
url: string;
|
|
120
|
+
code?: string;
|
|
121
|
+
}) => void): Promise<{
|
|
122
|
+
user: string;
|
|
123
|
+
expiresAt?: number;
|
|
124
|
+
}>;
|
|
125
|
+
/**
|
|
126
|
+
* Refreshes a member's access token, starting up to 30 minutes before `expiresAt`.
|
|
127
|
+
* Return null only when a new authorization is required. Throw on temporary failures so omem
|
|
128
|
+
* retries without prompting. A successful refresh is followed by provide.
|
|
129
|
+
*/
|
|
130
|
+
refresh?(ctx: CredentialContext): Promise<{
|
|
131
|
+
expiresAt?: number;
|
|
132
|
+
} | null>;
|
|
133
|
+
/** Read-only: is this person still logged in? */
|
|
134
|
+
/**
|
|
135
|
+
* `expiresAt`: for a member with a refresh callback, the access token deadline (not a reminder).
|
|
136
|
+
* Otherwise, it is the actual login deadline. Leave it out of login results and give null here
|
|
137
|
+
* if the tool handles renewal on its own and has no useful login deadline to report.
|
|
138
|
+
*/
|
|
139
|
+
check?(ctx: CredentialContext): Promise<{
|
|
140
|
+
state: "ok" | "expired" | "missing";
|
|
141
|
+
user?: string;
|
|
142
|
+
expiresAt?: number | null;
|
|
143
|
+
}>;
|
|
144
|
+
/** When they log out (revoke what you hold); omem removes the secret and the declared state directories afterwards. */
|
|
145
|
+
logout?(ctx: CredentialContext): Promise<void>;
|
|
146
|
+
/** After a login or a refresh: write the credential where this person's tools look for it. */
|
|
147
|
+
provide?(ctx: CredentialContext): Promise<void>;
|
|
148
|
+
provides: {
|
|
149
|
+
backends?: string[];
|
|
150
|
+
commands?: CredentialCommand[];
|
|
151
|
+
};
|
|
152
|
+
/** Query access for req.user (the subject), using ctx only to authenticate the query.
|
|
153
|
+
* Only return verifiedRead for a command when the resource service confirms this subject can
|
|
154
|
+
* read its entire result, and the complete argv is a read of exactly req.resource. Leave it
|
|
155
|
+
* unset for advisory answers, ambiguous options, or a service that only checks the login in ctx.
|
|
156
|
+
*/
|
|
157
|
+
/** req.user is the omem id; `account` is the account this person last logged in with for this credential
|
|
158
|
+
* (from your login or check) and `email` the email omem has for them, each present when known. Map them to
|
|
159
|
+
* the principal your service checks; answer allowed: null when you cannot tell who it is. */
|
|
160
|
+
precheck?(ctx: CredentialContext, req: {
|
|
161
|
+
resource: string;
|
|
162
|
+
user: string;
|
|
163
|
+
account?: string;
|
|
164
|
+
email?: string;
|
|
165
|
+
command?: {
|
|
166
|
+
name: string;
|
|
167
|
+
args: readonly string[];
|
|
168
|
+
};
|
|
169
|
+
}): Promise<{
|
|
170
|
+
allowed: boolean | null;
|
|
171
|
+
verifiedRead?: true;
|
|
172
|
+
missing?: string;
|
|
173
|
+
applyUrl?: string;
|
|
174
|
+
}>;
|
|
175
|
+
};
|
|
176
|
+
export type CredentialApi = {
|
|
177
|
+
credential(def: CredentialDef): void;
|
|
178
|
+
/** The owner's values of this plugin's settings; read when needed so a change takes effect without reloading. In-process plugins only. */
|
|
179
|
+
settings(): Record<string, string | number | boolean | string[]>;
|
|
180
|
+
};
|
|
181
|
+
export {};
|
package/dist/hook.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export type PluginHookFormat = "webhook" | "openai-chat";
|
|
2
|
+
export type PluginHookJson = null | boolean | number | string | PluginHookJson[] | {
|
|
3
|
+
[key: string]: PluginHookJson;
|
|
4
|
+
};
|
|
5
|
+
export type PluginHookAcceptState = {
|
|
6
|
+
duplicate: boolean;
|
|
7
|
+
conflict: boolean;
|
|
8
|
+
deliveryId: string;
|
|
9
|
+
};
|
|
10
|
+
export type PluginHookResponse = {
|
|
11
|
+
status: number;
|
|
12
|
+
headers?: Record<string, string>;
|
|
13
|
+
body: PluginHookJson;
|
|
14
|
+
};
|
|
15
|
+
export type PluginHookAccept = (request: PluginHookRequest, state: PluginHookAcceptState) => PluginHookResponse;
|
|
16
|
+
export type PluginHookOptions = {
|
|
17
|
+
name: string;
|
|
18
|
+
label?: string;
|
|
19
|
+
ack?: "first";
|
|
20
|
+
format?: PluginHookFormat | "auto";
|
|
21
|
+
secretHeader?: string;
|
|
22
|
+
headers?: string[];
|
|
23
|
+
dedup?: {
|
|
24
|
+
headers?: string[];
|
|
25
|
+
bodyFields?: string[];
|
|
26
|
+
requireMatch?: boolean;
|
|
27
|
+
windowHours?: number;
|
|
28
|
+
};
|
|
29
|
+
rateLimit?: {
|
|
30
|
+
perMinute: number;
|
|
31
|
+
burst?: number;
|
|
32
|
+
};
|
|
33
|
+
unauthorizedBody?: PluginHookJson;
|
|
34
|
+
rateLimitedBody?: PluginHookJson;
|
|
35
|
+
unavailableBody?: PluginHookJson;
|
|
36
|
+
};
|
|
37
|
+
export type PluginHookEvent = {
|
|
38
|
+
format: PluginHookFormat;
|
|
39
|
+
data: unknown;
|
|
40
|
+
trust: "untrusted";
|
|
41
|
+
};
|
|
42
|
+
export type PluginHookRequest = {
|
|
43
|
+
method: "POST";
|
|
44
|
+
headers: Record<string, string>;
|
|
45
|
+
query: Record<string, string>;
|
|
46
|
+
body: string;
|
|
47
|
+
event: PluginHookEvent;
|
|
48
|
+
deliveryId: string;
|
|
49
|
+
deliveryKey: string | null;
|
|
50
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { PluginHookAccept, PluginHookOptions, PluginHookRequest } from "./hook.ts";
|
|
2
|
+
export type * from "./hook.ts";
|
|
3
|
+
/** The part of the host context used by object readers and tools. */
|
|
4
|
+
export type PluginObjectContext = {
|
|
5
|
+
plugin: string;
|
|
6
|
+
userId: string;
|
|
7
|
+
spaceId: string;
|
|
8
|
+
runId: string | null;
|
|
9
|
+
actor: "agent" | "user";
|
|
10
|
+
conversationId: string | null;
|
|
11
|
+
connection(provider: string): Promise<PluginConnection | null>;
|
|
12
|
+
emit(signal: PluginSignal): Promise<void>;
|
|
13
|
+
settings(): Record<string, string | number | boolean | string[]>;
|
|
14
|
+
/** Save some of this user's values of the plugin's settings (checked against the manifest's fields; null resets one). Tool calls only. */
|
|
15
|
+
saveSettings(patch: Record<string, unknown>): Promise<Record<string, string | number | boolean | string[]>>;
|
|
16
|
+
};
|
|
17
|
+
export type PluginConnection = {
|
|
18
|
+
account: string;
|
|
19
|
+
scopes: string[];
|
|
20
|
+
base: string | null;
|
|
21
|
+
fetch(path: string, init?: RequestInit): Promise<Response>;
|
|
22
|
+
};
|
|
23
|
+
export type PluginSignal = {
|
|
24
|
+
kind: string;
|
|
25
|
+
keys: Record<string, unknown>;
|
|
26
|
+
payload?: unknown;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* `revision`: your own mark of a change that is not a status (head commit + comment count); when it
|
|
30
|
+
* moves while the status stays, omem records `object.<kind>.updated`. `note`: what changed, in a line.
|
|
31
|
+
*/
|
|
32
|
+
export type PluginObjectState = {
|
|
33
|
+
title: string;
|
|
34
|
+
status: string;
|
|
35
|
+
link: string;
|
|
36
|
+
fields?: {
|
|
37
|
+
label: string;
|
|
38
|
+
value: string;
|
|
39
|
+
}[];
|
|
40
|
+
revision?: string;
|
|
41
|
+
note?: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* A button on the object's card (merge, rerun failed checks): one of the plugin's own tools
|
|
45
|
+
* (`<plugin id>_…`), called with the object's key in `arg` (default `key`). An agent calling the same
|
|
46
|
+
* tool goes through the same approval rung. `statuses`: shown only in these; `confirm`: one more
|
|
47
|
+
* sentence for the confirmation dialog.
|
|
48
|
+
*/
|
|
49
|
+
export type PluginObjectAction = {
|
|
50
|
+
id: string;
|
|
51
|
+
label: string;
|
|
52
|
+
tool: string;
|
|
53
|
+
arg?: string;
|
|
54
|
+
statuses?: string[];
|
|
55
|
+
confirm?: string;
|
|
56
|
+
};
|
|
57
|
+
export type PluginObject = {
|
|
58
|
+
kind: string;
|
|
59
|
+
label: string;
|
|
60
|
+
match(url: string): string | null;
|
|
61
|
+
read(ctx: PluginObjectContext, key: string): Promise<PluginObjectState>;
|
|
62
|
+
statuses: Record<string, string>;
|
|
63
|
+
final: string[];
|
|
64
|
+
poll?: {
|
|
65
|
+
minutes: number;
|
|
66
|
+
};
|
|
67
|
+
actions?: PluginObjectAction[];
|
|
68
|
+
};
|
|
69
|
+
/** `refresh`: objects omem reads again now (kind without the plugin prefix); `emit`: signals to record. */
|
|
70
|
+
export type PluginHookResult = {
|
|
71
|
+
refresh?: {
|
|
72
|
+
kind: string;
|
|
73
|
+
key: string;
|
|
74
|
+
}[];
|
|
75
|
+
emit?: PluginSignal[];
|
|
76
|
+
};
|
|
77
|
+
/** Called at `POST /api/hooks/<plugin id>/<name>/<secret>`; the owner makes the secret on the plugin's page. */
|
|
78
|
+
export type PluginHook = PluginHookOptions & {
|
|
79
|
+
accept?: PluginHookAccept;
|
|
80
|
+
handle(ctx: PluginObjectContext, req: PluginHookRequest): PluginHookResult | void | Promise<PluginHookResult | void>;
|
|
81
|
+
};
|
|
82
|
+
export type PluginObjectApi = {
|
|
83
|
+
object(def: PluginObject): void;
|
|
84
|
+
hook(def: PluginHook): void;
|
|
85
|
+
};
|