weflayr 0.23.0 → 0.26.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 (225) hide show
  1. package/README.md +2 -2
  2. package/dist/{api → src/api}/generated/facade.gen.d.ts +163 -12
  3. package/dist/{api → src/api}/generated/facade.gen.js +10 -2
  4. package/dist/src/api/generated/index.d.ts +2 -0
  5. package/dist/{api → src/api}/generated/index.js +9 -1
  6. package/dist/{api → src/api}/generated/sdk.gen.d.ts +35 -3
  7. package/dist/{api → src/api}/generated/sdk.gen.js +88 -4
  8. package/{src/api/generated/types.gen.ts → dist/src/api/generated/types.gen.d.ts} +692 -116
  9. package/dist/{api → src/api}/makeEndpoint.js +1 -3
  10. package/dist/src/auto-instrument.d.ts +42 -0
  11. package/dist/src/auto-instrument.js +156 -0
  12. package/dist/src/index.d.ts +9 -0
  13. package/dist/src/index.js +49 -0
  14. package/dist/src/instrumentation/anthropic/get_cache_and_reasoning_telemetry.d.ts +20 -0
  15. package/dist/src/instrumentation/anthropic/get_cache_and_reasoning_telemetry.js +114 -0
  16. package/dist/src/instrumentation/anthropic/get_cache_config_telemetry.d.ts +28 -0
  17. package/dist/src/instrumentation/anthropic/get_cache_config_telemetry.js +92 -0
  18. package/dist/src/instrumentation/anthropic/get_streaming_accumulation_telemetry.d.ts +25 -0
  19. package/dist/src/instrumentation/anthropic/get_streaming_accumulation_telemetry.js +141 -0
  20. package/dist/src/instrumentation/anthropic/get_structured_output_schema_telemetry.d.ts +9 -0
  21. package/dist/src/instrumentation/anthropic/get_structured_output_schema_telemetry.js +17 -0
  22. package/dist/src/instrumentation/anthropic/get_tool_definitions_telemetry.d.ts +15 -0
  23. package/dist/src/instrumentation/anthropic/get_tool_definitions_telemetry.js +50 -0
  24. package/dist/src/instrumentation/anthropic/set_telemetry_attributes.d.ts +15 -0
  25. package/dist/src/instrumentation/anthropic/set_telemetry_attributes.js +39 -0
  26. package/dist/src/instrumentation/bedrock/get_cache_config_telemetry.d.ts +22 -0
  27. package/dist/src/instrumentation/bedrock/get_cache_config_telemetry.js +97 -0
  28. package/dist/src/instrumentation/bedrock/get_cache_telemetry.d.ts +22 -0
  29. package/dist/src/instrumentation/bedrock/get_cache_telemetry.js +102 -0
  30. package/dist/src/instrumentation/bedrock/get_input_message_content_telemetry.d.ts +15 -0
  31. package/dist/src/instrumentation/bedrock/get_input_message_content_telemetry.js +91 -0
  32. package/dist/src/instrumentation/bedrock/get_model_id_telemetry.d.ts +21 -0
  33. package/dist/src/instrumentation/bedrock/get_model_id_telemetry.js +54 -0
  34. package/dist/src/instrumentation/bedrock/get_reasoning_output_telemetry.d.ts +19 -0
  35. package/dist/src/instrumentation/bedrock/get_reasoning_output_telemetry.js +81 -0
  36. package/dist/src/instrumentation/bedrock/get_streaming_output_message_telemetry.d.ts +27 -0
  37. package/dist/src/instrumentation/bedrock/get_streaming_output_message_telemetry.js +126 -0
  38. package/dist/src/instrumentation/bedrock/get_tool_call_output_telemetry.d.ts +17 -0
  39. package/dist/src/instrumentation/bedrock/get_tool_call_output_telemetry.js +85 -0
  40. package/dist/src/instrumentation/bedrock/get_tool_definitions_telemetry.d.ts +15 -0
  41. package/dist/src/instrumentation/bedrock/get_tool_definitions_telemetry.js +68 -0
  42. package/dist/src/instrumentation/bedrock/set_telemetry_attributes.d.ts +18 -0
  43. package/dist/src/instrumentation/bedrock/set_telemetry_attributes.js +47 -0
  44. package/dist/src/instrumentation/cohere/get_chat_telemetry.d.ts +23 -0
  45. package/dist/src/instrumentation/cohere/get_chat_telemetry.js +77 -0
  46. package/dist/src/instrumentation/cohere/get_embeddings_telemetry.d.ts +18 -0
  47. package/dist/src/instrumentation/cohere/get_embeddings_telemetry.js +88 -0
  48. package/dist/src/instrumentation/cohere/get_structured_output_schema_telemetry.d.ts +12 -0
  49. package/dist/src/instrumentation/cohere/get_structured_output_schema_telemetry.js +18 -0
  50. package/dist/src/instrumentation/cohere/get_tool_call_output_telemetry.d.ts +31 -0
  51. package/dist/src/instrumentation/cohere/get_tool_call_output_telemetry.js +106 -0
  52. package/dist/src/instrumentation/cohere/get_tool_definitions_telemetry.d.ts +27 -0
  53. package/dist/src/instrumentation/cohere/get_tool_definitions_telemetry.js +75 -0
  54. package/dist/src/instrumentation/cohere/set_telemetry_attributes.d.ts +17 -0
  55. package/dist/src/instrumentation/cohere/set_telemetry_attributes.js +44 -0
  56. package/dist/src/instrumentation/elevenlabs/full_instrumentation.d.ts +28 -0
  57. package/dist/src/instrumentation/elevenlabs/full_instrumentation.js +209 -0
  58. package/dist/src/instrumentation/google/get_audio_telemetry.d.ts +9 -0
  59. package/dist/src/instrumentation/google/get_audio_telemetry.js +28 -0
  60. package/dist/src/instrumentation/google/get_cache_operations_telemetry.d.ts +23 -0
  61. package/dist/src/instrumentation/google/get_cache_operations_telemetry.js +154 -0
  62. package/dist/src/instrumentation/google/get_cache_telemetry.d.ts +16 -0
  63. package/dist/src/instrumentation/google/get_cache_telemetry.js +38 -0
  64. package/dist/src/instrumentation/google/get_embeddings_telemetry.d.ts +12 -0
  65. package/dist/src/instrumentation/google/get_embeddings_telemetry.js +85 -0
  66. package/dist/src/instrumentation/google/get_provider_name.d.ts +11 -0
  67. package/{src → dist/src}/instrumentation/google/get_provider_name.js +11 -12
  68. package/{src/instrumentation/google/get_reasoning_telemetry.js → dist/src/instrumentation/google/get_reasoning_telemetry.d.ts} +1 -11
  69. package/dist/src/instrumentation/google/get_reasoning_telemetry.js +21 -0
  70. package/dist/src/instrumentation/google/get_structured_output_schema_telemetry.d.ts +12 -0
  71. package/dist/src/instrumentation/google/get_structured_output_schema_telemetry.js +19 -0
  72. package/dist/src/instrumentation/google/set_telemetry_attributes.d.ts +18 -0
  73. package/dist/src/instrumentation/google/set_telemetry_attributes.js +98 -0
  74. package/dist/src/instrumentation/openai/get_audio_telemetry.d.ts +25 -0
  75. package/dist/src/instrumentation/openai/get_audio_telemetry.js +123 -0
  76. package/dist/src/instrumentation/openai/get_bedrock_mantle_telemetry.d.ts +35 -0
  77. package/dist/src/instrumentation/openai/get_bedrock_mantle_telemetry.js +148 -0
  78. package/dist/src/instrumentation/openai/get_cache_and_reasoning_telemetry.d.ts +27 -0
  79. package/dist/src/instrumentation/openai/get_cache_and_reasoning_telemetry.js +72 -0
  80. package/dist/src/instrumentation/openai/get_cache_config_telemetry.d.ts +28 -0
  81. package/dist/src/instrumentation/openai/get_cache_config_telemetry.js +91 -0
  82. package/dist/src/instrumentation/openai/get_embeddings_telemetry.d.ts +18 -0
  83. package/dist/src/instrumentation/openai/get_embeddings_telemetry.js +86 -0
  84. package/dist/src/instrumentation/openai/get_streaming_usage.d.ts +21 -0
  85. package/dist/src/instrumentation/openai/get_streaming_usage.js +74 -0
  86. package/dist/src/instrumentation/openai/get_structured_output_schema_telemetry.d.ts +12 -0
  87. package/dist/src/instrumentation/openai/get_structured_output_schema_telemetry.js +20 -0
  88. package/dist/src/instrumentation/openai/set_telemetry_attributes.d.ts +17 -0
  89. package/dist/src/instrumentation/openai/set_telemetry_attributes.js +47 -0
  90. package/dist/src/instrumentation/shared/get_structured_output_schema_telemetry.d.ts +35 -0
  91. package/dist/src/instrumentation/shared/get_structured_output_schema_telemetry.js +76 -0
  92. package/dist/src/instrumentation/vercel/full_instrumentation.d.ts +3 -0
  93. package/dist/src/instrumentation/vercel/full_instrumentation.js +54 -0
  94. package/dist/src/instrumentation/vercel/get_cache_creation_telemetry.d.ts +22 -0
  95. package/dist/src/instrumentation/vercel/get_cache_creation_telemetry.js +66 -0
  96. package/dist/src/instrumentation/vercel/get_structured_output_schema_telemetry.d.ts +24 -0
  97. package/dist/src/instrumentation/vercel/get_structured_output_schema_telemetry.js +84 -0
  98. package/dist/src/logger.d.ts +1 -0
  99. package/dist/src/logger.js +6 -0
  100. package/dist/src/otel/exporter.d.ts +19 -0
  101. package/dist/src/otel/exporter.js +94 -0
  102. package/dist/src/otel/propagation.d.ts +46 -0
  103. package/dist/src/otel/propagation.js +110 -0
  104. package/dist/src/otel/span-filter.d.ts +3 -0
  105. package/dist/src/otel/span-filter.js +61 -0
  106. package/dist/src/otel/span-processor.d.ts +55 -0
  107. package/dist/src/otel/span-processor.js +169 -0
  108. package/dist/src/otel/vercel-ai-sdk-span-filter.d.ts +12 -0
  109. package/dist/src/otel/vercel-ai-sdk-span-filter.js +88 -0
  110. package/dist/src/setup.d.ts +50 -0
  111. package/dist/src/setup.js +155 -0
  112. package/package.json +11 -5
  113. package/.prettierignore +0 -2
  114. package/.prettierrc.json +0 -7
  115. package/LICENSE-MIT +0 -21
  116. package/NOTICE +0 -12
  117. package/dist/api/generated/index.d.ts +0 -2
  118. package/dist/api/generated/types.gen.d.ts +0 -749
  119. package/eslint.config.mjs +0 -36
  120. package/index.d.ts +0 -167
  121. package/openapi-ts.config.mjs +0 -9
  122. package/scripts/generate_facade.mjs +0 -86
  123. package/src/api/caseConversion.ts +0 -58
  124. package/src/api/generated/client/client.gen.ts +0 -277
  125. package/src/api/generated/client/index.ts +0 -27
  126. package/src/api/generated/client/types.gen.ts +0 -218
  127. package/src/api/generated/client/utils.gen.ts +0 -316
  128. package/src/api/generated/client.gen.ts +0 -16
  129. package/src/api/generated/core/auth.gen.ts +0 -48
  130. package/src/api/generated/core/bodySerializer.gen.ts +0 -82
  131. package/src/api/generated/core/params.gen.ts +0 -178
  132. package/src/api/generated/core/pathSerializer.gen.ts +0 -171
  133. package/src/api/generated/core/queryKeySerializer.gen.ts +0 -117
  134. package/src/api/generated/core/serverSentEvents.gen.ts +0 -242
  135. package/src/api/generated/core/types.gen.ts +0 -110
  136. package/src/api/generated/core/utils.gen.ts +0 -140
  137. package/src/api/generated/facade.gen.ts +0 -68
  138. package/src/api/generated/index.ts +0 -4
  139. package/src/api/generated/sdk.gen.ts +0 -121
  140. package/src/api/index.ts +0 -45
  141. package/src/api/makeEndpoint.ts +0 -54
  142. package/src/auto-instrument.js +0 -171
  143. package/src/index.js +0 -19
  144. package/src/instrumentation/anthropic/get_cache_and_reasoning_telemetry.js +0 -107
  145. package/src/instrumentation/anthropic/get_streaming_stop_reason_telemetry.js +0 -121
  146. package/src/instrumentation/anthropic/get_tool_definitions_telemetry.js +0 -50
  147. package/src/instrumentation/anthropic/set_telemetry_attributes.js +0 -37
  148. package/src/instrumentation/bedrock/get_cache_telemetry.js +0 -104
  149. package/src/instrumentation/bedrock/get_input_message_content_telemetry.js +0 -94
  150. package/src/instrumentation/bedrock/get_streaming_output_message_telemetry.js +0 -87
  151. package/src/instrumentation/bedrock/set_telemetry_attributes.js +0 -36
  152. package/src/instrumentation/cohere/get_chat_telemetry.js +0 -88
  153. package/src/instrumentation/cohere/get_embeddings_telemetry.js +0 -107
  154. package/src/instrumentation/cohere/set_telemetry_attributes.js +0 -32
  155. package/src/instrumentation/elevenlabs/full_instrumentation.js +0 -236
  156. package/src/instrumentation/google/get_audio_telemetry.js +0 -30
  157. package/src/instrumentation/google/get_cache_telemetry.js +0 -25
  158. package/src/instrumentation/google/get_embeddings_telemetry.js +0 -99
  159. package/src/instrumentation/google/set_telemetry_attributes.js +0 -98
  160. package/src/instrumentation/openai/get_audio_telemetry.js +0 -149
  161. package/src/instrumentation/openai/get_cache_and_reasoning_telemetry.js +0 -71
  162. package/src/instrumentation/openai/get_embeddings_telemetry.js +0 -107
  163. package/src/instrumentation/openai/get_streaming_usage.js +0 -81
  164. package/src/instrumentation/openai/set_telemetry_attributes.js +0 -39
  165. package/src/instrumentation/vercel/full_instrumentation.js +0 -44
  166. package/src/logger.js +0 -8
  167. package/src/otel/exporter.js +0 -108
  168. package/src/otel/propagation.js +0 -133
  169. package/src/otel/span-filter.js +0 -69
  170. package/src/otel/span-processor.js +0 -162
  171. package/src/otel/vercel-ai-sdk-span-filter.js +0 -79
  172. package/src/setup.js +0 -167
  173. package/tests/api/index.test.js +0 -437
  174. package/tests/index.test.js +0 -824
  175. package/tests/instrumentation/anthropic/get_cache_and_reasoning_telemetry.test.js +0 -158
  176. package/tests/instrumentation/anthropic/get_streaming_stop_reason_telemetry.test.js +0 -117
  177. package/tests/instrumentation/anthropic/get_tool_definitions_telemetry.test.js +0 -82
  178. package/tests/instrumentation/bedrock/get_cache_telemetry.test.js +0 -102
  179. package/tests/instrumentation/bedrock/get_input_message_content_telemetry.test.js +0 -89
  180. package/tests/instrumentation/bedrock/get_streaming_output_message_telemetry.test.js +0 -87
  181. package/tests/instrumentation/cohere/get_chat_telemetry.test.js +0 -148
  182. package/tests/instrumentation/cohere/get_embeddings_telemetry.test.js +0 -132
  183. package/tests/instrumentation/elevenlabs/full_instrumentation.test.js +0 -258
  184. package/tests/instrumentation/google/get_embeddings_telemetry.test.js +0 -128
  185. package/tests/instrumentation/google/get_reasoning_telemetry.test.js +0 -41
  186. package/tests/instrumentation/google/set_telemetry_attributes.test.js +0 -219
  187. package/tests/instrumentation/openai/get_audio_telemetry.test.js +0 -170
  188. package/tests/instrumentation/openai/get_cache_and_reasoning_telemetry.test.js +0 -83
  189. package/tests/instrumentation/openai/get_embeddings_telemetry.test.js +0 -145
  190. package/tests/instrumentation/openai/get_streaming_usage.test.js +0 -105
  191. package/tests/instrumentation/vercel/full_instrumentation.test.js +0 -16
  192. package/tests/otel/vercel-ai-sdk-span-filter.test.js +0 -159
  193. package/tsconfig.json +0 -18
  194. /package/dist/{api → src/api}/caseConversion.d.ts +0 -0
  195. /package/dist/{api → src/api}/caseConversion.js +0 -0
  196. /package/dist/{api → src/api}/generated/client/client.gen.d.ts +0 -0
  197. /package/dist/{api → src/api}/generated/client/client.gen.js +0 -0
  198. /package/dist/{api → src/api}/generated/client/index.d.ts +0 -0
  199. /package/dist/{api → src/api}/generated/client/index.js +0 -0
  200. /package/dist/{api → src/api}/generated/client/types.gen.d.ts +0 -0
  201. /package/dist/{api → src/api}/generated/client/types.gen.js +0 -0
  202. /package/dist/{api → src/api}/generated/client/utils.gen.d.ts +0 -0
  203. /package/dist/{api → src/api}/generated/client/utils.gen.js +0 -0
  204. /package/dist/{api → src/api}/generated/client.gen.d.ts +0 -0
  205. /package/dist/{api → src/api}/generated/client.gen.js +0 -0
  206. /package/dist/{api → src/api}/generated/core/auth.gen.d.ts +0 -0
  207. /package/dist/{api → src/api}/generated/core/auth.gen.js +0 -0
  208. /package/dist/{api → src/api}/generated/core/bodySerializer.gen.d.ts +0 -0
  209. /package/dist/{api → src/api}/generated/core/bodySerializer.gen.js +0 -0
  210. /package/dist/{api → src/api}/generated/core/params.gen.d.ts +0 -0
  211. /package/dist/{api → src/api}/generated/core/params.gen.js +0 -0
  212. /package/dist/{api → src/api}/generated/core/pathSerializer.gen.d.ts +0 -0
  213. /package/dist/{api → src/api}/generated/core/pathSerializer.gen.js +0 -0
  214. /package/dist/{api → src/api}/generated/core/queryKeySerializer.gen.d.ts +0 -0
  215. /package/dist/{api → src/api}/generated/core/queryKeySerializer.gen.js +0 -0
  216. /package/dist/{api → src/api}/generated/core/serverSentEvents.gen.d.ts +0 -0
  217. /package/dist/{api → src/api}/generated/core/serverSentEvents.gen.js +0 -0
  218. /package/dist/{api → src/api}/generated/core/types.gen.d.ts +0 -0
  219. /package/dist/{api → src/api}/generated/core/types.gen.js +0 -0
  220. /package/dist/{api → src/api}/generated/core/utils.gen.d.ts +0 -0
  221. /package/dist/{api → src/api}/generated/core/utils.gen.js +0 -0
  222. /package/dist/{api → src/api}/generated/types.gen.js +0 -0
  223. /package/dist/{api → src/api}/index.d.ts +0 -0
  224. /package/dist/{api → src/api}/index.js +0 -0
  225. /package/dist/{api → src/api}/makeEndpoint.d.ts +0 -0
package/eslint.config.mjs DELETED
@@ -1,36 +0,0 @@
1
- export default [
2
- {
3
- languageOptions: {
4
- ecmaVersion: 2023,
5
- sourceType: "commonjs",
6
- globals: {
7
- // Node.js
8
- require: "readonly",
9
- module: "readonly",
10
- exports: "writable",
11
- __dirname: "readonly",
12
- __filename: "readonly",
13
- process: "readonly",
14
- Buffer: "readonly",
15
- console: "readonly",
16
- setTimeout: "readonly",
17
- clearTimeout: "readonly",
18
- setInterval: "readonly",
19
- clearInterval: "readonly",
20
- // Web platform (available in modern Node)
21
- fetch: "readonly",
22
- URL: "readonly",
23
- ReadableStream: "readonly",
24
- TransformStream: "readonly",
25
- TextEncoder: "readonly",
26
- TextDecoder: "readonly",
27
- },
28
- },
29
- rules: {
30
- "no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
31
- "no-undef": "error",
32
- "prefer-const": "warn",
33
- eqeqeq: ["error", "smart"],
34
- },
35
- },
36
- ];
package/index.d.ts DELETED
@@ -1,167 +0,0 @@
1
- /** Arbitrary key-value tags applied to OTel spans. */
2
- export type Tags = Record<string, string | number | boolean>;
3
-
4
- /**
5
- * Span attributes the mask callback can read or scrub. The OpenTelemetry GenAI
6
- * semantic-convention keys get autocomplete; the index signature catches user
7
- * tags and provider-specific attributes (e.g. Vercel AI's `ai.*`).
8
- */
9
- export interface OtelSpanAttributes {
10
- 'gen_ai.system'?: string;
11
- 'gen_ai.operation.name'?: string;
12
- 'gen_ai.request.model'?: string;
13
- 'gen_ai.request.temperature'?: number;
14
- 'gen_ai.request.max_tokens'?: number;
15
- 'gen_ai.response.model'?: string;
16
- 'gen_ai.response.id'?: string;
17
- 'gen_ai.response.finish_reasons'?: string[];
18
- 'gen_ai.usage.input_tokens'?: number;
19
- 'gen_ai.usage.output_tokens'?: number;
20
- /** Only populated when `captureMessageContent=true`. */
21
- 'gen_ai.prompt'?: string;
22
- /** Only populated when `captureMessageContent=true`. */
23
- 'gen_ai.completion'?: string;
24
- 'gen_ai.tool.name'?: string;
25
- 'gen_ai.tool.call.id'?: string;
26
- 'gen_ai.tool.call.arguments'?: string;
27
- 'error.type'?: string;
28
- [key: string]: unknown;
29
- }
30
-
31
- /** LLM provider SDKs the `autoInstrument` registry knows how to wire up. */
32
- export const AiSdk: {
33
- readonly OPENAI: 'openai';
34
- readonly ANTHROPIC: 'anthropic';
35
- readonly BEDROCK: 'bedrock';
36
- readonly COHERE: 'cohere';
37
- readonly GOOGLE_GENAI: 'google-genai';
38
- readonly ELEVENLABS: 'elevenlabs';
39
- readonly VERCEL_AI_GATEWAY: 'vercel_ai_gateway';
40
- };
41
- export type AiSdk = (typeof AiSdk)[keyof typeof AiSdk];
42
-
43
- /**
44
- * Allowed values for `propagateMetadata({ providerName })`: the actual AI
45
- * providers a call can be attributed to. Unlike AiSdk this names providers,
46
- * not SDKs — google-genai is an SDK whose calls are labelled gemini or vertex,
47
- * and mistral is reached via the OpenAI SDK on the wire but reported as itself.
48
- */
49
- export const AIProviderName: {
50
- readonly OPENAI: 'openai';
51
- readonly ANTHROPIC: 'anthropic';
52
- readonly BEDROCK: 'bedrock';
53
- readonly COHERE: 'cohere';
54
- readonly ELEVENLABS: 'elevenlabs';
55
- readonly MISTRAL: 'mistral';
56
- readonly VERCEL_AI_GATEWAY: 'vercel_ai_gateway';
57
- readonly GEMINI: 'gemini';
58
- readonly VERTEX: 'vertex';
59
- };
60
- export type AIProviderName = (typeof AIProviderName)[keyof typeof AIProviderName];
61
-
62
- export interface SetupOptions {
63
- /** Weflayr API key. The server resolves your project_uuid from this token. */
64
- apiKey: string;
65
- /** Override the intake base URL. Defaults to WEFLAYR_BASE_URL or https://api.weflayr.com. */
66
- baseUrl?: string;
67
- /** Tags applied to every emitted span. */
68
- defaultTags?: Tags;
69
- /**
70
- * `'batch'` (default) groups spans for throughput. `'immediate'` flushes every
71
- * span synchronously — recommended for short-lived runtimes (Lambda, edge).
72
- */
73
- exportMode?: 'batch' | 'immediate';
74
- /**
75
- * When `false`, sets OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=false
76
- * so instrumentations strip `gen_ai.prompt` / `gen_ai.completion` from spans
77
- * before they're emitted. Defaults to `true`.
78
- */
79
- captureMessageContent?: boolean;
80
- /**
81
- * Last-line-of-defense scrubber. Receives the span attribute bag just before
82
- * export; return the (optionally mutated) bag.
83
- */
84
- mask?: (attrs: OtelSpanAttributes) => OtelSpanAttributes;
85
- }
86
-
87
- /** Initializes the OpenTelemetry tracer + exporter. Call once at app start. */
88
- export function setup(options: SetupOptions): void;
89
-
90
- /**
91
- * Loads and registers OpenTelemetry instrumentation packages for the given provider SDKs.
92
- * Throws a clear "install package X" error if the matching package isn't installed.
93
- *
94
- * @example
95
- * await weflayr.autoInstrument({ aiSdks: weflayr.AiSdk.OPENAI, apiKey: '...' });
96
- * await weflayr.autoInstrument({ aiSdks: [weflayr.AiSdk.OPENAI, weflayr.AiSdk.ANTHROPIC] });
97
- */
98
- export function autoInstrument(
99
- options: { aiSdks: AiSdk | AiSdk[] } & Partial<SetupOptions>
100
- ): Promise<void>;
101
-
102
- export interface PropagateMetadataOptions {
103
- /** Product-side feature triggering the LLM call (e.g. `"onboarding-summary"`). */
104
- featureName: string;
105
- /** Name of the end-user / tenant customer the call is made for. */
106
- customerName?: string;
107
- /** @deprecated Use `customerName` instead. */
108
- customerId?: string;
109
- /**
110
- * Override for the provider seen on the wire. Set this only if it differs
111
- * from the SDK auto-detected by OpenTelemetry — e.g. calls routed through
112
- * `vercel_ai_gateway` that proxies to OpenAI/Anthropic but should be
113
- * reported as the gateway.
114
- */
115
- providerName?: AIProviderName;
116
- /**
117
- * Arbitrary scalar key/value pairs to attach. Values must be `string`,
118
- * `number`, or `boolean` so they survive the ClickHouse `Map(String,
119
- * String)` column they land in. Avoid `featureName` / `customerName` keys
120
- * here — they have dedicated fields.
121
- */
122
- extraTags?: Record<string, string | number | boolean>;
123
- }
124
-
125
- /**
126
- * Attach Weflayr metadata to every LLM span created inside `fn`.
127
- *
128
- * Every invocation mints a fresh `uuid` that is stamped on every span inside
129
- * the scope, so all calls made under one `propagateMetadata` block can be
130
- * correlated downstream.
131
- *
132
- * @example
133
- * await weflayr.propagateMetadata(
134
- * { featureName: 'onboarding', customerName: 'Acme Corp', extraTags: { variant: 'control' } },
135
- * async () => { await openai.chat.completions.create({ ... }); },
136
- * );
137
- */
138
- export function propagateMetadata<T>(
139
- options: PropagateMetadataOptions,
140
- fn: () => Promise<T> | T
141
- ): Promise<T> | T;
142
-
143
- /**
144
- * Decorator form. Apply to a class method to propagate metadata around every call.
145
- * Each invocation of the wrapped function mints its own `uuid`.
146
- *
147
- * @example
148
- * class ChatService {
149
- * @weflayr.propagateMetadata({ featureName: 'chat', customerName: 'Acme Corp' })
150
- * async reply(userId: string) { ... }
151
- * }
152
- */
153
- export function propagateMetadata(
154
- options: PropagateMetadataOptions
155
- ): <T>(target: T, key?: string, descriptor?: PropertyDescriptor) => T;
156
-
157
- /** Flush any pending spans. Await before a short-lived runtime exits. */
158
- export function flush(): Promise<void>;
159
-
160
- /**
161
- * Endpoint functions for the Weflayr public API (revenue, key metrics, customer
162
- * tags), generated from the platform's OpenAPI spec.
163
- */
164
- export * as api from './dist/api';
165
-
166
- /** A client for the public API, authenticated with a project API key. */
167
- export { client, type ApiClientOptions } from './dist/api';
@@ -1,9 +0,0 @@
1
- import { defineConfig } from '@hey-api/openapi-ts';
2
-
3
- // Regenerated by `make generate-sdk-api-clients`; src/api/generated/ is wiped
4
- // on every run, the handwritten facade lives in src/api/index.ts.
5
- export default defineConfig({
6
- input: '../observability_dashboard/app_api/openapi.json',
7
- output: 'src/api/generated',
8
- plugins: ['@hey-api/client-fetch'],
9
- });
@@ -1,86 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- // Generates src/api/generated/facade.gen.ts: one camelCase-facing wrapper
5
- // per public-API endpoint exported from src/api/generated/sdk.gen.ts.
6
- //
7
- // Run via `npm run generate-api`, right after `openapi-ts` regenerates
8
- // src/api/generated/ (which wipes the directory first, so this always
9
- // starts from a clean slate). Do not edit facade.gen.ts by hand - it is
10
- // overwritten on every run.
11
- //
12
- // @hey-api/openapi-ts names an operation's request/response types after its
13
- // PascalCase operation name (e.g. operation `getRevenue` gets types
14
- // `GetRevenueData`, `GetRevenueResponse`, `GetRevenueError`), so the
15
- // only thing this script needs from the generated source is the list of
16
- // operation names - the type names, and the per-endpoint camelCase/snake_case
17
- // conversion, follow mechanically from there.
18
-
19
- import { readFileSync, writeFileSync } from 'node:fs';
20
- import path from 'node:path';
21
- import { fileURLToPath } from 'node:url';
22
-
23
- const GENERATED_DIR = path.join(
24
- path.dirname(fileURLToPath(import.meta.url)),
25
- '..',
26
- 'src',
27
- 'api',
28
- 'generated'
29
- );
30
- const SDK_PATH = path.join(GENERATED_DIR, 'sdk.gen.ts');
31
- const TYPES_PATH = path.join(GENERATED_DIR, 'types.gen.ts');
32
- const OUTPUT_PATH = path.join(GENERATED_DIR, 'facade.gen.ts');
33
-
34
- const HEADER = `// Generated by services/sdk_node_js/scripts/generate_facade.mjs from
35
- // sdk.gen.ts. Do not edit by hand.
36
-
37
- import { makeEndpoint } from '../makeEndpoint.js';
38
- import type { CamelCaseDeep } from '../caseConversion.js';
39
- import * as generated from './sdk.gen.js';
40
- import type * as generatedTypes from './types.gen.js';
41
- `;
42
-
43
- function pascalCase(operationName) {
44
- return operationName[0].toUpperCase() + operationName.slice(1);
45
- }
46
-
47
- function collectOperationNames(sdkSource) {
48
- return [...sdkSource.matchAll(/^export const (\w+) = </gm)].map((match) => match[1]);
49
- }
50
-
51
- function collectExportedTypeNames(typesSource) {
52
- return new Set([...typesSource.matchAll(/^export type (\w+)/gm)].map((match) => match[1]));
53
- }
54
-
55
- function main() {
56
- const sdkSource = readFileSync(SDK_PATH, 'utf8');
57
- const typesSource = readFileSync(TYPES_PATH, 'utf8');
58
- const operationNames = collectOperationNames(sdkSource);
59
- const exportedTypeNames = collectExportedTypeNames(typesSource);
60
-
61
- const lines = [HEADER];
62
- for (const operationName of operationNames) {
63
- const pascal = pascalCase(operationName);
64
- for (const suffix of ['Data', 'Response', 'Error']) {
65
- const typeName = `${pascal}${suffix}`;
66
- if (!exportedTypeNames.has(typeName)) {
67
- throw new Error(
68
- `generate_facade.mjs: expected type '${typeName}' for operation '${operationName}' ` +
69
- "not found in types.gen.ts - has @hey-api/openapi-ts's naming convention changed?"
70
- );
71
- }
72
- }
73
- lines.push(
74
- `export const ${operationName} = makeEndpoint<\n` +
75
- ` CamelCaseDeep<Omit<generatedTypes.${pascal}Data, 'url'>>,\n` +
76
- ` CamelCaseDeep<generatedTypes.${pascal}Response>,\n` +
77
- ` CamelCaseDeep<generatedTypes.${pascal}Error>\n` +
78
- `>(generated.${operationName});`
79
- );
80
- }
81
-
82
- writeFileSync(OUTPUT_PATH, lines.join('\n\n') + '\n');
83
- console.log(`Generated ${OUTPUT_PATH} (${operationNames.length} endpoints)`);
84
- }
85
-
86
- main();
@@ -1,58 +0,0 @@
1
- /**
2
- * Converts between the wire's snake_case JSON keys (also the Python SDK's
3
- * native casing) and the camelCase keys this SDK exposes to JS callers.
4
- *
5
- * `tags` (see CustomerTags / CustomerTagsOutput) is a free-form map of
6
- * user-chosen tag names, not a fixed schema - its own field name is renamed
7
- * like any other, but the keys inside it are left untouched in both
8
- * directions, otherwise a tag literally named e.g. "utm_source" would be
9
- * silently mangled into "utmSource" on the way out.
10
- */
11
-
12
- const OPAQUE_KEYS = new Set(['tags']);
13
-
14
- export type CamelCase<S extends string> = S extends `${infer Head}_${infer Tail}`
15
- ? `${Head}${Capitalize<CamelCase<Tail>>}`
16
- : S;
17
-
18
- export type CamelCaseDeep<T> = T extends readonly (infer Item)[]
19
- ? CamelCaseDeep<Item>[]
20
- : T extends object
21
- ? { [Key in keyof T as CamelCase<Key & string>]: CamelCaseDeep<T[Key]> }
22
- : T;
23
-
24
- function isPlainObject(value: unknown): value is Record<string, unknown> {
25
- return typeof value === 'object' && value !== null && !Array.isArray(value);
26
- }
27
-
28
- function snakeToCamel(key: string): string {
29
- return key.replace(/_[a-z0-9]/g, (match) => match[1].toUpperCase());
30
- }
31
-
32
- function camelToSnake(key: string): string {
33
- return key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
34
- }
35
-
36
- function convertKeysDeep(value: unknown, convertKey: (key: string) => string): unknown {
37
- if (Array.isArray(value)) {
38
- return value.map((item) => convertKeysDeep(item, convertKey));
39
- }
40
- if (!isPlainObject(value)) {
41
- return value;
42
- }
43
- const converted: Record<string, unknown> = {};
44
- for (const [key, entryValue] of Object.entries(value)) {
45
- converted[convertKey(key)] = OPAQUE_KEYS.has(key)
46
- ? entryValue
47
- : convertKeysDeep(entryValue, convertKey);
48
- }
49
- return converted;
50
- }
51
-
52
- export function toCamelCaseDeep<T>(value: T): CamelCaseDeep<T> {
53
- return convertKeysDeep(value, snakeToCamel) as CamelCaseDeep<T>;
54
- }
55
-
56
- export function toSnakeCaseDeep(value: unknown): unknown {
57
- return convertKeysDeep(value, camelToSnake);
58
- }
@@ -1,277 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
-
3
- import { createSseClient } from '../core/serverSentEvents.gen.js';
4
- import type { HttpMethod } from '../core/types.gen.js';
5
- import { getValidRequestBody } from '../core/utils.gen.js';
6
- import type { Client, Config, RequestOptions, ResolvedRequestOptions } from './types.gen.js';
7
- import {
8
- buildUrl,
9
- createConfig,
10
- createInterceptors,
11
- getParseAs,
12
- mergeConfigs,
13
- mergeHeaders,
14
- setAuthParams,
15
- } from './utils.gen.js';
16
-
17
- type ReqInit = Omit<RequestInit, 'body' | 'headers'> & {
18
- body?: any;
19
- headers: ReturnType<typeof mergeHeaders>;
20
- };
21
-
22
- export const createClient = (config: Config = {}): Client => {
23
- let _config = mergeConfigs(createConfig(), config);
24
-
25
- const getConfig = (): Config => ({ ..._config });
26
-
27
- const setConfig = (config: Config): Config => {
28
- _config = mergeConfigs(_config, config);
29
- return getConfig();
30
- };
31
-
32
- const interceptors = createInterceptors<Request, Response, unknown, ResolvedRequestOptions>();
33
-
34
- const beforeRequest = async <
35
- TData = unknown,
36
- TResponseStyle extends 'data' | 'fields' = 'fields',
37
- ThrowOnError extends boolean = boolean,
38
- Url extends string = string,
39
- >(
40
- options: RequestOptions<TData, TResponseStyle, ThrowOnError, Url>,
41
- ) => {
42
- const opts = {
43
- ..._config,
44
- ...options,
45
- fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
46
- headers: mergeHeaders(_config.headers, options.headers),
47
- serializedBody: undefined as string | undefined,
48
- };
49
-
50
- if (opts.security) {
51
- await setAuthParams(opts);
52
- }
53
-
54
- if (opts.requestValidator) {
55
- await opts.requestValidator(opts);
56
- }
57
-
58
- if (opts.body !== undefined && opts.bodySerializer) {
59
- opts.serializedBody = opts.bodySerializer(opts.body) as string | undefined;
60
- }
61
-
62
- // remove Content-Type header if body is empty to avoid sending invalid requests
63
- if (opts.body === undefined || opts.serializedBody === '') {
64
- opts.headers.delete('Content-Type');
65
- }
66
-
67
- const resolvedOpts = opts as typeof opts &
68
- ResolvedRequestOptions<TResponseStyle, ThrowOnError, Url>;
69
- const url = buildUrl(resolvedOpts);
70
-
71
- return { opts: resolvedOpts, url };
72
- };
73
-
74
- const request: Client['request'] = async (options) => {
75
- const throwOnError = options.throwOnError ?? _config.throwOnError;
76
- const responseStyle = options.responseStyle ?? _config.responseStyle;
77
-
78
- let request: Request | undefined;
79
- let response: Response | undefined;
80
-
81
- try {
82
- const { opts, url } = await beforeRequest(options);
83
- const requestInit: ReqInit = {
84
- redirect: 'follow',
85
- ...opts,
86
- body: getValidRequestBody(opts),
87
- };
88
-
89
- request = new Request(url, requestInit);
90
-
91
- for (const fn of interceptors.request.fns) {
92
- if (fn) {
93
- request = await fn(request, opts);
94
- }
95
- }
96
-
97
- // fetch must be assigned here, otherwise it would throw the error:
98
- // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
99
- const _fetch = opts.fetch!;
100
-
101
- response = await _fetch(request);
102
-
103
- for (const fn of interceptors.response.fns) {
104
- if (fn) {
105
- response = await fn(response, request, opts);
106
- }
107
- }
108
-
109
- const result = {
110
- request,
111
- response,
112
- };
113
-
114
- if (response.ok) {
115
- const parseAs =
116
- (opts.parseAs === 'auto'
117
- ? getParseAs(response.headers.get('Content-Type'))
118
- : opts.parseAs) ?? 'json';
119
-
120
- if (response.status === 204 || response.headers.get('Content-Length') === '0') {
121
- let emptyData: any;
122
- switch (parseAs) {
123
- case 'arrayBuffer':
124
- case 'blob':
125
- case 'text':
126
- emptyData = await response[parseAs]();
127
- break;
128
- case 'formData':
129
- emptyData = new FormData();
130
- break;
131
- case 'stream':
132
- emptyData = response.body;
133
- break;
134
- case 'json':
135
- default:
136
- emptyData = {};
137
- break;
138
- }
139
- return opts.responseStyle === 'data'
140
- ? emptyData
141
- : {
142
- data: emptyData,
143
- ...result,
144
- };
145
- }
146
-
147
- let data: any;
148
- switch (parseAs) {
149
- case 'arrayBuffer':
150
- case 'blob':
151
- case 'formData':
152
- case 'text':
153
- data = await response[parseAs]();
154
- break;
155
- case 'json': {
156
- // Some servers return 200 with no Content-Length and empty body.
157
- // response.json() would throw; read as text and parse if non-empty.
158
- const text = await response.text();
159
- data = text ? JSON.parse(text) : {};
160
- break;
161
- }
162
- case 'stream':
163
- return opts.responseStyle === 'data'
164
- ? response.body
165
- : {
166
- data: response.body,
167
- ...result,
168
- };
169
- }
170
-
171
- if (parseAs === 'json') {
172
- if (opts.responseValidator) {
173
- await opts.responseValidator(data);
174
- }
175
-
176
- if (opts.responseTransformer) {
177
- data = await opts.responseTransformer(data);
178
- }
179
- }
180
-
181
- return opts.responseStyle === 'data'
182
- ? data
183
- : {
184
- data,
185
- ...result,
186
- };
187
- }
188
-
189
- const textError = await response.text();
190
- let jsonError: unknown;
191
-
192
- try {
193
- jsonError = JSON.parse(textError);
194
- } catch {
195
- // noop
196
- }
197
-
198
- throw jsonError ?? textError;
199
- } catch (error) {
200
- let finalError = error;
201
-
202
- for (const fn of interceptors.error.fns) {
203
- if (fn) {
204
- finalError = await fn(finalError, response, request, options as ResolvedRequestOptions);
205
- }
206
- }
207
-
208
- finalError = finalError || {};
209
-
210
- if (throwOnError) {
211
- throw finalError;
212
- }
213
-
214
- // TODO: we probably want to return error and improve types
215
- return responseStyle === 'data'
216
- ? undefined
217
- : {
218
- error: finalError,
219
- request,
220
- response,
221
- };
222
- }
223
- };
224
-
225
- const makeMethodFn = (method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
226
- request({ ...options, method });
227
-
228
- const makeSseFn = (method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
229
- const { opts, url } = await beforeRequest(options);
230
- return createSseClient({
231
- ...opts,
232
- body: opts.body as BodyInit | null | undefined,
233
- method,
234
- onRequest: async (url, init) => {
235
- let request = new Request(url, init);
236
- for (const fn of interceptors.request.fns) {
237
- if (fn) {
238
- request = await fn(request, opts);
239
- }
240
- }
241
- return request;
242
- },
243
- serializedBody: getValidRequestBody(opts) as BodyInit | null | undefined,
244
- url,
245
- });
246
- };
247
-
248
- const _buildUrl: Client['buildUrl'] = (options) => buildUrl({ ..._config, ...options });
249
-
250
- return {
251
- buildUrl: _buildUrl,
252
- connect: makeMethodFn('CONNECT'),
253
- delete: makeMethodFn('DELETE'),
254
- get: makeMethodFn('GET'),
255
- getConfig,
256
- head: makeMethodFn('HEAD'),
257
- interceptors,
258
- options: makeMethodFn('OPTIONS'),
259
- patch: makeMethodFn('PATCH'),
260
- post: makeMethodFn('POST'),
261
- put: makeMethodFn('PUT'),
262
- request,
263
- setConfig,
264
- sse: {
265
- connect: makeSseFn('CONNECT'),
266
- delete: makeSseFn('DELETE'),
267
- get: makeSseFn('GET'),
268
- head: makeSseFn('HEAD'),
269
- options: makeSseFn('OPTIONS'),
270
- patch: makeSseFn('PATCH'),
271
- post: makeSseFn('POST'),
272
- put: makeSseFn('PUT'),
273
- trace: makeSseFn('TRACE'),
274
- },
275
- trace: makeMethodFn('TRACE'),
276
- } as Client;
277
- };
@@ -1,27 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
-
3
- export type { Auth } from '../core/auth.gen.js';
4
- export type { QuerySerializerOptions } from '../core/bodySerializer.gen.js';
5
- export {
6
- formDataBodySerializer,
7
- jsonBodySerializer,
8
- urlSearchParamsBodySerializer,
9
- } from '../core/bodySerializer.gen.js';
10
- export { buildClientParams } from '../core/params.gen.js';
11
- export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen.js';
12
- export type { ServerSentEventsResult } from '../core/serverSentEvents.gen.js';
13
- export type { ClientMeta } from '../core/types.gen.js';
14
- export { createClient } from './client.gen.js';
15
- export type {
16
- Client,
17
- ClientOptions,
18
- Config,
19
- CreateClientConfig,
20
- Options,
21
- RequestOptions,
22
- RequestResult,
23
- ResolvedRequestOptions,
24
- ResponseStyle,
25
- TDataShape,
26
- } from './types.gen.js';
27
- export { createConfig, mergeHeaders } from './utils.gen.js';