@databricks/sdk-core 0.0.0-dev → 0.1.0-dev.2

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 (164) hide show
  1. package/LICENSE +203 -0
  2. package/README.md +11 -1
  3. package/dist/api/execute.d.ts +12 -0
  4. package/dist/api/execute.d.ts.map +1 -0
  5. package/dist/api/execute.js +77 -0
  6. package/dist/api/execute.js.map +1 -0
  7. package/dist/api/index.d.ts +12 -0
  8. package/dist/api/index.d.ts.map +1 -0
  9. package/dist/api/index.js +8 -0
  10. package/dist/api/index.js.map +1 -0
  11. package/dist/api/limiter.d.ts +9 -0
  12. package/dist/api/limiter.d.ts.map +1 -0
  13. package/dist/api/limiter.js +2 -0
  14. package/dist/api/limiter.js.map +1 -0
  15. package/dist/api/options.d.ts +22 -0
  16. package/dist/api/options.d.ts.map +1 -0
  17. package/dist/api/options.js +2 -0
  18. package/dist/api/options.js.map +1 -0
  19. package/dist/api/retrier.d.ts +58 -0
  20. package/dist/api/retrier.d.ts.map +1 -0
  21. package/dist/api/retrier.js +70 -0
  22. package/dist/api/retrier.js.map +1 -0
  23. package/dist/apierror/apierror.d.ts +53 -0
  24. package/dist/apierror/apierror.d.ts.map +1 -0
  25. package/dist/apierror/apierror.js +217 -0
  26. package/dist/apierror/apierror.js.map +1 -0
  27. package/dist/apierror/codes/codes.d.ts +140 -0
  28. package/dist/apierror/codes/codes.d.ts.map +1 -0
  29. package/dist/apierror/codes/codes.js +167 -0
  30. package/dist/apierror/codes/codes.js.map +1 -0
  31. package/dist/apierror/codes/index.d.ts +7 -0
  32. package/dist/apierror/codes/index.d.ts.map +1 -0
  33. package/dist/apierror/codes/index.js +7 -0
  34. package/dist/apierror/codes/index.js.map +1 -0
  35. package/dist/apierror/details.d.ts +177 -0
  36. package/dist/apierror/details.d.ts.map +1 -0
  37. package/dist/apierror/details.js +250 -0
  38. package/dist/apierror/details.js.map +1 -0
  39. package/dist/apierror/index.d.ts +8 -0
  40. package/dist/apierror/index.d.ts.map +1 -0
  41. package/dist/apierror/index.js +7 -0
  42. package/dist/apierror/index.js.map +1 -0
  43. package/dist/clientinfo/agent.d.ts +56 -0
  44. package/dist/clientinfo/agent.d.ts.map +1 -0
  45. package/dist/clientinfo/agent.js +114 -0
  46. package/dist/clientinfo/agent.js.map +1 -0
  47. package/dist/clientinfo/base.d.ts +39 -0
  48. package/dist/clientinfo/base.d.ts.map +1 -0
  49. package/dist/clientinfo/base.js +62 -0
  50. package/dist/clientinfo/base.js.map +1 -0
  51. package/dist/clientinfo/clientinfo.d.ts +61 -0
  52. package/dist/clientinfo/clientinfo.d.ts.map +1 -0
  53. package/dist/clientinfo/clientinfo.js +96 -0
  54. package/dist/clientinfo/clientinfo.js.map +1 -0
  55. package/dist/clientinfo/default.browser.d.ts +17 -0
  56. package/dist/clientinfo/default.browser.d.ts.map +1 -0
  57. package/dist/clientinfo/default.browser.js +20 -0
  58. package/dist/clientinfo/default.browser.js.map +1 -0
  59. package/dist/clientinfo/default.d.ts +14 -0
  60. package/dist/clientinfo/default.d.ts.map +1 -0
  61. package/dist/clientinfo/default.js +104 -0
  62. package/dist/clientinfo/default.js.map +1 -0
  63. package/dist/clientinfo/index.browser.d.ts +5 -0
  64. package/dist/clientinfo/index.browser.d.ts.map +1 -0
  65. package/dist/clientinfo/index.browser.js +4 -0
  66. package/dist/clientinfo/index.browser.js.map +1 -0
  67. package/dist/clientinfo/index.d.ts +5 -0
  68. package/dist/clientinfo/index.d.ts.map +1 -0
  69. package/dist/clientinfo/index.js +4 -0
  70. package/dist/clientinfo/index.js.map +1 -0
  71. package/dist/http/http.d.ts +40 -0
  72. package/dist/http/http.d.ts.map +1 -0
  73. package/dist/http/http.js +37 -0
  74. package/dist/http/http.js.map +1 -0
  75. package/dist/http/index.d.ts +8 -0
  76. package/dist/http/index.d.ts.map +1 -0
  77. package/dist/http/index.js +7 -0
  78. package/dist/http/index.js.map +1 -0
  79. package/dist/index.d.ts +6 -0
  80. package/dist/index.d.ts.map +1 -0
  81. package/dist/index.js +7 -0
  82. package/dist/index.js.map +1 -0
  83. package/dist/logger/index.d.ts +8 -0
  84. package/dist/logger/index.d.ts.map +1 -0
  85. package/dist/logger/index.js +7 -0
  86. package/dist/logger/index.js.map +1 -0
  87. package/dist/logger/logger.d.ts +49 -0
  88. package/dist/logger/logger.d.ts.map +1 -0
  89. package/dist/logger/logger.js +65 -0
  90. package/dist/logger/logger.js.map +1 -0
  91. package/dist/profiles/errors.d.ts +17 -0
  92. package/dist/profiles/errors.d.ts.map +1 -0
  93. package/dist/profiles/errors.js +19 -0
  94. package/dist/profiles/errors.js.map +1 -0
  95. package/dist/profiles/index.browser.d.ts +10 -0
  96. package/dist/profiles/index.browser.d.ts.map +1 -0
  97. package/dist/profiles/index.browser.js +8 -0
  98. package/dist/profiles/index.browser.js.map +1 -0
  99. package/dist/profiles/index.d.ts +15 -0
  100. package/dist/profiles/index.d.ts.map +1 -0
  101. package/dist/profiles/index.js +13 -0
  102. package/dist/profiles/index.js.map +1 -0
  103. package/dist/profiles/ini.d.ts +36 -0
  104. package/dist/profiles/ini.d.ts.map +1 -0
  105. package/dist/profiles/ini.js +113 -0
  106. package/dist/profiles/ini.js.map +1 -0
  107. package/dist/profiles/profile.d.ts +131 -0
  108. package/dist/profiles/profile.d.ts.map +1 -0
  109. package/dist/profiles/profile.js +307 -0
  110. package/dist/profiles/profile.js.map +1 -0
  111. package/dist/profiles/resolve.d.ts +29 -0
  112. package/dist/profiles/resolve.d.ts.map +1 -0
  113. package/dist/profiles/resolve.js +206 -0
  114. package/dist/profiles/resolve.js.map +1 -0
  115. package/dist/profiles/secret.d.ts +25 -0
  116. package/dist/profiles/secret.d.ts.map +1 -0
  117. package/dist/profiles/secret.js +38 -0
  118. package/dist/profiles/secret.js.map +1 -0
  119. package/dist/wkt/fieldmask.d.ts +32 -0
  120. package/dist/wkt/fieldmask.d.ts.map +1 -0
  121. package/dist/wkt/fieldmask.js +68 -0
  122. package/dist/wkt/fieldmask.js.map +1 -0
  123. package/dist/wkt/index.d.ts +4 -0
  124. package/dist/wkt/index.d.ts.map +1 -0
  125. package/dist/wkt/index.js +2 -0
  126. package/dist/wkt/index.js.map +1 -0
  127. package/dist/wkt/value.d.ts +13 -0
  128. package/dist/wkt/value.d.ts.map +1 -0
  129. package/dist/wkt/value.js +2 -0
  130. package/dist/wkt/value.js.map +1 -0
  131. package/package.json +82 -4
  132. package/src/api/execute.ts +102 -0
  133. package/src/api/index.ts +12 -0
  134. package/src/api/limiter.ts +8 -0
  135. package/src/api/options.ts +22 -0
  136. package/src/api/retrier.ts +108 -0
  137. package/src/apierror/apierror.ts +253 -0
  138. package/src/apierror/codes/codes.ts +189 -0
  139. package/src/apierror/codes/index.ts +7 -0
  140. package/src/apierror/details.ts +459 -0
  141. package/src/apierror/index.ts +24 -0
  142. package/src/clientinfo/agent.ts +125 -0
  143. package/src/clientinfo/base.ts +73 -0
  144. package/src/clientinfo/clientinfo.ts +129 -0
  145. package/src/clientinfo/default.browser.ts +24 -0
  146. package/src/clientinfo/default.ts +128 -0
  147. package/src/clientinfo/index.browser.ts +4 -0
  148. package/src/clientinfo/index.ts +4 -0
  149. package/src/http/http.ts +75 -0
  150. package/src/http/index.ts +8 -0
  151. package/src/index.ts +5 -0
  152. package/src/logger/index.ts +8 -0
  153. package/src/logger/logger.ts +99 -0
  154. package/src/profiles/errors.ts +28 -0
  155. package/src/profiles/index.browser.ts +10 -0
  156. package/src/profiles/index.ts +15 -0
  157. package/src/profiles/ini.ts +126 -0
  158. package/src/profiles/profile.ts +467 -0
  159. package/src/profiles/resolve.ts +251 -0
  160. package/src/profiles/secret.ts +40 -0
  161. package/src/wkt/fieldmask.ts +89 -0
  162. package/src/wkt/index.ts +3 -0
  163. package/src/wkt/value.ts +19 -0
  164. package/index.js +0 -1
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Defines structured error detail types for API errors.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ /**
7
+ * ErrorDetails contains the error details of an API error. It is the union of
8
+ * known error details types and unknown details.
9
+ */
10
+ export interface ErrorDetails {
11
+ errorInfo?: ErrorInfo;
12
+ requestInfo?: RequestInfo;
13
+ retryInfo?: RetryInfo;
14
+ debugInfo?: DebugInfo;
15
+ quotaFailure?: QuotaFailure;
16
+ preconditionFailure?: PreconditionFailure;
17
+ badRequest?: BadRequest;
18
+ resourceInfo?: ResourceInfo;
19
+ help?: Help;
20
+ /**
21
+ * UnknownDetails contains error details that cannot be parsed into one of
22
+ * the known types above.
23
+ */
24
+ unknownDetails: unknown[];
25
+ }
26
+ /** ErrorInfo describes the cause of the error with structured details. */
27
+ export interface ErrorInfo {
28
+ /**
29
+ * The reason of the error. This is a constant value that identifies the
30
+ * proximate cause of the error.
31
+ */
32
+ reason: string;
33
+ /** The logical grouping to which the "reason" belongs. */
34
+ domain: string;
35
+ /** Additional structured details about this error. */
36
+ metadata: Record<string, string>;
37
+ }
38
+ /**
39
+ * RequestInfo contains metadata about the request that clients can attach when
40
+ * filing a bug or providing other forms of feedback.
41
+ */
42
+ export interface RequestInfo {
43
+ /**
44
+ * An opaque string that should only be interpreted by the service that
45
+ * generated it. For example, it can be used to identify requests in the
46
+ * service's logs.
47
+ */
48
+ requestId: string;
49
+ /**
50
+ * Any data that was used to serve this request. For example, an encrypted
51
+ * stack trace that can be sent back to the service provider for debugging.
52
+ */
53
+ servingData: string;
54
+ }
55
+ /**
56
+ * RetryInfo describes when the clients can retry a failed request. Clients
57
+ * could ignore the recommendation here or retry when this information is
58
+ * missing from error responses.
59
+ *
60
+ * It's always recommended that clients should use exponential backoff when
61
+ * retrying.
62
+ *
63
+ * Clients should wait until `retryDelayMs` amount of time has passed since
64
+ * receiving the error response before retrying. If retrying requests also
65
+ * fail, clients should use an exponential backoff scheme to gradually increase
66
+ * the delay between retries based on `retryDelayMs`, until either a maximum
67
+ * number of retries have been reached or a maximum retry delay cap has been
68
+ * reached.
69
+ */
70
+ export interface RetryInfo {
71
+ /** Clients should wait at least this long between retrying the same request, in milliseconds. */
72
+ retryDelayMs: number;
73
+ }
74
+ /** Describes additional debugging info. */
75
+ export interface DebugInfo {
76
+ /** The stack trace entries indicating where the error occurred. */
77
+ stackEntries: string[];
78
+ /** Additional debugging information provided by the server. */
79
+ detail: string;
80
+ }
81
+ /**
82
+ * Describes how a quota check failed.
83
+ *
84
+ * For example if a daily limit was exceeded for the calling project,
85
+ * a service could respond with a QuotaFailure detail containing the project
86
+ * id and the description of the quota limit that was exceeded. If the
87
+ * calling project hasn't enabled the service in the developer console, then
88
+ * a service could respond with the project id and set `service_disabled`
89
+ * to true.
90
+ *
91
+ * Also see RetryInfo and Help types for other details about handling a
92
+ * quota failure.
93
+ */
94
+ export interface QuotaFailure {
95
+ /** Describes all quota violations. */
96
+ violations: QuotaFailureViolation[];
97
+ }
98
+ export interface QuotaFailureViolation {
99
+ /** The subject on which the quota check failed. */
100
+ subject: string;
101
+ /**
102
+ * A description of how the quota check failed. Clients can use this
103
+ * description to find more about the quota configuration in the service's
104
+ * public documentation, or find the relevant quota limit to adjust through
105
+ * developer console.
106
+ *
107
+ * For example: "Service disabled" or "Daily Limit for read operations
108
+ * exceeded".
109
+ */
110
+ description: string;
111
+ }
112
+ /** Describes what preconditions have failed. */
113
+ export interface PreconditionFailure {
114
+ /** Describes all precondition violations. */
115
+ violations: PreconditionFailureViolation[];
116
+ }
117
+ export interface PreconditionFailureViolation {
118
+ /** The type of PreconditionFailure. */
119
+ type: string;
120
+ /** The subject, relative to the type, that failed. */
121
+ subject: string;
122
+ /**
123
+ * A description of how the precondition failed. Developers can use this
124
+ * description to understand how to fix the failure.
125
+ *
126
+ * For example: "Terms of service not accepted".
127
+ */
128
+ description: string;
129
+ }
130
+ /**
131
+ * Describes violations in a client request. This error type focuses on the
132
+ * syntactic aspects of the request.
133
+ */
134
+ export interface BadRequest {
135
+ fieldViolations: BadRequestFieldViolation[];
136
+ }
137
+ export interface BadRequestFieldViolation {
138
+ /** A path leading to a field in the request body. */
139
+ field: string;
140
+ /** A description of why the request element is bad. */
141
+ description: string;
142
+ }
143
+ /** Describes the resource that is being accessed. */
144
+ export interface ResourceInfo {
145
+ /** A name for the type of resource being accessed. */
146
+ resourceType: string;
147
+ /** The name of the resource being accessed. */
148
+ resourceName: string;
149
+ /** The owner of the resource (optional). */
150
+ owner: string;
151
+ /** Describes what error is encountered when accessing this resource. */
152
+ description: string;
153
+ }
154
+ /**
155
+ * Provides links to documentation or for performing an out of band action.
156
+ *
157
+ * For example, if a quota check failed with an error indicating the calling
158
+ * project hasn't enabled the accessed service, this can contain a URL pointing
159
+ * directly to the right place in the developer console to flip the bit.
160
+ */
161
+ export interface Help {
162
+ /** URL(s) pointing to additional information on handling the current error. */
163
+ links: HelpLink[];
164
+ }
165
+ export interface HelpLink {
166
+ /** Describes what the link offers. */
167
+ description: string;
168
+ /** The URL of the link. */
169
+ url: string;
170
+ }
171
+ /**
172
+ * Parses an array of raw error detail values into a structured ErrorDetails
173
+ * object. If multiple details of the same known type are present, the last
174
+ * one wins.
175
+ */
176
+ export declare function parseErrorDetails(rawDetails: unknown[]): ErrorDetails;
177
+ //# sourceMappingURL=details.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"details.d.ts","sourceRoot":"","sources":["../../src/apierror/details.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,IAAI,CAAC,EAAE,IAAI,CAAC;IAEZ;;;OAGG;IACH,cAAc,EAA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D;IACrD,KAAK,EAAE,MAAM,CAAC;IAEd,uDAAuD;IACvD,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,qDAAqD;AACrD,MAAM,WAAW,YAAY;IAC3B,sDAAsD;IACtD,YAAY,EAAE,MAAM,CAAC;IAErB,+CAA+C;IAC/C,YAAY,EAAE,MAAM,CAAC;IAErB,4CAA4C;IAC5C,KAAK,EAAE,MAAM,CAAC;IAEd,wEAAwE;IACxE,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,IAAI;IACnB,+EAA+E;IAC/E,KAAK,EAAE,QAAQ,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,QAAQ;IACvB,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAC;IAEpB,2BAA2B;IAC3B,GAAG,EAAE,MAAM,CAAC;CACb;AA8OD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,OAAO,EAAE,GAAG,YAAY,CAiBrE"}
@@ -0,0 +1,250 @@
1
+ /**
2
+ * Defines structured error detail types for API errors.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ import { z } from 'zod';
7
+ // ---------------------------------------------------------------------------
8
+ // Zod schemas for the wire format (snake_case JSON from the API).
9
+ //
10
+ // Each schema validates the snake_case wire format from the API and transforms
11
+ // it into the camelCase TypeScript interface. Nullish fields default to their
12
+ // zero values (empty string, empty array, empty record) when absent or null.
13
+ // ---------------------------------------------------------------------------
14
+ // Reusable schema fragments. Nullish fields default to their zero values
15
+ // (empty string, empty array, empty record) when absent or null.
16
+ const nullishString = z
17
+ .string()
18
+ .nullish()
19
+ .transform(v => v ?? '');
20
+ const errorInfoSchema = z.object({
21
+ reason: nullishString,
22
+ domain: nullishString,
23
+ metadata: z
24
+ .record(z.string(), z.string())
25
+ .nullish()
26
+ .transform(v => v ?? {}),
27
+ });
28
+ const requestInfoSchema = z
29
+ .object({
30
+ request_id: nullishString,
31
+ serving_data: nullishString,
32
+ })
33
+ .transform(d => ({
34
+ requestId: d.request_id,
35
+ servingData: d.serving_data,
36
+ }));
37
+ // Parses a protobuf Duration string (e.g. "42.000000001s") into milliseconds.
38
+ // Null/undefined defaults to 0. Invalid format causes a Zod validation failure.
39
+ const nullishProtoDuration = z
40
+ .string()
41
+ .nullish()
42
+ .transform((v, ctx) => {
43
+ if (v === null || v === undefined) {
44
+ return 0;
45
+ }
46
+ const ms = parseProtoDuration(v);
47
+ if (ms === undefined) {
48
+ ctx.addIssue({ code: 'custom', message: 'Invalid protobuf duration.' });
49
+ return z.NEVER;
50
+ }
51
+ return ms;
52
+ });
53
+ const retryInfoSchema = z
54
+ .object({
55
+ retry_delay: nullishProtoDuration,
56
+ })
57
+ .transform(d => ({
58
+ retryDelayMs: d.retry_delay,
59
+ }));
60
+ const debugInfoSchema = z
61
+ .object({
62
+ stack_entries: z
63
+ .array(z.string())
64
+ .nullish()
65
+ .transform(v => v ?? []),
66
+ detail: nullishString,
67
+ })
68
+ .transform(d => ({
69
+ stackEntries: d.stack_entries,
70
+ detail: d.detail,
71
+ }));
72
+ const quotaViolationSchema = z.object({
73
+ subject: nullishString,
74
+ description: nullishString,
75
+ });
76
+ const quotaFailureSchema = z.object({
77
+ violations: z
78
+ .array(quotaViolationSchema)
79
+ .nullish()
80
+ .transform(v => v ?? []),
81
+ });
82
+ const preconditionViolationSchema = z.object({
83
+ type: nullishString,
84
+ subject: nullishString,
85
+ description: nullishString,
86
+ });
87
+ const preconditionFailureSchema = z.object({
88
+ violations: z
89
+ .array(preconditionViolationSchema)
90
+ .nullish()
91
+ .transform(v => v ?? []),
92
+ });
93
+ const fieldViolationSchema = z.object({
94
+ field: nullishString,
95
+ description: nullishString,
96
+ });
97
+ const badRequestSchema = z
98
+ .object({
99
+ field_violations: z
100
+ .array(fieldViolationSchema)
101
+ .nullish()
102
+ .transform(v => v ?? []),
103
+ })
104
+ .transform(d => ({
105
+ fieldViolations: d.field_violations,
106
+ }));
107
+ const resourceInfoSchema = z
108
+ .object({
109
+ resource_type: nullishString,
110
+ resource_name: nullishString,
111
+ owner: nullishString,
112
+ description: nullishString,
113
+ })
114
+ .transform(d => ({
115
+ resourceType: d.resource_type,
116
+ resourceName: d.resource_name,
117
+ owner: d.owner,
118
+ description: d.description,
119
+ }));
120
+ const helpLinkSchema = z.object({
121
+ description: nullishString,
122
+ url: nullishString,
123
+ });
124
+ const helpSchema = z.object({
125
+ links: z
126
+ .array(helpLinkSchema)
127
+ .nullish()
128
+ .transform(v => v ?? []),
129
+ });
130
+ // Google RPC type URLs used to identify error detail types in the wire format.
131
+ const ERROR_INFO_TYPE = 'type.googleapis.com/google.rpc.ErrorInfo';
132
+ const REQUEST_INFO_TYPE = 'type.googleapis.com/google.rpc.RequestInfo';
133
+ const RETRY_INFO_TYPE = 'type.googleapis.com/google.rpc.RetryInfo';
134
+ const DEBUG_INFO_TYPE = 'type.googleapis.com/google.rpc.DebugInfo';
135
+ const QUOTA_FAILURE_TYPE = 'type.googleapis.com/google.rpc.QuotaFailure';
136
+ const PRECONDITION_FAILURE_TYPE = 'type.googleapis.com/google.rpc.PreconditionFailure';
137
+ const BAD_REQUEST_TYPE = 'type.googleapis.com/google.rpc.BadRequest';
138
+ const RESOURCE_INFO_TYPE = 'type.googleapis.com/google.rpc.ResourceInfo';
139
+ const HELP_TYPE = 'type.googleapis.com/google.rpc.Help';
140
+ // Checks whether a value is a plain object (not null, not an array).
141
+ function isRecord(value) {
142
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
143
+ }
144
+ // Parses a protobuf Duration string (e.g. "42.000000001s") into milliseconds.
145
+ // Returns undefined if the format is invalid.
146
+ function parseProtoDuration(s) {
147
+ if (!s.endsWith('s')) {
148
+ return undefined;
149
+ }
150
+ const seconds = Number(s.slice(0, -1));
151
+ if (Number.isNaN(seconds)) {
152
+ return undefined;
153
+ }
154
+ return seconds * 1000;
155
+ }
156
+ // Attempts to parse a single detail and assign it to the right ErrorDetails
157
+ // field. Returns true if the detail was recognized and valid, false otherwise.
158
+ function tryAssignDetail(ed, type, raw) {
159
+ switch (type) {
160
+ case ERROR_INFO_TYPE: {
161
+ const r = errorInfoSchema.safeParse(raw);
162
+ if (!r.success)
163
+ return false;
164
+ ed.errorInfo = r.data;
165
+ return true;
166
+ }
167
+ case REQUEST_INFO_TYPE: {
168
+ const r = requestInfoSchema.safeParse(raw);
169
+ if (!r.success)
170
+ return false;
171
+ ed.requestInfo = r.data;
172
+ return true;
173
+ }
174
+ case RETRY_INFO_TYPE: {
175
+ const r = retryInfoSchema.safeParse(raw);
176
+ if (!r.success)
177
+ return false;
178
+ ed.retryInfo = r.data;
179
+ return true;
180
+ }
181
+ case DEBUG_INFO_TYPE: {
182
+ const r = debugInfoSchema.safeParse(raw);
183
+ if (!r.success)
184
+ return false;
185
+ ed.debugInfo = r.data;
186
+ return true;
187
+ }
188
+ case QUOTA_FAILURE_TYPE: {
189
+ const r = quotaFailureSchema.safeParse(raw);
190
+ if (!r.success)
191
+ return false;
192
+ ed.quotaFailure = r.data;
193
+ return true;
194
+ }
195
+ case PRECONDITION_FAILURE_TYPE: {
196
+ const r = preconditionFailureSchema.safeParse(raw);
197
+ if (!r.success)
198
+ return false;
199
+ ed.preconditionFailure = r.data;
200
+ return true;
201
+ }
202
+ case BAD_REQUEST_TYPE: {
203
+ const r = badRequestSchema.safeParse(raw);
204
+ if (!r.success)
205
+ return false;
206
+ ed.badRequest = r.data;
207
+ return true;
208
+ }
209
+ case RESOURCE_INFO_TYPE: {
210
+ const r = resourceInfoSchema.safeParse(raw);
211
+ if (!r.success)
212
+ return false;
213
+ ed.resourceInfo = r.data;
214
+ return true;
215
+ }
216
+ case HELP_TYPE: {
217
+ const r = helpSchema.safeParse(raw);
218
+ if (!r.success)
219
+ return false;
220
+ ed.help = r.data;
221
+ return true;
222
+ }
223
+ default:
224
+ return false;
225
+ }
226
+ }
227
+ /**
228
+ * Parses an array of raw error detail values into a structured ErrorDetails
229
+ * object. If multiple details of the same known type are present, the last
230
+ * one wins.
231
+ */
232
+ export function parseErrorDetails(rawDetails) {
233
+ const ed = { unknownDetails: [] };
234
+ for (const rd of rawDetails) {
235
+ if (!isRecord(rd)) {
236
+ ed.unknownDetails.push(rd);
237
+ continue;
238
+ }
239
+ const type = rd['@type'];
240
+ if (typeof type !== 'string') {
241
+ ed.unknownDetails.push(rd);
242
+ continue;
243
+ }
244
+ if (!tryAssignDetail(ed, type, rd)) {
245
+ ed.unknownDetails.push(rd);
246
+ }
247
+ }
248
+ return ed;
249
+ }
250
+ //# sourceMappingURL=details.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"details.js","sourceRoot":"","sources":["../../src/apierror/details.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAkMtB,8EAA8E;AAC9E,kEAAkE;AAClE,EAAE;AACF,+EAA+E;AAC/E,8EAA8E;AAC9E,6EAA6E;AAC7E,8EAA8E;AAE9E,yEAAyE;AACzE,iEAAiE;AACjE,MAAM,aAAa,GAAG,CAAC;KACpB,MAAM,EAAE;KACR,OAAO,EAAE;KACT,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AAE3B,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,MAAM,EAAE,aAAa;IACrB,MAAM,EAAE,aAAa;IACrB,QAAQ,EAAE,CAAC;SACR,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;SAC9B,OAAO,EAAE;SACT,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;CAC3B,CAAC,CAAC;AAEH,MAAM,iBAAiB,GAAG,CAAC;KACxB,MAAM,CAAC;IACN,UAAU,EAAE,aAAa;IACzB,YAAY,EAAE,aAAa;CAC5B,CAAC;KACD,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACf,SAAS,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SAAS,CAAC,CAAC,CAAC;YACf,MAAM,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YACpC,IAAI,CAAC,CAAC,CAAC,OAAO;gBAAE,OAAO,KAAK,CAAC;YAC7B,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;YACjB,OAAO,IAAI,CAAC;QACd,CAAC;QACD;YACE,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAqB;IACrD,MAAM,EAAE,GAAiB,EAAC,cAAc,EAAE,EAAE,EAAC,CAAC;IAC9C,KAAK,MAAM,EAAE,IAAI,UAAU,EAAE,CAAC;QAC5B,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;YAClB,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC3B,SAAS;QACX,CAAC;QACD,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC;QACzB,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC3B,SAAS;QACX,CAAC;QACD,IAAI,CAAC,eAAe,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC;YACnC,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Databricks API error types.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ export { ApiError } from './apierror';
7
+ export type { ErrorDetails, ErrorInfo, RequestInfo, RetryInfo, DebugInfo, QuotaFailure, QuotaFailureViolation, PreconditionFailure, PreconditionFailureViolation, BadRequest, BadRequestFieldViolation, ResourceInfo, Help, HelpLink, } from './details';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/apierror/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,YAAY,EACV,YAAY,EACZ,SAAS,EACT,WAAW,EACX,SAAS,EACT,SAAS,EACT,YAAY,EACZ,qBAAqB,EACrB,mBAAmB,EACnB,4BAA4B,EAC5B,UAAU,EACV,wBAAwB,EACxB,YAAY,EACZ,IAAI,EACJ,QAAQ,GACT,MAAM,WAAW,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Databricks API error types.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ export { ApiError } from './apierror';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/apierror/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Detects the AI coding agent (e.g. Claude Code, Cursor, Gemini CLI) that
3
+ * is running the current Node.js process. The detected product name is
4
+ * appended to the user-agent header so that Databricks can understand
5
+ * which agents are invoking the SDK.
6
+ *
7
+ * The agent list and precedence rules are kept in sync across the Go,
8
+ * Java, Python, and TypeScript SDKs.
9
+ *
10
+ * @module
11
+ */
12
+ /**
13
+ * Checks environment variables for known AI agents and returns the
14
+ * detected product name.
15
+ *
16
+ * Explicit product-specific env vars always take precedence over the
17
+ * generic agents.md `AGENT` env var. `AGENT` is consulted only as a
18
+ * fallback when no explicit matcher fires, so that an explicit signal
19
+ * (e.g. `CLAUDECODE=1`) always wins over a conflicting `AGENT=<name>`
20
+ * value.
21
+ *
22
+ * Returns:
23
+ *
24
+ * - The product name when exactly one known env var is set.
25
+ * - `"multiple"` when multiple known env vars are set. Agent env vars
26
+ * can be stacked when one agent invokes another as a subagent (e.g.
27
+ * Claude Code spawning a Cursor CLI subprocess), so the child process
28
+ * inherits env vars from multiple layers.
29
+ * - When no known env var is set and `AGENT` is a non-empty value: the
30
+ * value itself if it names a known product, otherwise `"unknown"`.
31
+ * - `""` when nothing is set.
32
+ */
33
+ export declare function lookupAgentProvider(): string;
34
+ /**
35
+ * Returns the detected AI agent name, cached for the process lifetime.
36
+ *
37
+ * Returns one of:
38
+ *
39
+ * - The known product name when exactly one agent is detected via
40
+ * explicit env matchers, or when `AGENT` is set to a known product
41
+ * name and no explicit matcher fired.
42
+ * - `"multiple"` when multiple explicit matchers fire for different
43
+ * agents (typically nested agents, e.g. Cursor CLI running as a
44
+ * Claude Code subagent).
45
+ * - `"unknown"` when no explicit matcher fired and `AGENT` is set to a
46
+ * value that is not a known product name.
47
+ * - `""` when no agent is detected.
48
+ */
49
+ export declare function agentProvider(): string;
50
+ /**
51
+ * Clears the cached agent detection result so that the next call to
52
+ * {@link agentProvider} re-evaluates the environment. Exported for
53
+ * testing only.
54
+ */
55
+ export declare function clearAgentCache(): void;
56
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/clientinfo/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAgDH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAc5C;AAID;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAGtC;AAED;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAEtC"}
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Detects the AI coding agent (e.g. Claude Code, Cursor, Gemini CLI) that
3
+ * is running the current Node.js process. The detected product name is
4
+ * appended to the user-agent header so that Databricks can understand
5
+ * which agents are invoking the SDK.
6
+ *
7
+ * The agent list and precedence rules are kept in sync across the Go,
8
+ * Java, Python, and TypeScript SDKs.
9
+ *
10
+ * @module
11
+ */
12
+ // Name of the agents.md standard env var. When set to a value that no
13
+ // known agent recognizes, detection falls back to "unknown".
14
+ const AGENT_ENV_VAR = 'AGENT';
15
+ // Canonical list of AI coding agents. Keep this list in sync with the
16
+ // Go, Java, and Python SDKs. Agents are listed alphabetically by product
17
+ // name.
18
+ const KNOWN_AGENTS = [
19
+ // The amp agent also sets AGENT=amp, handled by the central fallback.
20
+ { envVar: 'AMP_CURRENT_THREAD_ID', product: 'amp' },
21
+ { envVar: 'ANTIGRAVITY_AGENT', product: 'antigravity' },
22
+ { envVar: 'AUGMENT_AGENT', product: 'augment' },
23
+ { envVar: 'CLAUDECODE', product: 'claude-code' },
24
+ { envVar: 'CLINE_ACTIVE', product: 'cline' },
25
+ { envVar: 'CODEX_CI', product: 'codex' },
26
+ { envVar: 'COPILOT_CLI', product: 'copilot-cli' },
27
+ { envVar: 'CURSOR_AGENT', product: 'cursor' },
28
+ { envVar: 'GEMINI_CLI', product: 'gemini-cli' },
29
+ // The goose agent also sets AGENT=goose, handled by the central
30
+ // fallback.
31
+ { envVar: 'GOOSE_TERMINAL', product: 'goose' },
32
+ { envVar: 'KIRO', product: 'kiro' },
33
+ { envVar: 'OPENCLAW_SHELL', product: 'openclaw' },
34
+ { envVar: 'OPENCODE', product: 'opencode' },
35
+ // Set by VS Code 1.121+ for agent-initiated terminal commands
36
+ // (https://code.visualstudio.com/updates/v1_121).
37
+ { envVar: 'VSCODE_AGENT', product: 'vscode-agent' },
38
+ { envVar: 'WINDSURF_AGENT', product: 'windsurf' },
39
+ ];
40
+ function agentEnvFallback() {
41
+ const v = process.env[AGENT_ENV_VAR];
42
+ if (v === undefined || v === '') {
43
+ return '';
44
+ }
45
+ if (KNOWN_AGENTS.some(a => a.product === v)) {
46
+ return v;
47
+ }
48
+ return 'unknown';
49
+ }
50
+ /**
51
+ * Checks environment variables for known AI agents and returns the
52
+ * detected product name.
53
+ *
54
+ * Explicit product-specific env vars always take precedence over the
55
+ * generic agents.md `AGENT` env var. `AGENT` is consulted only as a
56
+ * fallback when no explicit matcher fires, so that an explicit signal
57
+ * (e.g. `CLAUDECODE=1`) always wins over a conflicting `AGENT=<name>`
58
+ * value.
59
+ *
60
+ * Returns:
61
+ *
62
+ * - The product name when exactly one known env var is set.
63
+ * - `"multiple"` when multiple known env vars are set. Agent env vars
64
+ * can be stacked when one agent invokes another as a subagent (e.g.
65
+ * Claude Code spawning a Cursor CLI subprocess), so the child process
66
+ * inherits env vars from multiple layers.
67
+ * - When no known env var is set and `AGENT` is a non-empty value: the
68
+ * value itself if it names a known product, otherwise `"unknown"`.
69
+ * - `""` when nothing is set.
70
+ */
71
+ export function lookupAgentProvider() {
72
+ const matches = [];
73
+ for (const a of KNOWN_AGENTS) {
74
+ if (a.envVar in process.env) {
75
+ matches.push(a.product);
76
+ }
77
+ }
78
+ if (matches.length === 1) {
79
+ return matches[0];
80
+ }
81
+ if (matches.length > 1) {
82
+ return 'multiple';
83
+ }
84
+ return agentEnvFallback();
85
+ }
86
+ let cached;
87
+ /**
88
+ * Returns the detected AI agent name, cached for the process lifetime.
89
+ *
90
+ * Returns one of:
91
+ *
92
+ * - The known product name when exactly one agent is detected via
93
+ * explicit env matchers, or when `AGENT` is set to a known product
94
+ * name and no explicit matcher fired.
95
+ * - `"multiple"` when multiple explicit matchers fire for different
96
+ * agents (typically nested agents, e.g. Cursor CLI running as a
97
+ * Claude Code subagent).
98
+ * - `"unknown"` when no explicit matcher fired and `AGENT` is set to a
99
+ * value that is not a known product name.
100
+ * - `""` when no agent is detected.
101
+ */
102
+ export function agentProvider() {
103
+ cached ??= lookupAgentProvider();
104
+ return cached;
105
+ }
106
+ /**
107
+ * Clears the cached agent detection result so that the next call to
108
+ * {@link agentProvider} re-evaluates the environment. Exported for
109
+ * testing only.
110
+ */
111
+ export function clearAgentCache() {
112
+ cached = undefined;
113
+ }
114
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.js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