langsmith 0.7.8 → 0.7.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +161 -15
- package/dist/_openapi_client/client.cjs +814 -0
- package/dist/_openapi_client/client.d.ts +247 -0
- package/dist/_openapi_client/client.js +777 -0
- package/dist/_openapi_client/core/api-promise.cjs +100 -0
- package/dist/_openapi_client/core/api-promise.d.ts +45 -0
- package/dist/_openapi_client/core/api-promise.js +96 -0
- package/dist/_openapi_client/core/error.cjs +134 -0
- package/dist/_openapi_client/core/error.d.ts +45 -0
- package/dist/_openapi_client/core/error.js +118 -0
- package/dist/_openapi_client/core/pagination.cjs +374 -0
- package/dist/_openapi_client/core/pagination.d.ts +157 -0
- package/dist/_openapi_client/core/pagination.js +361 -0
- package/dist/_openapi_client/core/resource.cjs +17 -0
- package/dist/_openapi_client/core/resource.d.ts +5 -0
- package/dist/_openapi_client/core/resource.js +13 -0
- package/dist/_openapi_client/core/uploads.cjs +5 -0
- package/dist/_openapi_client/core/uploads.d.ts +2 -0
- package/dist/_openapi_client/core/uploads.js +1 -0
- package/dist/_openapi_client/index.cjs +29 -0
- package/dist/_openapi_client/index.d.ts +6 -0
- package/dist/_openapi_client/index.js +8 -0
- package/dist/_openapi_client/internal/builtin-types.cjs +4 -0
- package/dist/_openapi_client/internal/builtin-types.d.ts +72 -0
- package/dist/_openapi_client/internal/builtin-types.js +3 -0
- package/dist/_openapi_client/internal/detect-platform.cjs +162 -0
- package/dist/_openapi_client/internal/detect-platform.d.ts +14 -0
- package/dist/_openapi_client/internal/detect-platform.js +157 -0
- package/dist/_openapi_client/internal/errors.cjs +41 -0
- package/dist/_openapi_client/internal/errors.d.ts +2 -0
- package/dist/_openapi_client/internal/errors.js +36 -0
- package/dist/_openapi_client/internal/headers.cjs +79 -0
- package/dist/_openapi_client/internal/headers.d.ts +5 -0
- package/dist/_openapi_client/internal/headers.js +74 -0
- package/dist/_openapi_client/internal/parse.cjs +40 -0
- package/dist/_openapi_client/internal/parse.d.ts +11 -0
- package/dist/_openapi_client/internal/parse.js +37 -0
- package/dist/_openapi_client/internal/qs/formats.cjs +12 -0
- package/dist/_openapi_client/internal/qs/formats.d.ts +6 -0
- package/dist/_openapi_client/internal/qs/formats.js +8 -0
- package/dist/_openapi_client/internal/qs/stringify.cjs +277 -0
- package/dist/_openapi_client/internal/qs/stringify.d.ts +2 -0
- package/dist/_openapi_client/internal/qs/stringify.js +274 -0
- package/dist/_openapi_client/internal/qs/types.cjs +2 -0
- package/dist/_openapi_client/internal/qs/types.d.ts +56 -0
- package/dist/_openapi_client/internal/qs/types.js +1 -0
- package/dist/_openapi_client/internal/qs/utils.cjs +230 -0
- package/dist/_openapi_client/internal/qs/utils.d.ts +14 -0
- package/dist/_openapi_client/internal/qs/utils.js +217 -0
- package/dist/_openapi_client/internal/request-options.cjs +14 -0
- package/dist/_openapi_client/internal/request-options.d.ts +74 -0
- package/dist/_openapi_client/internal/request-options.js +10 -0
- package/dist/_openapi_client/internal/shim-types.cjs +4 -0
- package/dist/_openapi_client/internal/shim-types.d.ts +16 -0
- package/dist/_openapi_client/internal/shim-types.js +3 -0
- package/dist/_openapi_client/internal/shims.cjs +92 -0
- package/dist/_openapi_client/internal/shims.d.ts +25 -0
- package/dist/_openapi_client/internal/shims.js +85 -0
- package/dist/_openapi_client/internal/to-file.cjs +91 -0
- package/dist/_openapi_client/internal/to-file.d.ts +44 -0
- package/dist/_openapi_client/internal/to-file.js +88 -0
- package/dist/_openapi_client/internal/types.cjs +4 -0
- package/dist/_openapi_client/internal/types.d.ts +62 -0
- package/dist/_openapi_client/internal/types.js +3 -0
- package/dist/_openapi_client/internal/uploads.cjs +140 -0
- package/dist/_openapi_client/internal/uploads.d.ts +41 -0
- package/dist/_openapi_client/internal/uploads.js +130 -0
- package/dist/_openapi_client/internal/utils/env.cjs +22 -0
- package/dist/_openapi_client/internal/utils/env.d.ts +8 -0
- package/dist/_openapi_client/internal/utils/env.js +18 -0
- package/dist/_openapi_client/internal/utils/log.cjs +88 -0
- package/dist/_openapi_client/internal/utils/log.d.ts +36 -0
- package/dist/_openapi_client/internal/utils/log.js +82 -0
- package/dist/_openapi_client/internal/utils/path.cjs +79 -0
- package/dist/_openapi_client/internal/utils/path.d.ts +14 -0
- package/dist/_openapi_client/internal/utils/path.js +74 -0
- package/dist/_openapi_client/internal/utils/query.cjs +42 -0
- package/dist/_openapi_client/internal/utils/query.d.ts +1 -0
- package/dist/_openapi_client/internal/utils/query.js +6 -0
- package/dist/_openapi_client/internal/utils/sleep.cjs +7 -0
- package/dist/_openapi_client/internal/utils/sleep.d.ts +1 -0
- package/dist/_openapi_client/internal/utils/sleep.js +3 -0
- package/dist/_openapi_client/internal/utils/uuid.cjs +19 -0
- package/dist/_openapi_client/internal/utils/uuid.d.ts +4 -0
- package/dist/_openapi_client/internal/utils/uuid.js +15 -0
- package/dist/_openapi_client/internal/utils/values.cjs +112 -0
- package/dist/_openapi_client/internal/utils/values.d.ts +17 -0
- package/dist/_openapi_client/internal/utils/values.js +94 -0
- package/dist/_openapi_client/resources/annotation-queues/annotation-queues.cjs +138 -0
- package/dist/_openapi_client/resources/annotation-queues/annotation-queues.d.ts +367 -0
- package/dist/_openapi_client/resources/annotation-queues/annotation-queues.js +101 -0
- package/dist/_openapi_client/resources/annotation-queues/runs.cjs +46 -0
- package/dist/_openapi_client/resources/annotation-queues/runs.d.ts +128 -0
- package/dist/_openapi_client/resources/annotation-queues/runs.js +42 -0
- package/dist/_openapi_client/resources/commits.cjs +44 -0
- package/dist/_openapi_client/resources/commits.d.ts +204 -0
- package/dist/_openapi_client/resources/commits.js +40 -0
- package/dist/_openapi_client/resources/datasets/comparative.cjs +22 -0
- package/dist/_openapi_client/resources/datasets/comparative.d.ts +55 -0
- package/dist/_openapi_client/resources/datasets/comparative.js +18 -0
- package/dist/_openapi_client/resources/datasets/datasets.cjs +193 -0
- package/dist/_openapi_client/resources/datasets/datasets.d.ts +374 -0
- package/dist/_openapi_client/resources/datasets/datasets.js +156 -0
- package/dist/_openapi_client/resources/datasets/experiments.cjs +16 -0
- package/dist/_openapi_client/resources/datasets/experiments.d.ts +23 -0
- package/dist/_openapi_client/resources/datasets/experiments.js +12 -0
- package/dist/_openapi_client/resources/datasets/group.cjs +17 -0
- package/dist/_openapi_client/resources/datasets/group.d.ts +160 -0
- package/dist/_openapi_client/resources/datasets/group.js +13 -0
- package/dist/_openapi_client/resources/datasets/runs.cjs +29 -0
- package/dist/_openapi_client/resources/datasets/runs.d.ts +216 -0
- package/dist/_openapi_client/resources/datasets/runs.js +25 -0
- package/dist/_openapi_client/resources/datasets/share.cjs +32 -0
- package/dist/_openapi_client/resources/datasets/share.d.ts +28 -0
- package/dist/_openapi_client/resources/datasets/share.js +28 -0
- package/dist/_openapi_client/resources/datasets/splits.cjs +22 -0
- package/dist/_openapi_client/resources/datasets/splits.d.ts +30 -0
- package/dist/_openapi_client/resources/datasets/splits.js +18 -0
- package/dist/_openapi_client/resources/datasets/versions.cjs +23 -0
- package/dist/_openapi_client/resources/datasets/versions.d.ts +36 -0
- package/dist/_openapi_client/resources/datasets/versions.js +19 -0
- package/dist/_openapi_client/resources/evaluators.cjs +15 -0
- package/dist/_openapi_client/resources/evaluators.d.ts +125 -0
- package/dist/_openapi_client/resources/evaluators.js +11 -0
- package/dist/_openapi_client/resources/examples/bulk.cjs +24 -0
- package/dist/_openapi_client/resources/examples/bulk.d.ts +78 -0
- package/dist/_openapi_client/resources/examples/bulk.js +20 -0
- package/dist/_openapi_client/resources/examples/examples.cjs +124 -0
- package/dist/_openapi_client/resources/examples/examples.d.ts +182 -0
- package/dist/_openapi_client/resources/examples/examples.js +87 -0
- package/dist/_openapi_client/resources/examples/validate.cjs +21 -0
- package/dist/_openapi_client/resources/examples/validate.d.ts +38 -0
- package/dist/_openapi_client/resources/examples/validate.js +17 -0
- package/dist/_openapi_client/resources/feedback/configs.cjs +24 -0
- package/dist/_openapi_client/resources/feedback/configs.d.ts +18 -0
- package/dist/_openapi_client/resources/feedback/configs.js +20 -0
- package/dist/_openapi_client/resources/feedback/feedback.cjs +98 -0
- package/dist/_openapi_client/resources/feedback/feedback.d.ts +275 -0
- package/dist/_openapi_client/resources/feedback/feedback.js +61 -0
- package/dist/_openapi_client/resources/feedback/tokens.cjs +35 -0
- package/dist/_openapi_client/resources/feedback/tokens.d.ts +130 -0
- package/dist/_openapi_client/resources/feedback/tokens.js +31 -0
- package/dist/_openapi_client/resources/index.cjs +35 -0
- package/dist/_openapi_client/resources/index.d.ts +15 -0
- package/dist/_openapi_client/resources/index.js +17 -0
- package/dist/_openapi_client/resources/info.cjs +15 -0
- package/dist/_openapi_client/resources/info.d.ts +51 -0
- package/dist/_openapi_client/resources/info.js +11 -0
- package/dist/_openapi_client/resources/online-evaluators.cjs +70 -0
- package/dist/_openapi_client/resources/online-evaluators.d.ts +284 -0
- package/dist/_openapi_client/resources/online-evaluators.js +66 -0
- package/dist/_openapi_client/resources/public/datasets.cjs +47 -0
- package/dist/_openapi_client/resources/public/datasets.d.ts +152 -0
- package/dist/_openapi_client/resources/public/datasets.js +43 -0
- package/dist/_openapi_client/resources/public/public.cjs +62 -0
- package/dist/_openapi_client/resources/public/public.d.ts +32 -0
- package/dist/_openapi_client/resources/public/public.js +25 -0
- package/dist/_openapi_client/resources/repos/directories.cjs +40 -0
- package/dist/_openapi_client/resources/repos/directories.d.ts +72 -0
- package/dist/_openapi_client/resources/repos/directories.js +36 -0
- package/dist/_openapi_client/resources/repos/repos.cjs +93 -0
- package/dist/_openapi_client/resources/repos/repos.d.ts +188 -0
- package/dist/_openapi_client/resources/repos/repos.js +56 -0
- package/dist/_openapi_client/resources/runs/rules.cjs +9 -0
- package/dist/_openapi_client/resources/runs/rules.d.ts +3 -0
- package/dist/_openapi_client/resources/runs/rules.js +5 -0
- package/dist/_openapi_client/resources/runs/runs.cjs +102 -0
- package/dist/_openapi_client/resources/runs/runs.d.ts +542 -0
- package/dist/_openapi_client/resources/runs/runs.js +65 -0
- package/dist/_openapi_client/resources/sandboxes/boxes.cjs +86 -0
- package/dist/_openapi_client/resources/sandboxes/boxes.d.ts +1121 -0
- package/dist/_openapi_client/resources/sandboxes/boxes.js +82 -0
- package/dist/_openapi_client/resources/sandboxes/sandboxes.cjs +63 -0
- package/dist/_openapi_client/resources/sandboxes/sandboxes.d.ts +13 -0
- package/dist/_openapi_client/resources/sandboxes/sandboxes.js +26 -0
- package/dist/_openapi_client/resources/sandboxes/snapshots.cjs +39 -0
- package/dist/_openapi_client/resources/sandboxes/snapshots.d.ts +130 -0
- package/dist/_openapi_client/resources/sandboxes/snapshots.js +35 -0
- package/dist/_openapi_client/resources/sessions/insights.cjs +54 -0
- package/dist/_openapi_client/resources/sessions/insights.d.ts +246 -0
- package/dist/_openapi_client/resources/sessions/insights.js +50 -0
- package/dist/_openapi_client/resources/sessions/sessions.cjs +109 -0
- package/dist/_openapi_client/resources/sessions/sessions.d.ts +674 -0
- package/dist/_openapi_client/resources/sessions/sessions.js +72 -0
- package/dist/_openapi_client/resources/settings.cjs +15 -0
- package/dist/_openapi_client/resources/settings.d.ts +18 -0
- package/dist/_openapi_client/resources/settings.js +11 -0
- package/dist/_openapi_client/resources/workspaces.cjs +35 -0
- package/dist/_openapi_client/resources/workspaces.d.ts +84 -0
- package/dist/_openapi_client/resources/workspaces.js +31 -0
- package/dist/_openapi_client/version.cjs +5 -0
- package/dist/_openapi_client/version.d.ts +1 -0
- package/dist/_openapi_client/version.js +2 -0
- package/dist/client.cjs +48 -19
- package/dist/client.d.ts +5 -0
- package/dist/client.js +29 -0
- package/dist/env.cjs +3 -3
- package/dist/env.d.ts +1 -1
- package/dist/env.js +1 -1
- package/dist/experimental/otel/exporter.cjs +1 -1
- package/dist/experimental/otel/exporter.js +2 -2
- package/dist/experimental/vercel/telemetry.cjs +1 -1
- package/dist/experimental/vercel/telemetry.js +2 -2
- package/dist/index.cjs +4 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/run_trees.cjs +1 -1
- package/dist/run_trees.js +2 -2
- package/dist/sandbox/client.cjs +11 -3
- package/dist/sandbox/client.js +11 -3
- package/dist/sandbox/index.cjs +8 -2
- package/dist/sandbox/index.d.ts +3 -2
- package/dist/sandbox/index.js +2 -1
- package/dist/sandbox/mounts.cjs +114 -0
- package/dist/sandbox/mounts.d.ts +24 -0
- package/dist/sandbox/mounts.js +109 -0
- package/dist/sandbox/proxy_config.cjs +90 -5
- package/dist/sandbox/proxy_config.d.ts +19 -4
- package/dist/sandbox/proxy_config.js +86 -4
- package/dist/sandbox/types.d.ts +92 -3
- package/dist/traceable.cjs +1 -1
- package/dist/traceable.js +2 -2
- package/dist/utils/guard.cjs +13 -0
- package/dist/utils/guard.d.ts +6 -0
- package/dist/utils/guard.js +10 -0
- package/dist/utils/jestlike/globals.cjs +1 -1
- package/dist/utils/jestlike/globals.js +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.getPlatformHeaders = exports.isRunningInBrowser = void 0;
|
|
6
|
+
const version_js_1 = require("../version.cjs");
|
|
7
|
+
const isRunningInBrowser = () => {
|
|
8
|
+
return (
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
typeof window !== 'undefined' &&
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
typeof window.document !== 'undefined' &&
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
typeof navigator !== 'undefined');
|
|
15
|
+
};
|
|
16
|
+
exports.isRunningInBrowser = isRunningInBrowser;
|
|
17
|
+
/**
|
|
18
|
+
* Note this does not detect 'browser'; for that, use getBrowserInfo().
|
|
19
|
+
*/
|
|
20
|
+
function getDetectedPlatform() {
|
|
21
|
+
if (typeof Deno !== 'undefined' && Deno.build != null) {
|
|
22
|
+
return 'deno';
|
|
23
|
+
}
|
|
24
|
+
if (typeof EdgeRuntime !== 'undefined') {
|
|
25
|
+
return 'edge';
|
|
26
|
+
}
|
|
27
|
+
if (Object.prototype.toString.call(typeof globalThis.process !== 'undefined' ? globalThis.process : 0) === '[object process]') {
|
|
28
|
+
return 'node';
|
|
29
|
+
}
|
|
30
|
+
return 'unknown';
|
|
31
|
+
}
|
|
32
|
+
const getPlatformProperties = () => {
|
|
33
|
+
const detectedPlatform = getDetectedPlatform();
|
|
34
|
+
if (detectedPlatform === 'deno') {
|
|
35
|
+
return {
|
|
36
|
+
'X-Stainless-Lang': 'js',
|
|
37
|
+
'X-Stainless-Package-Version': version_js_1.VERSION,
|
|
38
|
+
'X-Stainless-OS': normalizePlatform(Deno.build.os),
|
|
39
|
+
'X-Stainless-Arch': normalizeArch(Deno.build.arch),
|
|
40
|
+
'X-Stainless-Runtime': 'deno',
|
|
41
|
+
'X-Stainless-Runtime-Version': typeof Deno.version === 'string' ? Deno.version : Deno.version?.deno ?? 'unknown',
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (typeof EdgeRuntime !== 'undefined') {
|
|
45
|
+
return {
|
|
46
|
+
'X-Stainless-Lang': 'js',
|
|
47
|
+
'X-Stainless-Package-Version': version_js_1.VERSION,
|
|
48
|
+
'X-Stainless-OS': 'Unknown',
|
|
49
|
+
'X-Stainless-Arch': `other:${EdgeRuntime}`,
|
|
50
|
+
'X-Stainless-Runtime': 'edge',
|
|
51
|
+
'X-Stainless-Runtime-Version': globalThis.process.version,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// Check if Node.js
|
|
55
|
+
if (detectedPlatform === 'node') {
|
|
56
|
+
return {
|
|
57
|
+
'X-Stainless-Lang': 'js',
|
|
58
|
+
'X-Stainless-Package-Version': version_js_1.VERSION,
|
|
59
|
+
'X-Stainless-OS': normalizePlatform(globalThis.process.platform ?? 'unknown'),
|
|
60
|
+
'X-Stainless-Arch': normalizeArch(globalThis.process.arch ?? 'unknown'),
|
|
61
|
+
'X-Stainless-Runtime': 'node',
|
|
62
|
+
'X-Stainless-Runtime-Version': globalThis.process.version ?? 'unknown',
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const browserInfo = getBrowserInfo();
|
|
66
|
+
if (browserInfo) {
|
|
67
|
+
return {
|
|
68
|
+
'X-Stainless-Lang': 'js',
|
|
69
|
+
'X-Stainless-Package-Version': version_js_1.VERSION,
|
|
70
|
+
'X-Stainless-OS': 'Unknown',
|
|
71
|
+
'X-Stainless-Arch': 'unknown',
|
|
72
|
+
'X-Stainless-Runtime': `browser:${browserInfo.browser}`,
|
|
73
|
+
'X-Stainless-Runtime-Version': browserInfo.version,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
// TODO add support for Cloudflare workers, etc.
|
|
77
|
+
return {
|
|
78
|
+
'X-Stainless-Lang': 'js',
|
|
79
|
+
'X-Stainless-Package-Version': version_js_1.VERSION,
|
|
80
|
+
'X-Stainless-OS': 'Unknown',
|
|
81
|
+
'X-Stainless-Arch': 'unknown',
|
|
82
|
+
'X-Stainless-Runtime': 'unknown',
|
|
83
|
+
'X-Stainless-Runtime-Version': 'unknown',
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
// Note: modified from https://github.com/JS-DevTools/host-environment/blob/b1ab79ecde37db5d6e163c050e54fe7d287d7c92/src/isomorphic.browser.ts
|
|
87
|
+
function getBrowserInfo() {
|
|
88
|
+
if (typeof navigator === 'undefined' || !navigator) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
// NOTE: The order matters here!
|
|
92
|
+
const browserPatterns = [
|
|
93
|
+
{ key: 'edge', pattern: /Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
94
|
+
{ key: 'ie', pattern: /MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
95
|
+
{ key: 'ie', pattern: /Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
96
|
+
{ key: 'chrome', pattern: /Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
97
|
+
{ key: 'firefox', pattern: /Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
98
|
+
{ key: 'safari', pattern: /(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/ },
|
|
99
|
+
];
|
|
100
|
+
// Find the FIRST matching browser
|
|
101
|
+
for (const { key, pattern } of browserPatterns) {
|
|
102
|
+
const match = pattern.exec(navigator.userAgent);
|
|
103
|
+
if (match) {
|
|
104
|
+
const major = match[1] || 0;
|
|
105
|
+
const minor = match[2] || 0;
|
|
106
|
+
const patch = match[3] || 0;
|
|
107
|
+
return { browser: key, version: `${major}.${minor}.${patch}` };
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
const normalizeArch = (arch) => {
|
|
113
|
+
// Node docs:
|
|
114
|
+
// - https://nodejs.org/api/process.html#processarch
|
|
115
|
+
// Deno docs:
|
|
116
|
+
// - https://doc.deno.land/deno/stable/~/Deno.build
|
|
117
|
+
if (arch === 'x32')
|
|
118
|
+
return 'x32';
|
|
119
|
+
if (arch === 'x86_64' || arch === 'x64')
|
|
120
|
+
return 'x64';
|
|
121
|
+
if (arch === 'arm')
|
|
122
|
+
return 'arm';
|
|
123
|
+
if (arch === 'aarch64' || arch === 'arm64')
|
|
124
|
+
return 'arm64';
|
|
125
|
+
if (arch)
|
|
126
|
+
return `other:${arch}`;
|
|
127
|
+
return 'unknown';
|
|
128
|
+
};
|
|
129
|
+
const normalizePlatform = (platform) => {
|
|
130
|
+
// Node platforms:
|
|
131
|
+
// - https://nodejs.org/api/process.html#processplatform
|
|
132
|
+
// Deno platforms:
|
|
133
|
+
// - https://doc.deno.land/deno/stable/~/Deno.build
|
|
134
|
+
// - https://github.com/denoland/deno/issues/14799
|
|
135
|
+
platform = platform.toLowerCase();
|
|
136
|
+
// NOTE: this iOS check is untested and may not work
|
|
137
|
+
// Node does not work natively on IOS, there is a fork at
|
|
138
|
+
// https://github.com/nodejs-mobile/nodejs-mobile
|
|
139
|
+
// however it is unknown at the time of writing how to detect if it is running
|
|
140
|
+
if (platform.includes('ios'))
|
|
141
|
+
return 'iOS';
|
|
142
|
+
if (platform === 'android')
|
|
143
|
+
return 'Android';
|
|
144
|
+
if (platform === 'darwin')
|
|
145
|
+
return 'MacOS';
|
|
146
|
+
if (platform === 'win32')
|
|
147
|
+
return 'Windows';
|
|
148
|
+
if (platform === 'freebsd')
|
|
149
|
+
return 'FreeBSD';
|
|
150
|
+
if (platform === 'openbsd')
|
|
151
|
+
return 'OpenBSD';
|
|
152
|
+
if (platform === 'linux')
|
|
153
|
+
return 'Linux';
|
|
154
|
+
if (platform)
|
|
155
|
+
return `Other:${platform}`;
|
|
156
|
+
return 'Unknown';
|
|
157
|
+
};
|
|
158
|
+
let _platformHeaders;
|
|
159
|
+
const getPlatformHeaders = () => {
|
|
160
|
+
return (_platformHeaders ??= getPlatformProperties());
|
|
161
|
+
};
|
|
162
|
+
exports.getPlatformHeaders = getPlatformHeaders;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const isRunningInBrowser: () => boolean;
|
|
2
|
+
type Arch = 'x32' | 'x64' | 'arm' | 'arm64' | `other:${string}` | 'unknown';
|
|
3
|
+
type PlatformName = 'MacOS' | 'Linux' | 'Windows' | 'FreeBSD' | 'OpenBSD' | 'iOS' | 'Android' | `Other:${string}` | 'Unknown';
|
|
4
|
+
type Browser = 'ie' | 'edge' | 'chrome' | 'firefox' | 'safari';
|
|
5
|
+
type PlatformProperties = {
|
|
6
|
+
'X-Stainless-Lang': 'js';
|
|
7
|
+
'X-Stainless-Package-Version': string;
|
|
8
|
+
'X-Stainless-OS': PlatformName;
|
|
9
|
+
'X-Stainless-Arch': Arch;
|
|
10
|
+
'X-Stainless-Runtime': 'node' | 'deno' | 'edge' | `browser:${Browser}` | 'unknown';
|
|
11
|
+
'X-Stainless-Runtime-Version': string;
|
|
12
|
+
};
|
|
13
|
+
export declare const getPlatformHeaders: () => PlatformProperties;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
+
import { VERSION } from '../version.js';
|
|
4
|
+
export const isRunningInBrowser = () => {
|
|
5
|
+
return (
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
typeof window !== 'undefined' &&
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
typeof window.document !== 'undefined' &&
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
typeof navigator !== 'undefined');
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Note this does not detect 'browser'; for that, use getBrowserInfo().
|
|
15
|
+
*/
|
|
16
|
+
function getDetectedPlatform() {
|
|
17
|
+
if (typeof Deno !== 'undefined' && Deno.build != null) {
|
|
18
|
+
return 'deno';
|
|
19
|
+
}
|
|
20
|
+
if (typeof EdgeRuntime !== 'undefined') {
|
|
21
|
+
return 'edge';
|
|
22
|
+
}
|
|
23
|
+
if (Object.prototype.toString.call(typeof globalThis.process !== 'undefined' ? globalThis.process : 0) === '[object process]') {
|
|
24
|
+
return 'node';
|
|
25
|
+
}
|
|
26
|
+
return 'unknown';
|
|
27
|
+
}
|
|
28
|
+
const getPlatformProperties = () => {
|
|
29
|
+
const detectedPlatform = getDetectedPlatform();
|
|
30
|
+
if (detectedPlatform === 'deno') {
|
|
31
|
+
return {
|
|
32
|
+
'X-Stainless-Lang': 'js',
|
|
33
|
+
'X-Stainless-Package-Version': VERSION,
|
|
34
|
+
'X-Stainless-OS': normalizePlatform(Deno.build.os),
|
|
35
|
+
'X-Stainless-Arch': normalizeArch(Deno.build.arch),
|
|
36
|
+
'X-Stainless-Runtime': 'deno',
|
|
37
|
+
'X-Stainless-Runtime-Version': typeof Deno.version === 'string' ? Deno.version : Deno.version?.deno ?? 'unknown',
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (typeof EdgeRuntime !== 'undefined') {
|
|
41
|
+
return {
|
|
42
|
+
'X-Stainless-Lang': 'js',
|
|
43
|
+
'X-Stainless-Package-Version': VERSION,
|
|
44
|
+
'X-Stainless-OS': 'Unknown',
|
|
45
|
+
'X-Stainless-Arch': `other:${EdgeRuntime}`,
|
|
46
|
+
'X-Stainless-Runtime': 'edge',
|
|
47
|
+
'X-Stainless-Runtime-Version': globalThis.process.version,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// Check if Node.js
|
|
51
|
+
if (detectedPlatform === 'node') {
|
|
52
|
+
return {
|
|
53
|
+
'X-Stainless-Lang': 'js',
|
|
54
|
+
'X-Stainless-Package-Version': VERSION,
|
|
55
|
+
'X-Stainless-OS': normalizePlatform(globalThis.process.platform ?? 'unknown'),
|
|
56
|
+
'X-Stainless-Arch': normalizeArch(globalThis.process.arch ?? 'unknown'),
|
|
57
|
+
'X-Stainless-Runtime': 'node',
|
|
58
|
+
'X-Stainless-Runtime-Version': globalThis.process.version ?? 'unknown',
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const browserInfo = getBrowserInfo();
|
|
62
|
+
if (browserInfo) {
|
|
63
|
+
return {
|
|
64
|
+
'X-Stainless-Lang': 'js',
|
|
65
|
+
'X-Stainless-Package-Version': VERSION,
|
|
66
|
+
'X-Stainless-OS': 'Unknown',
|
|
67
|
+
'X-Stainless-Arch': 'unknown',
|
|
68
|
+
'X-Stainless-Runtime': `browser:${browserInfo.browser}`,
|
|
69
|
+
'X-Stainless-Runtime-Version': browserInfo.version,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
// TODO add support for Cloudflare workers, etc.
|
|
73
|
+
return {
|
|
74
|
+
'X-Stainless-Lang': 'js',
|
|
75
|
+
'X-Stainless-Package-Version': VERSION,
|
|
76
|
+
'X-Stainless-OS': 'Unknown',
|
|
77
|
+
'X-Stainless-Arch': 'unknown',
|
|
78
|
+
'X-Stainless-Runtime': 'unknown',
|
|
79
|
+
'X-Stainless-Runtime-Version': 'unknown',
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
// Note: modified from https://github.com/JS-DevTools/host-environment/blob/b1ab79ecde37db5d6e163c050e54fe7d287d7c92/src/isomorphic.browser.ts
|
|
83
|
+
function getBrowserInfo() {
|
|
84
|
+
if (typeof navigator === 'undefined' || !navigator) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
// NOTE: The order matters here!
|
|
88
|
+
const browserPatterns = [
|
|
89
|
+
{ key: 'edge', pattern: /Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
90
|
+
{ key: 'ie', pattern: /MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
91
|
+
{ key: 'ie', pattern: /Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
92
|
+
{ key: 'chrome', pattern: /Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
93
|
+
{ key: 'firefox', pattern: /Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
94
|
+
{ key: 'safari', pattern: /(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/ },
|
|
95
|
+
];
|
|
96
|
+
// Find the FIRST matching browser
|
|
97
|
+
for (const { key, pattern } of browserPatterns) {
|
|
98
|
+
const match = pattern.exec(navigator.userAgent);
|
|
99
|
+
if (match) {
|
|
100
|
+
const major = match[1] || 0;
|
|
101
|
+
const minor = match[2] || 0;
|
|
102
|
+
const patch = match[3] || 0;
|
|
103
|
+
return { browser: key, version: `${major}.${minor}.${patch}` };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
const normalizeArch = (arch) => {
|
|
109
|
+
// Node docs:
|
|
110
|
+
// - https://nodejs.org/api/process.html#processarch
|
|
111
|
+
// Deno docs:
|
|
112
|
+
// - https://doc.deno.land/deno/stable/~/Deno.build
|
|
113
|
+
if (arch === 'x32')
|
|
114
|
+
return 'x32';
|
|
115
|
+
if (arch === 'x86_64' || arch === 'x64')
|
|
116
|
+
return 'x64';
|
|
117
|
+
if (arch === 'arm')
|
|
118
|
+
return 'arm';
|
|
119
|
+
if (arch === 'aarch64' || arch === 'arm64')
|
|
120
|
+
return 'arm64';
|
|
121
|
+
if (arch)
|
|
122
|
+
return `other:${arch}`;
|
|
123
|
+
return 'unknown';
|
|
124
|
+
};
|
|
125
|
+
const normalizePlatform = (platform) => {
|
|
126
|
+
// Node platforms:
|
|
127
|
+
// - https://nodejs.org/api/process.html#processplatform
|
|
128
|
+
// Deno platforms:
|
|
129
|
+
// - https://doc.deno.land/deno/stable/~/Deno.build
|
|
130
|
+
// - https://github.com/denoland/deno/issues/14799
|
|
131
|
+
platform = platform.toLowerCase();
|
|
132
|
+
// NOTE: this iOS check is untested and may not work
|
|
133
|
+
// Node does not work natively on IOS, there is a fork at
|
|
134
|
+
// https://github.com/nodejs-mobile/nodejs-mobile
|
|
135
|
+
// however it is unknown at the time of writing how to detect if it is running
|
|
136
|
+
if (platform.includes('ios'))
|
|
137
|
+
return 'iOS';
|
|
138
|
+
if (platform === 'android')
|
|
139
|
+
return 'Android';
|
|
140
|
+
if (platform === 'darwin')
|
|
141
|
+
return 'MacOS';
|
|
142
|
+
if (platform === 'win32')
|
|
143
|
+
return 'Windows';
|
|
144
|
+
if (platform === 'freebsd')
|
|
145
|
+
return 'FreeBSD';
|
|
146
|
+
if (platform === 'openbsd')
|
|
147
|
+
return 'OpenBSD';
|
|
148
|
+
if (platform === 'linux')
|
|
149
|
+
return 'Linux';
|
|
150
|
+
if (platform)
|
|
151
|
+
return `Other:${platform}`;
|
|
152
|
+
return 'Unknown';
|
|
153
|
+
};
|
|
154
|
+
let _platformHeaders;
|
|
155
|
+
export const getPlatformHeaders = () => {
|
|
156
|
+
return (_platformHeaders ??= getPlatformProperties());
|
|
157
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.castToError = void 0;
|
|
6
|
+
exports.isAbortError = isAbortError;
|
|
7
|
+
function isAbortError(err) {
|
|
8
|
+
return (typeof err === 'object' &&
|
|
9
|
+
err !== null &&
|
|
10
|
+
// Spec-compliant fetch implementations
|
|
11
|
+
(('name' in err && err.name === 'AbortError') ||
|
|
12
|
+
// Expo fetch
|
|
13
|
+
('message' in err && String(err.message).includes('FetchRequestCanceledException'))));
|
|
14
|
+
}
|
|
15
|
+
const castToError = (err) => {
|
|
16
|
+
if (err instanceof Error)
|
|
17
|
+
return err;
|
|
18
|
+
if (typeof err === 'object' && err !== null) {
|
|
19
|
+
try {
|
|
20
|
+
if (Object.prototype.toString.call(err) === '[object Error]') {
|
|
21
|
+
// @ts-ignore - not all envs have native support for cause yet
|
|
22
|
+
const error = new Error(err.message, err.cause ? { cause: err.cause } : {});
|
|
23
|
+
if (err.stack)
|
|
24
|
+
error.stack = err.stack;
|
|
25
|
+
// @ts-ignore - not all envs have native support for cause yet
|
|
26
|
+
if (err.cause && !error.cause)
|
|
27
|
+
error.cause = err.cause;
|
|
28
|
+
if (err.name)
|
|
29
|
+
error.name = err.name;
|
|
30
|
+
return error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch { }
|
|
34
|
+
try {
|
|
35
|
+
return new Error(JSON.stringify(err));
|
|
36
|
+
}
|
|
37
|
+
catch { }
|
|
38
|
+
}
|
|
39
|
+
return new Error(err);
|
|
40
|
+
};
|
|
41
|
+
exports.castToError = castToError;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
+
export function isAbortError(err) {
|
|
4
|
+
return (typeof err === 'object' &&
|
|
5
|
+
err !== null &&
|
|
6
|
+
// Spec-compliant fetch implementations
|
|
7
|
+
(('name' in err && err.name === 'AbortError') ||
|
|
8
|
+
// Expo fetch
|
|
9
|
+
('message' in err && String(err.message).includes('FetchRequestCanceledException'))));
|
|
10
|
+
}
|
|
11
|
+
export const castToError = (err) => {
|
|
12
|
+
if (err instanceof Error)
|
|
13
|
+
return err;
|
|
14
|
+
if (typeof err === 'object' && err !== null) {
|
|
15
|
+
try {
|
|
16
|
+
if (Object.prototype.toString.call(err) === '[object Error]') {
|
|
17
|
+
// @ts-ignore - not all envs have native support for cause yet
|
|
18
|
+
const error = new Error(err.message, err.cause ? { cause: err.cause } : {});
|
|
19
|
+
if (err.stack)
|
|
20
|
+
error.stack = err.stack;
|
|
21
|
+
// @ts-ignore - not all envs have native support for cause yet
|
|
22
|
+
if (err.cause && !error.cause)
|
|
23
|
+
error.cause = err.cause;
|
|
24
|
+
if (err.name)
|
|
25
|
+
error.name = err.name;
|
|
26
|
+
return error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch { }
|
|
30
|
+
try {
|
|
31
|
+
return new Error(JSON.stringify(err));
|
|
32
|
+
}
|
|
33
|
+
catch { }
|
|
34
|
+
}
|
|
35
|
+
return new Error(err);
|
|
36
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.isEmptyHeaders = exports.buildHeaders = void 0;
|
|
6
|
+
const values_js_1 = require("./utils/values.cjs");
|
|
7
|
+
const brand_privateNullableHeaders = /* @__PURE__ */ Symbol('brand.privateNullableHeaders');
|
|
8
|
+
function* iterateHeaders(headers) {
|
|
9
|
+
if (!headers)
|
|
10
|
+
return;
|
|
11
|
+
if (brand_privateNullableHeaders in headers) {
|
|
12
|
+
const { values, nulls } = headers;
|
|
13
|
+
yield* values.entries();
|
|
14
|
+
for (const name of nulls) {
|
|
15
|
+
yield [name, null];
|
|
16
|
+
}
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
let shouldClear = false;
|
|
20
|
+
let iter;
|
|
21
|
+
if (headers instanceof Headers) {
|
|
22
|
+
iter = headers.entries();
|
|
23
|
+
}
|
|
24
|
+
else if ((0, values_js_1.isReadonlyArray)(headers)) {
|
|
25
|
+
iter = headers;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
shouldClear = true;
|
|
29
|
+
iter = Object.entries(headers ?? {});
|
|
30
|
+
}
|
|
31
|
+
for (let row of iter) {
|
|
32
|
+
const name = row[0];
|
|
33
|
+
if (typeof name !== 'string')
|
|
34
|
+
throw new TypeError('expected header name to be a string');
|
|
35
|
+
const values = (0, values_js_1.isReadonlyArray)(row[1]) ? row[1] : [row[1]];
|
|
36
|
+
let didClear = false;
|
|
37
|
+
for (const value of values) {
|
|
38
|
+
if (value === undefined)
|
|
39
|
+
continue;
|
|
40
|
+
// Objects keys always overwrite older headers, they never append.
|
|
41
|
+
// Yield a null to clear the header before adding the new values.
|
|
42
|
+
if (shouldClear && !didClear) {
|
|
43
|
+
didClear = true;
|
|
44
|
+
yield [name, null];
|
|
45
|
+
}
|
|
46
|
+
yield [name, value];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const buildHeaders = (newHeaders) => {
|
|
51
|
+
const targetHeaders = new Headers();
|
|
52
|
+
const nullHeaders = new Set();
|
|
53
|
+
for (const headers of newHeaders) {
|
|
54
|
+
const seenHeaders = new Set();
|
|
55
|
+
for (const [name, value] of iterateHeaders(headers)) {
|
|
56
|
+
const lowerName = name.toLowerCase();
|
|
57
|
+
if (!seenHeaders.has(lowerName)) {
|
|
58
|
+
targetHeaders.delete(name);
|
|
59
|
+
seenHeaders.add(lowerName);
|
|
60
|
+
}
|
|
61
|
+
if (value === null) {
|
|
62
|
+
targetHeaders.delete(name);
|
|
63
|
+
nullHeaders.add(lowerName);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
targetHeaders.append(name, value);
|
|
67
|
+
nullHeaders.delete(lowerName);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return { [brand_privateNullableHeaders]: true, values: targetHeaders, nulls: nullHeaders };
|
|
72
|
+
};
|
|
73
|
+
exports.buildHeaders = buildHeaders;
|
|
74
|
+
const isEmptyHeaders = (headers) => {
|
|
75
|
+
for (const _ of iterateHeaders(headers))
|
|
76
|
+
return false;
|
|
77
|
+
return true;
|
|
78
|
+
};
|
|
79
|
+
exports.isEmptyHeaders = isEmptyHeaders;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
type HeaderValue = string | undefined | null;
|
|
2
|
+
export type HeadersLike = Headers | readonly HeaderValue[][] | Record<string, HeaderValue | readonly HeaderValue[]> | undefined | null | NullableHeaders;
|
|
3
|
+
export declare const buildHeaders: (newHeaders: HeadersLike[]) => NullableHeaders;
|
|
4
|
+
export declare const isEmptyHeaders: (headers: HeadersLike) => boolean;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
+
import { isReadonlyArray } from './utils/values.js';
|
|
4
|
+
const brand_privateNullableHeaders = /* @__PURE__ */ Symbol('brand.privateNullableHeaders');
|
|
5
|
+
function* iterateHeaders(headers) {
|
|
6
|
+
if (!headers)
|
|
7
|
+
return;
|
|
8
|
+
if (brand_privateNullableHeaders in headers) {
|
|
9
|
+
const { values, nulls } = headers;
|
|
10
|
+
yield* values.entries();
|
|
11
|
+
for (const name of nulls) {
|
|
12
|
+
yield [name, null];
|
|
13
|
+
}
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
let shouldClear = false;
|
|
17
|
+
let iter;
|
|
18
|
+
if (headers instanceof Headers) {
|
|
19
|
+
iter = headers.entries();
|
|
20
|
+
}
|
|
21
|
+
else if (isReadonlyArray(headers)) {
|
|
22
|
+
iter = headers;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
shouldClear = true;
|
|
26
|
+
iter = Object.entries(headers ?? {});
|
|
27
|
+
}
|
|
28
|
+
for (let row of iter) {
|
|
29
|
+
const name = row[0];
|
|
30
|
+
if (typeof name !== 'string')
|
|
31
|
+
throw new TypeError('expected header name to be a string');
|
|
32
|
+
const values = isReadonlyArray(row[1]) ? row[1] : [row[1]];
|
|
33
|
+
let didClear = false;
|
|
34
|
+
for (const value of values) {
|
|
35
|
+
if (value === undefined)
|
|
36
|
+
continue;
|
|
37
|
+
// Objects keys always overwrite older headers, they never append.
|
|
38
|
+
// Yield a null to clear the header before adding the new values.
|
|
39
|
+
if (shouldClear && !didClear) {
|
|
40
|
+
didClear = true;
|
|
41
|
+
yield [name, null];
|
|
42
|
+
}
|
|
43
|
+
yield [name, value];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export const buildHeaders = (newHeaders) => {
|
|
48
|
+
const targetHeaders = new Headers();
|
|
49
|
+
const nullHeaders = new Set();
|
|
50
|
+
for (const headers of newHeaders) {
|
|
51
|
+
const seenHeaders = new Set();
|
|
52
|
+
for (const [name, value] of iterateHeaders(headers)) {
|
|
53
|
+
const lowerName = name.toLowerCase();
|
|
54
|
+
if (!seenHeaders.has(lowerName)) {
|
|
55
|
+
targetHeaders.delete(name);
|
|
56
|
+
seenHeaders.add(lowerName);
|
|
57
|
+
}
|
|
58
|
+
if (value === null) {
|
|
59
|
+
targetHeaders.delete(name);
|
|
60
|
+
nullHeaders.add(lowerName);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
targetHeaders.append(name, value);
|
|
64
|
+
nullHeaders.delete(lowerName);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return { [brand_privateNullableHeaders]: true, values: targetHeaders, nulls: nullHeaders };
|
|
69
|
+
};
|
|
70
|
+
export const isEmptyHeaders = (headers) => {
|
|
71
|
+
for (const _ of iterateHeaders(headers))
|
|
72
|
+
return false;
|
|
73
|
+
return true;
|
|
74
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.defaultParseResponse = defaultParseResponse;
|
|
6
|
+
const log_js_1 = require("./utils/log.cjs");
|
|
7
|
+
async function defaultParseResponse(client, props) {
|
|
8
|
+
const { response, requestLogID, retryOfRequestLogID, startTime } = props;
|
|
9
|
+
const body = await (async () => {
|
|
10
|
+
// fetch refuses to read the body when the status code is 204.
|
|
11
|
+
if (response.status === 204) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
if (props.options.__binaryResponse) {
|
|
15
|
+
return response;
|
|
16
|
+
}
|
|
17
|
+
const contentType = response.headers.get('content-type');
|
|
18
|
+
const mediaType = contentType?.split(';')[0]?.trim();
|
|
19
|
+
const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
|
|
20
|
+
if (isJSON) {
|
|
21
|
+
const contentLength = response.headers.get('content-length');
|
|
22
|
+
if (contentLength === '0') {
|
|
23
|
+
// if there is no content we can't do anything
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
const json = await response.json();
|
|
27
|
+
return json;
|
|
28
|
+
}
|
|
29
|
+
const text = await response.text();
|
|
30
|
+
return text;
|
|
31
|
+
})();
|
|
32
|
+
(0, log_js_1.loggerFor)(client).debug(`[${requestLogID}] response parsed`, (0, log_js_1.formatRequestDetails)({
|
|
33
|
+
retryOfRequestLogID,
|
|
34
|
+
url: response.url,
|
|
35
|
+
status: response.status,
|
|
36
|
+
body,
|
|
37
|
+
durationMs: Date.now() - startTime,
|
|
38
|
+
}));
|
|
39
|
+
return body;
|
|
40
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FinalRequestOptions } from './request-options.js';
|
|
2
|
+
import { type Langsmith } from '../client.js';
|
|
3
|
+
export type APIResponseProps = {
|
|
4
|
+
response: Response;
|
|
5
|
+
options: FinalRequestOptions;
|
|
6
|
+
controller: AbortController;
|
|
7
|
+
requestLogID: string;
|
|
8
|
+
retryOfRequestLogID: string | undefined;
|
|
9
|
+
startTime: number;
|
|
10
|
+
};
|
|
11
|
+
export declare function defaultParseResponse<T>(client: Langsmith, props: APIResponseProps): Promise<T>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
+
import { formatRequestDetails, loggerFor } from './utils/log.js';
|
|
4
|
+
export async function defaultParseResponse(client, props) {
|
|
5
|
+
const { response, requestLogID, retryOfRequestLogID, startTime } = props;
|
|
6
|
+
const body = await (async () => {
|
|
7
|
+
// fetch refuses to read the body when the status code is 204.
|
|
8
|
+
if (response.status === 204) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
if (props.options.__binaryResponse) {
|
|
12
|
+
return response;
|
|
13
|
+
}
|
|
14
|
+
const contentType = response.headers.get('content-type');
|
|
15
|
+
const mediaType = contentType?.split(';')[0]?.trim();
|
|
16
|
+
const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
|
|
17
|
+
if (isJSON) {
|
|
18
|
+
const contentLength = response.headers.get('content-length');
|
|
19
|
+
if (contentLength === '0') {
|
|
20
|
+
// if there is no content we can't do anything
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
const json = await response.json();
|
|
24
|
+
return json;
|
|
25
|
+
}
|
|
26
|
+
const text = await response.text();
|
|
27
|
+
return text;
|
|
28
|
+
})();
|
|
29
|
+
loggerFor(client).debug(`[${requestLogID}] response parsed`, formatRequestDetails({
|
|
30
|
+
retryOfRequestLogID,
|
|
31
|
+
url: response.url,
|
|
32
|
+
status: response.status,
|
|
33
|
+
body,
|
|
34
|
+
durationMs: Date.now() - startTime,
|
|
35
|
+
}));
|
|
36
|
+
return body;
|
|
37
|
+
}
|