@hallohuman/hightea 0.1.30 → 0.1.32

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.
Files changed (40) hide show
  1. package/LICENSE +5 -0
  2. package/dist/bin.js +30 -362
  3. package/dist/chunk-3emak1d3.js +2 -0
  4. package/dist/chunk-55a0ndzw.js +5 -0
  5. package/dist/chunk-5hvk5pvs.js +9 -0
  6. package/dist/chunk-749gsvce.js +139 -0
  7. package/dist/chunk-7mgx0krk.js +5 -0
  8. package/dist/chunk-ah99zytf.js +58 -0
  9. package/dist/chunk-c7atktnb.js +5 -0
  10. package/dist/chunk-dvsftn8z.js +5 -0
  11. package/dist/chunk-dzr0pvfa.js +1 -0
  12. package/dist/chunk-gbwfgq6g.js +1 -0
  13. package/dist/chunk-h9f45p57.js +4 -0
  14. package/dist/chunk-hrtxeg8j.js +1 -0
  15. package/dist/chunk-nfmmht3j.js +2 -0
  16. package/dist/chunk-pdnrwmme.js +1 -0
  17. package/dist/chunk-pexgyagn.js +2 -0
  18. package/dist/chunk-v221hgba.js +2 -0
  19. package/dist/chunk-vr4rsfaf.js +13 -0
  20. package/dist/chunk-w2f84aab.js +1 -0
  21. package/dist/chunk-wyzpk81n.js +13 -0
  22. package/dist/plugin/plugin.json +4 -1
  23. package/dist/plugin/plugin.mjs +51 -15364
  24. package/package.json +2 -1
  25. package/dist/chunk-0ab6h39c.js +0 -402
  26. package/dist/chunk-0r70ekxd.js +0 -8
  27. package/dist/chunk-13tpn1g6.js +0 -465
  28. package/dist/chunk-3rgfnt23.js +0 -16
  29. package/dist/chunk-5mezgvms.js +0 -139
  30. package/dist/chunk-9e325ntw.js +0 -89
  31. package/dist/chunk-cx3yvvkz.js +0 -7295
  32. package/dist/chunk-d5h204vj.js +0 -14
  33. package/dist/chunk-dvnzt54t.js +0 -7168
  34. package/dist/chunk-dvt4hb8z.js +0 -1491
  35. package/dist/chunk-gk8tyqac.js +0 -184
  36. package/dist/chunk-h8pdqn31.js +0 -157
  37. package/dist/chunk-ph04jess.js +0 -17
  38. package/dist/chunk-sbqmqp8e.js +0 -123
  39. package/dist/chunk-w0ebwtch.js +0 -161
  40. package/dist/chunk-y5r2yxx1.js +0 -347
@@ -1,465 +0,0 @@
1
- // ../client/src/index.ts
2
- var sourceOf = (kind, id) => ({ kind, id });
3
- var sameSource = (a, b) => a !== undefined && b !== undefined && a.kind === b.kind && a.id === b.id;
4
- var sourceText = (source) => `${source.kind}:${source.id}`;
5
- function requirePerson(caller, operation) {
6
- if (caller.kind === "agent") {
7
- throw new Error(`${operation}: a person must grant this; agent ${caller.id} cannot`);
8
- }
9
- }
10
- var SOURCE_FIELD = "source";
11
- var AGENT_SOURCE_KEY = "x-hh/source";
12
- var neutralFields = ["command", "cwd", "env", "schedule", "restart", "depends_on", "health"];
13
- var fieldsOf = (service) => ({
14
- command: service.command,
15
- cwd: service.cwd,
16
- env: service.env,
17
- schedule: service.schedule,
18
- restart: service.restart,
19
- depends_on: service.depends_on,
20
- health: service.health
21
- });
22
- var canonical = (value) => {
23
- if (value === undefined)
24
- return "undefined";
25
- if (Array.isArray(value))
26
- return `[${value.map(canonical).join(",")}]`;
27
- if (value !== null && typeof value === "object") {
28
- const keys = Object.keys(value).sort();
29
- return `{${keys.map((k) => `${JSON.stringify(k)}:${canonical(value[k])}`).join(",")}}`;
30
- }
31
- return JSON.stringify(value);
32
- };
33
- var changedFields = (before, after) => {
34
- const a = fieldsOf(before);
35
- const b = fieldsOf(after);
36
- return neutralFields.filter((field) => canonical(a[field]) !== canonical(b[field]));
37
- };
38
- var SERVICES_CHANNEL = "x-hh-services://";
39
- var operate = (host, operationId, rest) => host.call("x-ahpd/invokeOperation", { channel: SERVICES_CHANNEL, operationId, ...rest });
40
- var listOf = async (host) => {
41
- const answer = await host.call("subscribe", { channel: SERVICES_CHANNEL });
42
- await host.call("unsubscribe", { channel: SERVICES_CHANNEL });
43
- const state = answer?.snapshot?.state;
44
- if (typeof state?.error === "string")
45
- throw new Error(`the machine's services could not be read: ${state.error}`);
46
- if (state === undefined || !Array.isArray(state.rows))
47
- throw new Error("the services channel answered no rows");
48
- const rows = state.rows;
49
- return {
50
- services: rows.flatMap((row) => row.record === undefined ? [] : [withState(row.record, row.state)]),
51
- readOnly: rows.flatMap((row) => row.readOnly === undefined ? [] : [{ name: row.name, reason: row.readOnly }]),
52
- capabilities: state.capabilities,
53
- ifVersion: state.ifVersion,
54
- ...typeof state.file === "string" ? { file: state.file } : {}
55
- };
56
- };
57
- var withState = (record, state) => {
58
- if (!isRecord(state) || typeof state.status !== "string")
59
- return record;
60
- return { ...record, state: { status: state.status, ...typeof state.why === "string" ? { why: state.why } : {} } };
61
- };
62
- var DEPLOYS_CHANNEL = "x-hh-deploys://";
63
- async function deployService(host, call) {
64
- if (typeof call?.service !== "string" || call.service.trim() === "")
65
- throw new Error("deployService: service is a non-empty name");
66
- if (typeof call?.version !== "string" || call.version.trim() === "")
67
- throw new Error("deployService: version is a branch, a tag or a commit sha");
68
- const answer = await host.call("x-ahpd/invokeOperation", {
69
- channel: DEPLOYS_CHANNEL,
70
- operationId: "deploy",
71
- target: { id: call.service },
72
- input: { service: call.service, version: call.version }
73
- });
74
- if (!isRecord(answer))
75
- throw new Error(`the deploys channel answered no record: ${JSON.stringify(answer)}`);
76
- if (answer["ok"] === true) {
77
- const service = answer["service"];
78
- const sha = answer["sha"];
79
- const deployId = answer["deployId"];
80
- if (typeof service !== "string" || typeof sha !== "string" || typeof deployId !== "string" || answer["state"] !== "started") {
81
- throw new Error(`the deploys channel answered a start without service, sha, deployId and state: ${JSON.stringify(answer)}`);
82
- }
83
- return { ok: true, service, sha, deployId, state: "started" };
84
- }
85
- const code = answer["code"];
86
- const message = answer["message"];
87
- if (answer["ok"] === false && typeof code === "string" && code !== "" && typeof message === "string") {
88
- return { ok: false, code, message };
89
- }
90
- throw new Error(`the deploys channel answered neither a start nor a named refusal: ${JSON.stringify(answer)}`);
91
- }
92
- var runOf = (value) => {
93
- if (!isRecord(value))
94
- return;
95
- const service = value["service"];
96
- const deployId = value["deployId"];
97
- const state = value["state"];
98
- if (typeof service !== "string" || typeof deployId !== "string" || typeof state !== "string")
99
- return;
100
- const step = value["step"];
101
- const from = value["from"];
102
- const to = value["to"];
103
- const at = value["at"];
104
- const last = value["last"];
105
- const reason = isRecord(last) && typeof last["reason"] === "string" ? last["reason"] : undefined;
106
- const exit = isRecord(last) && (last["exit"] === null || typeof last["exit"] === "number") ? last["exit"] : undefined;
107
- return {
108
- service,
109
- deployId,
110
- state,
111
- ...typeof step === "string" ? { step } : {},
112
- ...from === null || typeof from === "string" ? { from } : {},
113
- ...typeof to === "string" ? { to } : {},
114
- ...typeof at === "string" ? { at } : {},
115
- ...reason === undefined ? {} : { reason },
116
- ...exit === undefined ? {} : { exit }
117
- };
118
- };
119
- async function deploys(host) {
120
- const answer = await host.call("subscribe", { channel: DEPLOYS_CHANNEL });
121
- await host.call("unsubscribe", { channel: DEPLOYS_CHANNEL });
122
- const state = answer?.snapshot?.state;
123
- if (state === undefined)
124
- throw new Error("the deploys channel answered no state");
125
- const runs = Array.isArray(state["runs"]) ? state["runs"].flatMap((row) => {
126
- const run = runOf(row);
127
- return run === undefined ? [] : [run];
128
- }) : [];
129
- const machine = typeof state["machine"] === "string" ? state["machine"] : "";
130
- const error = typeof state["error"] === "string" ? state["error"] : undefined;
131
- return { machine, runs, ...error === undefined ? {} : { error } };
132
- }
133
- async function preview(plan, host, options) {
134
- const plannedHosts = hostsOf(plan);
135
- const services = plan.services === undefined ? undefined : await previewServices(plan.services, host, options);
136
- return {
137
- ...services ?? { create: [], change: [], unchanged: [], readOnly: [], remove: [], keep: [], unmanaged: [] },
138
- ...plan.agents === undefined ? {} : { agents: await previewAgents(plan.agents, host, options) },
139
- ...plannedHosts.length === 0 ? {} : { hosts: await previewHosts(plannedHosts, options) }
140
- };
141
- }
142
- async function previewServices(plannedServices, host, options) {
143
- const current = await listOf(host);
144
- const fields = current.capabilities?.fields ?? [];
145
- if (!fields.includes(SOURCE_FIELD)) {
146
- throw new Error(`this machine's services driver records no "${SOURCE_FIELD}" (its fields are ${fields.join(", ")}); it cannot say which client wrote an entry, so nothing is written`);
147
- }
148
- const byName = new Map(current.services.map((service) => [service.name, service]));
149
- const readOnly = new Map(current.readOnly.map((entry) => [entry.name, entry.reason]));
150
- const create = [];
151
- const change = [];
152
- const unchanged = [];
153
- const planned = new Set;
154
- for (const service of plannedServices) {
155
- planned.add(service.name);
156
- const before = byName.get(service.name);
157
- if (readOnly.has(service.name)) {
158
- throw new Error(`${service.name} is read-only on this machine: ${readOnly.get(service.name) ?? ""}`);
159
- }
160
- if (before === undefined) {
161
- create.push(service);
162
- } else {
163
- const changed = changedFields(before, service);
164
- if (changed.length === 0)
165
- unchanged.push(service.name);
166
- else
167
- change.push({ name: service.name, before, after: service, changed });
168
- }
169
- }
170
- const candidates = options.prune === true ? current.services.filter((service) => sameSource(service.source, options.source) && !planned.has(service.name)) : [];
171
- if (candidates.length > 0 && options.removal === undefined) {
172
- const named = candidates.map((service) => `${service.name} (${service.state?.status ?? "state unknown"})`).join(", ");
173
- throw new Error(`prune would remove ${named}: pass stop (stop each program, then remove the entry) or keep (leave it running here and clear its source)`);
174
- }
175
- const remove = options.removal === "stop" ? candidates : [];
176
- const keep = options.removal === "keep" ? candidates : [];
177
- const unmanaged = options.prune === true ? current.services.filter((service) => !sameSource(service.source, options.source) && !planned.has(service.name)) : [];
178
- return { ifVersion: current.ifVersion, create, change, unchanged, readOnly: current.readOnly, remove, keep, unmanaged };
179
- }
180
- function hostsOf(plan) {
181
- const entries = plan.hosts;
182
- if (entries === undefined)
183
- return [];
184
- if (!Array.isArray(entries))
185
- throw new Error("the plan's hosts is not a list: a host entry is {name, agents}");
186
- const named = new Set;
187
- return entries.map((entry, index) => {
188
- if (!isRecord(entry))
189
- throw new Error(`host entry ${index + 1} is not an object: a host entry is {name, agents}`);
190
- const name = entry.name;
191
- if (typeof name !== "string" || name.trim().length === 0) {
192
- throw new Error(`host entry ${index + 1} names no machine: every host entry needs a non-empty "name"`);
193
- }
194
- const unknown = Object.keys(entry).filter((key) => key !== "name" && key !== "agents");
195
- if (unknown.length > 0)
196
- throw new Error(`host entry ${name}: unknown ${unknown.length === 1 ? "field" : "fields"} ${unknown.join(", ")} (a host entry is {name, agents})`);
197
- if (named.has(name))
198
- throw new Error(`${name} is named twice in one plan`);
199
- named.add(name);
200
- const agents = entry.agents;
201
- if (agents !== undefined && (!Array.isArray(agents) || !agents.every((id) => typeof id === "string" && id.length > 0 && id.length <= 256))) {
202
- throw new Error(`host entry ${name}: agents must be a list of agent member ids`);
203
- }
204
- return agents === undefined ? { name } : { name, agents };
205
- });
206
- }
207
- function hostJoinFor(entries, options) {
208
- const workspace = options.hostJoin;
209
- if (workspace !== undefined)
210
- return workspace;
211
- const named = entries.map((entry) => `host:${entry.name}`).join(", ");
212
- throw new Error(`host entries need a workspace to mint their join links and this apply has none: ${named}. ` + "Nothing is sent and no host is created from a plan: run it with the workspace's origin and slug, signed in as a person, or take the hosts out of the plan.");
213
- }
214
- async function previewHosts(entries, options) {
215
- requirePerson(options.source.kind === "agent" ? { kind: "agent", id: options.source.id } : { kind: "person", id: options.source.id }, "host-join");
216
- hostJoinFor(entries, options);
217
- const pending = entries.map((entry) => ({ name: entry.name, agents: [...entry.agents ?? []] }));
218
- if (options.prune !== true)
219
- return { pending };
220
- return { pending, pruneNote: "host links are not pruned; each unconsumed link expires on its own, and its expiry is printed when it is minted" };
221
- }
222
- var AGENTS_CHANNEL = "x-ahpd-agents://";
223
- var AGENT_FIELDS = ["engine", "owner", "name", "description", "tags", "model"];
224
- var isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
225
- var sourceInConfig = (id, config) => {
226
- const raw = config[AGENT_SOURCE_KEY];
227
- if (raw === undefined)
228
- return;
229
- if (!isRecord(raw))
230
- throw new Error(`${id}: config.${AGENT_SOURCE_KEY} is not a source ({kind, id})`);
231
- const kind = raw.kind;
232
- const sourceId = raw.id;
233
- if (kind !== "file" && kind !== "program" && kind !== "agent" && kind !== "ci") {
234
- throw new Error(`${id}: config.${AGENT_SOURCE_KEY}.kind is not one of file, program, agent, ci`);
235
- }
236
- if (typeof sourceId !== "string" || sourceId === "")
237
- throw new Error(`${id}: config.${AGENT_SOURCE_KEY}.id is empty`);
238
- return { kind, id: sourceId };
239
- };
240
- var agentOf = (entry) => {
241
- if (!isRecord(entry))
242
- throw new Error("the agents channel answered an entry that is not an object");
243
- const held = isRecord(entry.record) ? entry.record : entry;
244
- const id = entry.id;
245
- if (typeof id !== "string" || id === "")
246
- throw new Error("the agents channel answered a record that names no id");
247
- const revision = typeof held.revision === "number" && Number.isInteger(held.revision) && held.revision >= 0 ? held.revision : undefined;
248
- const config = isRecord(held.config) ? held.config : {};
249
- const source = sourceInConfig(id, config);
250
- return { id, ...revision === undefined ? {} : { revision }, record: held, ...source === undefined ? {} : { source } };
251
- };
252
- async function listAgents(host) {
253
- const answer = await host.call("subscribe", { channel: AGENTS_CHANNEL });
254
- await host.call("unsubscribe", { channel: AGENTS_CHANNEL });
255
- const state = answer?.snapshot?.state;
256
- const records = isRecord(state) ? state.records : undefined;
257
- if (!Array.isArray(records))
258
- throw new Error("the agents channel answered no records");
259
- return records.map(agentOf);
260
- }
261
- var agentFieldsOf = (agent) => ({
262
- engine: agent.engine,
263
- owner: agent.owner,
264
- name: agent.name,
265
- ...agent.description === undefined ? {} : { description: agent.description },
266
- ...agent.tags === undefined ? {} : { tags: agent.tags },
267
- ...agent.model === undefined ? {} : { model: agent.model }
268
- });
269
- var withoutSource = (config) => Object.fromEntries(Object.entries(config).filter(([key]) => key !== AGENT_SOURCE_KEY));
270
- var changedAgentFields = (before, after) => {
271
- const fields = agentFieldsOf(after);
272
- const changed = AGENT_FIELDS.filter((field) => canonical(before.record[field]) !== canonical(fields[field]));
273
- const config = isRecord(before.record.config) ? before.record.config : {};
274
- if (canonical(withoutSource(config)) !== canonical(withoutSource(after.config ?? {})))
275
- changed.push("config");
276
- return changed;
277
- };
278
- async function previewAgents(plan, host, options) {
279
- const current = await listAgents(host);
280
- const byId = new Map(current.map((agent) => [agent.id, agent]));
281
- const create = [];
282
- const change = [];
283
- const unchanged = [];
284
- const planned = new Set;
285
- for (const agent of plan) {
286
- if (planned.has(agent.id))
287
- throw new Error(`${agent.id} is named twice in one plan`);
288
- planned.add(agent.id);
289
- const before = byId.get(agent.id);
290
- if (before === undefined) {
291
- create.push(agent);
292
- } else {
293
- const changed = changedAgentFields(before, agent);
294
- if (changed.length === 0)
295
- unchanged.push(agent.id);
296
- else if (before.revision === undefined)
297
- throw new Error(`${agent.id} has no revision on this machine; it cannot be edited from here`);
298
- else
299
- change.push({ id: agent.id, before, after: agent, changed });
300
- }
301
- }
302
- const remove = options.prune === true ? current.filter((agent) => sameSource(agent.source, options.source) && !planned.has(agent.id)) : [];
303
- for (const agent of remove) {
304
- if (agent.revision === undefined)
305
- throw new Error(`${agent.id} has no revision on this machine; it cannot be removed from here`);
306
- }
307
- return { create, change, unchanged, remove };
308
- }
309
- async function applyPreview(shown, host, workspace) {
310
- let ifVersion = shown.ifVersion ?? "";
311
- const written = [];
312
- const hostLinks = [];
313
- for (const entry of shown.hosts?.pending ?? []) {
314
- if (workspace === undefined) {
315
- throw new Error(`host ${entry.name}: host links need a workspace to mint them and this apply has none; nothing was minted`);
316
- }
317
- let link;
318
- try {
319
- link = await workspace.mintHostJoin(entry.agents);
320
- } catch (error) {
321
- throw new Error(`host ${entry.name} was not minted: ${error.message}`);
322
- }
323
- hostLinks.push({ name: entry.name, link });
324
- }
325
- for (const service of shown.create) {
326
- const answer = await operate(host, "put", { input: { service, ifVersion: "absent" } });
327
- ifVersion = answer.ifVersion ?? ifVersion;
328
- written.push(service.name);
329
- }
330
- for (const entry of shown.change) {
331
- const answer = await operate(host, "put", { input: { service: entry.after, ifVersion } });
332
- ifVersion = answer.ifVersion ?? ifVersion;
333
- written.push(entry.name);
334
- }
335
- const kept = [];
336
- for (const entry of shown.keep ?? []) {
337
- const answer = await operate(host, "put", { input: { service: { name: entry.name, source: null }, ifVersion } });
338
- ifVersion = answer.ifVersion ?? ifVersion;
339
- kept.push(entry.name);
340
- }
341
- const removed = [];
342
- for (const entry of shown.remove ?? []) {
343
- if (entry.state?.status.toLowerCase() === "running") {
344
- await operate(host, "stop", { target: { id: entry.name }, input: {} });
345
- }
346
- const answer = await operate(host, "remove", { target: { id: entry.name }, input: { ifVersion } });
347
- ifVersion = answer.ifVersion ?? ifVersion;
348
- removed.push(entry.name);
349
- }
350
- if (shown.agents !== undefined) {
351
- for (const agent of shown.agents.create) {
352
- await putAgent(host, agent, 0);
353
- written.push(`agent:${agent.id}`);
354
- }
355
- for (const entry of shown.agents.change) {
356
- if (entry.before.revision === undefined)
357
- throw new Error(`${entry.id} has no revision on this machine; it cannot be edited from here`);
358
- await putAgent(host, entry.after, entry.before.revision);
359
- written.push(`agent:${entry.id}`);
360
- }
361
- for (const entry of shown.agents.remove) {
362
- if (entry.revision === undefined)
363
- throw new Error(`${entry.id} has no revision on this machine; it cannot be removed from here`);
364
- await removeAgent(host, entry.id, entry.revision);
365
- removed.push(`agent:${entry.id}`);
366
- }
367
- }
368
- const hostNote = shown.hosts?.pruneNote === undefined ? undefined : hostLinks.length === 0 ? "host links are not pruned; this apply minted none, so nothing of its own is outstanding" : `host links are not pruned; unconsumed ones expire at ${hostLinks.map((entry) => entry.link.expiresAt).sort()[0]}`;
369
- return {
370
- preview: shown,
371
- written,
372
- removed,
373
- kept,
374
- ...shown.hosts === undefined ? {} : { hostLinks },
375
- ...hostNote === undefined ? {} : { hostNote }
376
- };
377
- }
378
- var putAgent = (host, agent, ifRevision) => host.call("x-ahpd/agents/put", {
379
- id: agent.id,
380
- ...agentFieldsOf(agent),
381
- config: { ...agent.config, [AGENT_SOURCE_KEY]: agent.source },
382
- ifRevision
383
- });
384
- var removeAgent = (host, id, ifRevision) => host.call("x-ahpd/agents/remove", { id, ifRevision });
385
- function describe(preview) {
386
- const lines = [];
387
- for (const service of preview.create)
388
- lines.push(`+ ${service.name}`);
389
- for (const change of preview.change)
390
- lines.push(`~ ${change.name} (${change.changed.join(", ")})`);
391
- for (const service of preview.remove ?? []) {
392
- const running = service.state?.status.toLowerCase() === "running";
393
- lines.push(`- ${service.name} (${running ? "stop, then remove" : "remove"}; source ${sourceText(service.source)})`);
394
- }
395
- for (const service of preview.keep ?? [])
396
- lines.push(`= ${service.name} (kept: left running here, source cleared)`);
397
- for (const service of preview.unmanaged ?? []) {
398
- const why = service.source === undefined ? "no source" : `source ${sourceText(service.source)}`;
399
- lines.push(`? ${service.name} (not managed by this apply: ${why})`);
400
- }
401
- for (const name of preview.unchanged)
402
- lines.push(`= ${name}`);
403
- for (const entry of preview.readOnly)
404
- lines.push(`! ${entry.name} read-only: ${entry.reason}`);
405
- if (preview.hosts !== undefined) {
406
- for (const entry of preview.hosts.pending) {
407
- const agents = entry.agents.length === 0 ? "no agents" : `agents ${entry.agents.join(",")}`;
408
- lines.push(`+ host:${entry.name} (pending link: the machine must join; ${agents})`);
409
- }
410
- if (preview.hosts.pruneNote !== undefined)
411
- lines.push(`note: ${preview.hosts.pruneNote}`);
412
- }
413
- if (preview.agents !== undefined) {
414
- for (const agent of preview.agents.create)
415
- lines.push(`+ agent:${agent.id}`);
416
- for (const change of preview.agents.change)
417
- lines.push(`~ agent:${change.id} (${change.changed.join(", ")})`);
418
- for (const agent of preview.agents.remove) {
419
- lines.push(`- agent:${agent.id} (source ${agent.source === undefined ? "unknown" : sourceText(agent.source)})`);
420
- }
421
- for (const id of preview.agents.unchanged)
422
- lines.push(`= agent:${id}`);
423
- }
424
- return lines;
425
- }
426
-
427
- // ../client/src/ahp.ts
428
- import WebSocket from "ws";
429
- async function connectAhp(url, options) {
430
- const endpoint = options.token === undefined ? url : `${url}${url.includes("?") ? "&" : "?"}tkn=${encodeURIComponent(options.token)}`;
431
- const ws = new WebSocket(endpoint);
432
- const waiting = new Map;
433
- let closed;
434
- let nextId = 0;
435
- ws.on("message", (data) => {
436
- const frame = JSON.parse(String(data));
437
- if (frame.id !== undefined && frame.method === undefined)
438
- waiting.get(frame.id)?.(frame);
439
- });
440
- ws.on("close", (code, reason) => {
441
- closed = `${String(code)} ${reason.toString()}`;
442
- for (const resolve of waiting.values())
443
- resolve({ error: { code: 0, message: `closed: ${closed}` } });
444
- });
445
- await new Promise((resolve, reject) => {
446
- ws.once("open", () => resolve());
447
- ws.once("error", (error) => reject(error));
448
- });
449
- const call = (method, params) => new Promise((resolve, reject) => {
450
- if (closed !== undefined)
451
- return reject(new Error(`the machine's connection closed: ${closed}`));
452
- const id = ++nextId;
453
- waiting.set(id, (frame) => {
454
- if (frame.error !== undefined)
455
- reject(new Error(frame.error.message));
456
- else
457
- resolve(frame.result);
458
- });
459
- ws.send(JSON.stringify({ jsonrpc: "2.0", id, method, params }));
460
- });
461
- await call("initialize", { channel: "ahp-root://", protocolVersions: ["1.1.0"], clientId: options.clientId });
462
- return { call, close: () => ws.close() };
463
- }
464
-
465
- export { sourceOf, deployService, deploys, preview, applyPreview, describe, connectAhp };
@@ -1,16 +0,0 @@
1
- import {
2
- agentAppsOnPath2,
3
- installLineOf2,
4
- describedApp2,
5
- appInstalled2,
6
- isShippedApp2,
7
- noAgentAppsLine2
8
- } from "./chunk-dvnzt54t.js";
9
- export {
10
- agentAppsOnPath2 as agentAppsOnPath,
11
- appInstalled2 as appInstalled,
12
- describedApp2 as describedApp,
13
- installLineOf2 as installLineOf,
14
- isShippedApp2 as isShippedApp,
15
- noAgentAppsLine2 as noAgentAppsLine
16
- };
@@ -1,139 +0,0 @@
1
- import"./chunk-0ab6h39c.js";
2
- import {
3
- ownerIo,
4
- sendOwner
5
- } from "./chunk-sbqmqp8e.js";
6
-
7
- // src/source.ts
8
- var USAGE = `hightea source bind --origin https://your-deployment --workspace SLUG --source SOURCE --host HOST [--refresh 1h] [--session-file FILE] [--json]
9
- ` + `hightea source unbind --origin https://your-deployment --workspace SLUG --source SOURCE [--session-file FILE] [--json]
10
- ` + `hightea source set-refresh --origin https://your-deployment --workspace SLUG --source SOURCE --every 1h [--session-file FILE] [--json]
11
- ` + "hightea source show --origin https://your-deployment --workspace SLUG --source SOURCE [--session-file FILE] [--json]";
12
- function parseRefreshInterval(text) {
13
- const raw = text.trim().toLowerCase();
14
- if (raw === "")
15
- return "INVALID";
16
- if (raw === "none" || raw === "off")
17
- return null;
18
- const match = /^(\d+)(s|m|h|d)$/u.exec(raw);
19
- if (match === null)
20
- return "INVALID";
21
- const unit = { s: 1000, m: 60000, h: 3600000, d: 86400000 }[match[2]];
22
- const ms = Number(match[1]) * unit;
23
- return Number.isSafeInteger(ms) && ms > 0 ? ms : "INVALID";
24
- }
25
- var BOUND_ELSEWHERE = { SOURCE_BINDING_CONFLICT: 4 };
26
- function defaults() {
27
- return ownerIo();
28
- }
29
- async function send(target, io, request) {
30
- if (target.workspace.trim().length === 0 || target.source.trim().length === 0) {
31
- return { exit: 1, error: `SOURCE_INPUT: --workspace and --source are required.
32
- ${USAGE}` };
33
- }
34
- return sendOwner(target, io, {
35
- ...request,
36
- label: "SOURCE",
37
- extraExits: BOUND_ELSEWHERE,
38
- path: `/sources/${encodeURIComponent(target.source)}${request.path}`
39
- });
40
- }
41
- function datasetLine(source) {
42
- const field = (name) => source[name] === null || source[name] === undefined ? "none" : String(source[name]);
43
- const listing = source.listing === true ? ", first list running" : source.listing === false ? ", no list running" : "";
44
- return `${field("status")} on ${field("hostId")} as dataset ${field("dataset")} (freshness ${field("freshness")}${listing})`;
45
- }
46
- async function sourceBind(target, io = defaults()) {
47
- if (target.host.trim().length === 0) {
48
- io.err(`SOURCE_INPUT: --host is required (the host id that serves the source).
49
- ${USAGE}`);
50
- return 1;
51
- }
52
- const refreshMs = target.refresh === undefined ? undefined : parseRefreshInterval(target.refresh);
53
- if (refreshMs === "INVALID" || refreshMs === null) {
54
- io.err(`SOURCE_INPUT: --refresh takes a whole count and one unit — 30m, 1h, 2d — and a bind never clears a schedule.
55
- ${USAGE}`);
56
- return 1;
57
- }
58
- const sent = await send(target, io, {
59
- method: "POST",
60
- path: "/bind",
61
- body: refreshMs === undefined ? { hostId: target.host.trim() } : { hostId: target.host.trim(), refreshMs },
62
- what: "bind"
63
- });
64
- if ("error" in sent) {
65
- io.err(sent.error);
66
- return sent.exit;
67
- }
68
- if (target.json) {
69
- io.out(JSON.stringify(sent.answer));
70
- return 0;
71
- }
72
- const source = sent.answer.source ?? {};
73
- io.out(`bound ${String(source.sourceId ?? target.source)} to ${String(source.hostId ?? target.host)}: ${datasetLine(source)}`);
74
- io.out("The source's first list fills its dataset; run `hightea source show` to watch its freshness.");
75
- return 0;
76
- }
77
- async function sourceUnbind(target, io = defaults()) {
78
- const sent = await send(target, io, { method: "POST", path: "/unbind", what: "unbind" });
79
- if ("error" in sent) {
80
- io.err(sent.error);
81
- return sent.exit;
82
- }
83
- if (target.json) {
84
- io.out(JSON.stringify(sent.answer));
85
- return 0;
86
- }
87
- const source = sent.answer.source ?? {};
88
- io.out(`unbound ${String(source.sourceId ?? target.source)} from ${String(source.hostId ?? "its host")}: ${datasetLine(source)}`);
89
- io.out("Rows kept; rebind refreshes them.");
90
- return 0;
91
- }
92
- async function sourceShow(target, io = defaults()) {
93
- const sent = await send(target, io, { method: "GET", path: "", what: "read" });
94
- if ("error" in sent) {
95
- io.err(sent.error);
96
- return sent.exit;
97
- }
98
- if (target.json) {
99
- io.out(JSON.stringify(sent.answer));
100
- return 0;
101
- }
102
- const source = sent.answer.source ?? {};
103
- const position = source.position;
104
- io.out(`${String(source.sourceId ?? target.source)}: ${datasetLine(source)}`);
105
- io.out(`position ${position === null || position === undefined ? "none" : `${String(position.epoch)}/${String(position.ordinal)}`}, ` + `last error ${source.lastError === null || source.lastError === undefined ? "none" : String(source.lastError)}, ` + `dropped ${String(source.dropped ?? 0)}, duplicates ${String(source.duplicates ?? 0)}`);
106
- return 0;
107
- }
108
- async function sourceSetRefresh(target, io = defaults()) {
109
- if (target.every.trim().length === 0) {
110
- io.err(`SOURCE_INPUT: --every is required (1h, 30m, 2d, or none).
111
- ${USAGE}`);
112
- return 1;
113
- }
114
- const everyMs = parseRefreshInterval(target.every);
115
- if (everyMs === "INVALID") {
116
- io.err(`SOURCE_INPUT: --every takes a whole count and one unit — 45s, 30m, 1h, 2d — or none.
117
- ${USAGE}`);
118
- return 1;
119
- }
120
- const sent = await send(target, io, { method: "POST", path: "/schedule", body: { everyMs }, what: "set its refresh interval" });
121
- if ("error" in sent) {
122
- io.err(sent.error);
123
- return sent.exit;
124
- }
125
- if (target.json) {
126
- io.out(JSON.stringify(sent.answer));
127
- return 0;
128
- }
129
- const source = sent.answer.source ?? {};
130
- const declared = source.reconcileMs === null || source.reconcileMs === undefined ? "no schedule (refreshes only when the host reports a gap)" : `refresh every ${Math.round(Number(source.reconcileMs) / 60000)} min`;
131
- io.out(`${String(source.sourceId ?? target.source)}: ${declared}; ${datasetLine(source)}`);
132
- return 0;
133
- }
134
- export {
135
- sourceBind,
136
- sourceSetRefresh,
137
- sourceShow,
138
- sourceUnbind
139
- };