@netnodeag/kraftwerk 0.76.0 → 0.78.0

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 (65) hide show
  1. package/README.md +33 -27
  2. package/dist/cli/cloud.d.ts +2 -0
  3. package/dist/cli/cloud.js +262 -0
  4. package/dist/cli/daemon.js +9 -0
  5. package/dist/cli/doctor.js +16 -8
  6. package/dist/cli/init.js +2 -2
  7. package/dist/cli/invite.d.ts +2 -0
  8. package/dist/cli/invite.js +48 -0
  9. package/dist/cli/kraftwerk.js +7 -0
  10. package/dist/client/relay.d.ts +40 -0
  11. package/dist/client/relay.js +35 -0
  12. package/dist/client/routes.d.ts +5 -0
  13. package/dist/client/routes.js +5 -0
  14. package/dist/config.d.ts +15 -28
  15. package/dist/config.js +5 -19
  16. package/dist/core/chat/channel-turns.d.ts +2 -2
  17. package/dist/core/chat/channel-turns.js +2 -2
  18. package/dist/core/chat/sessions.d.ts +20 -3
  19. package/dist/core/chat/sessions.js +22 -7
  20. package/dist/core/chat/types.d.ts +21 -0
  21. package/dist/core/cloud.d.ts +152 -0
  22. package/dist/core/cloud.js +98 -0
  23. package/dist/core/routines.d.ts +22 -2
  24. package/dist/core/routines.js +26 -0
  25. package/dist/server/api/chats.js +45 -8
  26. package/dist/server/api/cloud.d.ts +86 -0
  27. package/dist/server/api/cloud.js +51 -0
  28. package/dist/server/api/devices.d.ts +15 -9
  29. package/dist/server/api/devices.js +3 -2
  30. package/dist/server/api/index.d.ts +108 -11
  31. package/dist/server/api/index.js +2 -0
  32. package/dist/server/api/router.d.ts +3 -2
  33. package/dist/server/api/router.js +12 -0
  34. package/dist/server/api/workspace.d.ts +16 -1
  35. package/dist/server/api/workspace.js +2 -1
  36. package/dist/server/cloud.d.ts +104 -33
  37. package/dist/server/cloud.js +279 -185
  38. package/dist/server/hub-context.d.ts +1 -1
  39. package/dist/server/hub-context.js +3 -3
  40. package/dist/server/members.d.ts +87 -0
  41. package/dist/server/members.js +117 -0
  42. package/dist/server/relay.d.ts +21 -1
  43. package/dist/server/relay.js +74 -3
  44. package/dist/server/server.d.ts +3 -2
  45. package/dist/server/server.js +13 -6
  46. package/dist/server/trust.d.ts +16 -0
  47. package/dist/server/trust.js +12 -1
  48. package/package.json +1 -1
  49. package/schema/kraftwerk.schema.json +4 -4
  50. package/web/dist/assets/{dist-T1sNLC62.js → dist-B-yVL5lk.js} +1 -1
  51. package/web/dist/assets/{dist-DFXmaDc5.js → dist-B9EMB1Ie.js} +1 -1
  52. package/web/dist/assets/{dist-BQpWYkxm.js → dist-BTc878j7.js} +1 -1
  53. package/web/dist/assets/{dist-fgB7OEJy.js → dist-C90kUzps.js} +1 -1
  54. package/web/dist/assets/{dist-l7foWlFx.js → dist-CpLdAqFQ.js} +1 -1
  55. package/web/dist/assets/{dist-flnLXEzU.js → dist-Crnb8VVO.js} +1 -1
  56. package/web/dist/assets/{dist-vuciRCSz.js → dist-D0rjnN8S.js} +1 -1
  57. package/web/dist/assets/{dist-BTVP-6On.js → dist-D4SDXoGw.js} +1 -1
  58. package/web/dist/assets/{dist-BwIca_Uj.js → dist-DHRhdODt.js} +1 -1
  59. package/web/dist/assets/{dist-BYkcY-Vl.js → dist-DQbifCX0.js} +1 -1
  60. package/web/dist/assets/dist-lSJ-O7kT.js +1 -0
  61. package/web/dist/assets/{editor-C6Ok8NPo.js → editor-DHAdW1g_.js} +3 -3
  62. package/web/dist/assets/{index-z4tpCCzk.js → index-D7JVAjll.js} +5 -5
  63. package/web/dist/index.html +1 -1
  64. package/web/dist-remote/sw.js +1 -1
  65. package/web/dist/assets/dist-BURf1l-A.js +0 -1
@@ -1,53 +1,124 @@
1
+ import { type Credentials, type CloudUrlSource, type InviteResponse } from "../core/cloud.js";
1
2
  /**
2
- * The cloud manager client: kraftwerk.yml `cloud:` makes this instance
3
- * register with the kraftwerk cloud when the inspector starts and heartbeat
4
- * while it runs — the same record ~/.kraftwerk/instances holds locally,
5
- * kept on a server so an admin (and, with an account token, the user)
6
- * sees every instance across machines.
3
+ * The machine client: the daemon registers THIS MACHINE with the kraftwerk
4
+ * cloud once and heartbeats while it runs; the workspaces it serves ride
5
+ * along as children of that record (see core/cloud.ts for the contract and
6
+ * the settings). One per process, and only the daemon starts it
7
+ * (startMachineCloud from `kraftwerk daemon`): a standalone `kraftwerk ui`
8
+ * and test fixtures never talk to the cloud.
7
9
  *
8
- * Identity: the first registration hands out an id + secret, stored under
9
- * ~/.kraftwerk/cloud/<hash(url, root)>.json and presented on every later
10
- * call, so a restart updates the record instead of creating a new one.
11
- * When the cloud does not recognise the id (data reset) it hands out a
12
- * fresh one and the file is rewritten.
13
- *
14
- * Everything is best-effort: a cloud that is down never affects the UI.
15
- * The status is reported in /api/meta so the UI can show it.
10
+ * start ensure the machine key (relay.json, relay stays off), drop the
11
+ * retired per-workspace identities (~/.kraftwerk/cloud/), and,
12
+ * unless cloud.json or KRAFTWERK_CLOUD_URL=off says no, register
13
+ * — anonymous: the answer carries a claim code until someone
14
+ * claims the machine (`kraftwerk login`, or the code in the UI)
15
+ * heartbeat every `interval` the cloud asked for; the workspace list rides
16
+ * along whenever it changed (opened, closed, vetoed, claimed).
17
+ * A claim made in the cloud arrives in the answer
18
+ * privacy while unclaimed, entries carry name/slug/ws-id only — no
19
+ * roots; once claimed, roots too, and the routines that ran
20
+ * here (`routines`, sent when it changed; private ones never)
21
+ * members the machine's credentials and the served workspaces are
22
+ * what member sessions over the relay are verified with
23
+ * (server/members.ts), and what `kraftwerk invite` asks the
24
+ * cloud with (createWorkspaceInvite)
25
+ * recovery a cloud that no longer knows the machine (data reset) gets a
26
+ * fresh registration; a cloud that is down is retried at the
27
+ * same cadence and never affects the UI
28
+ * goodbye on shutdown (bounded), and when `kraftwerk cloud off` reaches
29
+ * the running daemon
16
30
  */
17
31
  export type CloudState = "off" | "connecting" | "connected" | "error";
18
32
  export interface CloudStatus {
19
33
  url: string;
20
34
  state: CloudState;
21
- /** Last error message while connecting or heartbeating. */
35
+ /** Why it is off, when it is. */
36
+ reason?: string;
37
+ /** Where the URL came from (env, cloud.json, a deprecated kraftwerk.yml cloud.url, the default). */
38
+ source?: CloudUrlSource;
39
+ /** Last error message while registering or heartbeating. */
22
40
  error?: string;
23
- /** Instance id in the cloud once registered. */
41
+ /** The machine's id in the cloud (its relay id). */
24
42
  id?: string;
25
- /** Email of the linked kraftwerk account, when a token was presented and accepted. */
43
+ /** This machine's handle@machine. */
44
+ machine?: string;
45
+ /** Email of the account that claimed the machine; null while unclaimed. */
26
46
  account?: string | null;
27
- /** Effective seconds between heartbeats (the cloud may raise the configured one). */
47
+ /** Effective seconds between heartbeats (what the cloud asked for). */
28
48
  interval?: number;
49
+ /** Last successful register or heartbeat. */
29
50
  lastSeen?: string;
30
- /** XXXX-XXXX the user types into the cloud UI to claim this instance; null once claimed. */
51
+ /** XXXX-XXXX that claims this machine in the cloud; null once claimed. */
31
52
  claimCode?: string | null;
32
- /** The cloud page that claims this instance after sign-in. */
53
+ /** The cloud page that claims this machine after sign-in. */
33
54
  claimUrl?: string | null;
55
+ /** Workspaces reported (vetoed ones left out). */
56
+ workspaces?: number;
34
57
  }
58
+ /** What the daemon serves right now; `ws` runs code inside that workspace (the routine report reads its state). */
59
+ export type WorkspaceSource = () => Array<{
60
+ root: string;
61
+ slug: string;
62
+ name: string;
63
+ ws?: {
64
+ run<T>(fn: () => T): T;
65
+ };
66
+ }>;
35
67
  export declare const cloudStatus: () => CloudStatus;
36
68
  /**
37
- * Start the client once the inspector listens. Resolves after the first
38
- * registration attempt (success or not); the heartbeat loop runs on its
39
- * own afterwards.
69
+ * Start the machine client (the daemon, once its workspaces are open).
70
+ * Resolves after the first registration attempt; the heartbeat runs on its
71
+ * own afterwards. A second start in the same process is ignored.
72
+ */
73
+ export declare function startMachineCloud(opts: {
74
+ version: string;
75
+ workspaces: WorkspaceSource;
76
+ owner?: unknown;
77
+ }): Promise<CloudStatus>;
78
+ /**
79
+ * Settings changed (`kraftwerk cloud on|off`, a URL): turn the client on or
80
+ * off to match; off says goodbye first. Without a started client (a
81
+ * standalone server) nothing happens.
82
+ */
83
+ export declare function applyMachineCloud(): Promise<CloudStatus>;
84
+ /** A round now (the CLI's `login` waits for a claim): registers when needed, else heartbeats. */
85
+ export declare function syncMachineCloud(): Promise<CloudStatus>;
86
+ /** Release the claim (`kraftwerk logout`): the cloud hands out a fresh claim code. */
87
+ export declare function unlinkMachineCloud(): Promise<CloudStatus>;
88
+ /**
89
+ * Stop the client and tell the cloud the machine is going away (bounded:
90
+ * an exit handler waits for this). `owner`: only the client that owner
91
+ * started (a hub stopping in a test leaves another's alone).
92
+ */
93
+ export declare function stopMachineCloud(owner?: unknown): Promise<void>;
94
+ /**
95
+ * What member verification needs (server/members.ts): the cloud's origin,
96
+ * this machine's credentials. Null when no machine client runs (a
97
+ * standalone server, the cloud turned off).
40
98
  */
41
- export declare function startCloudSync(url: string, version: string): Promise<void>;
42
- /** Stop the heartbeat loop (server close, tests). */
43
- export declare function stopCloudSync(): void;
99
+ export declare function machineLink(): {
100
+ url: string;
101
+ creds: Credentials;
102
+ version: string;
103
+ } | null;
104
+ /** The served workspace whose kraftwerk.yml `id` is `id` (vetoed ones not), or null. */
105
+ export declare function servedWorkspace(id: string): Promise<{
106
+ slug: string;
107
+ name: string;
108
+ root: string;
109
+ } | null>;
44
110
  /**
45
- * Tell the cloud we are going away, so the record flips to "stopped" now
46
- * instead of after the grace period. Bounded: an exit handler waits for
47
- * this, and a slow cloud must not hold the process.
111
+ * An invite to a served workspace (`kraftwerk invite`): the cloud's machine
112
+ * path, so only a claimed machine that reports the workspace gets one.
113
+ * `which` is the workspace's slug or root.
48
114
  */
49
- export declare function cloudGoodbye(): Promise<void>;
50
- /** Every served workspace: stop its heartbeat (the server closes). */
51
- export declare function stopAllCloudSync(): void;
52
- /** Every served workspace says goodbye, in parallel (still bounded per workspace). */
53
- export declare function cloudGoodbyeAll(): Promise<void>;
115
+ export declare function createWorkspaceInvite(which: {
116
+ slug?: string;
117
+ root?: string;
118
+ }, role?: "owner" | "member"): Promise<InviteResponse & {
119
+ workspace: {
120
+ id: string;
121
+ slug: string;
122
+ name: string;
123
+ };
124
+ }>;