@executioncontrolprotocol/app 0.50.0 → 0.60.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 (131) hide show
  1. package/README.md +4 -31
  2. package/dist/client/api.d.ts +107 -0
  3. package/dist/client/api.d.ts.map +1 -0
  4. package/dist/client/api.js +216 -0
  5. package/dist/client/api.js.map +1 -0
  6. package/dist/client/index.d.ts +11 -0
  7. package/dist/client/index.d.ts.map +1 -0
  8. package/dist/client/index.js +11 -0
  9. package/dist/client/index.js.map +1 -0
  10. package/dist/client/launch.d.ts +47 -0
  11. package/dist/client/launch.d.ts.map +1 -0
  12. package/dist/client/launch.js +50 -0
  13. package/dist/client/launch.js.map +1 -0
  14. package/dist/client/results.d.ts +85 -0
  15. package/dist/client/results.d.ts.map +1 -0
  16. package/dist/client/results.js +181 -0
  17. package/dist/client/results.js.map +1 -0
  18. package/dist/client/run-follow.d.ts +40 -0
  19. package/dist/client/run-follow.d.ts.map +1 -0
  20. package/dist/client/run-follow.js +91 -0
  21. package/dist/client/run-follow.js.map +1 -0
  22. package/dist/client/sse.d.ts +99 -0
  23. package/dist/client/sse.d.ts.map +1 -0
  24. package/dist/client/sse.js +168 -0
  25. package/dist/client/sse.js.map +1 -0
  26. package/dist/form/run-input-fields.d.ts +85 -0
  27. package/dist/form/run-input-fields.d.ts.map +1 -0
  28. package/dist/form/run-input-fields.js +147 -0
  29. package/dist/form/run-input-fields.js.map +1 -0
  30. package/dist/graph/edge-manifest.d.ts +87 -0
  31. package/dist/graph/edge-manifest.d.ts.map +1 -0
  32. package/dist/graph/edge-manifest.js +261 -0
  33. package/dist/graph/edge-manifest.js.map +1 -0
  34. package/dist/graph/edge-panel-logic.d.ts +24 -0
  35. package/dist/graph/edge-panel-logic.d.ts.map +1 -0
  36. package/dist/graph/edge-panel-logic.js +36 -0
  37. package/dist/graph/edge-panel-logic.js.map +1 -0
  38. package/dist/graph/execution-to-reactflow.d.ts +14 -0
  39. package/dist/graph/execution-to-reactflow.d.ts.map +1 -0
  40. package/dist/graph/execution-to-reactflow.js +497 -0
  41. package/dist/graph/execution-to-reactflow.js.map +1 -0
  42. package/dist/graph/extract-data-edges.d.ts +111 -6
  43. package/dist/graph/extract-data-edges.d.ts.map +1 -1
  44. package/dist/graph/extract-data-edges.js +477 -81
  45. package/dist/graph/extract-data-edges.js.map +1 -1
  46. package/dist/graph/index.d.ts +17 -9
  47. package/dist/graph/index.d.ts.map +1 -1
  48. package/dist/graph/index.js +16 -8
  49. package/dist/graph/index.js.map +1 -1
  50. package/dist/graph/io-from-schema.d.ts +27 -19
  51. package/dist/graph/io-from-schema.d.ts.map +1 -1
  52. package/dist/graph/io-from-schema.js +56 -88
  53. package/dist/graph/io-from-schema.js.map +1 -1
  54. package/dist/graph/json-schema.d.ts +29 -0
  55. package/dist/graph/json-schema.d.ts.map +1 -0
  56. package/dist/graph/json-schema.js +63 -0
  57. package/dist/graph/json-schema.js.map +1 -0
  58. package/dist/graph/layout.d.ts +19 -2
  59. package/dist/graph/layout.d.ts.map +1 -1
  60. package/dist/graph/layout.js +51 -37
  61. package/dist/graph/layout.js.map +1 -1
  62. package/dist/graph/map-run-events.d.ts +83 -3
  63. package/dist/graph/map-run-events.d.ts.map +1 -1
  64. package/dist/graph/map-run-events.js +262 -21
  65. package/dist/graph/map-run-events.js.map +1 -1
  66. package/dist/graph/markers.d.ts +27 -0
  67. package/dist/graph/markers.d.ts.map +1 -0
  68. package/dist/graph/markers.js +41 -0
  69. package/dist/graph/markers.js.map +1 -0
  70. package/dist/graph/ports-from-schema.d.ts +35 -0
  71. package/dist/graph/ports-from-schema.d.ts.map +1 -0
  72. package/dist/graph/ports-from-schema.js +215 -0
  73. package/dist/graph/ports-from-schema.js.map +1 -0
  74. package/dist/graph/progress.d.ts +25 -14
  75. package/dist/graph/progress.d.ts.map +1 -1
  76. package/dist/graph/progress.js +38 -16
  77. package/dist/graph/progress.js.map +1 -1
  78. package/dist/graph/types.d.ts +279 -45
  79. package/dist/graph/types.d.ts.map +1 -1
  80. package/dist/graph/types.js +20 -1
  81. package/dist/graph/types.js.map +1 -1
  82. package/dist/graph/value-schema-hint.d.ts +15 -17
  83. package/dist/graph/value-schema-hint.d.ts.map +1 -1
  84. package/dist/graph/value-schema-hint.js +67 -146
  85. package/dist/graph/value-schema-hint.js.map +1 -1
  86. package/dist/index.d.ts +8 -5
  87. package/dist/index.d.ts.map +1 -1
  88. package/dist/index.js +8 -3
  89. package/dist/index.js.map +1 -1
  90. package/dist/version.d.ts +6 -0
  91. package/dist/version.d.ts.map +1 -0
  92. package/dist/version.js +7 -0
  93. package/dist/version.js.map +1 -0
  94. package/dist/web/assets/index--o6Bbdb5.js +21 -0
  95. package/dist/web/assets/index-CRT7x_c8.css +1 -0
  96. package/dist/web/index.html +4 -4
  97. package/package.json +18 -30
  98. package/dist/graph/patch-source.d.ts +0 -8
  99. package/dist/graph/patch-source.d.ts.map +0 -1
  100. package/dist/graph/patch-source.js +0 -17
  101. package/dist/graph/patch-source.js.map +0 -1
  102. package/dist/graph/ports-from-zod.d.ts +0 -28
  103. package/dist/graph/ports-from-zod.d.ts.map +0 -1
  104. package/dist/graph/ports-from-zod.js +0 -177
  105. package/dist/graph/ports-from-zod.js.map +0 -1
  106. package/dist/graph/workflow-to-reactflow.d.ts +0 -11
  107. package/dist/graph/workflow-to-reactflow.d.ts.map +0 -1
  108. package/dist/graph/workflow-to-reactflow.js +0 -214
  109. package/dist/graph/workflow-to-reactflow.js.map +0 -1
  110. package/dist/host/adapter.d.ts +0 -59
  111. package/dist/host/adapter.d.ts.map +0 -1
  112. package/dist/host/adapter.js +0 -2
  113. package/dist/host/adapter.js.map +0 -1
  114. package/dist/host/constants.d.ts +0 -21
  115. package/dist/host/constants.d.ts.map +0 -1
  116. package/dist/host/constants.js +0 -21
  117. package/dist/host/constants.js.map +0 -1
  118. package/dist/host/local-client.d.ts +0 -36
  119. package/dist/host/local-client.d.ts.map +0 -1
  120. package/dist/host/local-client.js +0 -131
  121. package/dist/host/local-client.js.map +0 -1
  122. package/dist/host/protocol.d.ts +0 -75
  123. package/dist/host/protocol.d.ts.map +0 -1
  124. package/dist/host/protocol.js +0 -2
  125. package/dist/host/protocol.js.map +0 -1
  126. package/dist/host/round-trip.d.ts +0 -19
  127. package/dist/host/round-trip.d.ts.map +0 -1
  128. package/dist/host/round-trip.js +0 -37
  129. package/dist/host/round-trip.js.map +0 -1
  130. package/dist/web/assets/index-7fmDKtvn.js +0 -105
  131. package/dist/web/assets/index-BffrVIsz.css +0 -1
package/README.md CHANGED
@@ -1,35 +1,8 @@
1
1
  # `@executioncontrolprotocol/app`
2
2
 
3
- Visual App for ECP (Execution Control Protocol): a `HostAdapter` UI, the React Flow
4
- graph encoder, and a prebuilt static bundle (`dist/web`). The App is a viewer and
5
- co-editor of workflow files. It stores no secrets and makes no model calls.
3
+ Visual App: execution graph, validation panel, live run overlay, and run history. Served by the
4
+ host at `/app/`.
6
5
 
7
- Open it with the JIT CLI plugin:
6
+ **Entrypoints:** `src/index.ts` (library helpers), `dist/web/` (Vite bundle)
8
7
 
9
- ```sh
10
- ecp plugins link plugins/plugin-app
11
- ecp app product.ecp.ts
12
- ```
13
-
14
- Until `0.50.0` is on the registry, do not expect first-use JIT from npm. There is no
15
- hosted browser demo and no `ecp up`. CLI `oclif.jitPlugins` pins `"^0.50"`.
16
-
17
- ## Library
18
-
19
- ```ts
20
- import {
21
- canRoundTrip,
22
- createLocalHostAdapter,
23
- workflowToReactFlow,
24
- } from "@executioncontrolprotocol/app"
25
-
26
- const adapter = createLocalHostAdapter({ baseUrl, token })
27
- const loaded = await adapter.load()
28
- const graph = workflowToReactFlow(loaded.manifest)
29
- ```
30
-
31
- Graph edits that cannot round-trip (relative imports, computed `.with()` values) open
32
- read-only. Encoder-written Fluent files stay editable.
33
-
34
- React is an optional peer, needed only when you import the UI components. `plugin-app`
35
- serves `dist/web` and does not need React at run time.
8
+ Open with `ecp app <path>`. Playwright acceptance: `packages/app/test/e2e/a8-app.spec.ts`.
@@ -0,0 +1,107 @@
1
+ import type { CommitData, CommitInput, ExecuteData, ExecuteInput, OperationError, OperationResponse, RetrieveData, RetrieveInput } from "@executioncontrolprotocol/protocol";
2
+ /**
3
+ * `fetch` signature the App client depends on (injectable for tests).
4
+ * @category App
5
+ */
6
+ export type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
7
+ /**
8
+ * Thrown when the host rejects the token (HTTP 401). The App shows its unauthorised screen.
9
+ * @category App
10
+ */
11
+ export declare class UnauthorizedError extends Error {
12
+ /** Always `ECP_UNAUTHORIZED`. */
13
+ readonly code = "ECP_UNAUTHORIZED";
14
+ /** @param message Host message, when it sent one. */
15
+ constructor(message?: string);
16
+ }
17
+ /**
18
+ * Thrown by the file routes and on network failures: carries the host's refusal.
19
+ * @category App
20
+ */
21
+ export declare class HostRequestError extends Error {
22
+ /** Catalogue code (`ECP_NOT_FOUND`, `ECP_HOST_UNAVAILABLE`, …). */
23
+ readonly code: string;
24
+ /** HTTP status, or 0 when the host could not be reached. */
25
+ readonly status: number;
26
+ /** Full refusal. */
27
+ readonly error: OperationError;
28
+ /**
29
+ * @param error Refusal from the host (or synthesised for network failures).
30
+ * @param status HTTP status, 0 when there was no response.
31
+ */
32
+ constructor(error: OperationError, status: number);
33
+ }
34
+ /**
35
+ * True when `value` has the `{ ok, data }` / `{ ok: false, error }` envelope shape.
36
+ * @category App
37
+ */
38
+ export declare function isOperationResponse(value: unknown): value is OperationResponse<unknown>;
39
+ /**
40
+ * Turn an HTTP status and parsed body into an operation envelope. 401 throws
41
+ * {@link UnauthorizedError}; a body that is not an envelope becomes an `ECP_INTERNAL` refusal.
42
+ * @category App
43
+ */
44
+ export declare function toOperationResponse<T>(status: number, body: unknown): OperationResponse<T>;
45
+ /**
46
+ * Options for the watch stream URL ({@link AppHostClient.watchUrl}).
47
+ * @category App
48
+ */
49
+ export interface WatchUrlOptions {
50
+ /** Storage collections to stream (`run`, `execution`, `config`). Host default: all three. */
51
+ types?: Array<"run" | "execution" | "config">;
52
+ /** Only stream run changes for this run id. */
53
+ runId?: string;
54
+ /** Absolute `.ecp.json` path to watch (with its `$script.path` files). */
55
+ path?: string;
56
+ }
57
+ /**
58
+ * Options for {@link AppHostClient}.
59
+ * @category App
60
+ */
61
+ export interface AppHostClientOptions {
62
+ /** `fetch` implementation. Defaults to the global `fetch`. */
63
+ fetch?: FetchLike;
64
+ /** Called before {@link UnauthorizedError} is thrown, so the App can switch screens. */
65
+ onUnauthorized?: () => void;
66
+ }
67
+ /**
68
+ * Browser client for the host HTTP API: the three operations plus the App's file routes.
69
+ * Every request carries `Authorization: Bearer <token>`.
70
+ * @category App
71
+ */
72
+ export declare class AppHostClient {
73
+ readonly baseUrl: string;
74
+ readonly token: string;
75
+ /** `fetch` used for every request (also by the watch stream). */
76
+ readonly fetch: FetchLike;
77
+ private readonly onUnauthorized;
78
+ /**
79
+ * @param baseUrl Host origin (`window.location.origin` in the App).
80
+ * @param token Host bearer token.
81
+ * @param options {@link AppHostClientOptions}.
82
+ */
83
+ constructor(baseUrl: string, token: string, options?: AppHostClientOptions);
84
+ /** `POST /v1/retrieve`. */
85
+ retrieve(input: RetrieveInput): Promise<OperationResponse<RetrieveData>>;
86
+ /** `POST /v1/execute`. */
87
+ execute(input: ExecuteInput): Promise<OperationResponse<ExecuteData>>;
88
+ /** `POST /v1/commit`. */
89
+ commit(input: CommitInput): Promise<OperationResponse<CommitData>>;
90
+ /** `PUT /v1/file?path=`: replace an open `.ecp.json` file (must be on the App watch set). */
91
+ putFile(path: string, text: string): Promise<void>;
92
+ /** `GET /v1/file?path=`: text of an execution file or one of its `$script.path` files. */
93
+ getFile(path: string): Promise<string>;
94
+ /** `GET /v1/files?dir=`: absolute `*.ecp.json` paths under `dir`. */
95
+ listFiles(dir: string): Promise<string[]>;
96
+ /** Absolute URL of `GET /v1/runs/:runId/artifacts/:name`. */
97
+ artifactPath(runId: string, name: string): string;
98
+ /** Download one run artifact with local-token auth. */
99
+ fetchArtifact(runId: string, name: string): Promise<Blob>;
100
+ /** Absolute URL of the `/v1/watch` server-sent events stream. */
101
+ watchUrl(options?: WatchUrlOptions): string;
102
+ private url;
103
+ private send;
104
+ private refusal;
105
+ private post;
106
+ }
107
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/client/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACd,MAAM,oCAAoC,CAAA;AAE3C;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;AAQhF;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,iCAAiC;IACjC,QAAQ,CAAC,IAAI,sBAAoB;IAEjC,qDAAqD;gBACzC,OAAO,SAAiC;CAIrD;AAED;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,mEAAmE;IACnE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,4DAA4D;IAC5D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,oBAAoB;IACpB,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAA;IAE9B;;;OAGG;gBACS,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM;CAOlD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,iBAAiB,CAAC,OAAO,CAAC,CASvF;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAO1F;AA0BD;;;GA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E,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAS/C,6DAA6D;IAC7D,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;IAMjD,uDAAuD;IACjD,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAY/D,iEAAiE;IACjE,QAAQ,CAAC,OAAO,GAAE,eAAoB,GAAG,MAAM;IAS/C,OAAO,CAAC,GAAG;YAIG,IAAI;IAiBlB,OAAO,CAAC,OAAO;YAMD,IAAI;CAQnB"}
@@ -0,0 +1,216 @@
1
+ const UNAUTHORIZED_CODE = "ECP_UNAUTHORIZED";
2
+ const HOST_UNAVAILABLE_CODE = "ECP_HOST_UNAVAILABLE";
3
+ const INTERNAL_CODE = "ECP_INTERNAL";
4
+ const HTTP_UNAUTHORIZED = 401;
5
+ const JSON_CONTENT_TYPE = "application/json; charset=utf-8";
6
+ /**
7
+ * Thrown when the host rejects the token (HTTP 401). The App shows its unauthorised screen.
8
+ * @category App
9
+ */
10
+ export class UnauthorizedError extends Error {
11
+ /** Always `ECP_UNAUTHORIZED`. */
12
+ code = UNAUTHORIZED_CODE;
13
+ /** @param message Host message, when it sent one. */
14
+ constructor(message = "The host rejected the token.") {
15
+ super(message);
16
+ this.name = "UnauthorizedError";
17
+ }
18
+ }
19
+ /**
20
+ * Thrown by the file routes and on network failures: carries the host's refusal.
21
+ * @category App
22
+ */
23
+ export class HostRequestError extends Error {
24
+ /** Catalogue code (`ECP_NOT_FOUND`, `ECP_HOST_UNAVAILABLE`, …). */
25
+ code;
26
+ /** HTTP status, or 0 when the host could not be reached. */
27
+ status;
28
+ /** Full refusal. */
29
+ error;
30
+ /**
31
+ * @param error Refusal from the host (or synthesised for network failures).
32
+ * @param status HTTP status, 0 when there was no response.
33
+ */
34
+ constructor(error, status) {
35
+ super(error.message);
36
+ this.name = "HostRequestError";
37
+ this.code = error.code;
38
+ this.status = status;
39
+ this.error = error;
40
+ }
41
+ }
42
+ /**
43
+ * True when `value` has the `{ ok, data }` / `{ ok: false, error }` envelope shape.
44
+ * @category App
45
+ */
46
+ export function isOperationResponse(value) {
47
+ if (value === null || typeof value !== "object")
48
+ return false;
49
+ const record = value;
50
+ if (record.ok === true)
51
+ return "data" in record;
52
+ if (record.ok === false) {
53
+ const error = record.error;
54
+ return error !== null && typeof error === "object" && typeof error.code === "string";
55
+ }
56
+ return false;
57
+ }
58
+ /**
59
+ * Turn an HTTP status and parsed body into an operation envelope. 401 throws
60
+ * {@link UnauthorizedError}; a body that is not an envelope becomes an `ECP_INTERNAL` refusal.
61
+ * @category App
62
+ */
63
+ export function toOperationResponse(status, body) {
64
+ if (status === HTTP_UNAUTHORIZED)
65
+ throw unauthorizedFrom(body);
66
+ if (isOperationResponse(body))
67
+ return body;
68
+ return {
69
+ ok: false,
70
+ error: { code: INTERNAL_CODE, message: `The host answered HTTP ${status} without an operation envelope.` },
71
+ };
72
+ }
73
+ function unauthorizedFrom(body) {
74
+ return new UnauthorizedError(isOperationResponse(body) && !body.ok ? body.error.message : undefined);
75
+ }
76
+ function parseJson(text) {
77
+ try {
78
+ return JSON.parse(text);
79
+ }
80
+ catch {
81
+ return undefined;
82
+ }
83
+ }
84
+ function unavailable(error) {
85
+ const reason = error instanceof Error ? error.message : String(error);
86
+ return new HostRequestError({
87
+ code: HOST_UNAVAILABLE_CODE,
88
+ message: `The host could not be reached: ${reason}`,
89
+ suggestions: ["Start the host with `ecp host start`, then reload the App."],
90
+ }, 0);
91
+ }
92
+ /**
93
+ * Browser client for the host HTTP API: the three operations plus the App's file routes.
94
+ * Every request carries `Authorization: Bearer <token>`.
95
+ * @category App
96
+ */
97
+ export class AppHostClient {
98
+ baseUrl;
99
+ token;
100
+ /** `fetch` used for every request (also by the watch stream). */
101
+ fetch;
102
+ onUnauthorized;
103
+ /**
104
+ * @param baseUrl Host origin (`window.location.origin` in the App).
105
+ * @param token Host bearer token.
106
+ * @param options {@link AppHostClientOptions}.
107
+ */
108
+ constructor(baseUrl, token, options = {}) {
109
+ this.baseUrl = baseUrl;
110
+ this.token = token;
111
+ this.fetch = options.fetch ?? ((input, init) => globalThis.fetch(input, init));
112
+ this.onUnauthorized = options.onUnauthorized;
113
+ }
114
+ /** `POST /v1/retrieve`. */
115
+ retrieve(input) {
116
+ return this.post("/v1/retrieve", input);
117
+ }
118
+ /** `POST /v1/execute`. */
119
+ execute(input) {
120
+ return this.post("/v1/execute", input);
121
+ }
122
+ /** `POST /v1/commit`. */
123
+ commit(input) {
124
+ return this.post("/v1/commit", input);
125
+ }
126
+ /** `PUT /v1/file?path=`: replace an open `.ecp.json` file (must be on the App watch set). */
127
+ async putFile(path, text) {
128
+ const response = await this.send(`/v1/file?${new URLSearchParams({ path })}`, {
129
+ method: "PUT",
130
+ headers: { "Content-Type": "text/plain; charset=utf-8" },
131
+ body: text,
132
+ });
133
+ if (response.status === 204)
134
+ return;
135
+ const body = await response.text();
136
+ throw this.refusal(response.status, body);
137
+ }
138
+ /** `GET /v1/file?path=`: text of an execution file or one of its `$script.path` files. */
139
+ async getFile(path) {
140
+ const response = await this.send(`/v1/file?${new URLSearchParams({ path })}`, { method: "GET" });
141
+ const text = await response.text();
142
+ if (response.ok)
143
+ return text;
144
+ throw this.refusal(response.status, text);
145
+ }
146
+ /** `GET /v1/files?dir=`: absolute `*.ecp.json` paths under `dir`. */
147
+ async listFiles(dir) {
148
+ const response = await this.send(`/v1/files?${new URLSearchParams({ dir })}`, { method: "GET" });
149
+ const text = await response.text();
150
+ const envelope = toOperationResponse(response.status, parseJson(text));
151
+ if (!envelope.ok)
152
+ throw new HostRequestError(envelope.error, response.status);
153
+ const files = envelope.data.files;
154
+ return Array.isArray(files) ? files.filter((file) => typeof file === "string") : [];
155
+ }
156
+ /** Absolute URL of `GET /v1/runs/:runId/artifacts/:name`. */
157
+ artifactPath(runId, name) {
158
+ return this.url(`/v1/runs/${encodeURIComponent(runId)}/artifacts/${encodeURIComponent(name)}`);
159
+ }
160
+ /** Download one run artifact with local-token auth. */
161
+ async fetchArtifact(runId, name) {
162
+ const response = await this.send(`/v1/runs/${encodeURIComponent(runId)}/artifacts/${encodeURIComponent(name)}`, { method: "GET" });
163
+ if (!response.ok) {
164
+ const text = await response.text();
165
+ throw this.refusal(response.status, text);
166
+ }
167
+ return await response.blob();
168
+ }
169
+ /** Absolute URL of the `/v1/watch` server-sent events stream. */
170
+ watchUrl(options = {}) {
171
+ const params = new URLSearchParams();
172
+ if (options.types && options.types.length > 0)
173
+ params.set("types", options.types.join(","));
174
+ if (options.runId)
175
+ params.set("runId", options.runId);
176
+ if (options.path)
177
+ params.set("path", options.path);
178
+ const query = params.toString();
179
+ return this.url(`/v1/watch${query ? `?${query}` : ""}`);
180
+ }
181
+ url(pathName) {
182
+ return new URL(pathName, this.baseUrl).toString();
183
+ }
184
+ async send(pathName, init) {
185
+ let response;
186
+ try {
187
+ response = await this.fetch(this.url(pathName), {
188
+ ...init,
189
+ headers: { ...init.headers, Authorization: `Bearer ${this.token}` },
190
+ });
191
+ }
192
+ catch (error) {
193
+ throw unavailable(error);
194
+ }
195
+ if (response.status === HTTP_UNAUTHORIZED) {
196
+ this.onUnauthorized?.();
197
+ throw unauthorizedFrom(parseJson(await response.text()));
198
+ }
199
+ return response;
200
+ }
201
+ refusal(status, text) {
202
+ const envelope = toOperationResponse(status, parseJson(text));
203
+ if (!envelope.ok)
204
+ return new HostRequestError(envelope.error, status);
205
+ return new HostRequestError({ code: INTERNAL_CODE, message: `Unexpected HTTP ${status}.` }, status);
206
+ }
207
+ async post(pathName, body) {
208
+ const response = await this.send(pathName, {
209
+ method: "POST",
210
+ headers: { "Content-Type": JSON_CONTENT_TYPE },
211
+ body: JSON.stringify(body),
212
+ });
213
+ return toOperationResponse(response.status, parseJson(await response.text()));
214
+ }
215
+ }
216
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","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,CAAA;QACrE,OAAO,IAAI,gBAAgB,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,mBAAmB,MAAM,GAAG,EAAE,EAAE,MAAM,CAAC,CAAA;IACrG,CAAC;IAEO,KAAK,CAAC,IAAI,CAAI,QAAgB,EAAE,IAAa;QACnD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YACzC,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,iBAAiB,EAAE;YAC9C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CAAC,CAAA;QACF,OAAO,mBAAmB,CAAI,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;IAClF,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Browser client for the host HTTP API: launch fragment, typed operations, file routes,
3
+ * the watch stream and run following.
4
+ * @category App
5
+ */
6
+ export * from "./api.js";
7
+ export * from "./launch.js";
8
+ export * from "./results.js";
9
+ export * from "./run-follow.js";
10
+ export * from "./sse.js";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,UAAU,CAAA"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Browser client for the host HTTP API: launch fragment, typed operations, file routes,
3
+ * the watch stream and run following.
4
+ * @category App
5
+ */
6
+ export * from "./api.js";
7
+ export * from "./launch.js";
8
+ export * from "./results.js";
9
+ export * from "./run-follow.js";
10
+ export * from "./sse.js";
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,UAAU,CAAA"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * What the App was opened with: `ecp app` puts these in the URL fragment.
3
+ * @category App
4
+ */
5
+ export interface AppLaunchParams {
6
+ /** Host bearer token. */
7
+ token?: string;
8
+ /** Absolute path of an execution file to open. */
9
+ open?: string;
10
+ /** Saved execution id to open. */
11
+ id?: string;
12
+ /** Absolute directory whose `*.ecp.json` files the home view lists. */
13
+ dir?: string;
14
+ }
15
+ /**
16
+ * `sessionStorage` key holding the host token.
17
+ * @category App
18
+ */
19
+ export declare const TOKEN_STORAGE_KEY = "ecp.token";
20
+ /**
21
+ * Minimal storage surface (`sessionStorage` in the browser).
22
+ * @category App
23
+ */
24
+ export interface TokenStorage {
25
+ /** Read a value. */
26
+ getItem(key: string): string | null;
27
+ /** Write a value. */
28
+ setItem(key: string, value: string): void;
29
+ }
30
+ /**
31
+ * Parse `#token=…&open=…&id=…&dir=…` (leading `#` optional). Empty values are dropped.
32
+ * @category App
33
+ */
34
+ export declare function parseLaunchFragment(hash: string): AppLaunchParams;
35
+ /**
36
+ * Resolve launch parameters: a fragment token is saved to `storage`; without one, the
37
+ * stored token is used.
38
+ * @category App
39
+ */
40
+ export declare function resolveLaunch(hash: string, storage: TokenStorage): AppLaunchParams;
41
+ /**
42
+ * Fragment to keep in the address bar once the token is stored: the same parameters
43
+ * without `token`, or an empty string when nothing remains.
44
+ * @category App
45
+ */
46
+ export declare function fragmentWithoutToken(params: AppLaunchParams): string;
47
+ //# sourceMappingURL=launch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"launch.d.ts","sourceRoot":"","sources":["../../src/client/launch.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,yBAAyB;IACzB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kDAAkD;IAClD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,kCAAkC;IAClC,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,uEAAuE;IACvE,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,cAAc,CAAA;AAI5C;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,oBAAoB;IACpB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IACnC,qBAAqB;IACrB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CAC1C;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAQjE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,eAAe,CAQlF;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAQpE"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * `sessionStorage` key holding the host token.
3
+ * @category App
4
+ */
5
+ export const TOKEN_STORAGE_KEY = "ecp.token";
6
+ const LAUNCH_KEYS = ["token", "open", "id", "dir"];
7
+ /**
8
+ * Parse `#token=…&open=…&id=…&dir=…` (leading `#` optional). Empty values are dropped.
9
+ * @category App
10
+ */
11
+ export function parseLaunchFragment(hash) {
12
+ const params = new URLSearchParams(hash.startsWith("#") ? hash.slice(1) : hash);
13
+ const out = {};
14
+ for (const key of LAUNCH_KEYS) {
15
+ const value = params.get(key);
16
+ if (value)
17
+ out[key] = value;
18
+ }
19
+ return out;
20
+ }
21
+ /**
22
+ * Resolve launch parameters: a fragment token is saved to `storage`; without one, the
23
+ * stored token is used.
24
+ * @category App
25
+ */
26
+ export function resolveLaunch(hash, storage) {
27
+ const params = parseLaunchFragment(hash);
28
+ if (params.token) {
29
+ storage.setItem(TOKEN_STORAGE_KEY, params.token);
30
+ return params;
31
+ }
32
+ const stored = storage.getItem(TOKEN_STORAGE_KEY);
33
+ return stored ? { ...params, token: stored } : params;
34
+ }
35
+ /**
36
+ * Fragment to keep in the address bar once the token is stored: the same parameters
37
+ * without `token`, or an empty string when nothing remains.
38
+ * @category App
39
+ */
40
+ export function fragmentWithoutToken(params) {
41
+ const search = new URLSearchParams();
42
+ for (const key of LAUNCH_KEYS) {
43
+ const value = params[key];
44
+ if (key !== "token" && value)
45
+ search.set(key, value);
46
+ }
47
+ const text = search.toString();
48
+ return text ? `#${text}` : "";
49
+ }
50
+ //# sourceMappingURL=launch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"launch.js","sourceRoot":"","sources":["../../src/client/launch.ts"],"names":[],"mappings":"AAeA;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,WAAW,CAAA;AAE5C,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAU,CAAA;AAa3D;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;IAC/E,MAAM,GAAG,GAAoB,EAAE,CAAA;IAC/B,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC7B,IAAI,KAAK;YAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;IAC7B,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,OAAqB;IAC/D,MAAM,MAAM,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAA;IACxC,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,OAAO,CAAC,OAAO,CAAC,iBAAiB,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;QAChD,OAAO,MAAM,CAAA;IACf,CAAC;IACD,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAA;IACjD,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,CAAA;AACvD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAuB;IAC1D,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAA;IACpC,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;QACzB,IAAI,GAAG,KAAK,OAAO,IAAI,KAAK;YAAE,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IACtD,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAA;IAC9B,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;AAC/B,CAAC"}
@@ -0,0 +1,85 @@
1
+ import type { CapabilityEntry, ExecuteData, ExecutionManifest, OperationError, OperationResponse, RetrieveData, RunEvent, ValidationIssue } from "@executioncontrolprotocol/protocol";
2
+ import type { CapabilitySchemaIndex } from "../graph/types.js";
3
+ /**
4
+ * Validation as the App shows it, from `execute { mode: "validate" }`.
5
+ * @category App
6
+ */
7
+ export interface AppValidation {
8
+ /** No error-severity issue and no refusal. */
9
+ valid: boolean;
10
+ /** Issues, errors first. */
11
+ issues: ValidationIssue[];
12
+ /** Refusal, when the host refused instead of returning a validation result. */
13
+ error?: OperationError;
14
+ }
15
+ /**
16
+ * Result of {@link parseExecutionText}.
17
+ * @category App
18
+ */
19
+ export type ParsedExecution = {
20
+ ok: true;
21
+ manifest: ExecutionManifest;
22
+ } | {
23
+ ok: false;
24
+ error: OperationError;
25
+ };
26
+ /**
27
+ * The single `item` of a `retrieve` by id, or undefined for a refusal or a list.
28
+ * @category App
29
+ */
30
+ export declare function retrieveItem<T>(response: OperationResponse<RetrieveData>): T | undefined;
31
+ /**
32
+ * The `items` of a list `retrieve`, or an empty list for a refusal or a single item.
33
+ * @category App
34
+ */
35
+ export declare function retrieveItems<T>(response: OperationResponse<RetrieveData>): T[];
36
+ /**
37
+ * Present a refusal as a validation issue (for the issue list and the run error view).
38
+ * @category App
39
+ */
40
+ export declare function issueFromError(error: OperationError): ValidationIssue;
41
+ /**
42
+ * Fold an `execute { mode: "validate" }` response into {@link AppValidation}. Invalid
43
+ * executions come back refused with `error.issues`; other refusals become one issue.
44
+ * @category App
45
+ */
46
+ export declare function validationFromExecute(response: OperationResponse<ExecuteData>): AppValidation;
47
+ /**
48
+ * Parse execution file text. Anything other than a JSON object is an `ECP_EXECUTION_LOAD`
49
+ * error; schema problems are left to validation.
50
+ * @category App
51
+ */
52
+ export declare function parseExecutionText(text: string): ParsedExecution;
53
+ /**
54
+ * Capability id to its `accepts` / `returns` schemas, for typed graph ports.
55
+ * @category App
56
+ */
57
+ export declare function capabilitySchemaIndex(entries: readonly Partial<CapabilityEntry>[]): CapabilitySchemaIndex;
58
+ /**
59
+ * Node an issue belongs to: `issue.nodeId` when set, else the deepest node on the issue's
60
+ * JSON Pointer path through the manifest (an `@<nodeId>` segment counts too).
61
+ * @category App
62
+ */
63
+ export declare function issueNodeId(issue: Pick<ValidationIssue, "path" | "nodeId">, manifest?: ExecutionManifest): string | undefined;
64
+ /**
65
+ * Error-severity issues grouped by the node they belong to.
66
+ * @category App
67
+ */
68
+ export declare function nodeErrorIssues(issues: readonly ValidationIssue[], manifest?: ExecutionManifest): Record<string, ValidationIssue[]>;
69
+ /**
70
+ * Absolute path of a `$script.path` value: absolute paths are kept, relative ones are
71
+ * joined to the execution file's folder (the host resolves `.` / `..`).
72
+ * @category App
73
+ */
74
+ export declare function resolveScriptPath(executionPath: string, scriptPath: string): string;
75
+ /**
76
+ * Whether two absolute paths name the same file (separators and Windows drive case ignored).
77
+ * @category App
78
+ */
79
+ export declare function samePath(a: string | null | undefined, b: string | null | undefined): boolean;
80
+ /**
81
+ * Events with `seq` greater than `lastSeq`, in `seq` order.
82
+ * @category App
83
+ */
84
+ export declare function newRunEvents(events: readonly RunEvent[], lastSeq: number): RunEvent[];
85
+ //# sourceMappingURL=results.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"results.d.ts","sourceRoot":"","sources":["../../src/client/results.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,QAAQ,EACR,eAAe,EAChB,MAAM,oCAAoC,CAAA;AAC3C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAI9D;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,8CAA8C;IAC9C,KAAK,EAAE,OAAO,CAAA;IACd,4BAA4B;IAC5B,MAAM,EAAE,eAAe,EAAE,CAAA;IACzB,+EAA+E;IAC/E,KAAK,CAAC,EAAE,cAAc,CAAA;CACvB;AAED;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,iBAAiB,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,cAAc,CAAA;CAAE,CAAA;AAE9G;;;GAGG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,iBAAiB,CA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