@snaptrude/plugin-core 0.6.0 → 0.7.1

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 (89) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/api-manifest.json +206 -704
  3. package/dist/api/core/index.d.ts +5 -0
  4. package/dist/api/core/index.d.ts.map +1 -1
  5. package/dist/api/core/proposals/index.d.ts +475 -0
  6. package/dist/api/core/proposals/index.d.ts.map +1 -0
  7. package/dist/api/design/create/index.d.ts +209 -0
  8. package/dist/api/design/create/index.d.ts.map +1 -1
  9. package/dist/api/design/doors/index.d.ts +159 -0
  10. package/dist/api/design/doors/index.d.ts.map +1 -1
  11. package/dist/api/design/furniture/index.d.ts +34 -5
  12. package/dist/api/design/furniture/index.d.ts.map +1 -1
  13. package/dist/api/design/index.d.ts +83 -0
  14. package/dist/api/design/index.d.ts.map +1 -1
  15. package/dist/api/design/lock.d.ts +26 -0
  16. package/dist/api/design/lock.d.ts.map +1 -1
  17. package/dist/api/design/materials/index.d.ts +159 -2
  18. package/dist/api/design/materials/index.d.ts.map +1 -1
  19. package/dist/api/design/query/index.d.ts +115 -5
  20. package/dist/api/design/query/index.d.ts.map +1 -1
  21. package/dist/api/design/selection/index.d.ts +2 -2
  22. package/dist/api/design/transform/index.d.ts +83 -2
  23. package/dist/api/design/transform/index.d.ts.map +1 -1
  24. package/dist/api/design/update/index.d.ts +168 -0
  25. package/dist/api/design/update/index.d.ts.map +1 -1
  26. package/dist/api/design/windows/index.d.ts +113 -2
  27. package/dist/api/design/windows/index.d.ts.map +1 -1
  28. package/dist/api/entity/story.d.ts +101 -7
  29. package/dist/api/entity/story.d.ts.map +1 -1
  30. package/dist/api/presentation/aiInspiration.d.ts +1967 -7
  31. package/dist/api/presentation/aiInspiration.d.ts.map +1 -1
  32. package/dist/api/presentation/import.d.ts +49 -4
  33. package/dist/api/presentation/import.d.ts.map +1 -1
  34. package/dist/api/presentation/index.d.ts +2 -3
  35. package/dist/api/presentation/index.d.ts.map +1 -1
  36. package/dist/api/presentation/views.d.ts +210 -5
  37. package/dist/api/presentation/views.d.ts.map +1 -1
  38. package/dist/api/program/areas.d.ts +42 -12
  39. package/dist/api/program/areas.d.ts.map +1 -1
  40. package/dist/api/program/index.d.ts +3 -11
  41. package/dist/api/program/index.d.ts.map +1 -1
  42. package/dist/api/program/layout.d.ts +186 -11
  43. package/dist/api/program/layout.d.ts.map +1 -1
  44. package/dist/errors/codes.d.ts +34 -0
  45. package/dist/errors/codes.d.ts.map +1 -0
  46. package/dist/errors/envelope.d.ts +56 -0
  47. package/dist/errors/envelope.d.ts.map +1 -0
  48. package/dist/errors/index.d.ts +6 -0
  49. package/dist/errors/index.d.ts.map +1 -0
  50. package/dist/errors/plugin-error.d.ts +69 -0
  51. package/dist/errors/plugin-error.d.ts.map +1 -0
  52. package/dist/host-utils.d.ts +4 -0
  53. package/dist/host-utils.d.ts.map +1 -1
  54. package/dist/index.cjs +1993 -1033
  55. package/dist/index.cjs.map +1 -1
  56. package/dist/index.d.ts +1 -0
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +1874 -1030
  59. package/dist/index.js.map +1 -1
  60. package/package.json +2 -1
  61. package/scripts/generate-manifest.test.mjs +77 -0
  62. package/src/api/core/index.ts +5 -0
  63. package/src/api/core/proposals/index.ts +509 -0
  64. package/src/api/design/create/index.ts +249 -0
  65. package/src/api/design/doors/index.ts +168 -0
  66. package/src/api/design/furniture/index.ts +36 -5
  67. package/src/api/design/index.ts +87 -0
  68. package/src/api/design/lock.ts +27 -0
  69. package/src/api/design/materials/index.ts +182 -2
  70. package/src/api/design/query/index.ts +81 -0
  71. package/src/api/design/transform/index.ts +74 -2
  72. package/src/api/design/update/index.ts +167 -0
  73. package/src/api/design/windows/index.ts +128 -2
  74. package/src/api/entity/story.ts +105 -7
  75. package/src/api/presentation/aiInspiration.ts +761 -7
  76. package/src/api/presentation/import.ts +45 -4
  77. package/src/api/presentation/index.ts +2 -3
  78. package/src/api/presentation/views.ts +221 -5
  79. package/src/api/program/areas.ts +34 -12
  80. package/src/api/program/index.ts +3 -11
  81. package/src/api/program/layout.ts +195 -11
  82. package/src/errors/codes.ts +136 -0
  83. package/src/errors/envelope.ts +75 -0
  84. package/src/errors/index.ts +21 -0
  85. package/src/errors/plugin-error.ts +134 -0
  86. package/src/host-utils.ts +4 -0
  87. package/src/index.ts +1 -0
  88. package/test/errors.test.mjs +184 -0
  89. package/api-manifest.full.json +0 -5600
@@ -8,8 +8,20 @@ import { PluginApiReturn } from "../../types";
8
8
  * three of the space-planning workflow that starts with
9
9
  * {@linkcode PluginProgramAdjacencyApi} (`program.adjacency`).
10
10
  *
11
- * _(Authored ahead both methods are optional until the host lands them in
12
- * the next increment, and are kept out of the discovery manifest until then.)_
11
+ * Both {@linkcode PluginProgramLayoutApi.arrange} and
12
+ * {@linkcode PluginProgramLayoutApi.pack} run as an **asynchronous backend
13
+ * job** on the space-solver service:
14
+ *
15
+ * 1. `arrange` / `pack` start the job and **return immediately** — they do
16
+ * not wait for the layout.
17
+ * 2. Poll {@linkcode PluginProgramLayoutApi.getState} until `status` is no
18
+ * longer `"running"` — a run can take up to 20 minutes.
19
+ * 3. {@linkcode PluginProgramLayoutApi.cancel} aborts an in-flight run.
20
+ *
21
+ * `arrange` produces several candidate layouts and **auto-commits the first
22
+ * solution** as one undoable edit (there is no interactive solution-review
23
+ * over the plugin boundary); `pack` re-shapes and applies its single result
24
+ * directly. Both are **Pro-plan-gated**, matching the product UI.
13
25
  *
14
26
  * Accessed via `snaptrude.program.layout`.
15
27
  */
@@ -17,7 +29,29 @@ export declare abstract class PluginProgramLayoutApi {
17
29
  constructor();
18
30
  /**
19
31
  * Arrange the spaces inside the envelope using the computed adjacency data.
20
- * _(Authored ahead — optional until the host lands.)_
32
+ *
33
+ * Starts the backend job and **returns immediately** — poll
34
+ * {@linkcode PluginProgramLayoutApi.getState} until `status` leaves
35
+ * `"running"` (a run can take up to 20 minutes). The solver produces
36
+ * several candidate layouts; this **auto-commits the first solution** as one
37
+ * undoable edit (no interactive review over the plugin boundary). Starting a
38
+ * run while one is in flight replaces it.
39
+ *
40
+ * With no `options`, operates on the eligible Room/Department masses on the
41
+ * active storey and auto-detects the single buildable envelope there.
42
+ *
43
+ * @param options - Optional {@linkcode PluginProgramLayoutRunArgs} — the
44
+ * space / department masses to arrange and the envelope to fit them in.
45
+ * Omitted fields fall back to the active-storey defaults.
46
+ * @returns A {@linkcode PluginProgramLayoutRunResult} — `{ success: true }`
47
+ * when the job was started. Solver failures surface through
48
+ * {@linkcode PluginProgramLayoutApi.getState} (`status: "inactive"`), not
49
+ * as a rejected call.
50
+ * @throws When the project is not on a Pro plan.
51
+ * @throws When a `spaceId` / `departmentId` / `envelopeId` does not resolve.
52
+ * @throws When more than one envelope is on the active storey and none was
53
+ * given (ambiguous).
54
+ * @throws When plugin writes are disabled.
21
55
  *
22
56
  * @examplePrompt Arrange the rooms in the envelope
23
57
  * @examplePrompt Lay out the departments inside the building envelope
@@ -26,13 +60,40 @@ export declare abstract class PluginProgramLayoutApi {
26
60
  * # Example
27
61
  * ```ts
28
62
  * const { success, error } = await snaptrude.program.layout.arrange()
29
- * if (!success) console.log("Arrange failed:", error)
63
+ * if (!success) throw new Error(error)
64
+ * // poll until the layout is applied
65
+ * let job = await snaptrude.program.layout.getState()
66
+ * while (job?.status === "running") {
67
+ * await new Promise((r) => setTimeout(r, 5000))
68
+ * job = await snaptrude.program.layout.getState()
69
+ * }
30
70
  * ```
31
71
  */
32
- arrange?: () => PluginApiReturn<PluginProgramLayoutRunResult>;
72
+ abstract arrange(options?: PluginProgramLayoutRunArgs): PluginApiReturn<PluginProgramLayoutRunResult>;
33
73
  /**
34
74
  * Pack the spaces into the envelope (a tighter fit than arrange).
35
- * _(Authored ahead — optional until the host lands.)_
75
+ *
76
+ * Like {@linkcode PluginProgramLayoutApi.arrange}, this starts the backend
77
+ * job and **returns immediately** — poll
78
+ * {@linkcode PluginProgramLayoutApi.getState} until `status` leaves
79
+ * `"running"` (up to 20 minutes). Pack re-shapes mass geometry to fit and
80
+ * **applies its single result directly** (no solution review). Starting a
81
+ * run while one is in flight replaces it.
82
+ *
83
+ * With no `options`, operates on the eligible Room/Department masses on the
84
+ * active storey and auto-detects the single buildable envelope there.
85
+ *
86
+ * @param options - Optional {@linkcode PluginProgramLayoutRunArgs} — same
87
+ * shape as `arrange`; omitted fields fall back to the active-storey
88
+ * defaults.
89
+ * @returns A {@linkcode PluginProgramLayoutRunResult} — `{ success: true }`
90
+ * when the job was started. Solver failures surface through
91
+ * {@linkcode PluginProgramLayoutApi.getState} (`status: "inactive"`).
92
+ * @throws When the project is not on a Pro plan.
93
+ * @throws When a `spaceId` / `departmentId` / `envelopeId` does not resolve.
94
+ * @throws When more than one envelope is on the active storey and none was
95
+ * given (ambiguous).
96
+ * @throws When plugin writes are disabled.
36
97
  *
37
98
  * @examplePrompt Pack the rooms into the envelope
38
99
  * @examplePrompt Fit the program spaces tightly into the building
@@ -40,19 +101,91 @@ export declare abstract class PluginProgramLayoutApi {
40
101
  *
41
102
  * # Example
42
103
  * ```ts
43
- * const { success, error } = await snaptrude.program.layout.pack()
44
- * if (!success) console.log("Pack failed:", error)
104
+ * const { success } = await snaptrude.program.layout.pack({ envelopeId: "be_..." })
105
+ * let job = await snaptrude.program.layout.getState()
106
+ * while (job?.status === "running") {
107
+ * await new Promise((r) => setTimeout(r, 5000))
108
+ * job = await snaptrude.program.layout.getState()
109
+ * }
110
+ * ```
111
+ */
112
+ abstract pack(options?: PluginProgramLayoutRunArgs): PluginApiReturn<PluginProgramLayoutRunResult>;
113
+ /**
114
+ * Get the state of the layout run.
115
+ *
116
+ * The polling read for the async job started by
117
+ * {@linkcode PluginProgramLayoutApi.arrange} /
118
+ * {@linkcode PluginProgramLayoutApi.pack}. `status` values:
119
+ *
120
+ * | Status | Meaning |
121
+ * |---|---|
122
+ * | `"running"` | A run is in flight — keep polling |
123
+ * | `"active"` | The run finished and its layout is applied to the model |
124
+ * | `"inactive"` | A run finished without applying a layout (the solver failed or found no solution) |
125
+ *
126
+ * @returns A {@linkcode PluginProgramLayoutStateResult} with the run
127
+ * `status`, or `null` when no run result is available (never ran or was
128
+ * cancelled).
129
+ *
130
+ * @examplePrompt Is the arrange done?
131
+ * @examplePrompt Check the status of the layout run
132
+ * @examplePrompt Did the pack finish?
133
+ *
134
+ * # Example
135
+ * ```ts
136
+ * const job = await snaptrude.program.layout.getState()
137
+ * if (job?.status === "active") console.log("layout applied")
138
+ * ```
139
+ */
140
+ abstract getState(): PluginApiReturn<PluginProgramLayoutStateResult>;
141
+ /**
142
+ * Cancel the in-flight layout run.
143
+ *
144
+ * Aborts the backend job and discards any pending solution. A no-op
145
+ * (returns `false`) when nothing is running.
146
+ *
147
+ * @returns `true` when a run was cancelled, `false` when nothing was
148
+ * running.
149
+ * @throws When plugin writes are disabled.
150
+ *
151
+ * @examplePrompt Cancel the arrange
152
+ * @examplePrompt Stop the running layout job
153
+ * @examplePrompt Abort the pack in envelope
154
+ *
155
+ * # Example
156
+ * ```ts
157
+ * await snaptrude.program.layout.cancel()
45
158
  * ```
46
159
  */
47
- pack?: () => PluginApiReturn<PluginProgramLayoutRunResult>;
160
+ abstract cancel(): PluginApiReturn<boolean>;
48
161
  }
162
+ /**
163
+ * Arguments for {@linkcode PluginProgramLayoutApi.arrange} /
164
+ * {@linkcode PluginProgramLayoutApi.pack}. All fields are optional — omitted
165
+ * fields fall back to the eligible masses and the single envelope on the
166
+ * active storey.
167
+ *
168
+ * | Property | Type | Description |
169
+ * |---|---|---|
170
+ * | `spaceIds` | `string[] \| undefined` | Component ids of the Room masses to lay out |
171
+ * | `departmentIds` | `string[] \| undefined` | Component ids of the Department masses to lay out |
172
+ * | `envelopeId` | `string \| undefined` | The envelope to fit into — a mass component id or a buildable-envelope handle (`be_…`); omit to auto-detect the single envelope on the active storey |
173
+ */
174
+ export declare const PluginProgramLayoutRunArgs: z.ZodObject<{
175
+ spaceIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
176
+ departmentIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
177
+ envelopeId: z.ZodOptional<z.ZodString>;
178
+ }, z.core.$strip>;
179
+ export type PluginProgramLayoutRunArgs = z.infer<typeof PluginProgramLayoutRunArgs>;
49
180
  /**
50
181
  * Result of {@linkcode PluginProgramLayoutApi.arrange} /
51
- * {@linkcode PluginProgramLayoutApi.pack}.
182
+ * {@linkcode PluginProgramLayoutApi.pack} — reports whether the run was
183
+ * **started**, not whether the layout finished (poll
184
+ * {@linkcode PluginProgramLayoutApi.getState} for completion).
52
185
  *
53
186
  * | Property | Type | Description |
54
187
  * |---|---|---|
55
- * | `success` | `boolean` | Whether the layout run completed |
188
+ * | `success` | `boolean` | Whether the layout run was started |
56
189
  * | `error` | `string \| undefined` | Failure reason when `success` is `false` |
57
190
  */
58
191
  export declare const PluginProgramLayoutRunResult: z.ZodObject<{
@@ -60,4 +193,46 @@ export declare const PluginProgramLayoutRunResult: z.ZodObject<{
60
193
  error: z.ZodOptional<z.ZodString>;
61
194
  }, z.core.$strip>;
62
195
  export type PluginProgramLayoutRunResult = z.infer<typeof PluginProgramLayoutRunResult>;
196
+ /**
197
+ * The status of a layout run.
198
+ *
199
+ * | Value | Meaning |
200
+ * |---|---|
201
+ * | `"running"` | A run is in flight — keep polling |
202
+ * | `"active"` | The run finished and its layout is applied to the model |
203
+ * | `"inactive"` | A run finished without applying a layout (the solver failed or found no solution) |
204
+ */
205
+ export declare const PluginProgramLayoutJobStatus: z.ZodEnum<{
206
+ running: "running";
207
+ active: "active";
208
+ inactive: "inactive";
209
+ }>;
210
+ export type PluginProgramLayoutJobStatus = z.infer<typeof PluginProgramLayoutJobStatus>;
211
+ /**
212
+ * The state of a layout run.
213
+ *
214
+ * | Property | Type | Description |
215
+ * |---|---|---|
216
+ * | `status` | {@linkcode PluginProgramLayoutJobStatus} | `"running"` \| `"active"` \| `"inactive"` |
217
+ */
218
+ export declare const PluginProgramLayoutJobState: z.ZodObject<{
219
+ status: z.ZodEnum<{
220
+ running: "running";
221
+ active: "active";
222
+ inactive: "inactive";
223
+ }>;
224
+ }, z.core.$strip>;
225
+ export type PluginProgramLayoutJobState = z.infer<typeof PluginProgramLayoutJobState>;
226
+ /**
227
+ * Result of {@linkcode PluginProgramLayoutApi.getState} — the run state, or
228
+ * `null` when no run result is available (never ran or was cancelled).
229
+ */
230
+ export declare const PluginProgramLayoutStateResult: z.ZodNullable<z.ZodObject<{
231
+ status: z.ZodEnum<{
232
+ running: "running";
233
+ active: "active";
234
+ inactive: "inactive";
235
+ }>;
236
+ }, z.core.$strip>>;
237
+ export type PluginProgramLayoutStateResult = z.infer<typeof PluginProgramLayoutStateResult>;
63
238
  //# sourceMappingURL=layout.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../../src/api/program/layout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7C;;;;;;;;;;;;GAYG;AACH,8BAAsB,sBAAsB;;IAG1C;;;;;;;;;;;;;OAaG;IACI,OAAO,CAAC,EAAE,MAAM,eAAe,CAAC,4BAA4B,CAAC,CAAA;IAEpE;;;;;;;;;;;;;OAaG;IACI,IAAI,CAAC,EAAE,MAAM,eAAe,CAAC,4BAA4B,CAAC,CAAA;CAClE;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,4BAA4B;;;iBAGvC,CAAA;AACF,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAChD,OAAO,4BAA4B,CACpC,CAAA"}
1
+ {"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../../src/api/program/layout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7C;;;;;;;;;;;;;;;;;;;;;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
+ * The closed error-code registry — the single source of truth for every error
3
+ * that crosses the plugin wire (host → worker) or is minted client-side.
4
+ *
5
+ * APPEND-ONLY: codes are a published contract; never rename or remove one.
6
+ * Handle-resolution failures deliberately collapse to ONE code
7
+ * (`HANDLE_INVALID`) so error responses cannot be used as an existence /
8
+ * ownership oracle (PLUGIN_HANDLE_MIGRATION_HLD §6). `HANDLE_KIND_MISMATCH`
9
+ * stays distinct because the kind is information the caller already holds.
10
+ */
11
+ export declare const PLUGIN_ERROR_CODES: readonly ["VALIDATION", "INVALID_RPC_FORMAT", "METHOD_NOT_FOUND", "METHOD_NOT_PERMITTED", "HANDLE_INVALID", "HANDLE_KIND_MISMATCH", "RESOURCE_QUOTA_EXCEEDED", "RATE_LIMITED", "PRECONDITION_FAILED", "OPERATION_FAILED", "TIMEOUT", "CALL_TIMEOUT", "TRANSPORT_LOST", "PLUGIN_NOT_READY", "PLUGIN_TERMINATED", "RESULT_NOT_SERIALIZABLE", "RESULT_TOO_LARGE", "BATCH_PARTIAL", "STORY_UPDATE_FAILED", "STORY_HEIGHT_REJECTED", "NO_ACTIVE_STRUCTURE", "NO_ELIGIBLE_ELEMENTS", "PROPOSAL_SWITCH_BLOCKED", "INTERNAL", "UNKNOWN"];
12
+ export type PluginErrorCode = (typeof PLUGIN_ERROR_CODES)[number];
13
+ /**
14
+ * A known code, or a string outside the union — a plugin built against an
15
+ * older SDK may receive codes a newer host appended. Keeps autocomplete for
16
+ * known codes while staying open on the wire (forward compatibility).
17
+ */
18
+ export type WirePluginErrorCode = PluginErrorCode | (string & {});
19
+ export type PluginErrorCategory = "validation" | "not_found" | "permission" | "handle" | "quota" | "timeout" | "transport" | "lifecycle" | "execution" | "internal";
20
+ /**
21
+ * Client-side metadata for a code. NOT carried on the wire — every field is a
22
+ * pure function of the code, and this table ships inside plugin-core, so both
23
+ * endpoints derive it locally.
24
+ */
25
+ export interface CodeMeta {
26
+ /** Family of the code; picks the `PluginError` sugar subclass. */
27
+ category: PluginErrorCategory;
28
+ /** Fallback `hint` when the throw site provides none. */
29
+ hintTemplate?: string;
30
+ }
31
+ export declare const CODE_META: Record<PluginErrorCode, CodeMeta>;
32
+ /** Narrow an arbitrary string to a member of the closed code union. */
33
+ export declare function isPluginErrorCode(value: string): value is PluginErrorCode;
34
+ //# sourceMappingURL=codes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codes.d.ts","sourceRoot":"","sources":["../../src/errors/codes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,kgBA0BrB,CAAA;AAEV,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAA;AAEjE;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,eAAe,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;AAEjE,MAAM,MAAM,mBAAmB,GAC3B,YAAY,GACZ,WAAW,GACX,YAAY,GACZ,QAAQ,GACR,OAAO,GACP,SAAS,GACT,WAAW,GACX,WAAW,GACX,WAAW,GACX,UAAU,CAAA;AAEd;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB,kEAAkE;IAClE,QAAQ,EAAE,mBAAmB,CAAA;IAC7B,yDAAyD;IACzD,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,eAAe,EAAE,QAAQ,CA2DvD,CAAA;AAED,uEAAuE;AACvE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,eAAe,CAEzE"}
@@ -0,0 +1,56 @@
1
+ import type { WirePluginErrorCode } from "./codes";
2
+ /**
3
+ * Structured error payload carried on the `{success: false}` branch of the RPC
4
+ * wire result, next to the legacy `error: string` field (additive — old
5
+ * clients ignore it, old hosts never set it).
6
+ *
7
+ * Errors cross the worker boundary as THIS plain object, never as a thrown
8
+ * class: Comlink's throw transfer strips subclasses and custom fields and
9
+ * leaks host stacks. plugin-client reconstructs a typed `PluginError` from it
10
+ * (`fromEnvelope`).
11
+ */
12
+ export declare const ERROR_ENVELOPE_VERSION: 1;
13
+ export interface ErrorEnvelope {
14
+ envelopeVersion: typeof ERROR_ENVELOPE_VERSION;
15
+ code: WirePluginErrorCode;
16
+ /**
17
+ * Human-readable failure description. For INTERNAL/UNKNOWN this is a GENERIC
18
+ * message — the real message and stack stay host-side, logged under
19
+ * `errorId` (the worker is untrusted; internals must not leak).
20
+ */
21
+ message: string;
22
+ /**
23
+ * Per-occurrence id. For INTERNAL the host logs the real message and stack
24
+ * under this id (the sanitized message would otherwise be an undebuggable
25
+ * dead end). Other codes carry the id only to identify the occurrence in
26
+ * bug reports — the host does not log them. Client-minted ids carry a `c-`
27
+ * prefix.
28
+ */
29
+ errorId: string;
30
+ /** Structured, JSON-safe, code-specific data (issues / retryAfterMs / didYouMean / handles…). */
31
+ details?: Record<string, unknown>;
32
+ /**
33
+ * Wire id of the single primary offending handle, when the failure is
34
+ * handle-scoped. Multiple offenders go in `details.handles: string[]`.
35
+ * May echo ONLY ids the caller itself supplied (anti-oracle rule).
36
+ */
37
+ handle?: string;
38
+ /** Dotted method path of the failed call (e.g. "design.boolean.union"). */
39
+ methodPath?: string;
40
+ /** Machine-actionable fix suggestion (written for LLM plugin authors). */
41
+ hint?: string;
42
+ }
43
+ /**
44
+ * Structural guard for a wire value claiming to be an `ErrorEnvelope`.
45
+ *
46
+ * Checks shape only — deliberately does NOT reject codes outside the known
47
+ * union, so envelopes from a newer host still pass (forward compatibility).
48
+ */
49
+ export declare function isErrorEnvelope(value: unknown): value is ErrorEnvelope;
50
+ /**
51
+ * Mint a per-occurrence error id. Uses `crypto.randomUUID` when available
52
+ * (browser main thread and workers both have it); falls back to a
53
+ * counter+random suffix — uniqueness within a session is all that is needed.
54
+ */
55
+ export declare function newErrorId(prefix?: string): string;
56
+ //# sourceMappingURL=envelope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../src/errors/envelope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAElD;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,EAAG,CAAU,CAAA;AAEhD,MAAM,WAAW,aAAa;IAC5B,eAAe,EAAE,OAAO,sBAAsB,CAAA;IAC9C,IAAI,EAAE,mBAAmB,CAAA;IACzB;;;;OAIG;IACH,OAAO,EAAE,MAAM,CAAA;IACf;;;;;;OAMG;IACH,OAAO,EAAE,MAAM,CAAA;IACf,iGAAiG;IACjG,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACjC;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,2EAA2E;IAC3E,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,0EAA0E;IAC1E,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAStE;AAID;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,SAAK,GAAG,MAAM,CAK9C"}
@@ -0,0 +1,6 @@
1
+ export { PLUGIN_ERROR_CODES, CODE_META, isPluginErrorCode } from "./codes";
2
+ export type { PluginErrorCode, WirePluginErrorCode, PluginErrorCategory, CodeMeta } from "./codes";
3
+ export { ERROR_ENVELOPE_VERSION, isErrorEnvelope, newErrorId } from "./envelope";
4
+ export type { ErrorEnvelope } from "./envelope";
5
+ export { PluginError, PluginValidationError, PluginNotFoundError, PluginPermissionError, PluginHandleError, PluginQuotaError, PluginTimeoutError, PluginTransportError, PluginLifecycleError, PluginExecutionError, PluginInternalError, fromEnvelope, makeClientEnvelope, } from "./plugin-error";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAC1E,YAAY,EAAE,eAAe,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAElG,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAChF,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C,OAAO,EACL,WAAW,EACX,qBAAqB,EACrB,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,YAAY,EACZ,kBAAkB,GACnB,MAAM,gBAAgB,CAAA"}
@@ -0,0 +1,69 @@
1
+ import type { PluginErrorCategory, PluginErrorCode, WirePluginErrorCode } from "./codes";
2
+ import type { ErrorEnvelope } from "./envelope";
3
+ /**
4
+ * Typed error every failed plugin API call rejects with.
5
+ *
6
+ * Rehydrated client-side from the wire `ErrorEnvelope` (`fromEnvelope`) — the
7
+ * class itself never crosses the worker boundary. Branch on the stable string
8
+ * `code`; use `PluginError.is()` rather than `instanceof` (a bundled duplicate
9
+ * SDK copy breaks `instanceof`, never the brand).
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * try {
14
+ * await snaptrude.design.boolean.union(handles)
15
+ * } catch (e) {
16
+ * if (PluginError.is(e) && e.code === "RATE_LIMITED") {
17
+ * await sleep(e.details?.retryAfterMs as number)
18
+ * } else {
19
+ * throw e
20
+ * }
21
+ * }
22
+ * ```
23
+ */
24
+ export declare class PluginError extends Error {
25
+ readonly code: WirePluginErrorCode;
26
+ readonly errorId: string;
27
+ readonly details?: Record<string, unknown>;
28
+ readonly handle?: string;
29
+ readonly methodPath?: string;
30
+ readonly hint?: string;
31
+ constructor(envelope: ErrorEnvelope);
32
+ /** Canonical check — survives bundled duplicate SDK copies where `instanceof` fails. */
33
+ static is(value: unknown): value is PluginError;
34
+ /** Derived (not wire-carried) family of the code; unknown codes map to "internal". */
35
+ get category(): PluginErrorCategory;
36
+ }
37
+ export declare class PluginValidationError extends PluginError {
38
+ }
39
+ export declare class PluginNotFoundError extends PluginError {
40
+ }
41
+ export declare class PluginPermissionError extends PluginError {
42
+ }
43
+ export declare class PluginHandleError extends PluginError {
44
+ }
45
+ export declare class PluginQuotaError extends PluginError {
46
+ }
47
+ export declare class PluginTimeoutError extends PluginError {
48
+ }
49
+ export declare class PluginTransportError extends PluginError {
50
+ }
51
+ export declare class PluginLifecycleError extends PluginError {
52
+ }
53
+ export declare class PluginExecutionError extends PluginError {
54
+ }
55
+ export declare class PluginInternalError extends PluginError {
56
+ }
57
+ /**
58
+ * Rehydrate a wire envelope into the typed error the plugin catches.
59
+ * A code outside the known union (newer host) constructs the base
60
+ * `PluginError` with the code preserved verbatim.
61
+ */
62
+ export declare function fromEnvelope(envelope: ErrorEnvelope): PluginError;
63
+ /**
64
+ * Build an envelope for a CLIENT-detected failure (transport rejection,
65
+ * legacy host without `errorInfo`). Host-originated envelopes are built by
66
+ * the host's `toErrorEnvelope` mapper, never by this.
67
+ */
68
+ export declare function makeClientEnvelope(code: PluginErrorCode, message: string, extra?: Partial<Pick<ErrorEnvelope, "details" | "handle" | "methodPath" | "hint">>): ErrorEnvelope;
69
+ //# sourceMappingURL=plugin-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-error.d.ts","sourceRoot":"","sources":["../../src/errors/plugin-error.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAExF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAc/C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAA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+ import type { ErrorEnvelope } from "./errors";
2
3
  /**
3
4
  * UnionToIntersection is a type utility that converts a union type to an intersection type.
4
5
  */
@@ -37,7 +38,10 @@ export type PluginApiCallResult<M extends PluginApiMethod> = PluginApiMethodMap[
37
38
  export type PluginApiCallWrappedResult<M extends PluginApiMethod> = {
38
39
  success: boolean;
39
40
  data?: PluginApiCallResult<M>;
41
+ /** Legacy failure message — kept verbatim for already-published plugins. */
40
42
  error?: string;
43
+ /** Structured failure (hosts ≥ error-envelope rollout). Present iff `success` is false. */
44
+ errorInfo?: ErrorEnvelope;
41
45
  };
42
46
  export {};
43
47
  //# sourceMappingURL=host-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"host-utils.d.ts","sourceRoot":"","sources":["../src/host-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAItC;;GAEG;AACH,KAAK,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,GAAG,KAAK,CAAC,SAAS,CAC7E,CAAC,EAAE,MAAM,CAAC,KACP,IAAI,GACL,CAAC,GACD,KAAK,CAAA;AAET,KAAK,OAAO,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAA;AAE1C;;;GAGG;AACH,KAAK,UAAU,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAA;AAElE,KAAK,YAAY,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;AAE7E;;;GAGG;AACH,KAAK,kBAAkB,CAAC,CAAC,EAAE,MAAM,SAAS,MAAM,GAAG,EAAE,IAAI;KACt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