@pioneercompany/app-sdk 0.0.0-stage → 0.1.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 (73) hide show
  1. package/README.md +132 -2
  2. package/dist/client/index.d.ts +27 -0
  3. package/dist/client/index.d.ts.map +1 -0
  4. package/dist/client/index.js +101 -0
  5. package/dist/client/index.js.map +1 -0
  6. package/dist/error.d.ts +11 -0
  7. package/dist/error.d.ts.map +1 -0
  8. package/dist/error.js +19 -0
  9. package/dist/error.js.map +1 -0
  10. package/dist/server/config.d.ts +23 -0
  11. package/dist/server/config.d.ts.map +1 -0
  12. package/dist/server/config.js +66 -0
  13. package/dist/server/config.js.map +1 -0
  14. package/dist/server/index.d.ts +38 -0
  15. package/dist/server/index.d.ts.map +1 -0
  16. package/dist/server/index.js +99 -0
  17. package/dist/server/index.js.map +1 -0
  18. package/dist/server/output.d.ts +22 -0
  19. package/dist/server/output.d.ts.map +1 -0
  20. package/dist/server/output.js +31 -0
  21. package/dist/server/output.js.map +1 -0
  22. package/dist/server/pty.d.ts +56 -0
  23. package/dist/server/pty.d.ts.map +1 -0
  24. package/dist/server/pty.js +388 -0
  25. package/dist/server/pty.js.map +1 -0
  26. package/dist/server/transport.d.ts +21 -0
  27. package/dist/server/transport.d.ts.map +1 -0
  28. package/dist/server/transport.js +214 -0
  29. package/dist/server/transport.js.map +1 -0
  30. package/dist-cjs/client/index.d.ts +27 -0
  31. package/dist-cjs/client/index.d.ts.map +1 -0
  32. package/dist-cjs/client/index.js +106 -0
  33. package/dist-cjs/client/index.js.map +1 -0
  34. package/dist-cjs/error.d.ts +11 -0
  35. package/dist-cjs/error.d.ts.map +1 -0
  36. package/dist-cjs/error.js +25 -0
  37. package/dist-cjs/error.js.map +1 -0
  38. package/dist-cjs/package.json +1 -0
  39. package/dist-cjs/server/config.d.ts +23 -0
  40. package/dist-cjs/server/config.d.ts.map +1 -0
  41. package/dist-cjs/server/config.js +69 -0
  42. package/dist-cjs/server/config.js.map +1 -0
  43. package/dist-cjs/server/index.d.ts +38 -0
  44. package/dist-cjs/server/index.d.ts.map +1 -0
  45. package/dist-cjs/server/index.js +105 -0
  46. package/dist-cjs/server/index.js.map +1 -0
  47. package/dist-cjs/server/output.d.ts +22 -0
  48. package/dist-cjs/server/output.d.ts.map +1 -0
  49. package/dist-cjs/server/output.js +36 -0
  50. package/dist-cjs/server/output.js.map +1 -0
  51. package/dist-cjs/server/pty.d.ts +56 -0
  52. package/dist-cjs/server/pty.d.ts.map +1 -0
  53. package/dist-cjs/server/pty.js +391 -0
  54. package/dist-cjs/server/pty.js.map +1 -0
  55. package/dist-cjs/server/transport.d.ts +21 -0
  56. package/dist-cjs/server/transport.d.ts.map +1 -0
  57. package/dist-cjs/server/transport.js +218 -0
  58. package/dist-cjs/server/transport.js.map +1 -0
  59. package/docs/contract.md +195 -0
  60. package/docs/coverage.md +31 -0
  61. package/docs/errors.md +43 -0
  62. package/docs/publishing.md +96 -0
  63. package/docs/review.md +209 -0
  64. package/docs/terminal-integration.md +104 -0
  65. package/fixtures/protocol.json +40 -0
  66. package/package.json +30 -4
  67. package/src/client/index.ts +99 -0
  68. package/src/error.ts +18 -0
  69. package/src/server/config.ts +56 -0
  70. package/src/server/index.ts +107 -0
  71. package/src/server/output.ts +43 -0
  72. package/src/server/pty.ts +301 -0
  73. package/src/server/transport.ts +162 -0
package/README.md CHANGED
@@ -1,3 +1,133 @@
1
- # Temporary Holding Version
1
+ # @pioneercompany/app-sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ SDK for the current Pioneer Apps contract. ESM and CommonJS, Node.js 22+
4
+ server; browser client with no React or Node imports. No package root export.
5
+ Implementation coverage: [contract table](docs/coverage.md).
6
+ For registry setup and installation with Bun/npm/pnpm/Yarn, see
7
+ [npm publishing](docs/publishing.md). The public npm package is
8
+ `@pioneercompany/app-sdk`; older local archives used `@pioneer/app-sdk`.
9
+
10
+ ```sh
11
+ bun add @pioneercompany/app-sdk
12
+ # or: npm install @pioneercompany/app-sdk
13
+ ```
14
+
15
+ Consumers do not need a token or a custom registry for this public package.
16
+ GitHub Actions publishes through npm Trusted Publishing (OIDC), without a stored
17
+ publish secret. First-time package creation and the exact npm trust settings are
18
+ documented in the publishing guide.
19
+
20
+ ```ts
21
+ import { connectApp } from '@pioneercompany/app-sdk/client';
22
+ const app = await connectApp({ baseUrl: './' }); // Only for a root document!
23
+ // For nested documents render an authenticated <base href="../.../"> or pass
24
+ // the exact view root. Do not infer a grant token from pathname segments.
25
+ const unsubscribe = app.theme.subscribe(theme => {
26
+ document.body.style.background = theme.background;
27
+ });
28
+ const stateUrl = app.url('/state');
29
+ const terminalUrl = app.webSocketUrl('/terminal');
30
+ unsubscribe();
31
+ app.dispose();
32
+ ```
33
+
34
+ `connectApp` installs its listener synchronously before its promise is awaited.
35
+ Call it during browser module initialization, before iframe load or the dev
36
+ page's DOMContentLoaded. SSR imports are safe; connecting requires a browser.
37
+ Theme starts null. Iframes accept the parent window, including opaque origins;
38
+ direct dev pages accept their own window with exact origin matching. subscribe
39
+ immediately delivers an already known palette, then future updates. Connections
40
+ are independent and disposable. There is no handshake or resend request: a late
41
+ connection cannot recover a missed message. Theme grants no backend authority.
42
+ SDK does not mutate DOM/styles; applications apply data via their own state.
43
+ URL methods return strings, reject external/protocol-relative/traversal paths,
44
+ and interpret a leading slash relative to the configured view root. A base URL
45
+ is required (explicit option or HTML base element), including outside Pioneer.
46
+ No cookies/localStorage are used. Never put server configuration in browser code.
47
+ For a direct root dev server use `connectApp({baseUrl:'/'})`; for mounted paths
48
+ use the explicit mount root or base href. There is no process.env mode switch.
49
+
50
+ ```ts
51
+ import { createAppServerContext, nodeRequestHeaders } from '@pioneercompany/app-sdk/server';
52
+ const app = await createAppServerContext();
53
+ // In your existing HTTP handler:
54
+ const context = app.authenticateRequest(nodeRequestHeaders(req));
55
+ console.log(context.user.id); // Trusted only after credential authentication.
56
+ // In your readiness handler, before returning readiness:
57
+ app.authenticateServiceRequest(nodeRequestHeaders(req));
58
+ // Same adapter/authenticateRequest in your existing upgrade handler.
59
+ await app.close();
60
+ ```
61
+
62
+ SDK reads `PIONEER_BOOTSTRAP` and `APP_DATA`. It does not start a server or own the
63
+ process. Missing bootstrap fails closed. `bootstrap`, `bootstrapPath`, `appData`
64
+ options support explicit configuration with the same validation, not an auth
65
+ bypass. Contexts and errors do not serialize credentials. Treat input bootstrap
66
+ objects and environment as secrets; the SDK cannot erase caller-owned copies.
67
+
68
+ ```ts
69
+ const terminal = await app.host.pty.create({ cols: 120, rows: 30,
70
+ command: ['/bin/sh'], cwd: '/tmp' }); // Runs on the Gateway host OS account.
71
+ const subscription = await terminal.subscribe({
72
+ after: 0,
73
+ onOutput(frame) {
74
+ void consume(frame.bytes).then(() => frame.ack()).catch(handleError);
75
+ // ACK declares all data through frame.next consumed; serialize your consumer.
76
+ // frame.failed and frame.exitStatus describe supervision/process state.
77
+ },
78
+ onError: handleError,
79
+ });
80
+ await terminal.write('pwd\n'); // Accepted by Gateway, not proof of shell execution.
81
+ await terminal.resize({ cols: 100, rows: 28 });
82
+ subscription.dispose(); // Stops output, keeps process and lease.
83
+ await terminal.close(); // Destroys process.
84
+ await app.close(); // Destroys remaining owned PTYs and releases transport.
85
+ ```
86
+
87
+ Handles also provide `read({after,signal?})` for bounded legacy snapshots,
88
+ `keepalive({signal?})` for explicit maintenance and `onChanged(listener)` for
89
+ legacy invalidation hints. Gateway suppresses changed after any stream subscribe
90
+ on the connection. read does not ACK a stream. `frame.streamId` identifies replay
91
+ generations so an adapter can discard old queued receipts and trim accepted data.
92
+
93
+ The application must authorize access to handles; user identity does not cause
94
+ Gateway PTY impersonation. One context is shared by a backend execution, while
95
+ client themes belong to individual views. Use `PioneerError.code` and `source`
96
+ (`sdk` or `host`) for decisions, never parse messages. Host codes are preserved;
97
+ SDK codes cover invalid configuration, unauthorized/missing user, unavailable
98
+ capability, bounds, cancellation, ambiguous delivery, stale receipts, blocked
99
+ input, unconfirmed lease and incomplete cleanup. Unsubscribe is local: it does
100
+ not reset the shared connection or interrupt another PTY's input. Residual remote
101
+ output is bounded until stream replacement, PTY close or disconnect. A confirmed
102
+ ACK advances credit before the next output message, including a synchronous burst.
103
+ Transient keepalive failures have a finite recovery budget without blocking
104
+ ordinary operations immediately. Unknown creates and failed closes cause
105
+ context close to report `sdk.cleanup_incomplete`, even after local teardown.
106
+ See [the contract](docs/contract.md) for precise
107
+ limits, retry, ACK, replay, cancellation and ownership semantics.
108
+
109
+ Prepared commands for a later authorized review environment:
110
+
111
+ - `bun install --frozen-lockfile`: install the pinned build/test dependencies.
112
+ - `npm run build`: emit ESM/CJS, declarations/maps and the CJS package marker.
113
+ - `npm run typecheck`: compilation checks without emit.
114
+ - `npm test`: Node test runner through tsx, source tests without a build.
115
+ - `npm run test:package`: import/require acceptance of the already built package.
116
+
117
+ There are no lifecycle hooks or package-root export. Runtime dependency `ws`
118
+ is server-only; TypeScript/tsx/types are development dependencies. Browser
119
+ bundlers must select the explicit client entry. Exports point at build output;
120
+ a source checkout must be built before importing by package name. Sources are
121
+ included for source/declaration maps. Examples
122
+ are snippets, not a runnable demonstration application.
123
+
124
+ See [Terminal integration](docs/terminal-integration.md) for a relative tarball
125
+ dependency compatible with its CJS server and physical-root packaging rules,
126
+ both locally and in CI without a neighboring checkout. Direct dev UI does not
127
+ provision backend Host API authority; Terminal's local backend remains separate.
128
+
129
+ Current-contract implementation is complete by source audit; compilation,
130
+ package tracing and runtime acceptance require external verification.
131
+ Streaming has no capability subversion on Gateway;
132
+ older `host.pty` implementations may reject subscribe. New dev registration,
133
+ Terminal integration and future Python/Rust implementations are out of scope.
@@ -0,0 +1,27 @@
1
+ export { PioneerError } from "../error.js";
2
+ export interface Theme {
3
+ readonly appearance: "light" | "dark";
4
+ readonly background: string;
5
+ readonly foreground: string;
6
+ readonly muted: string;
7
+ readonly border: string;
8
+ readonly accent: string;
9
+ readonly "accent-foreground": string;
10
+ }
11
+ export interface ConnectAppOptions {
12
+ /** Exact grant root, absolute or relative to document URL; must end in /. */
13
+ baseUrl?: string;
14
+ }
15
+ export interface AppClient {
16
+ readonly theme: {
17
+ readonly current: Readonly<Theme> | null;
18
+ /** Delivers current synchronously if known, then future updates. */
19
+ subscribe(listener: (theme: Readonly<Theme>) => void): () => void;
20
+ };
21
+ url(path: string): string;
22
+ webSocketUrl(path: string): string;
23
+ dispose(): void;
24
+ }
25
+ /** Resolves immediately: Pioneer has no theme handshake or readiness event. */
26
+ export declare function connectApp(options?: ConnectAppOptions): Promise<AppClient>;
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,UAAU,EAAE,OAAO,GAAG,MAAM,CAAC;IACtC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;CACtC;AACD,MAAM,WAAW,iBAAiB;IAChC,6EAA6E;IAC7E,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AACD,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,KAAK,EAAE;QACd,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;QACzC,oEAAoE;QACpE,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;KACnE,CAAC;IACF,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACnC,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,+EAA+E;AAC/E,wBAAsB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,SAAS,CAAC,CAsEpF"}
@@ -0,0 +1,101 @@
1
+ import { failure } from "../error.js";
2
+ export { PioneerError } from "../error.js";
3
+ /** Resolves immediately: Pioneer has no theme handshake or readiness event. */
4
+ export async function connectApp(options = {}) {
5
+ if (typeof window === "undefined")
6
+ throw failure("sdk.browser_required");
7
+ // Only an explicit base element is trusted. document.baseURI alone could be
8
+ // an arbitrary nested document, and inferring a grant token is not a contract.
9
+ const configured = options.baseUrl ?? document.querySelector("base[href]")?.getAttribute("href");
10
+ if (!configured)
11
+ throw failure("sdk.base_url_required");
12
+ let root;
13
+ try {
14
+ root = new URL(configured, window.location.href);
15
+ }
16
+ catch {
17
+ throw failure("sdk.invalid_url");
18
+ }
19
+ if (!["http:", "https:"].includes(root.protocol) || root.origin !== new URL(window.location.href).origin ||
20
+ root.username || root.password || root.search || root.hash || !root.pathname.endsWith("/")) {
21
+ throw failure("sdk.invalid_url");
22
+ }
23
+ let disposed = false;
24
+ let current = null;
25
+ const listeners = new Set();
26
+ const receive = (event) => {
27
+ if (disposed)
28
+ return;
29
+ if (window.parent === window) {
30
+ if (event.source !== window || event.origin !== window.location.origin)
31
+ return;
32
+ }
33
+ else if (event.source !== window.parent)
34
+ return;
35
+ // Embedded origin may be opaque; direct dev views use self + exact origin.
36
+ // A theme message never authenticates a user or a backend request.
37
+ const data = event.data;
38
+ if (!data || data.type !== "pioneer.theme" || !data.palette)
39
+ return;
40
+ const value = data.palette;
41
+ if (value.appearance !== "dark" && value.appearance !== "light")
42
+ return;
43
+ const colors = ["background", "foreground", "muted", "border", "accent", "accent-foreground"];
44
+ for (const key of colors) {
45
+ if (typeof value[key] !== "string" || value[key].length > 128 || !CSS.supports("color", value[key]))
46
+ return;
47
+ }
48
+ current = Object.freeze({ appearance: value.appearance, ...Object.fromEntries(colors.map(key => [key, value[key]])) });
49
+ for (const listener of [...listeners]) {
50
+ if (disposed)
51
+ break;
52
+ if (!listeners.has(listener))
53
+ continue;
54
+ try {
55
+ listener(current);
56
+ }
57
+ catch { /* One consumer cannot block others. */ }
58
+ }
59
+ };
60
+ window.addEventListener("message", receive);
61
+ const url = (path) => {
62
+ if (disposed)
63
+ throw failure("sdk.closed");
64
+ // Reject encoded separators/dots too, including nested encoding: proxies
65
+ // disagree about decoding order. Query contents are left intact.
66
+ if (typeof path !== "string" || /[\u0000-\u0020\\]/.test(path) || path.startsWith("//") || /^[a-z][a-z0-9+.-]*:/i.test(path))
67
+ throw failure("sdk.invalid_url");
68
+ const pathname = path.split(/[?#]/, 1)[0];
69
+ if (/%(?:2e|2f|5c|25)/i.test(pathname) || pathname.split("/").some(part => part === "." || part === ".."))
70
+ throw failure("sdk.invalid_url");
71
+ const target = new URL(path.replace(/^\//, ""), root);
72
+ if (target.origin !== root.origin || !target.pathname.startsWith(root.pathname))
73
+ throw failure("sdk.invalid_url");
74
+ return target.href;
75
+ };
76
+ return Object.freeze({
77
+ theme: Object.freeze({
78
+ get current() { return current; },
79
+ subscribe(listener) {
80
+ if (disposed)
81
+ throw failure("sdk.closed");
82
+ listeners.add(listener);
83
+ if (current) {
84
+ try {
85
+ listener(current);
86
+ }
87
+ catch { /* Match update delivery isolation. */ }
88
+ }
89
+ return () => { listeners.delete(listener); };
90
+ },
91
+ }),
92
+ url,
93
+ webSocketUrl(path) {
94
+ const target = new URL(url(path));
95
+ target.protocol = target.protocol === "https:" ? "wss:" : "ws:";
96
+ return target.href;
97
+ },
98
+ dispose() { disposed = true; listeners.clear(); window.removeEventListener("message", receive); },
99
+ });
100
+ }
101
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources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AAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,11 @@
1
+ /** Stable machine code; messages contain no remote text, credentials or payloads. */
2
+ export declare class PioneerError extends Error {
3
+ readonly code: string;
4
+ readonly source: "sdk" | "host";
5
+ readonly rpcCode?: number | undefined;
6
+ readonly name = "PioneerError";
7
+ constructor(code: string, message: string, source?: "sdk" | "host", rpcCode?: number | undefined);
8
+ }
9
+ export declare const failure: (code: string) => PioneerError;
10
+ export declare function hostFailure(code: unknown, rpcCode?: number): PioneerError;
11
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,qBAAa,YAAa,SAAQ,KAAK;IAGnC,QAAQ,CAAC,IAAI,EAAE,MAAM;IAErB,QAAQ,CAAC,MAAM,EAAE,KAAK,GAAG,MAAM;IAC/B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM;IAL3B,QAAQ,CAAC,IAAI,kBAAkB;gBAEpB,IAAI,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,EACN,MAAM,GAAE,KAAK,GAAG,MAAc,EAC9B,OAAO,CAAC,EAAE,MAAM,YAAA;CAI5B;AAED,eAAO,MAAM,OAAO,GAAI,MAAM,MAAM,iBAAkE,CAAC;AACvG,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,YAAY,CAGzE"}
package/dist/error.js ADDED
@@ -0,0 +1,19 @@
1
+ /** Stable machine code; messages contain no remote text, credentials or payloads. */
2
+ export class PioneerError extends Error {
3
+ code;
4
+ source;
5
+ rpcCode;
6
+ name = "PioneerError";
7
+ constructor(code, message, source = "sdk", rpcCode) {
8
+ super(message);
9
+ this.code = code;
10
+ this.source = source;
11
+ this.rpcCode = rpcCode;
12
+ }
13
+ }
14
+ export const failure = (code) => new PioneerError(code, `Pioneer operation failed (${code}).`);
15
+ export function hostFailure(code, rpcCode) {
16
+ const safe = typeof code === "string" && /^host\.[a-z_]{1,64}$/.test(code) ? code : "host.operation_failed";
17
+ return new PioneerError(safe, `Gateway rejected operation (${safe}).`, "host", rpcCode);
18
+ }
19
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,MAAM,OAAO,YAAa,SAAQ,KAAK;IAG1B;IAEA;IACA;IALF,IAAI,GAAG,cAAc,CAAC;IAC/B,YACW,IAAY,EACrB,OAAe,EACN,SAAyB,KAAK,EAC9B,OAAgB;QAEzB,KAAK,CAAC,OAAO,CAAC,CAAC;QALN,SAAI,GAAJ,IAAI,CAAQ;QAEZ,WAAM,GAAN,MAAM,CAAwB;QAC9B,YAAO,GAAP,OAAO,CAAS;IAG3B,CAAC;CACF;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,YAAY,CAAC,IAAI,EAAE,6BAA6B,IAAI,IAAI,CAAC,CAAC;AACvG,MAAM,UAAU,WAAW,CAAC,IAAa,EAAE,OAAgB;IACzD,MAAM,IAAI,GAAG,OAAO,IAAI,KAAK,QAAQ,IAAI,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,uBAAuB,CAAC;IAC5G,OAAO,IAAI,YAAY,CAAC,IAAI,EAAE,+BAA+B,IAAI,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAC1F,CAAC"}
@@ -0,0 +1,23 @@
1
+ /** Input only: never attach this credential-bearing value to public contexts. */
2
+ export interface Bootstrap {
3
+ execution_id: string;
4
+ ui_base_path?: string;
5
+ ui_proxy: {
6
+ credential: string;
7
+ };
8
+ host_api: {
9
+ endpoint: string;
10
+ credential: string;
11
+ capabilities: string[];
12
+ } | null;
13
+ }
14
+ export interface ServerOptions {
15
+ bootstrap?: unknown;
16
+ bootstrapPath?: string;
17
+ appData?: string;
18
+ }
19
+ export declare function configuration(options: ServerOptions): Promise<{
20
+ bootstrap: Bootstrap;
21
+ appData: string;
22
+ }>;
23
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/server/config.ts"],"names":[],"mappings":"AAIA,iFAAiF;AACjF,MAAM,WAAW,SAAS;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IACjC,QAAQ,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,IAAI,CAAC;CACnF;AACD,MAAM,WAAW,aAAa;IAAG,SAAS,CAAC,EAAE,OAAO,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE;AAChG,wBAAsB,aAAa,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC;IAAE,SAAS,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CA2C9G"}
@@ -0,0 +1,66 @@
1
+ import { open } from "node:fs/promises";
2
+ import { isAbsolute } from "node:path";
3
+ import { failure } from "../error.js";
4
+ export async function configuration(options) {
5
+ const appData = options.appData ?? process.env.APP_DATA;
6
+ if (typeof appData !== "string" || !appData || !isAbsolute(appData) || appData.includes("\0"))
7
+ throw failure("sdk.invalid_app_data");
8
+ let value = options.bootstrap;
9
+ if (value === undefined) {
10
+ const path = options.bootstrapPath ?? process.env.PIONEER_BOOTSTRAP;
11
+ if (!path || !isAbsolute(path))
12
+ throw failure("sdk.bootstrap_missing");
13
+ try {
14
+ const file = await open(path, "r");
15
+ try {
16
+ const stat = await file.stat();
17
+ if (!stat.isFile() || stat.size > 16384)
18
+ throw failure("sdk.invalid_bootstrap");
19
+ const buffer = Buffer.alloc(16385);
20
+ let length = 0;
21
+ while (length < buffer.length) {
22
+ const read = await file.read(buffer, length, buffer.length - length, null);
23
+ if (!read.bytesRead)
24
+ break;
25
+ length += read.bytesRead;
26
+ }
27
+ if (length > 16384)
28
+ throw failure("sdk.invalid_bootstrap");
29
+ value = JSON.parse(buffer.subarray(0, length).toString("utf8"));
30
+ }
31
+ finally {
32
+ await file.close();
33
+ }
34
+ }
35
+ catch {
36
+ throw failure("sdk.invalid_bootstrap");
37
+ }
38
+ }
39
+ try {
40
+ // Copy only validated fields; reject non-JSON explicit configuration too.
41
+ const raw = JSON.stringify(value);
42
+ if (!raw || Buffer.byteLength(raw) > 16384)
43
+ throw new Error();
44
+ const v = JSON.parse(raw);
45
+ if (!v || !/^[A-Za-z0-9_-]{21}$/.test(v.execution_id) || typeof v.execution_id !== "string" ||
46
+ typeof v.ui_proxy?.credential !== "string" || !/^[a-f0-9]{64}$/.test(v.ui_proxy.credential) ||
47
+ (v.ui_base_path !== undefined && v.ui_base_path !== "/"))
48
+ throw new Error();
49
+ let host = null;
50
+ if (v.host_api !== null) {
51
+ const h = v.host_api;
52
+ if (!h || typeof h.endpoint !== "string" || typeof h.credential !== "string" || !/^[a-f0-9]{64}$/.test(h.credential) ||
53
+ !Array.isArray(h.capabilities) || !h.capabilities.every((c) => typeof c === "string" && c.length <= 128))
54
+ throw new Error();
55
+ const url = new URL(h.endpoint);
56
+ if (!["ws:", "wss:"].includes(url.protocol) || url.username || url.password || url.search || url.hash)
57
+ throw new Error();
58
+ host = { endpoint: url.href, credential: h.credential, capabilities: [...h.capabilities] };
59
+ }
60
+ return { appData, bootstrap: { execution_id: v.execution_id, ui_proxy: { credential: v.ui_proxy.credential }, host_api: host } };
61
+ }
62
+ catch {
63
+ throw failure("sdk.invalid_bootstrap");
64
+ }
65
+ }
66
+ //# sourceMappingURL=config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,EAAE,QAAQ,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,QAAQ,CAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,CAAC;IACnI,CAAC;IAAC,MAAM,CAAC;QAAC,MAAM,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAAC,CAAC;AACrD,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { IncomingMessage } from "node:http";
2
+ import type { ServerOptions } from "./config.js";
3
+ import { Pty } from "./pty.js";
4
+ import type { CreatePtyOptions } from "./pty.js";
5
+ export { PioneerError } from "../error.js";
6
+ export type { Bootstrap, ServerOptions } from "./config.js";
7
+ export type { OperationOptions } from "./transport.js";
8
+ export type { Dimensions, CreatePtyOptions, ReadPtyOptions, OutputFrame, OutputSubscription, SubscribeOptions } from "./pty.js";
9
+ export type { PtyHead, PtySnapshot } from "./output.js";
10
+ export type { Pty } from "./pty.js";
11
+ /** Return undefined for missing or duplicate fields. Header names are lowercase. */
12
+ export interface RequestHeaders {
13
+ get(name: string): string | undefined;
14
+ }
15
+ export interface UserContext {
16
+ readonly user: {
17
+ readonly id: string;
18
+ };
19
+ }
20
+ export interface AppServerContext {
21
+ readonly execution: {
22
+ readonly id: string;
23
+ };
24
+ readonly appData: string;
25
+ readonly host: {
26
+ readonly capabilities: readonly string[];
27
+ readonly pty: {
28
+ create(options: CreatePtyOptions): Promise<Pty>;
29
+ };
30
+ };
31
+ authenticateServiceRequest(headers: RequestHeaders): void;
32
+ authenticateRequest(headers: RequestHeaders): UserContext;
33
+ close(): Promise<void>;
34
+ }
35
+ /** Preserve raw duplicate detection for both HTTP and upgrade requests. */
36
+ export declare function nodeRequestHeaders(request: Pick<IncomingMessage, "rawHeaders">): RequestHeaders;
37
+ export declare function createAppServerContext(options?: ServerOptions): Promise<AppServerContext>;
38
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names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AAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAAC;IAC1D,mBAAmB,CAAC,OAAO,EAAE,cAAc,GAAG,WAAW,CAAC;IAC1D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,2EAA2E;AAC3E,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,YAAY,CAAC,GAAG,cAAc,CAU/F;AAED,wBAAsB,sBAAsB,CAAC,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA+DnG"}
@@ -0,0 +1,99 @@
1
+ import { timingSafeEqual } from "node:crypto";
2
+ import { configuration } from "./config.js";
3
+ import { Transport } from "./transport.js";
4
+ import { Pty } from "./pty.js";
5
+ import { failure } from "../error.js";
6
+ export { PioneerError } from "../error.js";
7
+ /** Preserve raw duplicate detection for both HTTP and upgrade requests. */
8
+ export function nodeRequestHeaders(request) {
9
+ return {
10
+ get(name) {
11
+ const values = [];
12
+ for (let i = 0; i < request.rawHeaders.length; i += 2) {
13
+ if (request.rawHeaders[i].toLowerCase() === name)
14
+ values.push(request.rawHeaders[i + 1]);
15
+ }
16
+ return values.length === 1 ? values[0] : undefined;
17
+ },
18
+ };
19
+ }
20
+ export async function createAppServerContext(options = {}) {
21
+ const { bootstrap, appData } = await configuration(options);
22
+ const expected = Buffer.from(bootstrap.ui_proxy.credential, "ascii");
23
+ const transport = new Transport(bootstrap.host_api);
24
+ const capabilities = Object.freeze([...(bootstrap.host_api?.capabilities ?? [])]);
25
+ const owned = new Set();
26
+ const creating = new Set();
27
+ const uncertainCreates = new Set();
28
+ let stopped = false;
29
+ let closing = null;
30
+ const assertOpen = () => { if (stopped)
31
+ throw failure("sdk.closed"); };
32
+ const authenticateServiceRequest = (headers) => {
33
+ assertOpen();
34
+ const actual = headers.get("pioneer-app-execution-credential");
35
+ if (typeof actual !== "string" || !/^[a-f0-9]{64}$/.test(actual) || !timingSafeEqual(Buffer.from(actual, "ascii"), expected))
36
+ throw failure("sdk.unauthorized");
37
+ };
38
+ return Object.freeze({
39
+ execution: Object.freeze({ id: bootstrap.execution_id }),
40
+ appData,
41
+ host: Object.freeze({
42
+ capabilities,
43
+ pty: Object.freeze({
44
+ async create(options) {
45
+ assertOpen();
46
+ if (!capabilities.includes("host.pty"))
47
+ throw failure("sdk.capability_unavailable");
48
+ if (owned.size + creating.size + uncertainCreates.size >= 8)
49
+ throw failure("sdk.capacity");
50
+ let terminal;
51
+ const creation = {};
52
+ const operation = Pty.create(transport, options, () => { owned.delete(terminal); }, value => {
53
+ if (value)
54
+ uncertainCreates.add(creation);
55
+ else
56
+ uncertainCreates.delete(creation);
57
+ });
58
+ creating.add(operation);
59
+ try {
60
+ terminal = await operation;
61
+ owned.add(terminal);
62
+ if (stopped) {
63
+ await terminal.close();
64
+ throw failure("sdk.closed");
65
+ }
66
+ return terminal;
67
+ }
68
+ finally {
69
+ creating.delete(operation);
70
+ }
71
+ },
72
+ }),
73
+ }),
74
+ authenticateServiceRequest,
75
+ authenticateRequest(headers) {
76
+ authenticateServiceRequest(headers);
77
+ const id = headers.get("pioneer-app-user-id");
78
+ if (typeof id !== "string" || !/^[A-Za-z0-9]{21}$/.test(id))
79
+ throw failure("sdk.user_missing");
80
+ return Object.freeze({ user: Object.freeze({ id }) });
81
+ },
82
+ close() {
83
+ if (closing)
84
+ return closing;
85
+ stopped = true;
86
+ closing = (async () => {
87
+ const settled = await Promise.allSettled([...creating]);
88
+ const terminals = new Set([...owned, ...settled.flatMap(r => r.status === "fulfilled" ? [r.value] : [])]);
89
+ const results = await Promise.allSettled([...terminals].map(terminal => terminal.close()));
90
+ transport.close();
91
+ expected.fill(0);
92
+ if (uncertainCreates.size || results.some(r => r.status === "rejected"))
93
+ throw failure("sdk.cleanup_incomplete");
94
+ })();
95
+ return closing;
96
+ },
97
+ });
98
+ }
99
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":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readonly exitStatus: number | null;
5
+ readonly failed: boolean;
6
+ }
7
+ export interface PtySnapshot {
8
+ readonly after: number;
9
+ readonly next: number;
10
+ readonly end: number;
11
+ readonly bytes: Uint8Array;
12
+ readonly exitStatus: number | null;
13
+ readonly failed: boolean;
14
+ readonly inputSequence: number;
15
+ }
16
+ export declare function unsigned(value: unknown): value is number;
17
+ export declare function decodeSnapshot(raw: unknown, after: number): PtySnapshot;
18
+ export declare function decodeHeads(raw: unknown): readonly {
19
+ id: string;
20
+ head: PtyHead;
21
+ }[];
22
+ //# sourceMappingURL=output.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/server/output.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B;AACD,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AACD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAExD;AAID,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,WAAW,CASvE;AACD,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,EAAE,CASlF"}
@@ -0,0 +1,31 @@
1
+ import { failure } from "../error.js";
2
+ export function unsigned(value) {
3
+ return Number.isSafeInteger(value) && value >= 0;
4
+ }
5
+ function status(value) {
6
+ return value === null || (unsigned(value) && value <= 0xffffffff);
7
+ }
8
+ export function decodeSnapshot(raw, after) {
9
+ const value = raw;
10
+ if (!value || !Array.isArray(value.bytes) || value.bytes.length > 16384 ||
11
+ !value.bytes.every(byte => unsigned(byte) && byte <= 255) ||
12
+ !unsigned(value.next) || value.next !== after + value.bytes.length ||
13
+ !unsigned(value.end) || value.end < value.next || !status(value.exit_status) ||
14
+ typeof value.failed !== "boolean" || !unsigned(value.input_sequence))
15
+ throw failure("sdk.invalid_output");
16
+ return Object.freeze({ after, next: value.next, end: value.end, bytes: Uint8Array.from(value.bytes),
17
+ exitStatus: value.exit_status, failed: value.failed, inputSequence: value.input_sequence });
18
+ }
19
+ export function decodeHeads(raw) {
20
+ const value = raw;
21
+ if (!value || !Array.isArray(value.sessions) || value.sessions.length > 8)
22
+ throw failure("sdk.invalid_output");
23
+ return value.sessions.map(item => {
24
+ if (!item || typeof item.session_id !== "string" || !unsigned(item.start) ||
25
+ !unsigned(item.end) || item.end < item.start || !status(item.exit_status) || typeof item.failed !== "boolean")
26
+ throw failure("sdk.invalid_output");
27
+ return { id: item.session_id, head: Object.freeze({ start: item.start, end: item.end,
28
+ exitStatus: item.exit_status, failed: item.failed }) };
29
+ });
30
+ }
31
+ //# sourceMappingURL=output.js.map