@pollis-inc/app 0.0.0-stage → 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.
@@ -0,0 +1,177 @@
1
+ /**
2
+ * `@pollis-inc/app/testing`: run your built App offline, in your test files.
3
+ *
4
+ * Each call runs one handler in the same sandbox the bot runtime uses, with
5
+ * the same permission checks and the same error messages, so a call your
6
+ * manifest does not allow fails in a test exactly as it would in a group.
7
+ * Nothing touches the network: `ctx.fetch` answers from the `http` fixtures
8
+ * you give, and state starts from the `state` you give.
9
+ *
10
+ * ```ts
11
+ * import { test } from "node:test";
12
+ * import assert from "node:assert/strict";
13
+ * import { testApp } from "@pollis-inc/app/testing";
14
+ *
15
+ * const app = await testApp();
16
+ *
17
+ * test("/hello replies", async () => {
18
+ * const result = await app.command("hello", "world");
19
+ * assert.deepEqual(result.replies, ["Hello, world!"]);
20
+ * });
21
+ * ```
22
+ *
23
+ * `pollis app test` builds the App and runs your `*.test.ts` files with this
24
+ * wired up. It needs the `pollis-app-dev` program (see the developer guide).
25
+ */
26
+ import type { Author, Message } from "./index.js";
27
+ import type { ResolvedManifest } from "./manifest.js";
28
+ /** A canned answer for `ctx.fetch`, matched by exact URL (and method, if given). */
29
+ export interface HttpFixture {
30
+ url: string;
31
+ method?: string;
32
+ /** Default 200. */
33
+ status?: number;
34
+ headers?: Record<string, string> | [string, string][];
35
+ /** A string, bytes, or any other value (sent as JSON). */
36
+ body?: string | Uint8Array | unknown;
37
+ }
38
+ /** What the admin granted, if you want to test a narrower installation than the manifest asks for. */
39
+ export interface Grants {
40
+ /** Channel name to channel id, e.g. `{ support: "support" }`. */
41
+ channels?: Record<string, string>;
42
+ history?: number;
43
+ events?: ("created" | "edited")[];
44
+ actions?: string[];
45
+ egress?: string[];
46
+ }
47
+ export interface JobOptions {
48
+ /** State before the job, by key. */
49
+ state?: Record<string, string | Uint8Array>;
50
+ /** Answers for `ctx.fetch`. A request with no fixture fails, as an unreachable host would. */
51
+ http?: HttpFixture[];
52
+ /** History `ctx.messages()` can return (still limited to what is granted). */
53
+ messages?: MessageInput[];
54
+ /** Default: everything the manifest asks for. */
55
+ grants?: Grants;
56
+ /** The runtime's clock, Unix milliseconds or a Date. Default 2027-01-15T08:00:00Z. */
57
+ now?: number | Date;
58
+ }
59
+ export interface TestOptions extends JobOptions {
60
+ /** Default: `$POLLIS_APP_COMPONENT`, else `dist/app.wasm`. */
61
+ component?: string;
62
+ /** Default: `$POLLIS_APP_MANIFEST`, else `dist/pollis-app.json`. */
63
+ manifest?: string;
64
+ /** The `pollis-app-dev` program. Default: `$POLLIS_APP_DEV_BIN`, else `pollis-app-dev` on PATH. */
65
+ bin?: string;
66
+ /** The bot's username, for `@mentions` and commands addressed `/name @username`. Default `test_bot`. */
67
+ botUsername?: string;
68
+ }
69
+ /** A message as tests describe it: everything optional. */
70
+ export interface MessageInput {
71
+ id?: string;
72
+ /** Channel id. In tests a channel's id is its name: `"support"` for `#support`. */
73
+ channel?: string;
74
+ author?: Partial<Author>;
75
+ text?: string;
76
+ replyTo?: string;
77
+ thread?: string;
78
+ sentAt?: number | Date;
79
+ editedAt?: number | Date;
80
+ }
81
+ export type Action = {
82
+ type: "post";
83
+ channel: string;
84
+ text: string;
85
+ } | {
86
+ type: "reply";
87
+ channel: string;
88
+ message: string;
89
+ text: string;
90
+ } | {
91
+ type: "react";
92
+ channel: string;
93
+ message: string;
94
+ emoji: string;
95
+ } | {
96
+ type: "editOwn";
97
+ channel: string;
98
+ message: string;
99
+ text: string;
100
+ } | {
101
+ type: "deleteOwn";
102
+ channel: string;
103
+ message: string;
104
+ };
105
+ /** What one handler run produced. */
106
+ export interface JobResult {
107
+ /** The handler finished without throwing, and nothing was refused that made it throw. */
108
+ ok: boolean;
109
+ /** Why the job failed: `kind` is e.g. `handler_failed`, `not_delivered`, `timeout`, `trap`. */
110
+ error?: {
111
+ kind: string;
112
+ message: string;
113
+ };
114
+ /** Everything the App queued, in order. Empty when the job failed: nothing would be sent. */
115
+ actions: Action[];
116
+ /** Texts of `reply` actions. */
117
+ replies: string[];
118
+ /** `post` actions. */
119
+ posts: {
120
+ channel: string;
121
+ text: string;
122
+ }[];
123
+ /** Emoji of `react` actions. */
124
+ reactions: string[];
125
+ /** State written by the job, as text (`null`: deleted). */
126
+ state: Record<string, string | null>;
127
+ /** Every `ctx.log` line and console output. */
128
+ logs: {
129
+ level: string;
130
+ text: string;
131
+ }[];
132
+ /** Every `ctx.fetch` that passed the egress check. */
133
+ fetches: {
134
+ method: string;
135
+ url: string;
136
+ headers: [string, string][];
137
+ body?: string;
138
+ }[];
139
+ }
140
+ /** A built App, ready to run in tests. */
141
+ export interface TestApp {
142
+ readonly manifest: ResolvedManifest;
143
+ /**
144
+ * A member sends this message in a channel, and it is routed as the runtime
145
+ * routes it: a command your manifest declares goes to `onCommand`; else a
146
+ * message that @mentions the bot goes to `onMention` (if you take
147
+ * mentions); else `onMessage`.
148
+ */
149
+ send(message: string | MessageInput, options?: JobOptions): Promise<JobResult>;
150
+ /** `onMessage`, directly. */
151
+ message(message: string | MessageInput, options?: JobOptions): Promise<JobResult>;
152
+ /** `onMention`, directly. */
153
+ mention(message: string | MessageInput, options?: JobOptions): Promise<JobResult>;
154
+ /** A member sends `/name args`, routed like {@link TestApp.send}: an undeclared command is an ordinary message. */
155
+ command(name: string, args?: string, options?: JobOptions & {
156
+ message?: MessageInput;
157
+ }): Promise<JobResult>;
158
+ /** A declared schedule fires. Default slot: the latest one at or before `now`. */
159
+ schedule(name: string, options?: JobOptions & {
160
+ slot?: number | Date;
161
+ }): Promise<JobResult>;
162
+ request(body: string, options?: JobOptions & {
163
+ id?: string;
164
+ requester?: Partial<Author>;
165
+ }): Promise<JobResult>;
166
+ webhook(body: string | Uint8Array | unknown, options?: JobOptions & {
167
+ headers?: Record<string, string>;
168
+ deliveryId?: string;
169
+ }): Promise<JobResult>;
170
+ /** Stop the runner. Optional: it also stops when the test process exits. */
171
+ close(): void;
172
+ }
173
+ /** 2027-01-15T08:00:00Z, the default clock. */
174
+ export declare const DEFAULT_NOW = 1800000000000;
175
+ /** Start the runner for a built App. */
176
+ export declare function testApp(options?: TestOptions): Promise<TestApp>;
177
+ export type { Message };
@@ -0,0 +1,245 @@
1
+ /**
2
+ * `@pollis-inc/app/testing`: run your built App offline, in your test files.
3
+ *
4
+ * Each call runs one handler in the same sandbox the bot runtime uses, with
5
+ * the same permission checks and the same error messages, so a call your
6
+ * manifest does not allow fails in a test exactly as it would in a group.
7
+ * Nothing touches the network: `ctx.fetch` answers from the `http` fixtures
8
+ * you give, and state starts from the `state` you give.
9
+ *
10
+ * ```ts
11
+ * import { test } from "node:test";
12
+ * import assert from "node:assert/strict";
13
+ * import { testApp } from "@pollis-inc/app/testing";
14
+ *
15
+ * const app = await testApp();
16
+ *
17
+ * test("/hello replies", async () => {
18
+ * const result = await app.command("hello", "world");
19
+ * assert.deepEqual(result.replies, ["Hello, world!"]);
20
+ * });
21
+ * ```
22
+ *
23
+ * `pollis app test` builds the App and runs your `*.test.ts` files with this
24
+ * wired up. It needs the `pollis-app-dev` program (see the developer guide).
25
+ */
26
+ import { spawn } from "node:child_process";
27
+ import { readFileSync } from "node:fs";
28
+ import { resolve } from "node:path";
29
+ import { createInterface } from "node:readline";
30
+ const encoder = new TextEncoder();
31
+ const decoder = new TextDecoder();
32
+ /** 2027-01-15T08:00:00Z, the default clock. */
33
+ export const DEFAULT_NOW = 1_800_000_000_000;
34
+ function bytes(value) {
35
+ if (value instanceof Uint8Array) {
36
+ return Array.from(value);
37
+ }
38
+ if (typeof value === "string") {
39
+ return Array.from(encoder.encode(value));
40
+ }
41
+ return Array.from(encoder.encode(JSON.stringify(value)));
42
+ }
43
+ function msOf(value, fallback) {
44
+ if (value === undefined) {
45
+ return fallback;
46
+ }
47
+ return value instanceof Date ? value.getTime() : value;
48
+ }
49
+ /** Start the runner for a built App. */
50
+ export async function testApp(options = {}) {
51
+ const component = resolve(options.component ?? process.env.POLLIS_APP_COMPONENT ?? "dist/app.wasm");
52
+ const manifestPath = resolve(options.manifest ?? process.env.POLLIS_APP_MANIFEST ?? "dist/pollis-app.json");
53
+ let manifest;
54
+ try {
55
+ manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
56
+ }
57
+ catch (e) {
58
+ throw new Error(`no built App at ${manifestPath}: run \`pollis app build\` first, or run your tests with \`pollis app test\` (${e.message})`);
59
+ }
60
+ const bin = options.bin ?? process.env.POLLIS_APP_DEV_BIN ?? "pollis-app-dev";
61
+ const defaults = options;
62
+ const defaultChannel = manifest.read.channels.find((c) => c !== "*")?.replace(/^#/, "") ?? "general";
63
+ let child;
64
+ let failure;
65
+ const waiting = [];
66
+ let ids = 0;
67
+ /** While a job is in flight the runner keeps the test process alive; idle, it does not. */
68
+ function hold(proc, held) {
69
+ for (const h of [proc, proc.stdin, proc.stdout, proc.stderr]) {
70
+ if (held) {
71
+ h.ref?.();
72
+ }
73
+ else {
74
+ h.unref?.();
75
+ }
76
+ }
77
+ }
78
+ function idle() {
79
+ if (child && waiting.length === 0) {
80
+ hold(child, false);
81
+ }
82
+ }
83
+ function start() {
84
+ if (child) {
85
+ return child;
86
+ }
87
+ const proc = spawn(bin, ["serve"], { stdio: ["pipe", "pipe", "pipe"] });
88
+ let stderr = "";
89
+ proc.stderr.on("data", (d) => {
90
+ stderr += String(d);
91
+ });
92
+ proc.on("error", (e) => {
93
+ const err = e.code === "ENOENT"
94
+ ? new Error(`\`${bin}\` not found: install it or set POLLIS_APP_DEV_BIN (the developer guide's "Testing" section says how)`)
95
+ : e;
96
+ failure = err;
97
+ for (const w of waiting.splice(0)) {
98
+ w.reject(err);
99
+ }
100
+ });
101
+ proc.on("exit", (code) => {
102
+ const err = new Error(`\`${bin} serve\` exited (${code}): ${stderr.trim()}`);
103
+ failure = err;
104
+ for (const w of waiting.splice(0)) {
105
+ w.reject(err);
106
+ }
107
+ });
108
+ createInterface({ input: proc.stdout }).on("line", (line) => {
109
+ const w = waiting.shift();
110
+ w?.resolve(line);
111
+ idle();
112
+ });
113
+ process.once("exit", () => proc.kill());
114
+ child = proc;
115
+ return proc;
116
+ }
117
+ function message(input, now) {
118
+ const m = typeof input === "string" ? { text: input } : (input ?? {});
119
+ ids += 1;
120
+ return {
121
+ id: m.id ?? `m${ids}`,
122
+ channel: m.channel ?? defaultChannel,
123
+ author: {
124
+ id: m.author?.id ?? "u-alice",
125
+ displayName: m.author?.displayName ?? "Alice",
126
+ isBot: m.author?.isBot ?? false,
127
+ },
128
+ text: m.text ?? "",
129
+ replyTo: m.replyTo,
130
+ thread: m.thread,
131
+ sentAt: msOf(m.sentAt, now),
132
+ editedAt: m.editedAt === undefined ? undefined : msOf(m.editedAt, now),
133
+ };
134
+ }
135
+ function grants(g) {
136
+ if (!g) {
137
+ return undefined;
138
+ }
139
+ return {
140
+ channels: Object.entries(g.channels ?? {}).map(([name, id]) => ({ id, name: name.replace(/^#/, "") })),
141
+ history: g.history ?? 0,
142
+ events: g.events ?? ["created"],
143
+ actions: g.actions ?? [],
144
+ egress: g.egress ?? [],
145
+ };
146
+ }
147
+ async function job(trigger, opts) {
148
+ const o = { ...defaults, ...opts };
149
+ const now = msOf(o.now, DEFAULT_NOW);
150
+ const request = {
151
+ component,
152
+ botUsername: options.botUsername,
153
+ manifest: manifestPath,
154
+ trigger,
155
+ grants: grants(o.grants),
156
+ messages: (o.messages ?? []).map((m) => message(m, now)),
157
+ state: Object.fromEntries(Object.entries(o.state ?? {}).map(([k, v]) => [k, bytes(v)])),
158
+ http: (o.http ?? []).map((f) => ({
159
+ url: f.url,
160
+ method: f.method,
161
+ status: f.status ?? 200,
162
+ headers: Array.isArray(f.headers) ? f.headers : Object.entries(f.headers ?? {}),
163
+ body: f.body === undefined ? [] : bytes(f.body),
164
+ })),
165
+ now,
166
+ };
167
+ if (failure) {
168
+ throw failure;
169
+ }
170
+ const proc = start();
171
+ hold(proc, true);
172
+ const line = await new Promise((resolveLine, reject) => {
173
+ waiting.push({ resolve: resolveLine, reject });
174
+ proc.stdin.write(JSON.stringify(request) + "\n");
175
+ });
176
+ return toResult(JSON.parse(line));
177
+ }
178
+ const now = () => msOf(defaults.now, DEFAULT_NOW);
179
+ /** The latest slot of schedule `name` at or before `at` (ms), as the runtime computes it. */
180
+ function slotAt(name, at) {
181
+ const spec = manifest.schedules?.find((s) => s.name === name);
182
+ if (!spec) {
183
+ return at;
184
+ }
185
+ const secs = Math.floor(at / 1000);
186
+ const offset = spec.offset ?? 0;
187
+ const slot = secs < offset ? offset : Math.floor((secs - offset) / spec.every) * spec.every + offset;
188
+ return slot * 1000;
189
+ }
190
+ return {
191
+ manifest,
192
+ send: (m, o) => job({ send: message(m, msOf(o?.now, now())) }, o),
193
+ message: (m, o) => job({ message: message(m, msOf(o?.now, now())) }, o),
194
+ mention: (m, o) => job({ mention: message(m, msOf(o?.now, now())) }, o),
195
+ command: (name, args = "", o) => job({
196
+ send: message({ text: `/${name}${args ? " " + args : ""}`, ...o?.message }, msOf(o?.now, now())),
197
+ }, o),
198
+ schedule: (name, o) => job({ schedule: { name, slot: msOf(o?.slot, slotAt(name, msOf(o?.now, now()))) } }, o),
199
+ request: (body, o) => job({
200
+ request: {
201
+ id: o?.id ?? `r${++ids}`,
202
+ requester: {
203
+ id: o?.requester?.id ?? "u-alice",
204
+ displayName: o?.requester?.displayName ?? "Alice",
205
+ isBot: o?.requester?.isBot ?? false,
206
+ },
207
+ body,
208
+ },
209
+ }, o),
210
+ webhook: (body, o) => job({
211
+ webhook: {
212
+ deliveryId: o?.deliveryId ?? `d${++ids}`,
213
+ headers: Object.entries({
214
+ ...(typeof body === "string" || body instanceof Uint8Array ? {} : { "content-type": "application/json" }),
215
+ ...o?.headers,
216
+ }),
217
+ body: bytes(body),
218
+ },
219
+ }, o),
220
+ close: () => {
221
+ child?.stdin.end();
222
+ child?.kill();
223
+ child = undefined;
224
+ },
225
+ };
226
+ }
227
+ function toResult(wire) {
228
+ const actions = wire.actions;
229
+ return {
230
+ ok: wire.ok,
231
+ error: wire.error,
232
+ actions,
233
+ replies: actions.flatMap((a) => (a.type === "reply" ? [a.text] : [])),
234
+ posts: actions.flatMap((a) => (a.type === "post" ? [{ channel: a.channel, text: a.text }] : [])),
235
+ reactions: actions.flatMap((a) => (a.type === "react" ? [a.emoji] : [])),
236
+ state: Object.fromEntries(wire.stateWrites.map((w) => [w.key, w.value === null ? null : decoder.decode(Uint8Array.from(w.value))])),
237
+ logs: wire.logs,
238
+ fetches: wire.fetches.map((f) => ({
239
+ method: f.method,
240
+ url: f.url,
241
+ headers: f.headers,
242
+ body: f.body === null ? undefined : decoder.decode(Uint8Array.from(f.body)),
243
+ })),
244
+ };
245
+ }
package/package.json CHANGED
@@ -1,6 +1,50 @@
1
1
  {
2
2
  "name": "@pollis-inc/app",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "Write Pollis Apps in TypeScript: handlers, a typed context and the manifest, compiled to a sandboxed component by `pollis app build`.",
5
+ "license": "MIT",
6
+ "homepage": "https://pollis.com/bots-developers.html",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/pollis-app/pollis.git",
10
+ "directory": "sdk/ts/app"
11
+ },
12
+ "type": "module",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ },
18
+ "./testing": {
19
+ "types": "./dist/testing.d.ts",
20
+ "default": "./dist/testing.js"
21
+ },
22
+ "./runtime": {
23
+ "types": "./dist/runtime.d.ts",
24
+ "default": "./dist/runtime.js"
25
+ },
26
+ "./manifest": {
27
+ "types": "./dist/manifest.d.ts",
28
+ "default": "./dist/manifest.js"
29
+ },
30
+ "./wit/app.wit": "./wit/app.wit",
31
+ "./package.json": "./package.json"
32
+ },
33
+ "files": [
34
+ "dist",
35
+ "wit"
36
+ ],
37
+ "engines": {
38
+ "node": ">=22.18"
39
+ },
40
+ "devDependencies": {
41
+ "@bytecodealliance/jco": "1.40.0",
42
+ "@types/node": "^22.19.0",
43
+ "typescript": "5.9.3"
44
+ },
45
+ "scripts": {
46
+ "gen": "node scripts/gen-host-types.mjs",
47
+ "build": "tsc -p tsconfig.json && node -e \"require('node:fs').cpSync('src/generated','dist/generated',{recursive:true})\"",
48
+ "test": "pnpm -s build && node --test test/*.test.ts"
49
+ }
6
50
  }
package/wit/app.wit ADDED
@@ -0,0 +1,168 @@
1
+ /// The capability interface between a Pollis App and the bot runtime (#2004).
2
+ ///
3
+ /// An App is a WebAssembly component that targets the `app` world below. The
4
+ /// runtime instantiates it fresh for every job, calls exactly one handler, and
5
+ /// lets it act only through the `host` imports, each checked against the
6
+ /// installation's effective grants (manifest intersected with the admin's
7
+ /// grants). The SDKs (`@pollis-inc/app`, the Rust SDK) are generated from this file.
8
+ ///
9
+ /// Versioning: this package is `pollis:app@0.1.0`. A change that removes or
10
+ /// retypes anything is a new version; the runtime keeps hosting the old one.
11
+ /// There is deliberately no import for deleting other people's messages,
12
+ /// removing members or changing roles: bots never moderate.
13
+ package pollis:app@0.1.0;
14
+
15
+ /// Data the runtime hands to an App and receives from it.
16
+ interface types {
17
+ /// Opaque message id (the envelope id).
18
+ type message-id = string;
19
+ /// Opaque channel id.
20
+ type channel-id = string;
21
+
22
+ record author {
23
+ id: string,
24
+ display-name: string,
25
+ is-bot: bool,
26
+ }
27
+
28
+ /// Attachment metadata only. Attachment bytes are a later capability.
29
+ record attachment {
30
+ name: string,
31
+ mime-type: string,
32
+ size: u64,
33
+ }
34
+
35
+ record message {
36
+ id: message-id,
37
+ channel: channel-id,
38
+ author: author,
39
+ text: string,
40
+ attachments: list<attachment>,
41
+ /// The message this one replies to, if any.
42
+ reply-to: option<message-id>,
43
+ /// The thread root this message belongs to, if any.
44
+ thread: option<message-id>,
45
+ /// Unix milliseconds.
46
+ sent-at: u64,
47
+ /// Unix milliseconds of the last edit, if edited.
48
+ edited-at: option<u64>,
49
+ }
50
+
51
+ /// A slash command addressed to this App (#2018).
52
+ record command {
53
+ /// Command name without the leading slash.
54
+ name: string,
55
+ /// Everything after the command name, unparsed.
56
+ args: string,
57
+ /// The message that carried the command.
58
+ message: message,
59
+ }
60
+
61
+ /// A schedule firing.
62
+ record schedule {
63
+ /// The schedule's name as declared by the App.
64
+ name: string,
65
+ /// The slot this firing is for, unix milliseconds.
66
+ slot: u64,
67
+ }
68
+
69
+ /// A request addressed to this App by a member.
70
+ record request {
71
+ id: string,
72
+ requester: author,
73
+ body: string,
74
+ }
75
+
76
+ /// An inbound webhook delivery.
77
+ record webhook {
78
+ delivery-id: string,
79
+ headers: list<tuple<string, string>>,
80
+ body: list<u8>,
81
+ }
82
+
83
+ record message-filter {
84
+ /// Only this channel; all granted channels when absent.
85
+ channel: option<channel-id>,
86
+ /// Unix milliseconds, inclusive. Clamped to the granted history window.
87
+ since: option<u64>,
88
+ /// Unix milliseconds, exclusive.
89
+ until: option<u64>,
90
+ /// Upper bound on results; the runtime may return fewer.
91
+ limit: u32,
92
+ }
93
+
94
+ record http-request {
95
+ method: string,
96
+ /// Absolute `https://` URL whose host is in the granted egress list.
97
+ url: string,
98
+ headers: list<tuple<string, string>>,
99
+ body: option<list<u8>>,
100
+ }
101
+
102
+ record http-response {
103
+ status: u16,
104
+ headers: list<tuple<string, string>>,
105
+ body: list<u8>,
106
+ }
107
+
108
+ enum log-level {
109
+ trace,
110
+ debug,
111
+ info,
112
+ warn,
113
+ error,
114
+ }
115
+ }
116
+
117
+ /// Functions the runtime provides. Every one that can be refused returns
118
+ /// `result`; the error string names the manifest field that refused it, e.g.
119
+ /// "`http-fetch` to `api.x.com` refused: not in `egress`".
120
+ interface host {
121
+ use types.{message-id, channel-id, message, message-filter, http-request, http-response, log-level};
122
+
123
+ /// Queue a new message in a granted channel. Applied only if the handler
124
+ /// returns ok.
125
+ post: func(channel: channel-id, text: string) -> result<_, string>;
126
+ /// Queue a reply to a message in a granted channel.
127
+ reply: func(message: message-id, text: string) -> result<_, string>;
128
+ /// Queue a reaction on a message in a granted channel.
129
+ react: func(message: message-id, emoji: string) -> result<_, string>;
130
+ /// Queue an edit of a message this bot sent.
131
+ edit-own: func(message: message-id, text: string) -> result<_, string>;
132
+ /// Queue deletion of a message this bot sent.
133
+ delete-own: func(message: message-id) -> result<_, string>;
134
+
135
+ /// Messages from granted channels inside the granted history window.
136
+ query-messages: func(filter: message-filter) -> result<list<message>, string>;
137
+
138
+ /// Sealed per-installation key-value state, within the manifest's quota.
139
+ /// Writes become durable only if the handler returns ok.
140
+ kv-get: func(key: string) -> result<option<list<u8>>, string>;
141
+ kv-set: func(key: string, value: list<u8>) -> result<_, string>;
142
+ kv-delete: func(key: string) -> result<_, string>;
143
+
144
+ /// One HTTPS request to a host in the granted egress list. Redirects are
145
+ /// followed only within the same host.
146
+ http-fetch: func(request: http-request) -> result<http-response, string>;
147
+
148
+ /// Write to the runtime's log. Never reaches the group.
149
+ log: func(level: log-level, text: string);
150
+ /// Unix milliseconds.
151
+ now: func() -> u64;
152
+ /// A cryptographically random value.
153
+ random: func() -> u64;
154
+ }
155
+
156
+ /// What an App is. Every handler must be exported; the runtime calls only
157
+ /// those whose trigger the installation's grants include.
158
+ world app {
159
+ use types.{message, command, schedule, request, webhook};
160
+ import host;
161
+
162
+ export on-message: func(message: message) -> result<_, string>;
163
+ export on-mention: func(message: message) -> result<_, string>;
164
+ export on-command: func(command: command) -> result<_, string>;
165
+ export on-schedule: func(schedule: schedule) -> result<_, string>;
166
+ export on-request: func(request: request) -> result<_, string>;
167
+ export on-webhook: func(webhook: webhook) -> result<_, string>;
168
+ }