mesedi 0.2.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/README.md +57 -5
  2. package/dist/_errorClassesGenerated.d.ts +18 -0
  3. package/dist/_errorClassesGenerated.d.ts.map +1 -0
  4. package/dist/_errorClassesGenerated.js +24 -0
  5. package/dist/_errorClassesGenerated.js.map +1 -0
  6. package/dist/anthropic_integration.d.ts.map +1 -1
  7. package/dist/anthropic_integration.js +51 -10
  8. package/dist/anthropic_integration.js.map +1 -1
  9. package/dist/client.d.ts +26 -6
  10. package/dist/client.d.ts.map +1 -1
  11. package/dist/client.js +35 -7
  12. package/dist/client.js.map +1 -1
  13. package/dist/cohere_integration.d.ts +42 -0
  14. package/dist/cohere_integration.d.ts.map +1 -0
  15. package/dist/cohere_integration.js +456 -0
  16. package/dist/cohere_integration.js.map +1 -0
  17. package/dist/compress.d.ts +69 -0
  18. package/dist/compress.d.ts.map +1 -0
  19. package/dist/compress.js +75 -0
  20. package/dist/compress.js.map +1 -0
  21. package/dist/context.d.ts +11 -2
  22. package/dist/context.d.ts.map +1 -1
  23. package/dist/context.js +13 -3
  24. package/dist/context.js.map +1 -1
  25. package/dist/errors.d.ts +137 -0
  26. package/dist/errors.d.ts.map +1 -0
  27. package/dist/errors.js +462 -0
  28. package/dist/errors.js.map +1 -0
  29. package/dist/events.d.ts +13 -0
  30. package/dist/events.d.ts.map +1 -1
  31. package/dist/events.js +26 -1
  32. package/dist/events.js.map +1 -1
  33. package/dist/gemini_integration.d.ts +33 -0
  34. package/dist/gemini_integration.d.ts.map +1 -0
  35. package/dist/gemini_integration.js +334 -0
  36. package/dist/gemini_integration.js.map +1 -0
  37. package/dist/halt_stream.d.ts.map +1 -1
  38. package/dist/halt_stream.js +11 -1
  39. package/dist/halt_stream.js.map +1 -1
  40. package/dist/index.d.ts +15 -2
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +9 -1
  43. package/dist/index.js.map +1 -1
  44. package/dist/integrations/langchain.d.ts +95 -0
  45. package/dist/integrations/langchain.d.ts.map +1 -0
  46. package/dist/integrations/langchain.js +549 -0
  47. package/dist/integrations/langchain.js.map +1 -0
  48. package/dist/integrations/langgraph.d.ts +99 -0
  49. package/dist/integrations/langgraph.d.ts.map +1 -0
  50. package/dist/integrations/langgraph.js +572 -0
  51. package/dist/integrations/langgraph.js.map +1 -0
  52. package/dist/integrations/mastra.d.ts +114 -0
  53. package/dist/integrations/mastra.d.ts.map +1 -0
  54. package/dist/integrations/mastra.js +354 -0
  55. package/dist/integrations/mastra.js.map +1 -0
  56. package/dist/integrations/openai_agents.d.ts +66 -0
  57. package/dist/integrations/openai_agents.d.ts.map +1 -0
  58. package/dist/integrations/openai_agents.js +243 -0
  59. package/dist/integrations/openai_agents.js.map +1 -0
  60. package/dist/integrations/promptfoo.d.ts +62 -0
  61. package/dist/integrations/promptfoo.d.ts.map +1 -0
  62. package/dist/integrations/promptfoo.js +76 -0
  63. package/dist/integrations/promptfoo.js.map +1 -0
  64. package/dist/integrations/ragas.d.ts +65 -0
  65. package/dist/integrations/ragas.d.ts.map +1 -0
  66. package/dist/integrations/ragas.js +78 -0
  67. package/dist/integrations/ragas.js.map +1 -0
  68. package/dist/integrations/vectara.d.ts +60 -0
  69. package/dist/integrations/vectara.d.ts.map +1 -0
  70. package/dist/integrations/vectara.js +59 -0
  71. package/dist/integrations/vectara.js.map +1 -0
  72. package/dist/observe.d.ts +355 -0
  73. package/dist/observe.d.ts.map +1 -1
  74. package/dist/observe.js +532 -0
  75. package/dist/observe.js.map +1 -1
  76. package/dist/ollama_integration.d.ts +126 -0
  77. package/dist/ollama_integration.d.ts.map +1 -0
  78. package/dist/ollama_integration.js +404 -0
  79. package/dist/ollama_integration.js.map +1 -0
  80. package/dist/openai_integration.d.ts +67 -0
  81. package/dist/openai_integration.d.ts.map +1 -0
  82. package/dist/openai_integration.js +574 -0
  83. package/dist/openai_integration.js.map +1 -0
  84. package/dist/tool.d.ts.map +1 -1
  85. package/dist/tool.js +189 -6
  86. package/dist/tool.js.map +1 -1
  87. package/dist/truncate.d.ts +84 -0
  88. package/dist/truncate.d.ts.map +1 -0
  89. package/dist/truncate.js +134 -0
  90. package/dist/truncate.js.map +1 -0
  91. package/dist/vertex_gemini_integration.d.ts +27 -0
  92. package/dist/vertex_gemini_integration.d.ts.map +1 -0
  93. package/dist/vertex_gemini_integration.js +229 -0
  94. package/dist/vertex_gemini_integration.js.map +1 -0
  95. package/dist/wrap.d.ts +36 -0
  96. package/dist/wrap.d.ts.map +1 -1
  97. package/dist/wrap.js +5 -2
  98. package/dist/wrap.js.map +1 -1
  99. package/package.json +36 -3
package/dist/context.js CHANGED
@@ -24,10 +24,20 @@ export class ExecutionContext {
24
24
  * `checkBudget()` at entry, which is a no-op when this is undefined.
25
25
  */
26
26
  budgetTracker;
27
+ /**
28
+ * Optional human-readable agent name set by
29
+ * `wrap({ agentName: "planner" }, fn)`. Used by `emitAgentHandoff`
30
+ * as a fallback when the caller does NOT supply `fromAgent`,
31
+ * so multi-agent code can avoid repeating the same string at every
32
+ * handoff site. Always undefined when wrap() was invoked without
33
+ * the agentName option.
34
+ */
35
+ agentName;
27
36
  sequence = 0;
28
- constructor(executionId, budgetTracker) {
37
+ constructor(executionId, budgetTracker, agentName) {
29
38
  this.executionId = executionId;
30
39
  this.budgetTracker = budgetTracker;
40
+ this.agentName = agentName;
31
41
  }
32
42
  nextSequence() {
33
43
  this.sequence += 1;
@@ -61,8 +71,8 @@ export function currentExecutionContext() {
61
71
  *
62
72
  * This is the workhorse `wrap()` calls internally.
63
73
  */
64
- export function runInExecutionContext(executionId, fn, budgetTracker) {
65
- const ctx = new ExecutionContext(executionId, budgetTracker);
74
+ export function runInExecutionContext(executionId, fn, budgetTracker, agentName) {
75
+ const ctx = new ExecutionContext(executionId, budgetTracker, agentName);
66
76
  return storage.run(ctx, fn);
67
77
  }
68
78
  /**
@@ -1 +1 @@
1
- {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B,MAAM,GAAG,GAAG,IAAI,gBAAgB,CAAC,WAAW,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;IACxE,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,OAAO,GAAG,UAAU,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC/D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU;IACxB,OAAO,MAAM,GAAG,UAAU,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Canonical provider-error vocabulary for the Mesedi SDK.
3
+ *
4
+ * Every provider integration (anthropic_integration, future
5
+ * openai_integration, cohere_integration, etc.) classifies its
6
+ * native exception types into ONE of the values in ErrorClass. The
7
+ * backend reads `error_class` from llm_call payloads and uses the
8
+ * canonical vocabulary to cluster cross-provider signals — e.g.
9
+ * when both Anthropic and OpenAI are rate-limiting at the same
10
+ * time, the `provider_incident` detector sees them under the same
11
+ * `rate_limited` bucket regardless of which exception class each
12
+ * SDK raised.
13
+ *
14
+ * Adding a new provider:
15
+ * 1. Map the provider's exception hierarchy to the closest match
16
+ * in ErrorClass. Use UNKNOWN for anything that cannot be
17
+ * attributed cleanly.
18
+ * 2. Set payload.provider to a stable lowercase identifier
19
+ * ("anthropic", "openai", "cohere", "gemini").
20
+ * 3. Include error_class and (when available) http_status on the
21
+ * failure-path llm_call event.
22
+ *
23
+ * The vocabulary is deliberately closed. Free-form error strings
24
+ * would defeat the cross-provider clustering the detectors rely on.
25
+ */
26
+ /** Closed vocabulary of canonical provider-error classes. Values
27
+ * come from `spec/error_classes.yaml` via the codegen-generated
28
+ * `_errorClassesGenerated.ts`. Re-export here under the historical
29
+ * `ErrorClass` name so all consumers keep working unchanged when a
30
+ * new class is added to the spec.
31
+ *
32
+ * The vocabulary is deliberately closed. Free-form error strings
33
+ * would defeat the cross-provider clustering the detectors rely on. */
34
+ export declare const ErrorClass: {
35
+ readonly RATE_LIMITED: "rate_limited";
36
+ readonly QUOTA_EXHAUSTED: "quota_exhausted";
37
+ readonly INTERNAL_ERROR: "internal_error";
38
+ readonly SERVICE_UNAVAILABLE: "service_unavailable";
39
+ readonly TIMEOUT: "timeout";
40
+ readonly INVALID_API_KEY: "invalid_api_key";
41
+ readonly CLIENT_ERROR: "client_error";
42
+ readonly UNKNOWN: "unknown";
43
+ };
44
+ export type ErrorClassValue = (typeof ErrorClass)[keyof typeof ErrorClass];
45
+ /**
46
+ * Frozen set of values that count as "provider-side" for the
47
+ * provider_incident detector. Sourced from the spec so Python /
48
+ * TypeScript / Go all see the SAME membership without manual sync.
49
+ */
50
+ export declare const PROVIDER_SIDE_ERROR_CLASSES: ReadonlySet<ErrorClassValue>;
51
+ /**
52
+ * Return the canonical ErrorClass for an Anthropic SDK exception.
53
+ * Falls back to UNKNOWN for anything not in the map (including
54
+ * non-Anthropic exceptions that somehow reached the instrumented
55
+ * call path).
56
+ */
57
+ export declare function classifyAnthropicException(err: unknown): ErrorClassValue;
58
+ /**
59
+ * Return the canonical ErrorClass for an OpenAI SDK exception.
60
+ *
61
+ * Two-step classification:
62
+ * 1. Look up class name in OPENAI_EXCEPTION_MAP.
63
+ * 2. If result is RATE_LIMITED, probe the body for
64
+ * `error.code === "insufficient_quota"` — OpenAI overloads
65
+ * RateLimitError to cover both true rate limit and billing-
66
+ * cap exhaustion. The QUOTA_EXHAUSTED bucket needs different
67
+ * remediation (raise quota vs. back off), so the detector
68
+ * routes them separately.
69
+ *
70
+ * Falls back to UNKNOWN for anything not in the map.
71
+ */
72
+ export declare function classifyOpenAIException(err: unknown): ErrorClassValue;
73
+ /**
74
+ * Return the canonical ErrorClass for a Cohere SDK exception.
75
+ * Falls back to UNKNOWN for anything not in the map.
76
+ */
77
+ export declare function classifyCohereException(err: unknown): ErrorClassValue;
78
+ /**
79
+ * Return the canonical ErrorClass for a Gemini SDK exception.
80
+ *
81
+ * Two-step classification:
82
+ * 1. Look up class name in GEMINI_EXCEPTION_MAP.
83
+ * 2. If result is RATE_LIMITED (ResourceExhausted), probe the
84
+ * exception message for substring "quota" — Google overloads
85
+ * ResourceExhausted to cover both true rate-limit and
86
+ * quota-exhaust.
87
+ *
88
+ * Falls back to UNKNOWN for unmapped classes.
89
+ */
90
+ export declare function classifyGeminiException(err: unknown): ErrorClassValue;
91
+ /**
92
+ * Return the canonical ErrorClass for an Ollama or httpx-transport
93
+ * exception raised inside an instrumented chat call.
94
+ *
95
+ * Two-step classification:
96
+ * 1. If the exception is an ollama.ResponseError, bucket by
97
+ * HTTP-code range from .status_code: 4xx → CLIENT_ERROR,
98
+ * 503 → SERVICE_UNAVAILABLE, other 5xx → INTERNAL_ERROR,
99
+ * anything else → UNKNOWN.
100
+ * 2. Otherwise, look up the class name in OLLAMA_EXCEPTION_MAP
101
+ * (covers RequestError + the dominant httpx transport errors).
102
+ * 3. Anything not in the map → UNKNOWN. Falls back rather than
103
+ * misattributing to a specific bucket.
104
+ */
105
+ export declare function classifyOllamaException(err: unknown): ErrorClassValue;
106
+ /**
107
+ * Return the HTTP status code from an Anthropic SDK exception if
108
+ * one is exposed, otherwise undefined. APIStatusError subclasses
109
+ * expose `status`; base APIError and connection/timeout errors
110
+ * don't.
111
+ */
112
+ export declare function extractHttpStatus(err: unknown): number | undefined;
113
+ /**
114
+ * Return the provider-recommended back-off window (seconds) from a
115
+ * provider SDK exception, or undefined when the provider did not
116
+ * supply one.
117
+ *
118
+ * Probes in order, returning the first successful parse:
119
+ *
120
+ * 1. `err.retryAfter` / `err.retry_after` attribute (some SDKs
121
+ * expose this directly).
122
+ * 2. The `Retry-After` HTTP header on `err.response.headers` /
123
+ * `err.headers`. Anthropic, OpenAI, Cohere, and Gemini SDKs
124
+ * all surface response headers on their status-error subclasses.
125
+ *
126
+ * Per RFC 7231, the Retry-After header value may be either:
127
+ * - A non-negative integer (delay-seconds), the common case.
128
+ * - An HTTP-date (`Wed, 21 Oct 2026 07:28:00 GMT`), the rare case
129
+ * used by some CDNs in front of providers.
130
+ *
131
+ * Both shapes are parsed. HTTP-date values that have already passed
132
+ * return 0 (back off but don't wait). Returns undefined on any parse
133
+ * failure so the caller can omit the field cleanly rather than
134
+ * shipping a corrupted value.
135
+ */
136
+ export declare function extractRetryAfter(err: unknown): number | undefined;
137
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAOH;;;;;;;uEAOuE;AACvE,eAAO,MAAM,UAAU;;;;;;;;;CAAoB,CAAC;AAE5C,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC;AAE3E;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,EAAE,WAAW,CAAC,eAAe,CACH,CAAC;AA4CnE;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,OAAO,GAAG,eAAe,CAKxE;AA0CD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,GAAG,eAAe,CASrE;AAuBD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,GAAG,eAAe,CAKrE;AA4BD;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,GAAG,eAAe,CAUrE;AAyBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,GAAG,eAAe,CAiBrE;AA0CD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAWlE;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAsBlE"}
package/dist/errors.js ADDED
@@ -0,0 +1,462 @@
1
+ /**
2
+ * Canonical provider-error vocabulary for the Mesedi SDK.
3
+ *
4
+ * Every provider integration (anthropic_integration, future
5
+ * openai_integration, cohere_integration, etc.) classifies its
6
+ * native exception types into ONE of the values in ErrorClass. The
7
+ * backend reads `error_class` from llm_call payloads and uses the
8
+ * canonical vocabulary to cluster cross-provider signals — e.g.
9
+ * when both Anthropic and OpenAI are rate-limiting at the same
10
+ * time, the `provider_incident` detector sees them under the same
11
+ * `rate_limited` bucket regardless of which exception class each
12
+ * SDK raised.
13
+ *
14
+ * Adding a new provider:
15
+ * 1. Map the provider's exception hierarchy to the closest match
16
+ * in ErrorClass. Use UNKNOWN for anything that cannot be
17
+ * attributed cleanly.
18
+ * 2. Set payload.provider to a stable lowercase identifier
19
+ * ("anthropic", "openai", "cohere", "gemini").
20
+ * 3. Include error_class and (when available) http_status on the
21
+ * failure-path llm_call event.
22
+ *
23
+ * The vocabulary is deliberately closed. Free-form error strings
24
+ * would defeat the cross-provider clustering the detectors rely on.
25
+ */
26
+ import { ERROR_CLASS_NAMES, PROVIDER_SIDE_ERROR_CLASS_VALUES, } from "./_errorClassesGenerated.js";
27
+ /** Closed vocabulary of canonical provider-error classes. Values
28
+ * come from `spec/error_classes.yaml` via the codegen-generated
29
+ * `_errorClassesGenerated.ts`. Re-export here under the historical
30
+ * `ErrorClass` name so all consumers keep working unchanged when a
31
+ * new class is added to the spec.
32
+ *
33
+ * The vocabulary is deliberately closed. Free-form error strings
34
+ * would defeat the cross-provider clustering the detectors rely on. */
35
+ export const ErrorClass = ERROR_CLASS_NAMES;
36
+ /**
37
+ * Frozen set of values that count as "provider-side" for the
38
+ * provider_incident detector. Sourced from the spec so Python /
39
+ * TypeScript / Go all see the SAME membership without manual sync.
40
+ */
41
+ export const PROVIDER_SIDE_ERROR_CLASSES = PROVIDER_SIDE_ERROR_CLASS_VALUES;
42
+ /**
43
+ * Mapping from Anthropic exception class names (string, not the
44
+ * class object) to canonical ErrorClass values. Keyed by name to
45
+ * avoid taking a hard runtime dependency on @anthropic-ai/sdk —
46
+ * the mesedi SDK works even if the anthropic package is not
47
+ * installed, and the mapping stays correct because exception class
48
+ * names are stable across anthropic SDK versions.
49
+ */
50
+ const ANTHROPIC_EXCEPTION_MAP = {
51
+ RateLimitError: ErrorClass.RATE_LIMITED,
52
+ APITimeoutError: ErrorClass.TIMEOUT,
53
+ DeadlineExceededError: ErrorClass.TIMEOUT,
54
+ APIConnectionError: ErrorClass.SERVICE_UNAVAILABLE,
55
+ ServiceUnavailableError: ErrorClass.SERVICE_UNAVAILABLE,
56
+ OverloadedError: ErrorClass.SERVICE_UNAVAILABLE,
57
+ InternalServerError: ErrorClass.INTERNAL_ERROR,
58
+ APIResponseValidationError: ErrorClass.INTERNAL_ERROR,
59
+ APIWebhookValidationError: ErrorClass.INTERNAL_ERROR,
60
+ AuthenticationError: ErrorClass.INVALID_API_KEY,
61
+ PermissionDeniedError: ErrorClass.INVALID_API_KEY,
62
+ BadRequestError: ErrorClass.CLIENT_ERROR,
63
+ NotFoundError: ErrorClass.CLIENT_ERROR,
64
+ ConflictError: ErrorClass.CLIENT_ERROR,
65
+ RequestTooLargeError: ErrorClass.CLIENT_ERROR,
66
+ UnprocessableEntityError: ErrorClass.CLIENT_ERROR,
67
+ // Client construction / configuration errors — raised before any
68
+ // network call. Customer code bug, not a provider incident.
69
+ MissingDependencyError: ErrorClass.CLIENT_ERROR,
70
+ MutuallyExclusiveAuthError: ErrorClass.CLIENT_ERROR,
71
+ StreamAlreadyConsumed: ErrorClass.CLIENT_ERROR,
72
+ // Auth-adjacent: Bedrock / Vertex workload-identity probe failed.
73
+ WorkloadIdentityError: ErrorClass.INVALID_API_KEY,
74
+ // Internal SDK marker for transient failures the SDK's own retry
75
+ // loop classifies as retryable. Safe default is SERVICE_UNAVAILABLE.
76
+ RetryableError: ErrorClass.SERVICE_UNAVAILABLE,
77
+ // Base classes — caught last, treated as unknown rather than
78
+ // falsely attributed to a specific bucket.
79
+ APIStatusError: ErrorClass.UNKNOWN,
80
+ APIError: ErrorClass.UNKNOWN,
81
+ AnthropicError: ErrorClass.UNKNOWN,
82
+ };
83
+ /**
84
+ * Return the canonical ErrorClass for an Anthropic SDK exception.
85
+ * Falls back to UNKNOWN for anything not in the map (including
86
+ * non-Anthropic exceptions that somehow reached the instrumented
87
+ * call path).
88
+ */
89
+ export function classifyAnthropicException(err) {
90
+ if (err instanceof Error && err.constructor.name) {
91
+ return ANTHROPIC_EXCEPTION_MAP[err.constructor.name] ?? ErrorClass.UNKNOWN;
92
+ }
93
+ return ErrorClass.UNKNOWN;
94
+ }
95
+ /**
96
+ * Mapping from OpenAI SDK exception class names to canonical
97
+ * ErrorClass values. Keyed by name (string) for the same
98
+ * dependency-avoidance reason as the Anthropic map: the mesedi
99
+ * SDK works even if the openai package is not installed.
100
+ *
101
+ * OpenAI's hierarchy (openai>=4.0):
102
+ * OpenAIError
103
+ * └── APIError
104
+ * ├── APIConnectionError
105
+ * │ └── APIConnectionTimeoutError
106
+ * └── APIStatusError → subclasses for 4xx/5xx
107
+ *
108
+ * NOTE: TypeScript SDK uses `APIConnectionTimeoutError` (different
109
+ * from Python's `APITimeoutError`). Both are listed below so the
110
+ * mapping is stable regardless of which casing the runtime presents.
111
+ *
112
+ * RateLimitError is overloaded by OpenAI to cover both true rate
113
+ * limiting AND insufficient_quota — classifyOpenAIException probes
114
+ * the body to distinguish, returning QUOTA_EXHAUSTED for the latter.
115
+ */
116
+ const OPENAI_EXCEPTION_MAP = {
117
+ RateLimitError: ErrorClass.RATE_LIMITED,
118
+ APIConnectionTimeoutError: ErrorClass.TIMEOUT,
119
+ APITimeoutError: ErrorClass.TIMEOUT,
120
+ APIConnectionError: ErrorClass.SERVICE_UNAVAILABLE,
121
+ InternalServerError: ErrorClass.INTERNAL_ERROR,
122
+ AuthenticationError: ErrorClass.INVALID_API_KEY,
123
+ PermissionDeniedError: ErrorClass.INVALID_API_KEY,
124
+ BadRequestError: ErrorClass.CLIENT_ERROR,
125
+ NotFoundError: ErrorClass.CLIENT_ERROR,
126
+ ConflictError: ErrorClass.CLIENT_ERROR,
127
+ UnprocessableEntityError: ErrorClass.CLIENT_ERROR,
128
+ // Base classes — caught last, treated as unknown rather than
129
+ // falsely attributed to a specific bucket.
130
+ APIStatusError: ErrorClass.UNKNOWN,
131
+ APIError: ErrorClass.UNKNOWN,
132
+ OpenAIError: ErrorClass.UNKNOWN,
133
+ };
134
+ /**
135
+ * Return the canonical ErrorClass for an OpenAI SDK exception.
136
+ *
137
+ * Two-step classification:
138
+ * 1. Look up class name in OPENAI_EXCEPTION_MAP.
139
+ * 2. If result is RATE_LIMITED, probe the body for
140
+ * `error.code === "insufficient_quota"` — OpenAI overloads
141
+ * RateLimitError to cover both true rate limit and billing-
142
+ * cap exhaustion. The QUOTA_EXHAUSTED bucket needs different
143
+ * remediation (raise quota vs. back off), so the detector
144
+ * routes them separately.
145
+ *
146
+ * Falls back to UNKNOWN for anything not in the map.
147
+ */
148
+ export function classifyOpenAIException(err) {
149
+ if (!(err instanceof Error) || !err.constructor.name) {
150
+ return ErrorClass.UNKNOWN;
151
+ }
152
+ const base = OPENAI_EXCEPTION_MAP[err.constructor.name] ?? ErrorClass.UNKNOWN;
153
+ if (base === ErrorClass.RATE_LIMITED && openaiIndicatesInsufficientQuota(err)) {
154
+ return ErrorClass.QUOTA_EXHAUSTED;
155
+ }
156
+ return base;
157
+ }
158
+ /** Mapping from Cohere TypeScript SDK exception class names to
159
+ * canonical ErrorClass values. cohere-ai>=7.x exposes typed errors
160
+ * under cohere.errors.*; older versions use a flatter hierarchy.
161
+ * Both are listed so the mapping is backward-compatible. */
162
+ const COHERE_EXCEPTION_MAP = {
163
+ TooManyRequestsError: ErrorClass.RATE_LIMITED,
164
+ GatewayTimeoutError: ErrorClass.TIMEOUT,
165
+ CohereConnectionError: ErrorClass.SERVICE_UNAVAILABLE,
166
+ ServiceUnavailableError: ErrorClass.SERVICE_UNAVAILABLE,
167
+ InternalServerError: ErrorClass.INTERNAL_ERROR,
168
+ NotImplementedError: ErrorClass.INTERNAL_ERROR,
169
+ UnauthorizedError: ErrorClass.INVALID_API_KEY,
170
+ ForbiddenError: ErrorClass.INVALID_API_KEY,
171
+ BadRequestError: ErrorClass.CLIENT_ERROR,
172
+ NotFoundError: ErrorClass.CLIENT_ERROR,
173
+ ClientClosedRequestError: ErrorClass.CLIENT_ERROR,
174
+ ApiError: ErrorClass.UNKNOWN,
175
+ CohereError: ErrorClass.UNKNOWN,
176
+ CohereAPIError: ErrorClass.UNKNOWN,
177
+ };
178
+ /**
179
+ * Return the canonical ErrorClass for a Cohere SDK exception.
180
+ * Falls back to UNKNOWN for anything not in the map.
181
+ */
182
+ export function classifyCohereException(err) {
183
+ if (err instanceof Error && err.constructor.name) {
184
+ return COHERE_EXCEPTION_MAP[err.constructor.name] ?? ErrorClass.UNKNOWN;
185
+ }
186
+ return ErrorClass.UNKNOWN;
187
+ }
188
+ /** Mapping from Google Gemini / google.api_core.exceptions class
189
+ * names to canonical ErrorClass values. The @google/generative-ai
190
+ * TS package surfaces errors with constructor.name matching the
191
+ * RPC status (matching the Python google.api_core hierarchy). */
192
+ const GEMINI_EXCEPTION_MAP = {
193
+ ResourceExhausted: ErrorClass.RATE_LIMITED,
194
+ DeadlineExceeded: ErrorClass.TIMEOUT,
195
+ RetryError: ErrorClass.TIMEOUT,
196
+ ServiceUnavailable: ErrorClass.SERVICE_UNAVAILABLE,
197
+ Cancelled: ErrorClass.SERVICE_UNAVAILABLE,
198
+ Aborted: ErrorClass.SERVICE_UNAVAILABLE,
199
+ InternalServerError: ErrorClass.INTERNAL_ERROR,
200
+ DataLoss: ErrorClass.INTERNAL_ERROR,
201
+ Unknown: ErrorClass.INTERNAL_ERROR,
202
+ NotImplemented: ErrorClass.INTERNAL_ERROR,
203
+ Unauthenticated: ErrorClass.INVALID_API_KEY,
204
+ PermissionDenied: ErrorClass.INVALID_API_KEY,
205
+ InvalidArgument: ErrorClass.CLIENT_ERROR,
206
+ FailedPrecondition: ErrorClass.CLIENT_ERROR,
207
+ OutOfRange: ErrorClass.CLIENT_ERROR,
208
+ NotFound: ErrorClass.CLIENT_ERROR,
209
+ AlreadyExists: ErrorClass.CLIENT_ERROR,
210
+ GoogleAPICallError: ErrorClass.UNKNOWN,
211
+ GoogleAPIError: ErrorClass.UNKNOWN,
212
+ };
213
+ /**
214
+ * Return the canonical ErrorClass for a Gemini SDK exception.
215
+ *
216
+ * Two-step classification:
217
+ * 1. Look up class name in GEMINI_EXCEPTION_MAP.
218
+ * 2. If result is RATE_LIMITED (ResourceExhausted), probe the
219
+ * exception message for substring "quota" — Google overloads
220
+ * ResourceExhausted to cover both true rate-limit and
221
+ * quota-exhaust.
222
+ *
223
+ * Falls back to UNKNOWN for unmapped classes.
224
+ */
225
+ export function classifyGeminiException(err) {
226
+ if (!(err instanceof Error) || !err.constructor.name) {
227
+ return ErrorClass.UNKNOWN;
228
+ }
229
+ const base = GEMINI_EXCEPTION_MAP[err.constructor.name] ?? ErrorClass.UNKNOWN;
230
+ if (base === ErrorClass.RATE_LIMITED) {
231
+ const msg = (err.message ?? "").toLowerCase();
232
+ if (msg.includes("quota"))
233
+ return ErrorClass.QUOTA_EXHAUSTED;
234
+ }
235
+ return base;
236
+ }
237
+ /** Mapping from Ollama + httpx exception class names to canonical
238
+ * ErrorClass values. Wave 2.5.2 twin of the Python _OLLAMA_EXCEPTION_MAP.
239
+ *
240
+ * Ollama is a local runtime: no API-key auth, no per-minute rate
241
+ * limiting, no billing-cap. So INVALID_API_KEY, RATE_LIMITED, and
242
+ * QUOTA_EXHAUSTED are absent from this map by design.
243
+ *
244
+ * ResponseError (Ollama-native HTTP error) carries .status_code and
245
+ * is bucketed by HTTP-code range inside classifyOllamaException —
246
+ * NOT mapped here because the class name alone doesn't carry the
247
+ * 4xx-vs-5xx distinction the detectors require. */
248
+ const OLLAMA_EXCEPTION_MAP = {
249
+ // Ollama-native chat-request layer
250
+ RequestError: ErrorClass.CLIENT_ERROR,
251
+ // httpx transport layer — Ollama runs on top of httpx; the two
252
+ // dominant local-runtime failures are 'server not running'
253
+ // (ConnectError) and 'model load timed out' (TimeoutException).
254
+ ConnectError: ErrorClass.SERVICE_UNAVAILABLE,
255
+ ConnectTimeout: ErrorClass.SERVICE_UNAVAILABLE,
256
+ TimeoutException: ErrorClass.TIMEOUT,
257
+ ReadTimeout: ErrorClass.TIMEOUT,
258
+ };
259
+ /**
260
+ * Return the canonical ErrorClass for an Ollama or httpx-transport
261
+ * exception raised inside an instrumented chat call.
262
+ *
263
+ * Two-step classification:
264
+ * 1. If the exception is an ollama.ResponseError, bucket by
265
+ * HTTP-code range from .status_code: 4xx → CLIENT_ERROR,
266
+ * 503 → SERVICE_UNAVAILABLE, other 5xx → INTERNAL_ERROR,
267
+ * anything else → UNKNOWN.
268
+ * 2. Otherwise, look up the class name in OLLAMA_EXCEPTION_MAP
269
+ * (covers RequestError + the dominant httpx transport errors).
270
+ * 3. Anything not in the map → UNKNOWN. Falls back rather than
271
+ * misattributing to a specific bucket.
272
+ */
273
+ export function classifyOllamaException(err) {
274
+ if (!(err instanceof Error) || !err.constructor.name) {
275
+ return ErrorClass.UNKNOWN;
276
+ }
277
+ // Step 1: ResponseError / status-bearing exceptions.
278
+ if (err.constructor.name === "ResponseError") {
279
+ const status = err.status_code;
280
+ if (typeof status !== "number" || !Number.isInteger(status)) {
281
+ return ErrorClass.UNKNOWN;
282
+ }
283
+ if (status >= 400 && status < 500)
284
+ return ErrorClass.CLIENT_ERROR;
285
+ if (status === 503)
286
+ return ErrorClass.SERVICE_UNAVAILABLE;
287
+ if (status >= 500 && status < 600)
288
+ return ErrorClass.INTERNAL_ERROR;
289
+ return ErrorClass.UNKNOWN;
290
+ }
291
+ // Step 2: class-name lookup for the simple cases.
292
+ return OLLAMA_EXCEPTION_MAP[err.constructor.name] ?? ErrorClass.UNKNOWN;
293
+ }
294
+ /** Probe an OpenAI exception's body for the insufficient_quota
295
+ * error code that distinguishes a billing-cap from a true rate
296
+ * limit. Best-effort; any missing attr / unexpected shape returns
297
+ * false rather than throwing. */
298
+ function openaiIndicatesInsufficientQuota(err) {
299
+ const obj = err;
300
+ // Probe 1: direct body attr (most common in current SDK).
301
+ if (obj.body && typeof obj.body === "object") {
302
+ const e = obj.body.error;
303
+ if (e && typeof e === "object" &&
304
+ e.code === "insufficient_quota") {
305
+ return true;
306
+ }
307
+ }
308
+ // Probe 2: older SDK exposes response.json() — call only if
309
+ // available, swallow any parse exception.
310
+ if (obj.response && typeof obj.response.json === "function") {
311
+ try {
312
+ const payload = obj.response.json();
313
+ if (payload && typeof payload === "object") {
314
+ const e = payload.error;
315
+ if (e && typeof e === "object" &&
316
+ e.code === "insufficient_quota") {
317
+ return true;
318
+ }
319
+ }
320
+ }
321
+ catch {
322
+ return false;
323
+ }
324
+ }
325
+ return false;
326
+ }
327
+ /**
328
+ * Return the HTTP status code from an Anthropic SDK exception if
329
+ * one is exposed, otherwise undefined. APIStatusError subclasses
330
+ * expose `status`; base APIError and connection/timeout errors
331
+ * don't.
332
+ */
333
+ export function extractHttpStatus(err) {
334
+ if (err && typeof err === "object" && "status" in err) {
335
+ const status = err.status;
336
+ if (typeof status === "number")
337
+ return status;
338
+ }
339
+ // Some Anthropic SDK versions expose status_code instead.
340
+ if (err && typeof err === "object" && "status_code" in err) {
341
+ const status = err.status_code;
342
+ if (typeof status === "number")
343
+ return status;
344
+ }
345
+ return undefined;
346
+ }
347
+ /**
348
+ * Return the provider-recommended back-off window (seconds) from a
349
+ * provider SDK exception, or undefined when the provider did not
350
+ * supply one.
351
+ *
352
+ * Probes in order, returning the first successful parse:
353
+ *
354
+ * 1. `err.retryAfter` / `err.retry_after` attribute (some SDKs
355
+ * expose this directly).
356
+ * 2. The `Retry-After` HTTP header on `err.response.headers` /
357
+ * `err.headers`. Anthropic, OpenAI, Cohere, and Gemini SDKs
358
+ * all surface response headers on their status-error subclasses.
359
+ *
360
+ * Per RFC 7231, the Retry-After header value may be either:
361
+ * - A non-negative integer (delay-seconds), the common case.
362
+ * - An HTTP-date (`Wed, 21 Oct 2026 07:28:00 GMT`), the rare case
363
+ * used by some CDNs in front of providers.
364
+ *
365
+ * Both shapes are parsed. HTTP-date values that have already passed
366
+ * return 0 (back off but don't wait). Returns undefined on any parse
367
+ * failure so the caller can omit the field cleanly rather than
368
+ * shipping a corrupted value.
369
+ */
370
+ export function extractRetryAfter(err) {
371
+ if (!err || typeof err !== "object")
372
+ return undefined;
373
+ const obj = err;
374
+ // Probe 1: direct attribute (camelCase OR snake_case).
375
+ const direct = obj.retryAfter ?? obj.retry_after;
376
+ const fromDirect = coerceRetryAfterValue(direct);
377
+ if (fromDirect !== undefined)
378
+ return fromDirect;
379
+ // Probe 2: Retry-After response header.
380
+ const response = obj.response;
381
+ let headers = undefined;
382
+ if (response && typeof response === "object") {
383
+ headers = response.headers;
384
+ }
385
+ if (headers === undefined) {
386
+ headers = obj.headers;
387
+ }
388
+ if (!headers)
389
+ return undefined;
390
+ const headerValue = readHeader(headers, "retry-after");
391
+ return coerceRetryAfterValue(headerValue);
392
+ }
393
+ /** Best-effort read of one header value across the shapes provider
394
+ * SDKs hand us: Fetch-style Headers (has .get()), plain object,
395
+ * Map. All header lookups are case-insensitive per HTTP spec. */
396
+ function readHeader(headers, name) {
397
+ const lower = name.toLowerCase();
398
+ // Fetch Headers / undici Headers: .get() is case-insensitive.
399
+ if (typeof headers.get === "function") {
400
+ try {
401
+ return headers.get(lower);
402
+ }
403
+ catch {
404
+ // fall through to map/object probes
405
+ }
406
+ }
407
+ // Map.
408
+ if (headers instanceof Map) {
409
+ for (const [k, v] of headers) {
410
+ if (typeof k === "string" && k.toLowerCase() === lower)
411
+ return v;
412
+ }
413
+ return undefined;
414
+ }
415
+ // Plain object — walk keys for case-insensitive match.
416
+ if (typeof headers === "object" && headers !== null) {
417
+ for (const [k, v] of Object.entries(headers)) {
418
+ if (k.toLowerCase() === lower)
419
+ return v;
420
+ }
421
+ }
422
+ return undefined;
423
+ }
424
+ /** Coerce a Retry-After value (number / numeric string / HTTP-date /
425
+ * Date) to a non-negative integer second count. Returns undefined
426
+ * on any parse failure. */
427
+ function coerceRetryAfterValue(raw) {
428
+ if (raw === null || raw === undefined)
429
+ return undefined;
430
+ if (typeof raw === "boolean")
431
+ return undefined; // reject bool→number coercion
432
+ if (typeof raw === "number") {
433
+ if (!Number.isFinite(raw))
434
+ return undefined;
435
+ return Math.max(0, Math.floor(raw));
436
+ }
437
+ if (raw instanceof Date) {
438
+ const delta = (raw.getTime() - Date.now()) / 1000;
439
+ if (!Number.isFinite(delta))
440
+ return undefined;
441
+ return Math.max(0, Math.floor(delta));
442
+ }
443
+ if (typeof raw === "string") {
444
+ const s = raw.trim();
445
+ if (s === "")
446
+ return undefined;
447
+ // Numeric path first (the common case).
448
+ if (/^-?\d+(\.\d+)?$/.test(s)) {
449
+ const n = Number(s);
450
+ if (Number.isFinite(n))
451
+ return Math.max(0, Math.floor(n));
452
+ return undefined;
453
+ }
454
+ // HTTP-date path. Date.parse returns NaN on failure.
455
+ const ts = Date.parse(s);
456
+ if (Number.isNaN(ts))
457
+ return undefined;
458
+ return Math.max(0, Math.floor((ts - Date.now()) / 1000));
459
+ }
460
+ return undefined;
461
+ }
462
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EACL,iBAAiB,EACjB,gCAAgC,GACjC,MAAM,6BAA6B,CAAC;AAErC;;;;;;;uEAOuE;AACvE,MAAM,CAAC,MAAM,UAAU,GAA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