@omem-ai/plugin-sdk 0.0.1 → 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 +126 -1
- package/dist/agent-login.d.ts +69 -0
- package/dist/blocks.d.ts +58 -9
- package/dist/blocks.js +229 -222
- package/dist/charts.d.ts +125 -0
- package/dist/charts.js +686 -0
- package/dist/client.d.ts +18 -1
- 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 +4 -1
package/dist/client.d.ts
CHANGED
|
@@ -16,6 +16,23 @@ export type OmemEvent = {
|
|
|
16
16
|
status: string;
|
|
17
17
|
};
|
|
18
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";
|
|
19
36
|
export type Omem = {
|
|
20
37
|
plugin: string;
|
|
21
38
|
/** The query of the shell's route (#/plugin/<id>?session=…): a link can open a given session. */
|
|
@@ -35,7 +52,7 @@ export type Omem = {
|
|
|
35
52
|
stream(name: string): OmemStream;
|
|
36
53
|
/**
|
|
37
54
|
* A voice conversation (the manifest says `voice: true`). The shell takes the microphone and talks to
|
|
38
|
-
* the voice model of
|
|
55
|
+
* the voice model of Settings → 后端与模型 → 语音 with `instructions` and no tools; this page gets the
|
|
39
56
|
* transcript as it grows and the whole of it at the end, never the audio. Call it from a click: the
|
|
40
57
|
* shell refuses a start the person did not just ask for (the promise rejects, `code: "gesture"`).
|
|
41
58
|
*/
|
|
@@ -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
|
+
};
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import type { ZodType } from "zod";
|
|
2
|
+
export type { CommandJudgeCall, CommandVerdict, CredentialApi, CredentialCommand, CredentialContext, CredentialDef, CredentialOutcome } from "./credential.ts";
|
|
3
|
+
import type { PluginConnection } from "./objects.ts";
|
|
4
|
+
export type CallContext = {
|
|
5
|
+
userId: string;
|
|
6
|
+
spaceId: string;
|
|
7
|
+
signal: AbortSignal;
|
|
8
|
+
connection(provider: string): Promise<PluginConnection | null>;
|
|
9
|
+
};
|
|
10
|
+
export type WriteContext = CallContext & {
|
|
11
|
+
idempotencyKey: string;
|
|
12
|
+
};
|
|
13
|
+
export type EventType = "item.status" | "item.created" | "review.finished" | "finding.decision" | "finding.resolution" | "finding.thread";
|
|
14
|
+
export type PluginEventV1 = {
|
|
15
|
+
v: 1;
|
|
16
|
+
id: string;
|
|
17
|
+
type: EventType;
|
|
18
|
+
at: string;
|
|
19
|
+
entity: {
|
|
20
|
+
kind: "item" | "run" | "finding";
|
|
21
|
+
id: string;
|
|
22
|
+
};
|
|
23
|
+
spaceId: string;
|
|
24
|
+
actor: {
|
|
25
|
+
kind: "user" | "agent" | "host";
|
|
26
|
+
id?: string;
|
|
27
|
+
};
|
|
28
|
+
data: Record<string, unknown>;
|
|
29
|
+
};
|
|
30
|
+
export type Subscription = {
|
|
31
|
+
id: string;
|
|
32
|
+
events: EventType[];
|
|
33
|
+
handle(ctx: CallContext, event: Readonly<PluginEventV1>): Promise<void>;
|
|
34
|
+
};
|
|
35
|
+
export type ExternalItem = {
|
|
36
|
+
key: string;
|
|
37
|
+
url: string;
|
|
38
|
+
title: string;
|
|
39
|
+
status: string;
|
|
40
|
+
kind?: "todo" | "watch";
|
|
41
|
+
assignee?: string;
|
|
42
|
+
parentKey?: string;
|
|
43
|
+
revision?: string;
|
|
44
|
+
updatedAt: string;
|
|
45
|
+
summary?: string;
|
|
46
|
+
};
|
|
47
|
+
export type ItemProvider = {
|
|
48
|
+
id: string;
|
|
49
|
+
label: string;
|
|
50
|
+
statuses: Record<string, "active" | "done" | "cancelled">;
|
|
51
|
+
/** What a subscription's target is, shown beside the box the person types it in: "仓库,写成 owner/repo". */
|
|
52
|
+
targetHint?: string;
|
|
53
|
+
pull(ctx: CallContext, req: {
|
|
54
|
+
target: string;
|
|
55
|
+
cursor?: string;
|
|
56
|
+
}): Promise<{
|
|
57
|
+
items: ExternalItem[];
|
|
58
|
+
cursor?: string;
|
|
59
|
+
done: boolean;
|
|
60
|
+
}>;
|
|
61
|
+
setStatus?(ctx: WriteContext, req: {
|
|
62
|
+
key: string;
|
|
63
|
+
status: string;
|
|
64
|
+
expectedRevision?: string;
|
|
65
|
+
}): Promise<{
|
|
66
|
+
revision?: string;
|
|
67
|
+
status: string;
|
|
68
|
+
}>;
|
|
69
|
+
};
|
|
70
|
+
export type MetricProvider = {
|
|
71
|
+
id: string;
|
|
72
|
+
label: string;
|
|
73
|
+
querySchema: ZodType;
|
|
74
|
+
collect(ctx: CallContext, req: {
|
|
75
|
+
metrics: readonly {
|
|
76
|
+
id: string;
|
|
77
|
+
query: unknown;
|
|
78
|
+
}[];
|
|
79
|
+
from: string;
|
|
80
|
+
to: string;
|
|
81
|
+
}): Promise<{
|
|
82
|
+
metricId: string;
|
|
83
|
+
at: string;
|
|
84
|
+
value: number;
|
|
85
|
+
dims?: Record<string, string>;
|
|
86
|
+
source?: string;
|
|
87
|
+
}[]>;
|
|
88
|
+
};
|
|
89
|
+
export type DiffAnchor = {
|
|
90
|
+
path: string;
|
|
91
|
+
line: number;
|
|
92
|
+
startLine?: number;
|
|
93
|
+
side: "LEFT" | "RIGHT";
|
|
94
|
+
head: string;
|
|
95
|
+
};
|
|
96
|
+
export type CommentRef = {
|
|
97
|
+
id: string;
|
|
98
|
+
url: string;
|
|
99
|
+
revision?: string;
|
|
100
|
+
};
|
|
101
|
+
export type ThreadState = {
|
|
102
|
+
state: "open" | "replied" | "resolved" | "outdated";
|
|
103
|
+
reply?: {
|
|
104
|
+
author: string;
|
|
105
|
+
at: string;
|
|
106
|
+
summary: string;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
/** An invalid diff position is reported by throwing an Error with code REVIEW_ANCHOR_OUTDATED. */
|
|
110
|
+
export type ReviewProvider = {
|
|
111
|
+
id: string;
|
|
112
|
+
label: string;
|
|
113
|
+
objectKind: string;
|
|
114
|
+
publish(ctx: WriteContext, req: {
|
|
115
|
+
objectKey: string;
|
|
116
|
+
findingId: number;
|
|
117
|
+
anchor: DiffAnchor;
|
|
118
|
+
body: string;
|
|
119
|
+
}): Promise<CommentRef>;
|
|
120
|
+
readThread(ctx: CallContext, ref: CommentRef): Promise<ThreadState>;
|
|
121
|
+
resolve?(ctx: WriteContext, ref: CommentRef, note?: string): Promise<ThreadState>;
|
|
122
|
+
};
|
|
123
|
+
export type RetrievalKind = "chunk" | "page" | "memory";
|
|
124
|
+
export type RetrievalRef = {
|
|
125
|
+
type: RetrievalKind | "source";
|
|
126
|
+
id: string;
|
|
127
|
+
score?: number;
|
|
128
|
+
};
|
|
129
|
+
export type Retriever = {
|
|
130
|
+
id: string;
|
|
131
|
+
label: string;
|
|
132
|
+
search(ctx: CallContext, req: {
|
|
133
|
+
query: string;
|
|
134
|
+
spaces: string[];
|
|
135
|
+
kinds: RetrievalKind[];
|
|
136
|
+
limit: number;
|
|
137
|
+
}): Promise<RetrievalRef[]>;
|
|
138
|
+
};
|
|
139
|
+
export type Reranker = {
|
|
140
|
+
id: string;
|
|
141
|
+
label: string;
|
|
142
|
+
score(ctx: CallContext, req: {
|
|
143
|
+
query: string;
|
|
144
|
+
candidates: {
|
|
145
|
+
id: string;
|
|
146
|
+
text: string;
|
|
147
|
+
}[];
|
|
148
|
+
}): Promise<number[]>;
|
|
149
|
+
};
|
|
150
|
+
/** The host supplies texts in the plugin's authorized spaces. Content may leave this machine. */
|
|
151
|
+
export type EmbedderProvider = {
|
|
152
|
+
id: string;
|
|
153
|
+
name: string;
|
|
154
|
+
model: string;
|
|
155
|
+
dimensions: number;
|
|
156
|
+
maxBatch?: number;
|
|
157
|
+
maxChars?: number;
|
|
158
|
+
embed(texts: string[], kind: "query" | "passage", signal: AbortSignal): Promise<number[][] | Float32Array[]>;
|
|
159
|
+
};
|
|
160
|
+
export type SourceDisplay = {
|
|
161
|
+
kind: "table";
|
|
162
|
+
columns: string[];
|
|
163
|
+
rowLines: [number, number][];
|
|
164
|
+
} | {
|
|
165
|
+
kind: "records";
|
|
166
|
+
items: {
|
|
167
|
+
title: string;
|
|
168
|
+
lines: [number, number];
|
|
169
|
+
}[];
|
|
170
|
+
};
|
|
171
|
+
export type ParserInput = {
|
|
172
|
+
name: string;
|
|
173
|
+
url?: string;
|
|
174
|
+
mimeType?: string;
|
|
175
|
+
bytes: Uint8Array;
|
|
176
|
+
};
|
|
177
|
+
export type ParsedSource = {
|
|
178
|
+
title?: string;
|
|
179
|
+
text: string;
|
|
180
|
+
meta?: Record<string, string>;
|
|
181
|
+
display?: SourceDisplay;
|
|
182
|
+
};
|
|
183
|
+
export type SourceParser = {
|
|
184
|
+
id: string;
|
|
185
|
+
label: string;
|
|
186
|
+
match: {
|
|
187
|
+
extensions?: string[];
|
|
188
|
+
mimeTypes?: string[];
|
|
189
|
+
urlPatterns?: string[];
|
|
190
|
+
};
|
|
191
|
+
parse(ctx: CallContext, input: ParserInput): Promise<ParsedSource>;
|
|
192
|
+
};
|
|
193
|
+
export type WikiPageKind = {
|
|
194
|
+
kind: string;
|
|
195
|
+
label: string;
|
|
196
|
+
describe: string;
|
|
197
|
+
template: string;
|
|
198
|
+
check?(ctx: CallContext, page: {
|
|
199
|
+
slug: string;
|
|
200
|
+
title: string;
|
|
201
|
+
body: string;
|
|
202
|
+
}): Promise<{
|
|
203
|
+
line?: number;
|
|
204
|
+
message: string;
|
|
205
|
+
}[]>;
|
|
206
|
+
upkeep?: {
|
|
207
|
+
everyDays?: number;
|
|
208
|
+
onSourcesChanged?: boolean;
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
export type OutletIdentity = {
|
|
212
|
+
provider: string;
|
|
213
|
+
subject: string;
|
|
214
|
+
};
|
|
215
|
+
export type OutletRecipient = {
|
|
216
|
+
id: string;
|
|
217
|
+
identities: OutletIdentity[];
|
|
218
|
+
};
|
|
219
|
+
export type OutNotification = {
|
|
220
|
+
about?: {
|
|
221
|
+
title: string;
|
|
222
|
+
link: string;
|
|
223
|
+
};
|
|
224
|
+
user: OutletRecipient;
|
|
225
|
+
title: string;
|
|
226
|
+
body: string;
|
|
227
|
+
link: string | null;
|
|
228
|
+
urgency: "normal" | "urgent" | "silent" | "later";
|
|
229
|
+
dedupKey: string;
|
|
230
|
+
};
|
|
231
|
+
export type OutAsk = OutNotification & {
|
|
232
|
+
kind: string;
|
|
233
|
+
options: {
|
|
234
|
+
label: string;
|
|
235
|
+
}[];
|
|
236
|
+
fields: Record<string, unknown>[];
|
|
237
|
+
requiresApproval: boolean;
|
|
238
|
+
allowText: boolean;
|
|
239
|
+
expiresAt: string | null;
|
|
240
|
+
};
|
|
241
|
+
export type Notifier = {
|
|
242
|
+
id: string;
|
|
243
|
+
name: string;
|
|
244
|
+
resolve?(user: OutletRecipient, signal: AbortSignal): Promise<{
|
|
245
|
+
ok: boolean;
|
|
246
|
+
hint?: string;
|
|
247
|
+
}>;
|
|
248
|
+
deliver(n: OutNotification, signal: AbortSignal): Promise<{
|
|
249
|
+
ref?: string;
|
|
250
|
+
}>;
|
|
251
|
+
update?(ref: string, n: OutNotification, signal: AbortSignal): Promise<void>;
|
|
252
|
+
ask?(a: OutAsk, signal: AbortSignal): Promise<{
|
|
253
|
+
ref?: string;
|
|
254
|
+
}>;
|
|
255
|
+
retract?(ref: string, signal: AbortSignal): Promise<void>;
|
|
256
|
+
};
|
|
257
|
+
export type OutletAnswer = {
|
|
258
|
+
notifier: string;
|
|
259
|
+
ref: string;
|
|
260
|
+
user: OutletIdentity;
|
|
261
|
+
choice?: number;
|
|
262
|
+
values?: Record<string, unknown>;
|
|
263
|
+
text?: string;
|
|
264
|
+
approved?: boolean;
|
|
265
|
+
};
|
|
266
|
+
export type FlowEvidence = {
|
|
267
|
+
text: string;
|
|
268
|
+
link?: string;
|
|
269
|
+
};
|
|
270
|
+
export type FlowContext = {
|
|
271
|
+
item: {
|
|
272
|
+
id: string;
|
|
273
|
+
title: string;
|
|
274
|
+
spaceId: string;
|
|
275
|
+
};
|
|
276
|
+
stage: {
|
|
277
|
+
id: string;
|
|
278
|
+
name: string;
|
|
279
|
+
since: string;
|
|
280
|
+
};
|
|
281
|
+
with: unknown;
|
|
282
|
+
materials: {
|
|
283
|
+
kind: string;
|
|
284
|
+
ref: string;
|
|
285
|
+
}[];
|
|
286
|
+
};
|
|
287
|
+
export type FlowProvider = {
|
|
288
|
+
id: string;
|
|
289
|
+
name: string;
|
|
290
|
+
describe: string;
|
|
291
|
+
params?: Record<string, unknown>;
|
|
292
|
+
};
|
|
293
|
+
export type FlowSignal = FlowProvider & {
|
|
294
|
+
check(ctx: FlowContext, signal: AbortSignal): Promise<{
|
|
295
|
+
done: boolean;
|
|
296
|
+
evidence?: FlowEvidence[];
|
|
297
|
+
waitingOn?: string;
|
|
298
|
+
recheckAfterSec?: number;
|
|
299
|
+
}>;
|
|
300
|
+
};
|
|
301
|
+
export type RunnerResult = {
|
|
302
|
+
ref: string;
|
|
303
|
+
status: "running" | "done" | "failed";
|
|
304
|
+
summary?: string;
|
|
305
|
+
evidence?: FlowEvidence[];
|
|
306
|
+
};
|
|
307
|
+
export type StageRunner = FlowProvider & {
|
|
308
|
+
/** Repeat calls with the same key, including after a host restart, must return the same operation. */
|
|
309
|
+
start(ctx: FlowContext & {
|
|
310
|
+
attempt: number;
|
|
311
|
+
idempotencyKey: string;
|
|
312
|
+
settings: Record<string, unknown>;
|
|
313
|
+
}, signal: AbortSignal): Promise<RunnerResult>;
|
|
314
|
+
check?(ref: string, signal: AbortSignal): Promise<RunnerResult>;
|
|
315
|
+
cancel?(ref: string, signal: AbortSignal): Promise<void>;
|
|
316
|
+
};
|
|
317
|
+
export type GateScope = {
|
|
318
|
+
flows?: string[];
|
|
319
|
+
stages?: string[];
|
|
320
|
+
};
|
|
321
|
+
export type StageGate = {
|
|
322
|
+
id: string;
|
|
323
|
+
name: string;
|
|
324
|
+
describe: string;
|
|
325
|
+
applies?: GateScope;
|
|
326
|
+
review(ctx: Pick<FlowContext, "item" | "stage"> & {
|
|
327
|
+
result: {
|
|
328
|
+
summary: string;
|
|
329
|
+
evidence: FlowEvidence[];
|
|
330
|
+
};
|
|
331
|
+
by: string;
|
|
332
|
+
}, signal: AbortSignal): Promise<{
|
|
333
|
+
ok: true;
|
|
334
|
+
} | {
|
|
335
|
+
ok: false;
|
|
336
|
+
reason: string;
|
|
337
|
+
evidence?: FlowEvidence[];
|
|
338
|
+
}>;
|
|
339
|
+
};
|
|
340
|
+
export type ProcessApi = {
|
|
341
|
+
stageGate(def: StageGate): void;
|
|
342
|
+
stageRunner(def: StageRunner): void;
|
|
343
|
+
flowSignal(def: FlowSignal): void;
|
|
344
|
+
answerAsk(input: OutletAnswer): Promise<void>;
|
|
345
|
+
notifier(def: Notifier): void;
|
|
346
|
+
retriever(def: Retriever): void;
|
|
347
|
+
reranker(def: Reranker): void;
|
|
348
|
+
embedder(def: EmbedderProvider): void;
|
|
349
|
+
sourceParser(def: SourceParser): void;
|
|
350
|
+
wikiPageKind(def: WikiPageKind): void;
|
|
351
|
+
subscribe(def: Subscription): void;
|
|
352
|
+
reviewProvider(def: ReviewProvider): void;
|
|
353
|
+
itemProvider(def: ItemProvider): void;
|
|
354
|
+
metricProvider(def: MetricProvider): void;
|
|
355
|
+
};
|