@tomradex/domain 0.0.0-stage → 0.2.16

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.
package/LICENSE ADDED
@@ -0,0 +1,204 @@
1
+ Copyright 2026 Haoyuan Tang
2
+
3
+
4
+ Apache License
5
+ Version 2.0, January 2004
6
+ http://www.apache.org/licenses/
7
+
8
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
9
+
10
+ 1. Definitions.
11
+
12
+ "License" shall mean the terms and conditions for use, reproduction,
13
+ and distribution as defined by Sections 1 through 9 of this document.
14
+
15
+ "Licensor" shall mean the copyright owner or entity authorized by
16
+ the copyright owner that is granting the License.
17
+
18
+ "Legal Entity" shall mean the union of the acting entity and all
19
+ other entities that control, are controlled by, or are under common
20
+ control with that entity. For the purposes of this definition,
21
+ "control" means (i) the power, direct or indirect, to cause the
22
+ direction or management of such entity, whether by contract or
23
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
24
+ outstanding shares, or (iii) beneficial ownership of such entity.
25
+
26
+ "You" (or "Your") shall mean an individual or Legal Entity
27
+ exercising permissions granted by this License.
28
+
29
+ "Source" form shall mean the preferred form for making modifications,
30
+ including but not limited to software source code, documentation
31
+ source, and configuration files.
32
+
33
+ "Object" form shall mean any form resulting from mechanical
34
+ transformation or translation of a Source form, including but
35
+ not limited to compiled object code, generated documentation,
36
+ and conversions to other media types.
37
+
38
+ "Work" shall mean the work of authorship, whether in Source or
39
+ Object form, made available under the License, as indicated by a
40
+ copyright notice that is included in or attached to the work
41
+ (an example is provided in the Appendix below).
42
+
43
+ "Derivative Works" shall mean any work, whether in Source or Object
44
+ form, that is based on (or derived from) the Work and for which the
45
+ editorial revisions, annotations, elaborations, or other modifications
46
+ represent, as a whole, an original work of authorship. For the purposes
47
+ of this License, Derivative Works shall not include works that remain
48
+ separable from, or merely link (or bind by name) to the interfaces of,
49
+ the Work and Derivative Works thereof.
50
+
51
+ "Contribution" shall mean any work of authorship, including
52
+ the original version of the Work and any modifications or additions
53
+ to that Work or Derivative Works thereof, that is intentionally
54
+ submitted to Licensor for inclusion in the Work by the copyright owner
55
+ or by an individual or Legal Entity authorized to submit on behalf of
56
+ the copyright owner. For the purposes of this definition, "submitted"
57
+ means any form of electronic, verbal, or written communication sent
58
+ to the Licensor or its representatives, including but not limited to
59
+ communication on electronic mailing lists, source code control systems,
60
+ and issue tracking systems that are managed by, or on behalf of, the
61
+ Licensor for the purpose of discussing and improving the Work, but
62
+ excluding communication that is conspicuously marked or otherwise
63
+ designated in writing by the copyright owner as "Not a Contribution."
64
+
65
+ "Contributor" shall mean Licensor and any individual or Legal Entity
66
+ on behalf of whom a Contribution has been received by Licensor and
67
+ subsequently incorporated within the Work.
68
+
69
+ 2. Grant of Copyright License. Subject to the terms and conditions of
70
+ this License, each Contributor hereby grants to You a perpetual,
71
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
72
+ copyright license to reproduce, prepare Derivative Works of,
73
+ publicly display, publicly perform, sublicense, and distribute the
74
+ Work and such Derivative Works in Source or Object form.
75
+
76
+ 3. Grant of Patent License. Subject to the terms and conditions of
77
+ this License, each Contributor hereby grants to You a perpetual,
78
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
79
+ (except as stated in this section) patent license to make, have made,
80
+ use, offer to sell, sell, import, and otherwise transfer the Work,
81
+ where such license applies only to those patent claims licensable
82
+ by such Contributor that are necessarily infringed by their
83
+ Contribution(s) alone or by combination of their Contribution(s)
84
+ with the Work to which such Contribution(s) was submitted. If You
85
+ institute patent litigation against any entity (including a
86
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
87
+ or a Contribution incorporated within the Work constitutes direct
88
+ or contributory patent infringement, then any patent licenses
89
+ granted to You under this License for that Work shall terminate
90
+ as of the date such litigation is filed.
91
+
92
+ 4. Redistribution. You may reproduce and distribute copies of the
93
+ Work or Derivative Works thereof in any medium, with or without
94
+ modifications, and in Source or Object form, provided that You
95
+ meet the following conditions:
96
+
97
+ (a) You must give any other recipients of the Work or
98
+ Derivative Works a copy of this License; and
99
+
100
+ (b) You must cause any modified files to carry prominent notices
101
+ stating that You changed the files; and
102
+
103
+ (c) You must retain, in the Source form of any Derivative Works
104
+ that You distribute, all copyright, patent, trademark, and
105
+ attribution notices from the Source form of the Work,
106
+ excluding those notices that do not pertain to any part of
107
+ the Derivative Works; and
108
+
109
+ (d) If the Work includes a "NOTICE" text file as part of its
110
+ distribution, then any Derivative Works that You distribute must
111
+ include a readable copy of the attribution notices contained
112
+ within such NOTICE file, excluding those notices that do not
113
+ pertain to any part of the Derivative Works, in at least one
114
+ of the following places: within a NOTICE text file distributed
115
+ as part of the Derivative Works; within the Source form or
116
+ documentation, if provided along with the Derivative Works; or,
117
+ within a display generated by the Derivative Works, if and
118
+ wherever such third-party notices normally appear. The contents
119
+ of the NOTICE file are for informational purposes only and
120
+ do not modify the License. You may add Your own attribution
121
+ notices within Derivative Works that You distribute, alongside
122
+ or as an addendum to the NOTICE text from the Work, provided
123
+ that such additional attribution notices cannot be construed
124
+ as modifying the License.
125
+
126
+ You may add Your own copyright statement to Your modifications and
127
+ may provide additional or different license terms and conditions
128
+ for use, reproduction, or distribution of Your modifications, or
129
+ for any such Derivative Works as a whole, provided Your use,
130
+ reproduction, and distribution of the Work otherwise complies with
131
+ the conditions stated in this License.
132
+
133
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
134
+ any Contribution intentionally submitted for inclusion in the Work
135
+ by You to the Licensor shall be under the terms and conditions of
136
+ this License, without any additional terms or conditions.
137
+ Notwithstanding the above, nothing herein shall supersede or modify
138
+ the terms of any separate license agreement you may have executed
139
+ with Licensor regarding such Contributions.
140
+
141
+ 6. Trademarks. This License does not grant permission to use the trade
142
+ names, trademarks, service marks, or product names of the Licensor,
143
+ except as required for reasonable and customary use in describing the
144
+ origin of the Work and reproducing the content of the NOTICE file.
145
+
146
+ 7. Disclaimer of Warranty. Unless required by applicable law or
147
+ agreed to in writing, Licensor provides the Work (and each
148
+ Contributor provides its Contributions) on an "AS IS" BASIS,
149
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
150
+ implied, including, without limitation, any warranties or conditions
151
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
152
+ PARTICULAR PURPOSE. You are solely responsible for determining the
153
+ appropriateness of using or redistributing the Work and assume any
154
+ risks associated with Your exercise of permissions under this License.
155
+
156
+ 8. Limitation of Liability. In no event and under no legal theory,
157
+ whether in tort (including negligence), contract, or otherwise,
158
+ unless required by applicable law (such as deliberate and grossly
159
+ negligent acts) or agreed to in writing, shall any Contributor be
160
+ liable to You for damages, including any direct, indirect, special,
161
+ incidental, or consequential damages of any character arising as a
162
+ result of this License or out of the use or inability to use the
163
+ Work (including but not limited to damages for loss of goodwill,
164
+ work stoppage, computer failure or malfunction, or any and all
165
+ other commercial damages or losses), even if such Contributor
166
+ has been advised of the possibility of such damages.
167
+
168
+ 9. Accepting Warranty or Additional Liability. While redistributing
169
+ the Work or Derivative Works thereof, You may choose to offer,
170
+ and charge a fee for, acceptance of support, warranty, indemnity,
171
+ or other liability obligations and/or rights consistent with this
172
+ License. However, in accepting such obligations, You may act only
173
+ on Your own behalf and on Your sole responsibility, not on behalf
174
+ of any other Contributor, and only if You agree to indemnify,
175
+ defend, and hold each Contributor harmless for any liability
176
+ incurred by, or claims asserted against, such Contributor by reason
177
+ of your accepting any such warranty or additional liability.
178
+
179
+ END OF TERMS AND CONDITIONS
180
+
181
+ APPENDIX: How to apply the Apache License to your work.
182
+
183
+ To apply the Apache License to your work, attach the following
184
+ boilerplate notice, with the fields enclosed by brackets "[]"
185
+ replaced with your own identifying information. (Don't include
186
+ the brackets!) The text should be enclosed in the appropriate
187
+ comment syntax for the file format. We also recommend that a
188
+ file or class name and description of purpose be included on the
189
+ same "printed page" as the copyright notice for easier
190
+ identification within third-party archives.
191
+
192
+ Copyright [yyyy] [name of copyright owner]
193
+
194
+ Licensed under the Apache License, Version 2.0 (the "License");
195
+ you may not use this file except in compliance with the License.
196
+ You may obtain a copy of the License at
197
+
198
+ http://www.apache.org/licenses/LICENSE-2.0
199
+
200
+ Unless required by applicable law or agreed to in writing, software
201
+ distributed under the License is distributed on an "AS IS" BASIS,
202
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
203
+ See the License for the specific language governing permissions and
204
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
- # Temporary Holding Version
1
+ # @tomradex/domain
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
+ The types a Tomrade plugin reads: issues (`Item`), fields, boards, views, projects and the history (`OplogEntry`), with the zod schemas and typed errors behind them. Plugins normally get these through [`@tomradex/plugin-sdk`](https://www.npmjs.com/package/@tomradex/plugin-sdk), which re-exports them.
@@ -0,0 +1,19 @@
1
+ /**
2
+ * How a ticket body points at a file of the project's Files store: by id, so a
3
+ * rename or a move in Files never breaks the link and never rewrites the body.
4
+ */
5
+ export declare const FILE_LINK = "tomrade-file://";
6
+ /** Each file id the text links to, once, in order of first mention. */
7
+ export declare function linkedFileIds(text: string | null | undefined): string[];
8
+ /** A linked file as an agent can use it: where it is now and what it is. */
9
+ export interface FileDescription {
10
+ fileId: string;
11
+ /** Relative to the Files store root. */
12
+ path: string;
13
+ name: string;
14
+ mime: string;
15
+ size: number;
16
+ /** On this machine, for engines that read files themselves; null when the store has no folder here. */
17
+ localPath: string | null;
18
+ }
19
+ //# sourceMappingURL=attachments.d.ts.map
@@ -0,0 +1,13 @@
1
+ /**
2
+ * How a ticket body points at a file of the project's Files store: by id, so a
3
+ * rename or a move in Files never breaks the link and never rewrites the body.
4
+ */
5
+ export const FILE_LINK = "tomrade-file://";
6
+ const LINKED = /tomrade-file:\/\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/gi;
7
+ /** Each file id the text links to, once, in order of first mention. */
8
+ export function linkedFileIds(text) {
9
+ if (!text)
10
+ return [];
11
+ return [...new Set([...text.matchAll(LINKED)].map((m) => m[1].toLowerCase()))];
12
+ }
13
+ //# sourceMappingURL=attachments.js.map
@@ -0,0 +1,73 @@
1
+ import { z } from "zod";
2
+ import type { FileDescription } from "./attachments.js";
3
+ import type { Author } from "./types.js";
4
+ /** Metadata only. File bytes and immutable versions belong to the Files plugin. */
5
+ export interface FileReference {
6
+ fileId: string;
7
+ versionId: string;
8
+ }
9
+ export interface DeliveryResource {
10
+ id: string;
11
+ name: string;
12
+ role: "input" | "output";
13
+ deliveryId: string | null;
14
+ file: FileReference;
15
+ createdBy: Author;
16
+ createdAt: number;
17
+ }
18
+ export interface DeliverySubmission {
19
+ id: string;
20
+ deliveryId: string;
21
+ report: string;
22
+ artifactIds: string[];
23
+ submittedBy: Author;
24
+ submittedAt: number;
25
+ }
26
+ export interface DeliveryReview {
27
+ id: string;
28
+ submissionId: string;
29
+ decision: "accepted" | "changes-requested";
30
+ comment: string;
31
+ reviewedBy: "human";
32
+ reviewedAt: number;
33
+ }
34
+ export interface TicketEvidence {
35
+ resources: DeliveryResource[];
36
+ submissions: DeliverySubmission[];
37
+ reviews: DeliveryReview[];
38
+ }
39
+ export declare const emptyEvidence: () => TicketEvidence;
40
+ export declare const fileReferenceSchema: z.ZodObject<{
41
+ fileId: z.ZodString;
42
+ versionId: z.ZodString;
43
+ }, z.core.$strip>;
44
+ export declare const addResourceSchema: z.ZodObject<{
45
+ name: z.ZodString;
46
+ role: z.ZodEnum<{
47
+ input: "input";
48
+ output: "output";
49
+ }>;
50
+ file: z.ZodObject<{
51
+ fileId: z.ZodString;
52
+ versionId: z.ZodString;
53
+ }, z.core.$strip>;
54
+ }, z.core.$strip>;
55
+ export declare const submitDeliverySchema: z.ZodObject<{
56
+ report: z.ZodString;
57
+ artifactIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
58
+ }, z.core.$strip>;
59
+ export declare const reviewDeliverySchema: z.ZodObject<{
60
+ submissionId: z.ZodString;
61
+ decision: z.ZodEnum<{
62
+ accepted: "accepted";
63
+ "changes-requested": "changes-requested";
64
+ }>;
65
+ comment: z.ZodDefault<z.ZodString>;
66
+ }, z.core.$strip>;
67
+ /** The future Files plugin supplies this resolver; no fallback file store exists. */
68
+ export interface FilesResolver {
69
+ getVersion(projectId: string, reference: FileReference): Promise<FileReference | null>;
70
+ /** The files behind these ids as they are now; an id with no file here is left out. */
71
+ describe(projectId: string, fileIds: string[]): Promise<FileDescription[]>;
72
+ }
73
+ //# sourceMappingURL=delivery.d.ts.map
@@ -0,0 +1,7 @@
1
+ import { z } from "zod";
2
+ export const emptyEvidence = () => ({ resources: [], submissions: [], reviews: [] });
3
+ export const fileReferenceSchema = z.object({ fileId: z.string().min(1), versionId: z.string().min(1) });
4
+ export const addResourceSchema = z.object({ name: z.string().trim().min(1), role: z.enum(["input", "output"]), file: fileReferenceSchema });
5
+ export const submitDeliverySchema = z.object({ report: z.string().trim().min(1), artifactIds: z.array(z.string()).default([]) });
6
+ export const reviewDeliverySchema = z.object({ submissionId: z.string().min(1), decision: z.enum(["accepted", "changes-requested"]), comment: z.string().default("") });
7
+ //# sourceMappingURL=delivery.js.map
@@ -0,0 +1,8 @@
1
+ import type { Author, Item, Provenance } from "./types.js";
2
+ export declare const isAi: (by: Author | string) => boolean;
3
+ export declare const isSync: (by: Author | string) => boolean;
4
+ /** Derived, never stored: a locked item reads as locked whoever wrote it last. */
5
+ export declare function provenanceOf(item: Pick<Item, "humanLocked" | "updatedBy">): Provenance;
6
+ /** 'Tomrade Next' -> 'TOM'. Falls back to a generic prefix for nameless input. */
7
+ export declare function keyPrefixFor(name: string): string;
8
+ //# sourceMappingURL=derive.d.ts.map
package/dist/derive.js ADDED
@@ -0,0 +1,14 @@
1
+ export const isAi = (by) => by.startsWith("ai:");
2
+ export const isSync = (by) => by.startsWith("sync:");
3
+ /** Derived, never stored: a locked item reads as locked whoever wrote it last. */
4
+ export function provenanceOf(item) {
5
+ if (item.humanLocked)
6
+ return "locked";
7
+ return isAi(item.updatedBy) ? "ai" : isSync(item.updatedBy) ? "sync" : "human";
8
+ }
9
+ /** 'Tomrade Next' -> 'TOM'. Falls back to a generic prefix for nameless input. */
10
+ export function keyPrefixFor(name) {
11
+ const letters = name.toUpperCase().replace(/[^A-Z]/g, "");
12
+ return letters.slice(0, 3) || "ISS";
13
+ }
14
+ //# sourceMappingURL=derive.js.map
@@ -0,0 +1,75 @@
1
+ export declare class ConflictError extends Error {
2
+ readonly itemId: string;
3
+ readonly expectedVersion: number;
4
+ readonly actualVersion: number;
5
+ constructor(itemId: string, expectedVersion: number, actualVersion: number);
6
+ }
7
+ export declare class HumanLockedError extends Error {
8
+ readonly itemId: string;
9
+ readonly fields: string[];
10
+ constructor(itemId: string, fields: string[]);
11
+ }
12
+ export declare class NotFoundError extends Error {
13
+ readonly itemId: string;
14
+ constructor(itemId: string);
15
+ }
16
+ /** The permanent delete refused because the caller is not a human. */
17
+ export declare class PurgeNotPermittedError extends Error {
18
+ readonly itemId: string;
19
+ readonly by: string;
20
+ constructor(itemId: string, by: string);
21
+ }
22
+ /** An extension claimed a human's authorship outside a human-initiated call. */
23
+ export declare class ExtensionAuthorError extends Error {
24
+ readonly pluginId: string;
25
+ readonly entity: string;
26
+ readonly op: string;
27
+ constructor(pluginId: string, entity: string, op: string);
28
+ }
29
+ /** A blocks edit refused because "blocked until done" only means something on a DAG. */
30
+ export declare class DependencyCycleError extends Error {
31
+ readonly itemId: string;
32
+ readonly path: string[];
33
+ constructor(itemId: string, path: string[]);
34
+ }
35
+ /** A destructive write refused because something still depends on the target. */
36
+ export declare class InUseError extends Error {
37
+ readonly entityId: string;
38
+ readonly reason: string;
39
+ constructor(entityId: string, reason: string);
40
+ }
41
+ /** A custom-field write refused: unknown field, wrong type, or an option the field does not have. */
42
+ export declare class FieldValueError extends Error {
43
+ readonly fieldId: string;
44
+ readonly reason: string;
45
+ constructor(fieldId: string, reason: string);
46
+ }
47
+ /** A field definition change refused: a built-in, a taken name, an option on a non-select. */
48
+ export declare class FieldDefinitionError extends Error {
49
+ readonly fieldId: string;
50
+ readonly reason: string;
51
+ constructor(fieldId: string, reason: string);
52
+ }
53
+ /**
54
+ * What a failed model call means for the person — each wants a different fix: the key, the address, a wait.
55
+ * `slow`: the model was reached but gave no answer in time; only a check that waits for one says it.
56
+ */
57
+ export type ModelErrorKind = "auth" | "quota" | "rate" | "model" | "server" | "network" | "slow" | "other";
58
+ /** Why a model turned a working key down: the wrong API for it, not open to this key's tier or account, or not known. */
59
+ export type ModelRefusal = "method" | "tier" | "unknown";
60
+ export declare function modelRefusal(message: string): ModelRefusal | null;
61
+ /** Only a key the provider calls wrong or missing is `auth`; a model it will not serve this key is `model`, even on a 403. */
62
+ export declare function modelErrorKind(message: string): ModelErrorKind;
63
+ /** The provider's own words in a failed call's detail (its JSON `message`), or null; cut short where the detail was. */
64
+ export declare function providerMessage(detail: string): string | null;
65
+ /**
66
+ * An undo aimed at one write — a toast's — refused because the thing changed
67
+ * again since. The marker survives IPC's message wrapping, so the renderer can
68
+ * say it in the person's language.
69
+ */
70
+ export declare const STALE_UNDO = "[stale-undo]";
71
+ export declare class StaleUndoError extends Error {
72
+ readonly entityId: string;
73
+ constructor(entityId: string);
74
+ }
75
+ //# sourceMappingURL=errors.d.ts.map
package/dist/errors.js ADDED
@@ -0,0 +1,155 @@
1
+ export class ConflictError extends Error {
2
+ itemId;
3
+ expectedVersion;
4
+ actualVersion;
5
+ constructor(itemId, expectedVersion, actualVersion) {
6
+ super(`Item ${itemId} version conflict: expected ${expectedVersion}, got ${actualVersion} (it was edited by someone else)`);
7
+ this.itemId = itemId;
8
+ this.expectedVersion = expectedVersion;
9
+ this.actualVersion = actualVersion;
10
+ this.name = "ConflictError";
11
+ }
12
+ }
13
+ export class HumanLockedError extends Error {
14
+ itemId;
15
+ fields;
16
+ constructor(itemId, fields) {
17
+ super(`Item ${itemId} is human-locked; AI may not edit fields: ${fields.join(", ")}`);
18
+ this.itemId = itemId;
19
+ this.fields = fields;
20
+ this.name = "HumanLockedError";
21
+ }
22
+ }
23
+ export class NotFoundError extends Error {
24
+ itemId;
25
+ constructor(itemId) {
26
+ super(`Item ${itemId} not found`);
27
+ this.itemId = itemId;
28
+ this.name = "NotFoundError";
29
+ }
30
+ }
31
+ /** The permanent delete refused because the caller is not a human. */
32
+ export class PurgeNotPermittedError extends Error {
33
+ itemId;
34
+ by;
35
+ constructor(itemId, by) {
36
+ super(`Item ${itemId} may only be permanently deleted by a human; ${by} must use the reversible delete`);
37
+ this.itemId = itemId;
38
+ this.by = by;
39
+ this.name = "PurgeNotPermittedError";
40
+ }
41
+ }
42
+ /** An extension claimed a human's authorship outside a human-initiated call. */
43
+ export class ExtensionAuthorError extends Error {
44
+ pluginId;
45
+ entity;
46
+ op;
47
+ constructor(pluginId, entity, op) {
48
+ super(`Extension ${pluginId} may not write as a human (${entity} ${op}) unless a person asked for it`);
49
+ this.pluginId = pluginId;
50
+ this.entity = entity;
51
+ this.op = op;
52
+ this.name = "ExtensionAuthorError";
53
+ }
54
+ }
55
+ /** A blocks edit refused because "blocked until done" only means something on a DAG. */
56
+ export class DependencyCycleError extends Error {
57
+ itemId;
58
+ path;
59
+ constructor(itemId, path) {
60
+ super(`Blocking ${path[path.length - 1]} would close a cycle: ${path.join(" → ")}`);
61
+ this.itemId = itemId;
62
+ this.path = path;
63
+ this.name = "DependencyCycleError";
64
+ }
65
+ }
66
+ /** A destructive write refused because something still depends on the target. */
67
+ export class InUseError extends Error {
68
+ entityId;
69
+ reason;
70
+ constructor(entityId, reason) {
71
+ super(reason);
72
+ this.entityId = entityId;
73
+ this.reason = reason;
74
+ this.name = "InUseError";
75
+ }
76
+ }
77
+ /** A custom-field write refused: unknown field, wrong type, or an option the field does not have. */
78
+ export class FieldValueError extends Error {
79
+ fieldId;
80
+ reason;
81
+ constructor(fieldId, reason) {
82
+ super(`Field ${fieldId}: ${reason}`);
83
+ this.fieldId = fieldId;
84
+ this.reason = reason;
85
+ this.name = "FieldValueError";
86
+ }
87
+ }
88
+ /** A field definition change refused: a built-in, a taken name, an option on a non-select. */
89
+ export class FieldDefinitionError extends Error {
90
+ fieldId;
91
+ reason;
92
+ constructor(fieldId, reason) {
93
+ super(`Field ${fieldId}: ${reason}`);
94
+ this.fieldId = fieldId;
95
+ this.reason = reason;
96
+ this.name = "FieldDefinitionError";
97
+ }
98
+ }
99
+ const BAD_KEY = /\b401\b|authenticat|unauthori[sz]ed|invalid[ _-]?(api[ _-]?)?key|incorrect api key|api[ _-]?key[ _-]?(not valid|invalid|expired|missing|required)|(missing|no) api[ _-]?key/i;
100
+ export function modelRefusal(message) {
101
+ if (/not supported for (generateContent|this (api|method|endpoint))|not a chat model|only supported (in|on|by) (the )?(v1\/)?responses|not supported (in|on|by) (the )?(v1\/)?chat\/completions|does not support (chat|generateContent)/i.test(message))
102
+ return "method";
103
+ if (/model.{0,40}(not found|does not exist|not exist|unknown)|no such model|unknown model|model_not_found/i.test(message) && !/not have access to model/i.test(message))
104
+ return "unknown";
105
+ if (/free[ _-]?tier\w*.{0,80}\blimit: ?0\b|not available (on|for|in) (the |your |this )?(free |current )?(tier|plan)|not have access to (the |this )?model|not have permission to (use|access) (the |this )?model|not allow-?listed|model.{0,60}(not available|unavailable) (to|for) (you|this)/i.test(message))
106
+ return "tier";
107
+ return null;
108
+ }
109
+ /** Only a key the provider calls wrong or missing is `auth`; a model it will not serve this key is `model`, even on a 403. */
110
+ export function modelErrorKind(message) {
111
+ if (BAD_KEY.test(message))
112
+ return "auth";
113
+ if (modelRefusal(message))
114
+ return "model";
115
+ if (/\b403\b|api key|permission denied|forbidden/i.test(message))
116
+ return "auth";
117
+ if (/\b402\b|insufficient|balance|quota|billing|credit/i.test(message))
118
+ return "quota";
119
+ if (/\b429\b|rate.?limit|too many requests/i.test(message))
120
+ return "rate";
121
+ if (/\b404\b|model.{0,40}(not found|does not exist|not exist|unknown|invalid)|no such model|unknown model/i.test(message))
122
+ return "model";
123
+ if (/\b5\d\d\b|overloaded|bad gateway|service unavailable/i.test(message))
124
+ return "server";
125
+ if (/fetch failed|ECONNREFUSED|ECONNRESET|ENOTFOUND|EAI_AGAIN|ETIMEDOUT|network|timed? ?out|socket hang up|certificate/i.test(message))
126
+ return "network";
127
+ return "other";
128
+ }
129
+ /** The provider's own words in a failed call's detail (its JSON `message`), or null; cut short where the detail was. */
130
+ export function providerMessage(detail) {
131
+ const found = /"message"\s*:\s*"((?:[^"\\]|\\.)*)("|$)/.exec(detail);
132
+ if (!found?.[1].trim())
133
+ return null;
134
+ let said = found[1];
135
+ try {
136
+ said = JSON.parse(`"${said.replace(/\\$/, "")}"`);
137
+ }
138
+ catch { }
139
+ return found[2] ? said : `${said}…`;
140
+ }
141
+ /**
142
+ * An undo aimed at one write — a toast's — refused because the thing changed
143
+ * again since. The marker survives IPC's message wrapping, so the renderer can
144
+ * say it in the person's language.
145
+ */
146
+ export const STALE_UNDO = "[stale-undo]";
147
+ export class StaleUndoError extends Error {
148
+ entityId;
149
+ constructor(entityId) {
150
+ super(`${STALE_UNDO} ${entityId} changed again after that edit; undo it from History instead`);
151
+ this.entityId = entityId;
152
+ this.name = "StaleUndoError";
153
+ }
154
+ }
155
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,58 @@
1
+ import type { FieldValue, Item, Patch } from "./types.js";
2
+ /**
3
+ * Every attribute a view can filter, sort or group by is a field. Built-in
4
+ * fields are columns on `items` and are the same for every project; custom
5
+ * fields are rows in `fields` and their values live in `item_values`.
6
+ */
7
+ export type FieldType = "text" | "number" | "date" | "select" | "checkbox" | "labels" | "item";
8
+ /** The types a user may create. The rest are built-in only. */
9
+ export declare const CUSTOM_FIELD_TYPES: readonly FieldType[];
10
+ /** A checkbox is stored only when ticked; unticked is the absence of a value. */
11
+ export declare const CHECKED = 1;
12
+ export interface FieldOption {
13
+ id: string;
14
+ name: string;
15
+ description: string | null;
16
+ rank: number;
17
+ }
18
+ export interface FieldDef {
19
+ id: string;
20
+ /** Null for a built-in: it exists in every project. */
21
+ projectId: string | null;
22
+ name: string;
23
+ type: FieldType;
24
+ builtin: boolean;
25
+ /** Fixed options for a select. Empty when they come from `optionsFrom`. */
26
+ options: FieldOption[];
27
+ /** Built-in selects whose options are rows elsewhere; the caller resolves them. */
28
+ optionsFrom?: "boards" | "epics";
29
+ /** Derived or system-owned: shown and sortable, never written. */
30
+ readonly: boolean;
31
+ can: {
32
+ filter: boolean;
33
+ sort: boolean;
34
+ group: boolean;
35
+ };
36
+ rank: number;
37
+ /** Computed by a plugin from what it keeps (a ticket's spend, say); its value rides on `item.fields` when items are read. */
38
+ derived?: boolean;
39
+ /** How a number reads: `usd` is money. */
40
+ unit?: "usd";
41
+ }
42
+ export type BuiltinFieldId = "title" | "status" | "workType" | "priority" | "epic" | "labels" | "board" | "updated" | "key" | "provenance";
43
+ /** The fields every project has, in display order. Ids are reserved: a custom field can never claim one. */
44
+ export declare const BUILTIN_FIELDS: readonly FieldDef[];
45
+ export declare const BUILTIN_FIELD_IDS: Set<string>;
46
+ export declare const isBuiltinFieldId: (id: string) => id is BuiltinFieldId;
47
+ /** The empty-value sentinel a group key uses, and the literal a filter may name. */
48
+ export declare const EMPTY_KEY = "none";
49
+ /**
50
+ * The raw value of a field on an item, built-in or custom. Labels are the one
51
+ * multi-valued field; everything else is a scalar or null.
52
+ */
53
+ export declare function fieldValueOf(item: Item, fieldId: string): FieldValue | FieldValue[] | null;
54
+ /** Which column or swimlane an item falls into for a groupable field. */
55
+ export declare function groupKeyOf(item: Item, fieldId: string): string;
56
+ /** The patch a drop into `key` writes, for a groupable field; null when the field cannot be written. */
57
+ export declare function patchForGroup(fieldId: string, key: string, def: FieldDef | undefined): Patch | null;
58
+ //# sourceMappingURL=fields.d.ts.map