@ablehi/error-contract 0.0.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.
@@ -0,0 +1,151 @@
1
+ declare const ABLEHI_ERROR_DIGEST_SCHEMA_VERSION = "ablehi.error.digest.v1";
2
+ declare const GENERIC_ERROR_CODE = "INTERNAL_ERROR";
3
+ type ErrorSourceProject = "ablehi-server" | "ablehi-cf-execution-runtime" | "agentIntegrations";
4
+ type ErrorScope = "api_request" | "flow_run" | "flow_step" | "integration_invocation" | "native_runtime";
5
+ type ErrorCategory = "validation" | "auth" | "permission" | "not_found" | "rate_limit" | "provider" | "network" | "runtime" | "internal" | "canceled";
6
+ type ErrorSeverity = "info" | "warning" | "error";
7
+ type PublicDisplayTone = "neutral" | "warning" | "error";
8
+ type AgentRepairability = "none" | "retryable" | "edit_flow" | "connection_reauth" | "user_action" | "internal_only";
9
+ type SentryDiagnosticDisposition = "always" | "never";
10
+ type ErrorSourceRef = {
11
+ project: ErrorSourceProject;
12
+ component: string;
13
+ };
14
+ type ErrorSubjectRef = {
15
+ workspaceId?: string;
16
+ flowId?: string;
17
+ flowVersionId?: string;
18
+ flowRunId?: string;
19
+ stepId?: string;
20
+ nodeId?: string;
21
+ integrationId?: string;
22
+ actionId?: string;
23
+ toolRef?: string;
24
+ connectionId?: string;
25
+ requestId?: string;
26
+ traceRef?: string;
27
+ };
28
+ type ErrorAttemptRef = {
29
+ number: number;
30
+ };
31
+ type ErrorIssue = {
32
+ code: string;
33
+ path?: string[];
34
+ messageKey?: string;
35
+ params?: Record<string, string | number | boolean | null>;
36
+ };
37
+ type SafeProviderEvidence = {
38
+ httpStatus?: number;
39
+ effectiveStatus?: string;
40
+ providerCode?: string;
41
+ requestId?: string;
42
+ responseHeaders?: Record<string, string>;
43
+ truncated?: true;
44
+ };
45
+ type ErrorEvidence = {
46
+ issues?: ErrorIssue[];
47
+ provider?: SafeProviderEvidence;
48
+ truncated?: true;
49
+ };
50
+ type AblehiErrorDigest = {
51
+ schemaVersion: typeof ABLEHI_ERROR_DIGEST_SCHEMA_VERSION;
52
+ errorId: string;
53
+ code: string;
54
+ category: ErrorCategory;
55
+ severity: ErrorSeverity;
56
+ retryable: boolean;
57
+ source: ErrorSourceRef;
58
+ scope: ErrorScope;
59
+ subject: ErrorSubjectRef;
60
+ attempt?: ErrorAttemptRef;
61
+ occurredAt: string;
62
+ evidence?: ErrorEvidence;
63
+ };
64
+ type IntegrationErrorInput = {
65
+ source: ErrorSourceRef;
66
+ scope: "flow_step" | "integration_invocation";
67
+ subject: ErrorSubjectRef;
68
+ attempt?: ErrorAttemptRef;
69
+ code: string;
70
+ category?: ErrorCategory;
71
+ retryable?: boolean;
72
+ occurredAt: string;
73
+ evidence?: ErrorEvidence | Record<string, unknown>;
74
+ };
75
+ type NativeErrorInput = {
76
+ source: ErrorSourceRef;
77
+ scope: "api_request" | "native_runtime" | "flow_run";
78
+ subject: ErrorSubjectRef;
79
+ code?: string;
80
+ category?: ErrorCategory;
81
+ retryable?: boolean;
82
+ occurredAt: string;
83
+ evidence?: ErrorEvidence | Record<string, unknown>;
84
+ };
85
+ type ErrorNormalizationInput = IntegrationErrorInput | NativeErrorInput;
86
+ type PublicErrorActionHint = {
87
+ type: "reconnect";
88
+ connectionId?: string;
89
+ } | {
90
+ type: "retry";
91
+ } | {
92
+ type: "edit_flow";
93
+ } | {
94
+ type: "contact_support";
95
+ };
96
+ type PublicErrorView = {
97
+ errorId: string;
98
+ code: string;
99
+ category: ErrorCategory;
100
+ retryable: boolean;
101
+ displayTone: PublicDisplayTone;
102
+ message: {
103
+ titleKey: string;
104
+ bodyKey: string;
105
+ params?: Record<string, string | number | boolean>;
106
+ };
107
+ actionHints: PublicErrorActionHint[];
108
+ };
109
+ type AgentErrorView = {
110
+ errorId: string;
111
+ code: string;
112
+ category: ErrorCategory;
113
+ retryable: boolean;
114
+ repairability: AgentRepairability;
115
+ scope: ErrorScope;
116
+ subject: ErrorSubjectRef;
117
+ evidence?: ErrorEvidence;
118
+ };
119
+ type ErrorRegistryEntry = {
120
+ code: string;
121
+ category: ErrorCategory;
122
+ severity: ErrorSeverity;
123
+ retryable: boolean;
124
+ displayTone: PublicDisplayTone;
125
+ publicMessage: {
126
+ titleKey: string;
127
+ bodyKey: string;
128
+ };
129
+ actionHints: PublicErrorActionHint[];
130
+ repairability: AgentRepairability;
131
+ sentryDiagnostics: {
132
+ logs: SentryDiagnosticDisposition;
133
+ issues: SentryDiagnosticDisposition;
134
+ };
135
+ };
136
+ type ErrorContractParseResult<T> = {
137
+ ok: true;
138
+ value: T;
139
+ } | {
140
+ ok: false;
141
+ reason: string;
142
+ };
143
+ declare function lookupErrorRegistryEntry(code: string): ErrorRegistryEntry;
144
+ declare function listErrorRegistryEntries(): ErrorRegistryEntry[];
145
+ declare function normalizeErrorDigest(input: ErrorNormalizationInput): AblehiErrorDigest;
146
+ declare function isAblehiErrorDigest(value: unknown): value is AblehiErrorDigest;
147
+ declare function parseAblehiErrorDigest(value: unknown): ErrorContractParseResult<AblehiErrorDigest>;
148
+ declare function projectPublicErrorView(digest: AblehiErrorDigest): PublicErrorView;
149
+ declare function projectAgentErrorView(digest: AblehiErrorDigest): AgentErrorView;
150
+
151
+ export { ABLEHI_ERROR_DIGEST_SCHEMA_VERSION, type AblehiErrorDigest, type AgentErrorView, type AgentRepairability, type ErrorAttemptRef, type ErrorCategory, type ErrorContractParseResult, type ErrorEvidence, type ErrorIssue, type ErrorNormalizationInput, type ErrorRegistryEntry, type ErrorScope, type ErrorSeverity, type ErrorSourceProject, type ErrorSourceRef, type ErrorSubjectRef, GENERIC_ERROR_CODE, type IntegrationErrorInput, type NativeErrorInput, type PublicDisplayTone, type PublicErrorActionHint, type PublicErrorView, type SafeProviderEvidence, type SentryDiagnosticDisposition, isAblehiErrorDigest, listErrorRegistryEntries, lookupErrorRegistryEntry, normalizeErrorDigest, parseAblehiErrorDigest, projectAgentErrorView, projectPublicErrorView };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ var R="ablehi.error.digest.v1",_="INTERNAL_ERROR",h=new Set(["content-type","retry-after","x-request-id","request-id","x-correlation-id"]),A=new Set(["ablehi-server","ablehi-cf-execution-runtime","agentIntegrations"]),N=new Set(["api_request","flow_run","flow_step","integration_invocation","native_runtime"]),C=new Set(["validation","auth","permission","not_found","rate_limit","provider","network","runtime","internal","canceled"]),k=new Set(["info","warning","error"]),I=["workspaceId","flowId","flowVersionId","flowRunId","stepId","nodeId","integrationId","actionId","toolRef","connectionId","requestId","traceRef"],j=["workspaceId","flowId","flowVersionId","flowRunId","stepId","nodeId","integrationId","actionId","connectionId"],w=[o(_,{category:"internal",severity:"error",retryable:!1,displayTone:"error",titleKey:"errors.generic.title",bodyKey:"errors.generic.body",actionHints:[{type:"contact_support"}],repairability:"internal_only",issues:"always"}),o("VALIDATION_ERROR",{category:"validation",severity:"warning",retryable:!1,displayTone:"warning",titleKey:"errors.validation.title",bodyKey:"errors.validation.body",actionHints:[],repairability:"user_action",issues:"never"}),o("AUTH_INVALID",S("errors.auth.invalid.title","errors.auth.invalid.body")),o("AUTH_EXPIRED",S("errors.auth.expired.title","errors.auth.expired.body")),o("PERMISSION_DENIED",{category:"permission",severity:"warning",retryable:!1,displayTone:"warning",titleKey:"errors.permissionDenied.title",bodyKey:"errors.permissionDenied.body",actionHints:[],repairability:"user_action",issues:"never"}),o("NOT_FOUND",{category:"not_found",severity:"warning",retryable:!1,displayTone:"warning",titleKey:"errors.notFound.title",bodyKey:"errors.notFound.body",actionHints:[],repairability:"user_action",issues:"never"}),o("RATE_LIMITED",{category:"rate_limit",severity:"warning",retryable:!0,displayTone:"warning",titleKey:"errors.rateLimited.title",bodyKey:"errors.rateLimited.body",actionHints:[{type:"retry"}],repairability:"retryable",issues:"never"}),o("PROVIDER_ERROR",b("errors.provider.title","errors.provider.body")),o("NETWORK_UNREACHABLE",b("errors.network.title","errors.network.body")),o("HTTP_REQUEST_FAILED",b("errors.httpRequestFailed.title","errors.httpRequestFailed.body")),o("TOOL_NOT_FOUND",c("errors.toolNotFound.title","errors.toolNotFound.body")),o("FILE_NOT_FOUND",c("errors.fileNotFound.title","errors.fileNotFound.body")),o("FILE_RUNTIME_UNAVAILABLE",g("errors.fileRuntimeUnavailable.title","errors.fileRuntimeUnavailable.body")),o("FILE_TOO_LARGE",c("errors.fileTooLarge.title","errors.fileTooLarge.body")),o("FILE_STORE_QUOTA_EXCEEDED",c("errors.fileQuota.title","errors.fileQuota.body")),o("TOOL_RUNTIME_UNAVAILABLE",g("errors.toolRuntimeUnavailable.title","errors.toolRuntimeUnavailable.body")),o("TOOL_EXECUTION_FAILED",b("errors.toolExecutionFailed.title","errors.toolExecutionFailed.body")),o("HTTP_RUNTIME_UNAVAILABLE",g("errors.httpRuntimeUnavailable.title","errors.httpRuntimeUnavailable.body")),o("FLOW_RUN_CONNECTION_AUTH_MISMATCH",u("errors.connection.authMismatch.title","errors.connection.authMismatch.body")),o("CONNECTION_AUTH_PROFILE_UNSUPPORTED",u("errors.connection.profileUnsupported.title","errors.connection.profileUnsupported.body")),o("RUNTIME_CREDENTIAL_AUTH_MISMATCH",u("errors.connection.runtimeAuthMismatch.title","errors.connection.runtimeAuthMismatch.body")),o("EGRESS_GRANT_AUTH_MISMATCH",u("errors.connection.egressAuthMismatch.title","errors.connection.egressAuthMismatch.body")),o("RUNTIME_CREDENTIAL_REFRESH_FAILED",u("errors.connection.refreshFailed.title","errors.connection.refreshFailed.body")),o("CONNECTION_NOT_FOUND",u("errors.connection.notFound.title","errors.connection.notFound.body")),o("AMBIGUOUS_CONNECTION",u("errors.connection.ambiguous.title","errors.connection.ambiguous.body")),o("CREDENTIAL_UNAVAILABLE",u("errors.connection.credentialUnavailable.title","errors.connection.credentialUnavailable.body")),o("TRUSTED_SDK_CREDENTIAL_UNAVAILABLE",u("errors.connection.trustedCredentialUnavailable.title","errors.connection.trustedCredentialUnavailable.body")),o("TRUSTED_SDK_CREDENTIAL_FORBIDDEN",u("errors.connection.trustedCredentialForbidden.title","errors.connection.trustedCredentialForbidden.body")),o("TRUSTED_SDK_CREDENTIAL_RESOLUTION_FAILED",u("errors.connection.trustedCredentialResolutionFailed.title","errors.connection.trustedCredentialResolutionFailed.body")),o("REQUEST_MULTIPART_FILE_INVALID",c("errors.requestMultipartFileInvalid.title","errors.requestMultipartFileInvalid.body")),o("REQUEST_PATH_BINDING_INVALID",c("errors.requestPathBindingInvalid.title","errors.requestPathBindingInvalid.body")),o("REQUEST_PLAN_INVALID",c("errors.requestPlanInvalid.title","errors.requestPlanInvalid.body")),o("INTERPRETER_DATA_REF_UNRESOLVED",c("errors.interpreterDataRefUnresolved.title","errors.interpreterDataRefUnresolved.body")),o("FLOW_NODE_UNSUPPORTED",c("errors.flowNodeUnsupported.title","errors.flowNodeUnsupported.body")),o("FLOW_INTERPRETER_INVALID_IR",c("errors.flowInterpreterInvalidIr.title","errors.flowInterpreterInvalidIr.body")),o("FLOW_ACTION_OUTPUT_PROJECTION_FAILED",c("errors.flowActionOutputProjectionFailed.title","errors.flowActionOutputProjectionFailed.body")),o("CF_RUNTIME_UNKNOWN_FAILURE",g("errors.cfRuntimeUnknownFailure.title","errors.cfRuntimeUnknownFailure.body")),o("RUN_DISPATCH_UNAVAILABLE",g("errors.runDispatchUnavailable.title","errors.runDispatchUnavailable.body")),o("WFP_SCRIPT_NOT_READY",g("errors.wfpScriptNotReady.title","errors.wfpScriptNotReady.body")),o("FLOW_RUN_NOT_FOUND",c("errors.flowRunNotFound.title","errors.flowRunNotFound.body")),o("WORKSPACE_NOT_FOUND",c("errors.workspaceNotFound.title","errors.workspaceNotFound.body"))],m=new Map(w.map(e=>[e.code,e])),T=m.get(_);function O(e){return m.get(e)??T}function ue(){return w.map(e=>U(e))}function fe(e){let r=m.get(e.code??"")??T,t=K(e.source),n=H(e.scope),s=x(e.subject),f=q("attempt"in e?e.attempt:void 0),E=re(e.occurredAt),p=z(e.evidence),d={schemaVersion:R,errorId:oe({scope:n,subject:V(s),attempt:f?.number??"__none__",code:r.code}),code:r.code,category:r.category,severity:r.severity,retryable:r.retryable,source:t,scope:n,subject:s,occurredAt:E};return f!==void 0&&(d.attempt=f),p!==void 0&&(d.evidence=p),d}function ye(e){return P(e).ok}function P(e){if(!a(e))return i("digest must be a JSON object");let r=l(e,["schemaVersion","errorId","code","category","severity","retryable","source","scope","subject","attempt","occurredAt","evidence"]);if(r!==void 0)return i(`digest does not accept the "${r}" field`);if(e.schemaVersion!==R)return i("digest schemaVersion is invalid");if(typeof e.errorId!="string"||e.errorId.length===0)return i("digest errorId must be a non-empty string");if(typeof e.code!="string"||!m.has(e.code))return i("digest code is not registered");if(!ce(e.category))return i("digest category is invalid");if(!de(e.severity))return i("digest severity is invalid");if(typeof e.retryable!="boolean")return i("digest retryable must be boolean");let t=F(e.source);if(!t.ok)return t;let n=L(e.scope);if(!n.ok)return n;let s=M(e.subject);if(!s.ok)return s;let f;if(e.attempt!==void 0){let d=B(e.attempt);if(!d.ok)return d;f=d.value}if(typeof e.occurredAt!="string"||!D(e.occurredAt))return i("digest occurredAt must be an ISO timestamp");let E;if(e.evidence!==void 0){let d=J(e.evidence);if(!d.ok)return d;E=d.value}let p={schemaVersion:R,errorId:e.errorId,code:e.code,category:e.category,severity:e.severity,retryable:e.retryable,source:t.value,scope:n.value,subject:s.value,occurredAt:e.occurredAt};return f!==void 0&&(p.attempt=f),E!==void 0&&(p.evidence=E),{ok:!0,value:p}}function le(e){let r=O(e.code),t=Z(e);return{errorId:e.errorId,code:r.code,category:r.category,retryable:r.retryable,displayTone:r.displayTone,message:{titleKey:r.publicMessage.titleKey,bodyKey:r.publicMessage.bodyKey,...Object.keys(t).length===0?{}:{params:t}},actionHints:r.actionHints.map(n=>n.type==="reconnect"&&e.subject.connectionId!==void 0?{...n,connectionId:e.subject.connectionId}:{...n})}}function pe(e){let r=O(e.code),t={errorId:e.errorId,code:r.code,category:r.category,retryable:r.retryable,repairability:r.repairability,scope:e.scope,subject:{...e.subject}};return e.evidence!==void 0&&(t.evidence=ee(e.evidence)),t}function o(e,r){return{code:e,category:r.category,severity:r.severity,retryable:r.retryable,displayTone:r.displayTone,publicMessage:{titleKey:r.titleKey,bodyKey:r.bodyKey},actionHints:r.actionHints,repairability:r.repairability,sentryDiagnostics:{logs:"always",issues:r.issues}}}function S(e,r){return{category:"auth",severity:"warning",retryable:!1,displayTone:"warning",titleKey:e,bodyKey:r,actionHints:[],repairability:"user_action",issues:"never"}}function u(e,r){return{category:"auth",severity:"warning",retryable:!1,displayTone:"warning",titleKey:e,bodyKey:r,actionHints:[{type:"reconnect"}],repairability:"connection_reauth",issues:"never"}}function c(e,r){return{category:"validation",severity:"warning",retryable:!1,displayTone:"warning",titleKey:e,bodyKey:r,actionHints:[{type:"edit_flow"}],repairability:"edit_flow",issues:"never"}}function b(e,r){return{category:"provider",severity:"warning",retryable:!0,displayTone:"warning",titleKey:e,bodyKey:r,actionHints:[{type:"retry"}],repairability:"retryable",issues:"never"}}function g(e,r){return{category:"runtime",severity:"error",retryable:!0,displayTone:"error",titleKey:e,bodyKey:r,actionHints:[{type:"retry"}],repairability:"retryable",issues:"always"}}function U(e){return{...e,publicMessage:{...e.publicMessage},actionHints:e.actionHints.map(r=>({...r})),sentryDiagnostics:{...e.sentryDiagnostics}}}function K(e){return{project:A.has(e.project)?e.project:"ablehi-server",component:y(e.component,"unknown")}}function F(e){if(!a(e))return i("digest source must be a JSON object");let r=l(e,["project","component"]);return r!==void 0?i(`digest source does not accept the "${r}" field`):se(e.project)?typeof e.component!="string"||e.component.length===0?i("digest source component must be a non-empty string"):{ok:!0,value:{project:e.project,component:e.component}}:i("digest source project is invalid")}function H(e){return N.has(e)?e:"native_runtime"}function L(e){return ae(e)?{ok:!0,value:e}:i("digest scope is invalid")}function x(e){let r={};for(let t of I){let n=e[t];typeof n=="string"&&n.length>0&&(r[t]=y(n,n))}return r}function V(e){let r={};for(let t of j){let n=e[t];n!==void 0&&(r[t]=n)}return r}function M(e){if(!a(e))return i("digest subject must be a JSON object");let r=l(e,I);if(r!==void 0)return i(`digest subject does not accept the "${r}" field`);let t={};for(let n of I){let s=e[n];if(s!==void 0){if(typeof s!="string"||s.length===0)return i(`digest subject ${n} must be a non-empty string`);t[n]=s}}return{ok:!0,value:t}}function q(e){if(!(e===void 0||typeof e.number!="number"||!Number.isInteger(e.number)||e.number<=0))return{number:e.number}}function B(e){if(!a(e))return i("digest attempt must be a JSON object");let r=l(e,["number"]);return r!==void 0?i(`digest attempt does not accept the "${r}" field`):typeof e.number!="number"||!Number.isInteger(e.number)||e.number<=0?i("digest attempt number must be a positive integer"):{ok:!0,value:{number:e.number}}}function z(e){if(!a(e))return;let r={},t=$(e.issues);t!==void 0&&(r.issues=t);let n=W(e.provider);return n!==void 0&&(r.provider=n),e.truncated===!0&&(r.truncated=!0),Object.keys(r).length===0?void 0:r}function J(e){if(!a(e))return i("digest evidence must be a JSON object");let r=l(e,["issues","provider","truncated"]);if(r!==void 0)return i(`digest evidence does not accept the "${r}" field`);let t={};if(e.issues!==void 0){let n=G(e.issues);if(!n.ok)return n;t.issues=n.value}if(e.provider!==void 0){let n=Y(e.provider);if(!n.ok)return n;t.provider=n.value}if(e.truncated!==void 0){if(e.truncated!==!0)return i("digest evidence truncated must be true when present");t.truncated=!0}return{ok:!0,value:t}}function $(e){if(!Array.isArray(e))return;let r=[];for(let t of e.slice(0,10)){if(!a(t)||typeof t.code!="string")continue;let n={code:y(t.code,"issue")};if(Array.isArray(t.path)&&(n.path=t.path.filter(s=>typeof s=="string"&&s.length>0).slice(0,8)),typeof t.messageKey=="string"&&t.messageKey.length>0&&(n.messageKey=y(t.messageKey,t.messageKey)),a(t.params)){let s=te(t.params);s!==void 0&&(n.params=s)}r.push(n)}return r.length===0?void 0:r}function G(e){if(!Array.isArray(e))return i("digest evidence issues must be an array");if(e.length>10)return i("digest evidence issues exceeds the item limit");let r=[];for(let t of e){if(!a(t))return i("digest evidence issue must be a JSON object");let n=l(t,["code","path","messageKey","params"]);if(n!==void 0)return i(`digest evidence issue does not accept the "${n}" field`);if(typeof t.code!="string"||t.code.length===0)return i("digest evidence issue code must be a non-empty string");let s={code:t.code};if(t.path!==void 0){if(!Array.isArray(t.path)||t.path.some(f=>typeof f!="string"||f.length===0))return i("digest evidence issue path must be a string array");s.path=[...t.path]}if(t.messageKey!==void 0){if(typeof t.messageKey!="string"||t.messageKey.length===0)return i("digest evidence issue messageKey must be a non-empty string");s.messageKey=t.messageKey}if(t.params!==void 0){if(!a(t.params)||!ne(t.params))return i("digest evidence issue params must be scalar");s.params={...t.params}}r.push(s)}return{ok:!0,value:r}}function W(e){if(!a(e))return;let r={};typeof e.httpStatus=="number"&&Number.isInteger(e.httpStatus)&&(r.httpStatus=e.httpStatus),typeof e.effectiveStatus=="string"&&e.effectiveStatus.length>0&&(r.effectiveStatus=y(e.effectiveStatus,e.effectiveStatus)),typeof e.providerCode=="string"&&e.providerCode.length>0&&(r.providerCode=y(e.providerCode,e.providerCode)),typeof e.requestId=="string"&&e.requestId.length>0&&(r.requestId=y(e.requestId,e.requestId));let t=Q(e.responseHeaders);return t!==void 0&&(r.responseHeaders=t),e.truncated===!0&&(r.truncated=!0),Object.keys(r).length===0?void 0:r}function Y(e){if(!a(e))return i("digest provider evidence must be a JSON object");let r=l(e,["httpStatus","effectiveStatus","providerCode","requestId","responseHeaders","truncated"]);if(r!==void 0)return i(`digest provider evidence does not accept the "${r}" field`);let t={};if(e.httpStatus!==void 0){if(typeof e.httpStatus!="number"||!Number.isInteger(e.httpStatus))return i("digest provider httpStatus must be an integer");t.httpStatus=e.httpStatus}if(e.effectiveStatus!==void 0){if(typeof e.effectiveStatus!="string"||e.effectiveStatus.length===0)return i("digest provider effectiveStatus must be a non-empty string");t.effectiveStatus=e.effectiveStatus}if(e.providerCode!==void 0){if(typeof e.providerCode!="string"||e.providerCode.length===0)return i("digest provider providerCode must be a non-empty string");t.providerCode=e.providerCode}if(e.requestId!==void 0){if(typeof e.requestId!="string"||e.requestId.length===0)return i("digest provider requestId must be a non-empty string");t.requestId=e.requestId}if(e.responseHeaders!==void 0){let n=X(e.responseHeaders);if(!n.ok)return n;t.responseHeaders=n.value}if(e.truncated!==void 0){if(e.truncated!==!0)return i("digest provider truncated must be true when present");t.truncated=!0}return{ok:!0,value:t}}function Q(e){if(!a(e))return;let r={};for(let[t,n]of Object.entries(e)){let s=t.toLowerCase();h.has(s)&&typeof n=="string"&&(r[s]=y(n,n))}return Object.keys(r).length===0?void 0:r}function X(e){if(!a(e))return i("digest provider responseHeaders must be a JSON object");let r={};for(let[t,n]of Object.entries(e)){if(!h.has(t))return i(`digest provider responseHeaders does not accept "${t}"`);if(typeof n!="string")return i("digest provider responseHeaders values must be strings");r[t]=n}return{ok:!0,value:r}}function Z(e){let r={},t=e.evidence?.issues?.length??0;t>0&&(r.issueCount=t);let n=e.evidence?.provider?.responseHeaders?.["retry-after"];return n!==void 0&&n.length>0&&(r.retryAfter=n),r}function ee(e){return{...e.issues===void 0?{}:{issues:e.issues.map(r=>({...r,...r.path===void 0?{}:{path:[...r.path]},...r.params===void 0?{}:{params:{...r.params}}}))},...e.provider===void 0?{}:{provider:{...e.provider,...e.provider.responseHeaders===void 0?{}:{responseHeaders:{...e.provider.responseHeaders}}}},...e.truncated===!0?{truncated:!0}:{}}}function re(e){return D(e)?e:"1970-01-01T00:00:00.000Z"}function D(e){let r=Date.parse(e);return Number.isFinite(r)&&new Date(r).toISOString()===e}function y(e,r){let t=e.trim(),n=t.length===0?r:t;return n.length<=200?n:n.slice(0,200)}function te(e){let r={};for(let[t,n]of Object.entries(e))(n===null||typeof n=="string"||typeof n=="number"||typeof n=="boolean")&&(r[t]=n);return Object.keys(r).length===0?void 0:r}function ne(e){return Object.values(e).every(r=>r===null||typeof r=="string"||typeof r=="number"||typeof r=="boolean")}function oe(e){return`err_${ie(v(e))}`}function v(e){if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(t=>v(t)).join(",")}]`;let r=e;return`{${Object.keys(r).filter(t=>r[t]!==void 0).sort().map(t=>`${JSON.stringify(t)}:${v(r[t])}`).join(",")}}`}function ie(e){let r=0xcbf29ce484222325n,t=0x100000001b3n,n=0xffffffffffffffffn;for(let s=0;s<e.length;s+=1)r^=BigInt(e.charCodeAt(s)),r=r*t&n;return r.toString(36)}function i(e){return{ok:!1,reason:e}}function a(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function l(e,r){return Object.keys(e).find(t=>!r.includes(t))}function se(e){return typeof e=="string"&&A.has(e)}function ae(e){return typeof e=="string"&&N.has(e)}function ce(e){return typeof e=="string"&&C.has(e)}function de(e){return typeof e=="string"&&k.has(e)}export{R as ABLEHI_ERROR_DIGEST_SCHEMA_VERSION,_ as GENERIC_ERROR_CODE,ye as isAblehiErrorDigest,ue as listErrorRegistryEntries,O as lookupErrorRegistryEntry,fe as normalizeErrorDigest,P as parseAblehiErrorDigest,pe as projectAgentErrorView,le as projectPublicErrorView};
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@ablehi/error-contract",
3
+ "version": "0.0.1",
4
+ "description": "Ablehi normalized system error contract.",
5
+ "license": "Apache-2.0",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "type": "module",
10
+ "main": "dist/index.js",
11
+ "types": "dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
16
+ },
17
+ "./package.json": "./package.json"
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "devDependencies": {
23
+ "@typescript-eslint/eslint-plugin": "^8.62.0",
24
+ "@typescript-eslint/parser": "^8.62.0",
25
+ "eslint": "^10.5.0",
26
+ "tsup": "^8.5.1",
27
+ "typescript": "^6.0.3",
28
+ "vitest": "^4.1.9"
29
+ },
30
+ "scripts": {
31
+ "build": "tsup",
32
+ "typecheck": "tsc --noEmit -p tsconfig.json",
33
+ "test": "vitest run --passWithNoTests",
34
+ "lint": "eslint src --ext .ts",
35
+ "check": "pnpm build && pnpm typecheck && pnpm lint && pnpm test"
36
+ }
37
+ }