shadok-ai 0.20.60 → 0.20.62
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 +39 -0
- package/dist/external-users.d.ts +15 -0
- package/dist/external-users.js +17 -0
- package/dist/external-users.js.map +1 -1
- package/dist/guest-admit.d.ts +8 -0
- package/dist/guest-admit.js +8 -0
- package/dist/guest-admit.js.map +1 -1
- package/dist/guest-init.d.ts +206 -0
- package/dist/guest-init.js +293 -0
- package/dist/guest-init.js.map +1 -0
- package/dist/secret-audit.d.ts +1 -1
- package/dist/secret-audit.js +1 -1
- package/dist/secret-audit.js.map +1 -1
- package/dist/server.js +171 -6
- package/dist/server.js.map +1 -1
- package/dist/telegram.js +14 -1
- package/dist/telegram.js.map +1 -1
- package/dist/wa-bridge.js +6 -1
- package/dist/wa-bridge.js.map +1 -1
- package/package.json +1 -1
- package/public/index.html +81 -5
package/README.md
CHANGED
|
@@ -1151,6 +1151,45 @@ conversation, the same trust the site already has over what they type there.
|
|
|
1151
1151
|
Needs the multi-tenant deployment (External groups do), and HTTPS on the sites
|
|
1152
1152
|
that embed it.
|
|
1153
1153
|
|
|
1154
|
+
### First-run script (optional): prepare a guest's account before its agent's first message
|
|
1155
|
+
|
|
1156
|
+
An **External** group can carry a shell script that runs once for each new
|
|
1157
|
+
conversation — a new WhatsApp number, Telegram user or site visitor — once
|
|
1158
|
+
that person's agent exists and before it is given their first message. Use it
|
|
1159
|
+
for whatever the agent should find in place: a folder layout, a file fetched
|
|
1160
|
+
from another service, an account reserved for this person, a daily schedule or
|
|
1161
|
+
a webhook of its own. The agent's first turn is then only its answer.
|
|
1162
|
+
|
|
1163
|
+
Write it in the External group's settings (*First-run script*). It runs with
|
|
1164
|
+
`sh`, as that conversation's own Unix user, in its own folder, with the secrets
|
|
1165
|
+
of the door's profile, and it is given:
|
|
1166
|
+
|
|
1167
|
+
| Variable | Value |
|
|
1168
|
+
|---|---|
|
|
1169
|
+
| `SHADOK_GUEST_KEY` | the conversation: `wa-<number>`, `tg-<id>`, `web-<visitor>` |
|
|
1170
|
+
| `SHADOK_GUEST_DOOR` | `whatsapp`, `telegram`, `widget`, or `agent` |
|
|
1171
|
+
| `SHADOK_GUEST_DIR` | the conversation's folder (also the working directory) |
|
|
1172
|
+
| `SHADOK_GROUP_ID` | the group |
|
|
1173
|
+
| `SHADOK_SESSION_ID`, `SHADOK_SESSION_KEY`, `SHADOK_PORT` | the agent being prepared: what the scheduler and webhook scripts read |
|
|
1174
|
+
|
|
1175
|
+
The key is that agent's own and reaches nothing else: the script can schedule
|
|
1176
|
+
a prompt or open a webhook **for its agent**, the way the agent would — with
|
|
1177
|
+
the scheduler skill's `schedule.mjs` / `webhook.mjs`, or `POST /crons` and
|
|
1178
|
+
`POST /webhooks` with the `x-shadok-session-key` header. It cannot store
|
|
1179
|
+
secrets for the conversation.
|
|
1180
|
+
|
|
1181
|
+
- The person's first message waits for it: 60 seconds at most.
|
|
1182
|
+
- **A non-zero exit or a timeout closes the agent.** Whatever the script
|
|
1183
|
+
scheduled or opened goes with it, the account is erased, the person is asked
|
|
1184
|
+
to write again, and the script runs again at their next message. The panel shows the last run and why it failed; the
|
|
1185
|
+
server log has a `guests: first-run script FAILED` line.
|
|
1186
|
+
- It applies to **new** conversations only. People already talking when you
|
|
1187
|
+
add or change the script are not affected.
|
|
1188
|
+
- An agent you start yourself in the group runs it too (door `agent`) — the
|
|
1189
|
+
way to try a script without a phone.
|
|
1190
|
+
- What the script reserves in another service is not released when the
|
|
1191
|
+
conversation is erased.
|
|
1192
|
+
|
|
1154
1193
|
### Running in Docker
|
|
1155
1194
|
|
|
1156
1195
|
> Putting one instance online for someone else, on its own machine, behind a
|
package/dist/external-users.d.ts
CHANGED
|
@@ -37,6 +37,17 @@ export interface ExternalUserRow {
|
|
|
37
37
|
* operator asked to erase.
|
|
38
38
|
*/
|
|
39
39
|
retiring?: number;
|
|
40
|
+
/**
|
|
41
|
+
* `"pending"` while the group's first-run script has not SUCCEEDED for this
|
|
42
|
+
* conversation (`src/guest-init.ts`) — absent otherwise, which is also what
|
|
43
|
+
* every row written before the field existed reads as.
|
|
44
|
+
*
|
|
45
|
+
* Written with the row, at the mint, and dropped on success. It is on disk
|
|
46
|
+
* rather than in memory because the gap it covers is a server that stopped
|
|
47
|
+
* mid-script: without it the next message would find an account, conclude
|
|
48
|
+
* the conversation is an old one, and start an agent in a half-prepared home.
|
|
49
|
+
*/
|
|
50
|
+
init?: "pending";
|
|
40
51
|
}
|
|
41
52
|
/**
|
|
42
53
|
* What provisioning this conversation's user amounts to, against the registry.
|
|
@@ -69,6 +80,10 @@ export declare function withExternalUser(rows: readonly ExternalUserRow[], row:
|
|
|
69
80
|
export declare function externalUsersOfGroup(rows: readonly ExternalUserRow[], groupId: string): ExternalUserRow[];
|
|
70
81
|
/** The account minted for this conversation, or null. */
|
|
71
82
|
export declare function externalUserRow(rows: readonly ExternalUserRow[], groupId: string, conversation: string): ExternalUserRow | null;
|
|
83
|
+
/** Mark a conversation's first-run script as owed (new array). */
|
|
84
|
+
export declare function withInitPending(rows: readonly ExternalUserRow[], user: string): ExternalUserRow[];
|
|
85
|
+
/** The first-run script succeeded — or there is none left to run (new array). */
|
|
86
|
+
export declare function withInitDone(rows: readonly ExternalUserRow[], user: string): ExternalUserRow[];
|
|
72
87
|
/** Drop rows (new array) — a torn-down conversation, or a deleted group's lot. */
|
|
73
88
|
export declare function withoutExternalUsers(rows: readonly ExternalUserRow[], users: readonly string[]): ExternalUserRow[];
|
|
74
89
|
/**
|
package/dist/external-users.js
CHANGED
|
@@ -51,6 +51,19 @@ export function externalUserRow(rows, groupId, conversation) {
|
|
|
51
51
|
const unit = conversationUnit(groupId, conversation);
|
|
52
52
|
return rows.find((r) => r.unit === unit) ?? null;
|
|
53
53
|
}
|
|
54
|
+
/** Mark a conversation's first-run script as owed (new array). */
|
|
55
|
+
export function withInitPending(rows, user) {
|
|
56
|
+
return rows.map((r) => (r.user === user ? { ...r, init: "pending" } : r));
|
|
57
|
+
}
|
|
58
|
+
/** The first-run script succeeded — or there is none left to run (new array). */
|
|
59
|
+
export function withInitDone(rows, user) {
|
|
60
|
+
return rows.map((r) => {
|
|
61
|
+
if (r.user !== user || r.init === undefined)
|
|
62
|
+
return r;
|
|
63
|
+
const { init: _init, ...rest } = r;
|
|
64
|
+
return rest;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
54
67
|
/** Drop rows (new array) — a torn-down conversation, or a deleted group's lot. */
|
|
55
68
|
export function withoutExternalUsers(rows, users) {
|
|
56
69
|
const gone = new Set(users);
|
|
@@ -240,6 +253,10 @@ export function normalizeExternalUsers(raw) {
|
|
|
240
253
|
// read as live because its timestamp was mangled.
|
|
241
254
|
if (row.retiring != null)
|
|
242
255
|
kept.retiring = typeof row.retiring === "number" && Number.isFinite(row.retiring) ? row.retiring : 0;
|
|
256
|
+
// Same direction for the first-run script: any trace of the mark means it
|
|
257
|
+
// is still owed, never that it ran.
|
|
258
|
+
if (row.init != null)
|
|
259
|
+
kept.init = "pending";
|
|
243
260
|
out.push(kept);
|
|
244
261
|
}
|
|
245
262
|
return out;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-users.js","sourceRoot":"","sources":["../src/external-users.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"external-users.js","sourceRoot":"","sources":["../src/external-users.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,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AG,CAAC;AACb,CAAC;AAED,4EAA4E;AAC5E,+EAA+E;AAC/E,mEAAmE;AAEnE,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,YAAY,EAAE,qBAAqB,CAAC,CAAC;AAE1E,MAAM,UAAU,iBAAiB;IAC/B,IAAI,CAAC;QACH,OAAO,sBAAsB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAC3E,CAAC;IAAC,MAAM,CAAC;QACP,yEAAyE;QACzE,2EAA2E;QAC3E,uEAAuE;QACvE,0EAA0E;QAC1E,0EAA0E;QAC1E,oDAAoD;QACpD,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAgC;IAChE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACtD,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACvE,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,2CAA2C;AACxE,CAAC"}
|
package/dist/guest-admit.d.ts
CHANGED
|
@@ -45,6 +45,14 @@ export declare const GUEST_RATE_WINDOW_MS = 3600000;
|
|
|
45
45
|
/** The refusal's `code` on the wire, so a bridge classifies it without
|
|
46
46
|
* matching on the message text (the `busy` convention). */
|
|
47
47
|
export declare const GUEST_FULL_CODE = "guest-full";
|
|
48
|
+
/**
|
|
49
|
+
* The `error` code of a spawn refused because the group's first-run script
|
|
50
|
+
* failed (`src/guest-init.ts`). It lives here, beside the other code a bridge
|
|
51
|
+
* must recognise, so a bridge does not import the script runner to read it.
|
|
52
|
+
* Unlike the ceiling, trying again IS the answer: the account was erased and
|
|
53
|
+
* the next message starts over.
|
|
54
|
+
*/
|
|
55
|
+
export declare const GUEST_INIT_CODE = "guest-init";
|
|
48
56
|
/**
|
|
49
57
|
* This door's limits: what the operator stored, else the defaults.
|
|
50
58
|
*
|
package/dist/guest-admit.js
CHANGED
|
@@ -15,6 +15,14 @@ export const GUEST_RATE_WINDOW_MS = 3_600_000;
|
|
|
15
15
|
/** The refusal's `code` on the wire, so a bridge classifies it without
|
|
16
16
|
* matching on the message text (the `busy` convention). */
|
|
17
17
|
export const GUEST_FULL_CODE = "guest-full";
|
|
18
|
+
/**
|
|
19
|
+
* The `error` code of a spawn refused because the group's first-run script
|
|
20
|
+
* failed (`src/guest-init.ts`). It lives here, beside the other code a bridge
|
|
21
|
+
* must recognise, so a bridge does not import the script runner to read it.
|
|
22
|
+
* Unlike the ceiling, trying again IS the answer: the account was erased and
|
|
23
|
+
* the next message starts over.
|
|
24
|
+
*/
|
|
25
|
+
export const GUEST_INIT_CODE = "guest-init";
|
|
18
26
|
/**
|
|
19
27
|
* This door's limits: what the operator stored, else the defaults.
|
|
20
28
|
*
|
package/dist/guest-admit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guest-admit.js","sourceRoot":"","sources":["../src/guest-admit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAqC1D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAgB,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AAEpE,4CAA4C;AAC5C,MAAM,CAAC,MAAM,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C;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAQD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,iBAAiB,CAAC,KASjC;IACC,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IACzB,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACpE,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI;QAChC,OAAO;YACL,EAAE,EAAE,KAAK;YACT,GAAG,EAAE,MAAM;YACX,OAAO,EAAE,mDAAmD,MAAM,CAAC,IAAI,sBAAsB;SAC9F,CAAC;IACJ,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ,IAAI,oBAAoB,CAAC;IACtD,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,GAAG,MAAM,CAAC;IACjC,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC;IAC3D,IAAI,KAAK,IAAI,MAAM,CAAC,OAAO;QACzB,OAAO;YACL,EAAE,EAAE,KAAK;YACT,GAAG,EAAE,MAAM;YACX,OAAO,EAAE,6CAA6C,MAAM,CAAC,OAAO,2CAA2C;SAChH,CAAC;IACJ,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import type { Group } from "./groups.js";
|
|
2
|
+
/**
|
|
3
|
+
* The FIRST-RUN SCRIPT of an external group: a shell script the operator
|
|
4
|
+
* writes once, run for every NEW conversation of that group before its agent
|
|
5
|
+
* is given the first message, as that conversation's own Unix user and in its
|
|
6
|
+
* own directory.
|
|
7
|
+
*
|
|
8
|
+
* It runs once the agent and its channel EXIST, on purpose: the first version
|
|
9
|
+
* ran before the spawn, and could prepare files but nothing that belongs to an
|
|
10
|
+
* agent — a morning schedule, a webhook — because a key is only honoured for a
|
|
11
|
+
* session the server knows. Those stayed on the agent's first turn, which is
|
|
12
|
+
* the very thing the script is there to keep free. So it now holds the agent's
|
|
13
|
+
* own key (`SHADOK_SESSION_KEY`), and `ready` — what makes a bridge deliver the
|
|
14
|
+
* person's message — waits for it.
|
|
15
|
+
*
|
|
16
|
+
* It exists so the account is ready before the first message is answered. The
|
|
17
|
+
* alternative is to describe the setup in the profile's prompt and let the
|
|
18
|
+
* agent do it on its first turn: slower (the person waits on a model following
|
|
19
|
+
* instructions), and it hands a stranger's very first message to an agent that
|
|
20
|
+
* is busy with something else. A script is deterministic, costs no quota, and
|
|
21
|
+
* the agent's first turn is only the answer.
|
|
22
|
+
*
|
|
23
|
+
* Three rules shape everything below.
|
|
24
|
+
*
|
|
25
|
+
* - **It runs as the conversation, never as the server.** The server is root in
|
|
26
|
+
* the only deployment where an external group exists, so "run it as the
|
|
27
|
+
* server" would make this field a root shell (the lesson of the cron guard,
|
|
28
|
+
* invariant 60). It gets the same `setpriv` drop, the same allow-listed
|
|
29
|
+
* environment and the same profile secrets as that conversation's agent — it
|
|
30
|
+
* is strictly no more powerful than the agent it prepares the ground for.
|
|
31
|
+
* - **A conversation whose script did not succeed has no agent.** A half
|
|
32
|
+
* prepared account is the one outcome nobody chose: the admission is refused,
|
|
33
|
+
* the account is erased, and the person's next message starts over.
|
|
34
|
+
* - **Only the operator writes it.** It is stored beside the other door
|
|
35
|
+
* settings, root-owned, and reachable through an admin, browser-only route.
|
|
36
|
+
*
|
|
37
|
+
* Everything here is pure except the store at the bottom, so the rules are
|
|
38
|
+
* tested with no root, no account and no shell.
|
|
39
|
+
*/
|
|
40
|
+
/** What a script may weigh. Far past any setup script; a ceiling, not a need. */
|
|
41
|
+
export declare const GUEST_INIT_MAX_BYTES: number;
|
|
42
|
+
/**
|
|
43
|
+
* How long one run may take. The person's first message waits on it, so it is
|
|
44
|
+
* short on purpose: a script that needs longer belongs in the background of
|
|
45
|
+
* the script itself, not in front of someone waiting for an answer.
|
|
46
|
+
*/
|
|
47
|
+
export declare const GUEST_INIT_TIMEOUT_MS = 60000;
|
|
48
|
+
export { GUEST_INIT_CODE } from "./guest-admit.js";
|
|
49
|
+
/** Through which door the conversation came — `agent` for one a member opened
|
|
50
|
+
* in the group themselves, which is also how a script is tried without a phone. */
|
|
51
|
+
export type GuestInitDoor = "telegram" | "whatsapp" | "widget" | "agent";
|
|
52
|
+
/** The outcome of the latest run, kept for the operator's panel. */
|
|
53
|
+
export interface GuestInitRun {
|
|
54
|
+
at: number;
|
|
55
|
+
ok: boolean;
|
|
56
|
+
/** The conversation it ran for (`wa-…`, `tg-…`, `web-…`). */
|
|
57
|
+
conversation: string;
|
|
58
|
+
ms: number;
|
|
59
|
+
/** Why it failed — first line of stderr, or the timeout. Absent on success. */
|
|
60
|
+
detail?: string;
|
|
61
|
+
}
|
|
62
|
+
export interface GuestInit {
|
|
63
|
+
/** The external group this script belongs to. */
|
|
64
|
+
group: string;
|
|
65
|
+
script: string;
|
|
66
|
+
updatedAt: number;
|
|
67
|
+
/** The admin account that last wrote it. */
|
|
68
|
+
by: string;
|
|
69
|
+
last?: GuestInitRun;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A script as typed in the panel → what is stored. Line endings are unified
|
|
73
|
+
* (a textarea posts CRLF, and `sh` reads the CR as part of the last word of
|
|
74
|
+
* every line); nothing else is touched, because it is a program.
|
|
75
|
+
*/
|
|
76
|
+
export declare function cleanInitScript(v: unknown): {
|
|
77
|
+
ok: true;
|
|
78
|
+
script: string;
|
|
79
|
+
} | {
|
|
80
|
+
ok: false;
|
|
81
|
+
error: string;
|
|
82
|
+
};
|
|
83
|
+
/** The store as read from disk: malformed rows are dropped, one row per group. */
|
|
84
|
+
export declare function normalizeGuestInits(raw: unknown): GuestInit[];
|
|
85
|
+
export declare function guestInitOf(list: readonly GuestInit[], group: string): GuestInit | null;
|
|
86
|
+
/**
|
|
87
|
+
* Write (or, with an empty script, remove) a group's first-run script.
|
|
88
|
+
*
|
|
89
|
+
* Refused outside an EXTERNAL group: that is the only nature with one Unix
|
|
90
|
+
* account per conversation, and a script run once per stranger as the group's
|
|
91
|
+
* shared user would be writing into every other stranger's files.
|
|
92
|
+
*/
|
|
93
|
+
export declare function guestInitWriteFlow(input: {
|
|
94
|
+
list: readonly GuestInit[];
|
|
95
|
+
groups: readonly Pick<Group, "id" | "nature">[];
|
|
96
|
+
/** Why the instance cannot isolate conversations at all, or null. */
|
|
97
|
+
unavailable: string | null;
|
|
98
|
+
group: string;
|
|
99
|
+
script: unknown;
|
|
100
|
+
by: string;
|
|
101
|
+
now: number;
|
|
102
|
+
}): {
|
|
103
|
+
ok: true;
|
|
104
|
+
list: GuestInit[];
|
|
105
|
+
init: GuestInit | null;
|
|
106
|
+
} | {
|
|
107
|
+
ok: false;
|
|
108
|
+
status: number;
|
|
109
|
+
error: string;
|
|
110
|
+
};
|
|
111
|
+
/** Record a run's outcome on its group's row (new array). */
|
|
112
|
+
export declare function withInitRun(list: readonly GuestInit[], group: string, run: GuestInitRun): GuestInit[];
|
|
113
|
+
/** Drop the rows of groups that no longer exist (new array). */
|
|
114
|
+
export declare function withoutStaleInits(list: readonly GuestInit[], groups: readonly Pick<Group, "id">[]): GuestInit[];
|
|
115
|
+
/**
|
|
116
|
+
* The environment a run gets, in the order `cronCheckEnv` applies — and for
|
|
117
|
+
* the same reasons: an allow-list of the server's own variables (never a
|
|
118
|
+
* subtraction), then the profile's secrets, then the facts of THIS run, then
|
|
119
|
+
* the drop user's identity last so nothing above can keep `HOME=/root`.
|
|
120
|
+
*
|
|
121
|
+
* The conversation is handed over as DATA, in variables: a phone number or a
|
|
122
|
+
* visitor id is chosen by a stranger and must never be spliced into the text
|
|
123
|
+
* the shell parses.
|
|
124
|
+
*/
|
|
125
|
+
export declare function guestInitEnv(input: {
|
|
126
|
+
base: Record<string, string | undefined>;
|
|
127
|
+
secrets: Record<string, string>;
|
|
128
|
+
user: string | null;
|
|
129
|
+
home: string | null;
|
|
130
|
+
group: string;
|
|
131
|
+
conversation: string;
|
|
132
|
+
door: GuestInitDoor;
|
|
133
|
+
dir: string;
|
|
134
|
+
/**
|
|
135
|
+
* The agent this script prepares the ground for — it exists by the time the
|
|
136
|
+
* script runs, so the script can do for it what it could do for itself:
|
|
137
|
+
* schedule a prompt, open a webhook. The key is that agent's own, and the
|
|
138
|
+
* server boxes it to that one session for as long as the script runs.
|
|
139
|
+
*/
|
|
140
|
+
session: {
|
|
141
|
+
id: string;
|
|
142
|
+
port: string;
|
|
143
|
+
key: string;
|
|
144
|
+
};
|
|
145
|
+
}): Record<string, string>;
|
|
146
|
+
/** `sh -c <script>`, wrapped in the same `setpriv` drop as the agent's spawn. */
|
|
147
|
+
export declare function guestInitCommand(user: string | null, script: string): {
|
|
148
|
+
cmd: string;
|
|
149
|
+
argv: string[];
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Did the run succeed? The EXIT CODE decides, which is the opposite of a cron
|
|
153
|
+
* guard (invariant 16) and on purpose: a guard exits 1 to say "nothing to
|
|
154
|
+
* report", a setup script exits non-zero to say it did not set things up.
|
|
155
|
+
*/
|
|
156
|
+
export declare function initOutcome(r: {
|
|
157
|
+
/** The exit code, or null when it was killed or never started. */
|
|
158
|
+
code: number | null;
|
|
159
|
+
timedOut: boolean;
|
|
160
|
+
/** Why the shell could not be started at all. */
|
|
161
|
+
spawnError?: string;
|
|
162
|
+
stderr: string;
|
|
163
|
+
timeoutMs: number;
|
|
164
|
+
}): {
|
|
165
|
+
ok: true;
|
|
166
|
+
} | {
|
|
167
|
+
ok: false;
|
|
168
|
+
detail: string;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Run the script and say how it ended.
|
|
172
|
+
*
|
|
173
|
+
* Not `execFile` with a `timeout`, for one reason: that kills the shell and
|
|
174
|
+
* then waits for its output pipes to close — and a child the script left
|
|
175
|
+
* running (`something &`, or just the command the shell was in the middle of)
|
|
176
|
+
* keeps them open. A script stuck on a slow network call would hold a person's
|
|
177
|
+
* first message for as long as that call lasts, well past the ceiling. So the
|
|
178
|
+
* script gets a process group of its own, the WHOLE group is killed at the
|
|
179
|
+
* deadline, and the answer is taken when the shell exits, not when the pipes
|
|
180
|
+
* close. `killStragglers` is an optional second sweep for a process that left
|
|
181
|
+
* the group. The server passes none: the agent runs as the same Unix user by
|
|
182
|
+
* then, so "everything this user runs" is no longer just the script — and on a
|
|
183
|
+
* failure the whole account is erased anyway, processes first.
|
|
184
|
+
*/
|
|
185
|
+
export declare function runInitScript(input: {
|
|
186
|
+
cmd: string;
|
|
187
|
+
argv: string[];
|
|
188
|
+
cwd: string;
|
|
189
|
+
env: Record<string, string>;
|
|
190
|
+
timeoutMs?: number;
|
|
191
|
+
killStragglers?: () => void | Promise<unknown>;
|
|
192
|
+
}): Promise<{
|
|
193
|
+
ok: true;
|
|
194
|
+
} | {
|
|
195
|
+
ok: false;
|
|
196
|
+
detail: string;
|
|
197
|
+
}>;
|
|
198
|
+
/** What the panel is shown. The script itself is the operator's own text. */
|
|
199
|
+
export declare function publicGuestInit(init: GuestInit | null): {
|
|
200
|
+
script: string;
|
|
201
|
+
updatedAt: number | null;
|
|
202
|
+
by: string | null;
|
|
203
|
+
last: GuestInitRun | null;
|
|
204
|
+
};
|
|
205
|
+
export declare function loadGuestInits(): GuestInit[];
|
|
206
|
+
export declare function saveGuestInits(list: readonly GuestInit[]): void;
|