deepline 0.3.293 → 0.3.295
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/dist/bundling-sources/sdk/src/compat.ts +35 -7
- package/dist/bundling-sources/sdk/src/release.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-pool.ts +269 -267
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +3 -4
- package/dist/bundling-sources/shared_libs/play-runtime/tool-http-errors.ts +14 -1
- package/dist/cli/auth-EDTRERZP.mjs +31 -0
- package/dist/cli/auth-TDHKB277.js +31 -0
- package/dist/cli/billing-ELIDPILY.js +1749 -0
- package/dist/cli/billing-EXGXJVAU.mjs +1749 -0
- package/dist/cli/chunk-2S5Y3TZP.js +5688 -0
- package/dist/cli/chunk-3KC45UVF.js +150 -0
- package/dist/cli/chunk-3XX5TEA4.js +15 -0
- package/dist/cli/chunk-4MBOJQPL.mjs +0 -0
- package/dist/cli/chunk-4NEFYBF7.js +2240 -0
- package/dist/cli/chunk-5JLQPVNX.js +3056 -0
- package/dist/cli/chunk-5KDKFHZI.js +1269 -0
- package/dist/cli/chunk-6A3TJUWC.js +76 -0
- package/dist/cli/chunk-6O5YZOVN.mjs +890 -0
- package/dist/cli/chunk-7P5AA3SN.js +344 -0
- package/dist/cli/chunk-AYHLUHE5.js +52 -0
- package/dist/cli/chunk-CBVIJSHF.mjs +560 -0
- package/dist/cli/chunk-CFVVCN4A.js +735 -0
- package/dist/cli/chunk-COGTRVWW.js +30 -0
- package/dist/cli/chunk-D4AZUZO4.js +190 -0
- package/dist/cli/chunk-DLIRSHV6.mjs +28 -0
- package/dist/cli/chunk-EACVZI6N.mjs +1995 -0
- package/dist/cli/chunk-EDWJY6T4.mjs +3056 -0
- package/dist/cli/chunk-EXMLR72R.mjs +0 -0
- package/dist/cli/chunk-F35VOIQL.js +890 -0
- package/dist/cli/chunk-GAMFK2ZP.mjs +148 -0
- package/dist/cli/chunk-GHRQQPW2.mjs +2240 -0
- package/dist/cli/chunk-GONRLVV3.js +3440 -0
- package/dist/cli/chunk-GVUJJJ5G.mjs +76 -0
- package/dist/cli/chunk-H7HIDGZ7.mjs +150 -0
- package/dist/cli/chunk-HUZXWOSK.mjs +503 -0
- package/dist/cli/chunk-I5YZLGMG.js +1 -0
- package/dist/cli/chunk-ITOFSXIU.mjs +15 -0
- package/dist/cli/chunk-J5NA2TTX.js +503 -0
- package/dist/cli/chunk-JCS5TPNY.mjs +3440 -0
- package/dist/cli/chunk-JNNOCMQY.js +47 -0
- package/dist/cli/chunk-KRD6H754.mjs +30 -0
- package/dist/cli/chunk-LA46MMTL.js +560 -0
- package/dist/cli/chunk-LDWT7RJK.mjs +190 -0
- package/dist/cli/chunk-M2V26OR5.js +499 -0
- package/dist/cli/chunk-MIMASXO4.mjs +389 -0
- package/dist/cli/chunk-MROPCKW2.mjs +190 -0
- package/dist/cli/chunk-NXDRDJ4K.js +389 -0
- package/dist/cli/chunk-NXGCO4JB.mjs +344 -0
- package/dist/cli/chunk-OG64RBAC.js +6 -0
- package/dist/cli/chunk-OQYEC4GL.mjs +34 -0
- package/dist/cli/chunk-OWJZUE3Y.mjs +103 -0
- package/dist/cli/chunk-SDK3ZA2C.js +103 -0
- package/dist/cli/chunk-SFLARO4Y.mjs +47 -0
- package/dist/cli/chunk-SVIIIYIQ.js +923 -0
- package/dist/cli/chunk-TAC3JIFE.mjs +354 -0
- package/dist/cli/chunk-U3PI7HBM.js +34 -0
- package/dist/cli/chunk-UFS752TU.mjs +52 -0
- package/dist/cli/chunk-UI37DQE7.mjs +499 -0
- package/dist/cli/chunk-UNEMDKXN.js +1 -0
- package/dist/cli/chunk-WB6Z2Q44.mjs +1622 -0
- package/dist/cli/chunk-WJYPBHTE.js +148 -0
- package/dist/cli/chunk-WOHBA5PV.js +354 -0
- package/dist/cli/chunk-WQICC2B3.js +190 -0
- package/dist/cli/chunk-WZYKRD7T.mjs +6 -0
- package/dist/cli/chunk-XL2FO6CW.mjs +5688 -0
- package/dist/cli/chunk-XNYIZMNQ.js +28 -0
- package/dist/cli/chunk-XRK2TZT5.js +1995 -0
- package/dist/cli/chunk-YJYPL5OK.mjs +1269 -0
- package/dist/cli/chunk-YWNDYCXR.mjs +735 -0
- package/dist/cli/chunk-YWWAF7KZ.mjs +923 -0
- package/dist/cli/chunk-ZDO3TO3M.js +1622 -0
- package/dist/cli/client-4JVOYVC5.js +20 -0
- package/dist/cli/client-EEN2IJN2.mjs +20 -0
- package/dist/cli/csv-BOHBEP2I.mjs +585 -0
- package/dist/cli/csv-S5NYRUEX.js +585 -0
- package/dist/cli/db-CLODWCOB.mjs +486 -0
- package/dist/cli/db-F6PKFOOV.js +486 -0
- package/dist/cli/executions-5TQAKLJU.js +28 -0
- package/dist/cli/executions-MAKW6QOY.mjs +28 -0
- package/dist/cli/feedback-GV4QJFEN.js +107 -0
- package/dist/cli/feedback-XY24TW7H.mjs +107 -0
- package/dist/cli/getting-started.js +18 -76
- package/dist/cli/getting-started.mjs +10 -37
- package/dist/cli/git-6S2C22T5.js +23 -0
- package/dist/cli/git-OZLBD5HH.mjs +23 -0
- package/dist/cli/index.js +291 -54294
- package/dist/cli/index.mjs +209 -54352
- package/dist/cli/legacy-noops-LLCGDPQE.js +157 -0
- package/dist/cli/legacy-noops-TYH3TW2D.mjs +157 -0
- package/dist/cli/monitors-CABMB4DW.js +3251 -0
- package/dist/cli/monitors-TTD55HMK.mjs +3251 -0
- package/dist/cli/org-MSF3RG76.js +849 -0
- package/dist/cli/org-SFJ77MWY.mjs +849 -0
- package/dist/cli/play-NXHJSCKL.mjs +18439 -0
- package/dist/cli/play-OKSFNNO4.js +18439 -0
- package/dist/cli/providers-QC2ERERL.js +95 -0
- package/dist/cli/providers-TIIAZEUA.mjs +95 -0
- package/dist/cli/proxy-env-EBANZHPV.js +161 -0
- package/dist/cli/proxy-env-M4ZHXHRL.mjs +161 -0
- package/dist/cli/quickstart-ICANHLMI.js +69 -0
- package/dist/cli/quickstart-KWUOP3FI.mjs +69 -0
- package/dist/cli/search-U5H2FDOO.mjs +18 -0
- package/dist/cli/search-XQRQOLWS.js +18 -0
- package/dist/cli/secrets-3J6YTWFA.mjs +400 -0
- package/dist/cli/secrets-YNMNZNOM.js +400 -0
- package/dist/cli/sessions-CLEES4L6.mjs +15 -0
- package/dist/cli/sessions-J6VR47FG.js +15 -0
- package/dist/cli/settings-EEKZMTY4.js +846 -0
- package/dist/cli/settings-UVLOQZRH.mjs +846 -0
- package/dist/cli/setup-DLMDXPGJ.mjs +1257 -0
- package/dist/cli/setup-HC4Q7QM4.js +1257 -0
- package/dist/cli/skills-33PHFBSB.mjs +28 -0
- package/dist/cli/skills-LFRY3KPX.js +28 -0
- package/dist/cli/tools-3COEPKML.mjs +2955 -0
- package/dist/cli/tools-QXEVCN45.js +2955 -0
- package/dist/cli/update-LSAC4FF5.mjs +28 -0
- package/dist/cli/update-NXHSPYXA.js +28 -0
- package/dist/cli/workflow-7S44OECF.mjs +1936 -0
- package/dist/cli/workflow-QPZWYSZE.js +1936 -0
- package/dist/helpers.js +6 -32
- package/dist/helpers.mjs +2 -0
- package/dist/index.js +1972 -12825
- package/dist/index.mjs +1910 -12672
- package/dist/install-integrity.json +110 -0
- package/dist/monitor-fleet-contract.js +31 -730
- package/dist/monitor-fleet-contract.mjs +18 -667
- package/dist/monitor-input-contract.js +10 -390
- package/dist/monitor-input-contract.mjs +7 -348
- package/dist/plays/bundle-play-file.mjs +13 -5178
- package/dist/plays/csv-data-input.js +5 -3132
- package/dist/plays/csv-data-input.mjs +5 -3105
- package/dist/plays/run-request.js +56 -664
- package/dist/plays/run-request.mjs +30 -588
- package/dist/release.d.mts +1 -1
- package/dist/release.d.ts +1 -1
- package/dist/release.js +5 -212
- package/dist/release.mjs +5 -185
- package/package.json +1 -1
|
@@ -0,0 +1,1995 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkXNYIZMNQjs = require('./chunk-XNYIZMNQ.js');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunkD4AZUZO4js = require('./chunk-D4AZUZO4.js');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
var _chunk7P5AA3SNjs = require('./chunk-7P5AA3SN.js');
|
|
18
|
+
|
|
19
|
+
// src/errors.ts
|
|
20
|
+
var AuthError = class extends _chunk7P5AA3SNjs.DeeplineError {
|
|
21
|
+
/** Constructed by the SDK when Deepline rejects the caller's credentials. */
|
|
22
|
+
constructor(message = "Authentication failed. Check your DEEPLINE_API_KEY.") {
|
|
23
|
+
super(message, 401, "AUTH_ERROR");
|
|
24
|
+
this.name = "AuthError";
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var RateLimitError = class extends _chunk7P5AA3SNjs.DeeplineError {
|
|
28
|
+
/** Milliseconds to wait before retrying, from the `Retry-After` response header. Defaults to 5000. */
|
|
29
|
+
|
|
30
|
+
/** Constructed by the SDK after exhausting HTTP-level rate-limit retries. */
|
|
31
|
+
constructor(retryAfterMs = 5e3, message) {
|
|
32
|
+
super(
|
|
33
|
+
_nullishCoalesce(message, () => ( `Rate limited. Retry after ${retryAfterMs}ms.`)),
|
|
34
|
+
429,
|
|
35
|
+
"RATE_LIMIT"
|
|
36
|
+
);
|
|
37
|
+
this.name = "RateLimitError";
|
|
38
|
+
this.retryAfterMs = retryAfterMs;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var ToolRateLimitError = class extends RateLimitError {
|
|
42
|
+
/** Public tool id passed to `tools.execute`. */
|
|
43
|
+
|
|
44
|
+
/** Provider responsible for the operation, or `null`. */
|
|
45
|
+
|
|
46
|
+
/** Provider operation name, or `null`. */
|
|
47
|
+
|
|
48
|
+
/** Stable machine-readable failure code when one exists. */
|
|
49
|
+
|
|
50
|
+
/** Boundary responsible for the failure. */
|
|
51
|
+
|
|
52
|
+
/** Stable reason family for policy and diagnostics. */
|
|
53
|
+
|
|
54
|
+
/** Whether repeating the same semantic call is delivery-safe. */
|
|
55
|
+
|
|
56
|
+
/** Provider or Deepline request id, or `null`. */
|
|
57
|
+
|
|
58
|
+
/** Network failure kind, or `null` for non-network failures. */
|
|
59
|
+
|
|
60
|
+
/** Network boundary that failed, or `null` for non-network failures. */
|
|
61
|
+
|
|
62
|
+
/** Explicitly allowlisted diagnostics safe for SDK callers. */
|
|
63
|
+
|
|
64
|
+
/** Constructed by the SDK after a structured tool HTTP 429. */
|
|
65
|
+
constructor(message, options) {
|
|
66
|
+
super(_nullishCoalesce(options.retryAfterMs, () => ( 5e3)), message);
|
|
67
|
+
this.name = "ToolRateLimitError";
|
|
68
|
+
this.statusCode = _nullishCoalesce(options.statusCode, () => ( 429));
|
|
69
|
+
this.code = _nullishCoalesce(options.code, () => ( void 0));
|
|
70
|
+
this.toolId = options.toolId;
|
|
71
|
+
this.provider = options.provider;
|
|
72
|
+
this.operation = options.operation;
|
|
73
|
+
this.origin = options.origin;
|
|
74
|
+
this.category = options.category;
|
|
75
|
+
this.retryable = options.retryable;
|
|
76
|
+
this.requestId = options.requestId;
|
|
77
|
+
this.networkKind = options.networkKind;
|
|
78
|
+
this.networkScope = options.networkScope;
|
|
79
|
+
this.publicDetails = _nullishCoalesce(options.publicDetails, () => ( null));
|
|
80
|
+
this.details = options.details;
|
|
81
|
+
_chunk7P5AA3SNjs.brandAsToolExecutionError.call(void 0, this);
|
|
82
|
+
if (_chunk7P5AA3SNjs.isProviderTransientFailure.call(void 0, this)) {
|
|
83
|
+
_chunk7P5AA3SNjs.brandAsProviderTransientError.call(void 0, this);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
var ConfigError = class extends _chunk7P5AA3SNjs.DeeplineError {
|
|
88
|
+
/** Construct a local SDK configuration failure. */
|
|
89
|
+
constructor(message) {
|
|
90
|
+
super(message, void 0, "CONFIG_ERROR");
|
|
91
|
+
this.name = "ConfigError";
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// src/config.ts
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
var _fs = require('fs');
|
|
105
|
+
var _os = require('os');
|
|
106
|
+
var _path = require('path');
|
|
107
|
+
var HOST_URL_ENV = "DEEPLINE_HOST_URL";
|
|
108
|
+
var API_KEY_ENV = "DEEPLINE_API_KEY";
|
|
109
|
+
var ACTIVE_ORG_ID_ENV = "DEEPLINE_ACTIVE_ORG_ID";
|
|
110
|
+
var ACTIVE_ORG_NAME_ENV = "DEEPLINE_ACTIVE_ORG_NAME";
|
|
111
|
+
var FEATURES_ENV = "DEEPLINE_FEATURES";
|
|
112
|
+
var PROD_URL = "https://code.deepline.com";
|
|
113
|
+
var DEFAULT_TIMEOUT = 6e4;
|
|
114
|
+
var DEFAULT_MAX_RETRIES = 3;
|
|
115
|
+
var PROJECT_DEEPLINE_ENV_FILE = ".env.deepline";
|
|
116
|
+
var COWORK_IGNORED_WORKSPACE_DIRS = /* @__PURE__ */ new Set([
|
|
117
|
+
".auto-memory",
|
|
118
|
+
".claude",
|
|
119
|
+
".remote-plugins",
|
|
120
|
+
"outputs",
|
|
121
|
+
"plugins",
|
|
122
|
+
"uploads"
|
|
123
|
+
]);
|
|
124
|
+
var COWORK_PROJECT_MARKERS = [
|
|
125
|
+
".deepline",
|
|
126
|
+
".env.deepline",
|
|
127
|
+
".git",
|
|
128
|
+
"AGENTS.md",
|
|
129
|
+
"package.json",
|
|
130
|
+
"pyproject.toml"
|
|
131
|
+
];
|
|
132
|
+
var CLI_ENV_ALLOWED_KEYS = /* @__PURE__ */ new Set([
|
|
133
|
+
HOST_URL_ENV,
|
|
134
|
+
API_KEY_ENV,
|
|
135
|
+
ACTIVE_ORG_ID_ENV,
|
|
136
|
+
ACTIVE_ORG_NAME_ENV,
|
|
137
|
+
FEATURES_ENV
|
|
138
|
+
]);
|
|
139
|
+
function featureEnvValues(data) {
|
|
140
|
+
if (!Array.isArray(data.features)) return {};
|
|
141
|
+
return {
|
|
142
|
+
[FEATURES_ENV]: data.features.filter(
|
|
143
|
+
(key) => typeof key === "string" && key.trim() !== ""
|
|
144
|
+
).map((key) => key.trim()).join(",")
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function storedHostApiKey(baseUrl) {
|
|
148
|
+
return _nullishCoalesce(loadCliEnv(normalizeBaseUrl(baseUrl) || baseUrl)[API_KEY_ENV], () => ( ""));
|
|
149
|
+
}
|
|
150
|
+
function storedHostFeatures(baseUrl) {
|
|
151
|
+
return loadCliEnv(normalizeBaseUrl(baseUrl) || baseUrl)[FEATURES_ENV];
|
|
152
|
+
}
|
|
153
|
+
function baseUrlSlug(baseUrl) {
|
|
154
|
+
let url;
|
|
155
|
+
try {
|
|
156
|
+
url = new URL(baseUrl);
|
|
157
|
+
} catch (e) {
|
|
158
|
+
return "unknown";
|
|
159
|
+
}
|
|
160
|
+
const host = url.hostname || "unknown";
|
|
161
|
+
const port = url.port ? Number.parseInt(url.port, 10) : null;
|
|
162
|
+
let slug = host.replace(/[^a-zA-Z0-9]/g, "-");
|
|
163
|
+
if (port && port !== 80 && port !== 443) {
|
|
164
|
+
slug = `${slug}-${port}`;
|
|
165
|
+
}
|
|
166
|
+
return slug.toLowerCase().replace(/^-+|-+$/g, "");
|
|
167
|
+
}
|
|
168
|
+
function parseEnvFile(filePath) {
|
|
169
|
+
if (!_fs.existsSync.call(void 0, filePath)) return {};
|
|
170
|
+
const env = {};
|
|
171
|
+
const content = _fs.readFileSync.call(void 0, filePath, "utf-8");
|
|
172
|
+
for (const line of content.split(/\r?\n/)) {
|
|
173
|
+
const trimmed = line.trim();
|
|
174
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
175
|
+
const eqIndex = trimmed.indexOf("=");
|
|
176
|
+
if (eqIndex < 0) continue;
|
|
177
|
+
const key = trimmed.slice(0, eqIndex).trim();
|
|
178
|
+
let value = trimmed.slice(eqIndex + 1).trim();
|
|
179
|
+
if (value.length >= 2 && value.startsWith('"') && value.endsWith('"')) {
|
|
180
|
+
try {
|
|
181
|
+
value = JSON.parse(value);
|
|
182
|
+
} catch (e2) {
|
|
183
|
+
value = value.slice(1, -1);
|
|
184
|
+
}
|
|
185
|
+
} else if (value.length >= 2 && value.startsWith("'") && value.endsWith("'")) {
|
|
186
|
+
value = value.slice(1, -1);
|
|
187
|
+
}
|
|
188
|
+
if (key && value) {
|
|
189
|
+
env[key] = value;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return env;
|
|
193
|
+
}
|
|
194
|
+
function findNearestEnvFile(name, startDir = process.cwd()) {
|
|
195
|
+
let current = _path.resolve.call(void 0, startDir);
|
|
196
|
+
while (true) {
|
|
197
|
+
const filePath = _path.join.call(void 0, current, name);
|
|
198
|
+
if (_fs.existsSync.call(void 0, filePath)) return filePath;
|
|
199
|
+
const parent = _path.dirname.call(void 0, current);
|
|
200
|
+
if (parent === current) return null;
|
|
201
|
+
current = parent;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function isDirectory(path) {
|
|
205
|
+
try {
|
|
206
|
+
return _fs.statSync.call(void 0, path).isDirectory();
|
|
207
|
+
} catch (e3) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function canonicalPath(path) {
|
|
212
|
+
try {
|
|
213
|
+
return _fs.realpathSync.call(void 0, path);
|
|
214
|
+
} catch (e4) {
|
|
215
|
+
return _path.resolve.call(void 0, path);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
function isTruthy(value) {
|
|
219
|
+
return /^(1|true|yes|on)$/i.test(_nullishCoalesce(_optionalChain([value, 'optionalAccess', _ => _.trim, 'call', _2 => _2()]), () => ( "")));
|
|
220
|
+
}
|
|
221
|
+
function sessionRootFromPath(path) {
|
|
222
|
+
const trimmed = _optionalChain([path, 'optionalAccess', _3 => _3.trim, 'call', _4 => _4()]);
|
|
223
|
+
if (!trimmed) return null;
|
|
224
|
+
const match = /^\/sessions\/[^/]+(?=\/|$)/.exec(trimmed);
|
|
225
|
+
return _nullishCoalesce(_optionalChain([match, 'optionalAccess', _5 => _5[0]]), () => ( null));
|
|
226
|
+
}
|
|
227
|
+
function coworkSessionRoot() {
|
|
228
|
+
const home = _optionalChain([process, 'access', _6 => _6.env, 'access', _7 => _7.HOME, 'optionalAccess', _8 => _8.trim, 'call', _9 => _9()]);
|
|
229
|
+
const homeSessionRoot = sessionRootFromPath(home);
|
|
230
|
+
if (homeSessionRoot && isDirectory(_path.join.call(void 0, homeSessionRoot, "mnt"))) {
|
|
231
|
+
return homeSessionRoot;
|
|
232
|
+
}
|
|
233
|
+
const cwdSessionRoot = sessionRootFromPath(process.cwd());
|
|
234
|
+
if (cwdSessionRoot && isDirectory(_path.join.call(void 0, cwdSessionRoot, "mnt"))) {
|
|
235
|
+
return cwdSessionRoot;
|
|
236
|
+
}
|
|
237
|
+
if (isTruthy(process.env.CLAUDE_CODE_REMOTE) && home) {
|
|
238
|
+
const mountedRoot = _path.join.call(void 0, home, "mnt");
|
|
239
|
+
if (isDirectory(mountedRoot)) return _path.resolve.call(void 0, home);
|
|
240
|
+
}
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
function isCoworkLikeSandbox() {
|
|
244
|
+
const home = _optionalChain([process, 'access', _10 => _10.env, 'access', _11 => _11.HOME, 'optionalAccess', _12 => _12.trim, 'call', _13 => _13()]);
|
|
245
|
+
return isTruthy(process.env.CLAUDE_CODE_REMOTE) || sessionRootFromPath(home) !== null || sessionRootFromPath(process.cwd()) !== null;
|
|
246
|
+
}
|
|
247
|
+
function coworkProjectScore(path) {
|
|
248
|
+
let score = 0;
|
|
249
|
+
for (const marker of COWORK_PROJECT_MARKERS) {
|
|
250
|
+
if (_fs.existsSync.call(void 0, _path.join.call(void 0, path, marker))) score += 1;
|
|
251
|
+
}
|
|
252
|
+
return score;
|
|
253
|
+
}
|
|
254
|
+
function listCoworkWorkspaceDirCandidates() {
|
|
255
|
+
if (!isCoworkLikeSandbox()) {
|
|
256
|
+
return [];
|
|
257
|
+
}
|
|
258
|
+
const explicitProjectDir = _optionalChain([process, 'access', _14 => _14.env, 'access', _15 => _15.CLAUDE_PROJECT_DIR, 'optionalAccess', _16 => _16.trim, 'call', _17 => _17()]);
|
|
259
|
+
if (explicitProjectDir && isDirectory(explicitProjectDir)) {
|
|
260
|
+
return [_path.resolve.call(void 0, explicitProjectDir)];
|
|
261
|
+
}
|
|
262
|
+
const sessionRoot = coworkSessionRoot();
|
|
263
|
+
if (!sessionRoot) return [];
|
|
264
|
+
const mountedRoot = _path.join.call(void 0, sessionRoot, "mnt");
|
|
265
|
+
if (!isDirectory(mountedRoot)) return [];
|
|
266
|
+
let names;
|
|
267
|
+
try {
|
|
268
|
+
names = _fs.readdirSync.call(void 0, mountedRoot).sort();
|
|
269
|
+
} catch (e5) {
|
|
270
|
+
return [];
|
|
271
|
+
}
|
|
272
|
+
const candidates = [];
|
|
273
|
+
for (const name of names) {
|
|
274
|
+
if (name.startsWith(".") || COWORK_IGNORED_WORKSPACE_DIRS.has(name)) {
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
const candidate = _path.join.call(void 0, mountedRoot, name);
|
|
278
|
+
if (isDirectory(candidate)) candidates.push(candidate);
|
|
279
|
+
}
|
|
280
|
+
if (candidates.length <= 1) return candidates;
|
|
281
|
+
const projectLike = candidates.filter(
|
|
282
|
+
(candidate) => coworkProjectScore(candidate) > 0
|
|
283
|
+
);
|
|
284
|
+
return projectLike.length > 0 ? projectLike : candidates;
|
|
285
|
+
}
|
|
286
|
+
function isInIgnoredCoworkMount(path) {
|
|
287
|
+
const sessionRoot = coworkSessionRoot();
|
|
288
|
+
if (!sessionRoot) return false;
|
|
289
|
+
const mountedRoot = canonicalPath(_path.join.call(void 0, sessionRoot, "mnt"));
|
|
290
|
+
const resolvedPath = canonicalPath(path);
|
|
291
|
+
const prefix = `${mountedRoot}/`;
|
|
292
|
+
if (!resolvedPath.startsWith(prefix)) return false;
|
|
293
|
+
const relativePath = resolvedPath.slice(prefix.length);
|
|
294
|
+
const mountName = relativePath.split("/")[0];
|
|
295
|
+
return mountName.startsWith(".") || COWORK_IGNORED_WORKSPACE_DIRS.has(mountName);
|
|
296
|
+
}
|
|
297
|
+
function detectCoworkWorkspaceDir() {
|
|
298
|
+
const candidates = listCoworkWorkspaceDirCandidates();
|
|
299
|
+
return candidates.length === 1 ? candidates[0] : null;
|
|
300
|
+
}
|
|
301
|
+
function loadProjectEnvCandidates(startDir = process.cwd()) {
|
|
302
|
+
const filePaths = [];
|
|
303
|
+
const sources = /* @__PURE__ */ new Map();
|
|
304
|
+
const nearestFile = findNearestEnvFile(PROJECT_DEEPLINE_ENV_FILE, startDir);
|
|
305
|
+
if (nearestFile && !isInIgnoredCoworkMount(nearestFile)) {
|
|
306
|
+
filePaths.push(nearestFile);
|
|
307
|
+
sources.set(_path.resolve.call(void 0, nearestFile), "nearest");
|
|
308
|
+
}
|
|
309
|
+
const coworkWorkspaceDir = detectCoworkWorkspaceDir();
|
|
310
|
+
if (coworkWorkspaceDir) {
|
|
311
|
+
const coworkFile = _path.join.call(void 0, coworkWorkspaceDir, PROJECT_DEEPLINE_ENV_FILE);
|
|
312
|
+
if (_fs.existsSync.call(void 0, coworkFile) && !filePaths.some((filePath) => _path.resolve.call(void 0, filePath) === _path.resolve.call(void 0, coworkFile))) {
|
|
313
|
+
filePaths.push(coworkFile);
|
|
314
|
+
sources.set(_path.resolve.call(void 0, coworkFile), "cowork");
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return filePaths.map((filePath) => ({
|
|
318
|
+
filePath,
|
|
319
|
+
env: parseEnvFile(filePath),
|
|
320
|
+
source: _nullishCoalesce(sources.get(_path.resolve.call(void 0, filePath)), () => ( "nearest"))
|
|
321
|
+
}));
|
|
322
|
+
}
|
|
323
|
+
function normalizeBaseUrl(baseUrl) {
|
|
324
|
+
const trimmed = _nullishCoalesce(_optionalChain([baseUrl, 'optionalAccess', _18 => _18.trim, 'call', _19 => _19(), 'access', _20 => _20.replace, 'call', _21 => _21(/\/+$/, "")]), () => ( ""));
|
|
325
|
+
if (!trimmed) return "";
|
|
326
|
+
try {
|
|
327
|
+
const parsed = new URL(trimmed);
|
|
328
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
329
|
+
return "";
|
|
330
|
+
}
|
|
331
|
+
return parsed.toString().replace(/\/+$/, "");
|
|
332
|
+
} catch (e6) {
|
|
333
|
+
return "";
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
function firstNonEmpty(...values) {
|
|
337
|
+
for (const value of values) {
|
|
338
|
+
const trimmed = _optionalChain([value, 'optionalAccess', _22 => _22.trim, 'call', _23 => _23()]);
|
|
339
|
+
if (trimmed) return trimmed;
|
|
340
|
+
}
|
|
341
|
+
return "";
|
|
342
|
+
}
|
|
343
|
+
function formatEnvFileValue(value) {
|
|
344
|
+
return /^[a-zA-Z0-9_./:@%+=,-]+$/.test(value) ? value : JSON.stringify(value);
|
|
345
|
+
}
|
|
346
|
+
function mergePersistedEnvValues(existing, values) {
|
|
347
|
+
const merged = { ...existing, ...values };
|
|
348
|
+
const nextApiKey = values[API_KEY_ENV];
|
|
349
|
+
if (nextApiKey !== void 0 && nextApiKey !== existing[API_KEY_ENV] && values[ACTIVE_ORG_ID_ENV] === void 0) {
|
|
350
|
+
delete merged[ACTIVE_ORG_ID_ENV];
|
|
351
|
+
delete merged[ACTIVE_ORG_NAME_ENV];
|
|
352
|
+
delete merged[FEATURES_ENV];
|
|
353
|
+
}
|
|
354
|
+
if (values[FEATURES_ENV] === "") {
|
|
355
|
+
delete merged[FEATURES_ENV];
|
|
356
|
+
}
|
|
357
|
+
return merged;
|
|
358
|
+
}
|
|
359
|
+
function persistedEnvLines(values) {
|
|
360
|
+
return Object.entries(values).filter(
|
|
361
|
+
([key, value]) => CLI_ENV_ALLOWED_KEYS.has(key) && value.trim() !== ""
|
|
362
|
+
).map(([key, value]) => `${key}=${formatEnvFileValue(value)}`);
|
|
363
|
+
}
|
|
364
|
+
function sdkCliConfigDir(baseUrl) {
|
|
365
|
+
const home = _optionalChain([process, 'access', _24 => _24.env, 'access', _25 => _25.HOME, 'optionalAccess', _26 => _26.trim, 'call', _27 => _27()]) || _os.homedir.call(void 0, );
|
|
366
|
+
return _path.join.call(void 0, home, ".local", "deepline", baseUrlSlug(baseUrl || PROD_URL));
|
|
367
|
+
}
|
|
368
|
+
function sdkCliStateDirPath(baseUrl, homeDir = _optionalChain([process, 'access', _28 => _28.env, 'access', _29 => _29.HOME, 'optionalAccess', _30 => _30.trim, 'call', _31 => _31()]) || _os.homedir.call(void 0, )) {
|
|
369
|
+
return _path.join.call(void 0,
|
|
370
|
+
homeDir,
|
|
371
|
+
".local",
|
|
372
|
+
"deepline",
|
|
373
|
+
baseUrlSlug(baseUrl || PROD_URL),
|
|
374
|
+
"sdk-cli"
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
function sdkCliEnvFilePath(baseUrl) {
|
|
378
|
+
return _path.join.call(void 0, sdkCliConfigDir(baseUrl), ".env");
|
|
379
|
+
}
|
|
380
|
+
function loadCliEnv(baseUrl = PROD_URL) {
|
|
381
|
+
return parseEnvFile(sdkCliEnvFilePath(baseUrl));
|
|
382
|
+
}
|
|
383
|
+
function hostConfigDirPath(baseUrl) {
|
|
384
|
+
return sdkCliConfigDir(baseUrl);
|
|
385
|
+
}
|
|
386
|
+
function hostEnvFilePath(baseUrl) {
|
|
387
|
+
return sdkCliEnvFilePath(baseUrl);
|
|
388
|
+
}
|
|
389
|
+
function saveHostEnvValues(baseUrl, values) {
|
|
390
|
+
const filePath = sdkCliEnvFilePath(baseUrl);
|
|
391
|
+
const dir = _path.dirname.call(void 0, filePath);
|
|
392
|
+
if (!_fs.existsSync.call(void 0, dir)) {
|
|
393
|
+
_fs.mkdirSync.call(void 0, dir, { recursive: true });
|
|
394
|
+
}
|
|
395
|
+
const existing = parseEnvFile(filePath);
|
|
396
|
+
const merged = mergePersistedEnvValues(existing, values);
|
|
397
|
+
const lines = persistedEnvLines(merged);
|
|
398
|
+
_fs.writeFileSync.call(void 0, filePath, `${lines.join("\n")}
|
|
399
|
+
`, "utf-8");
|
|
400
|
+
}
|
|
401
|
+
function loadGlobalCliEnv() {
|
|
402
|
+
return loadCliEnv(PROD_URL);
|
|
403
|
+
}
|
|
404
|
+
function autoDetectBaseUrl() {
|
|
405
|
+
const projectEnvs = loadProjectEnvCandidates();
|
|
406
|
+
const globalEnv = loadGlobalCliEnv();
|
|
407
|
+
return normalizeBaseUrl(_nullishCoalesce(process.env[HOST_URL_ENV], () => ( ""))) || firstNonEmpty(
|
|
408
|
+
...projectEnvs.map(({ env }) => normalizeBaseUrl(env[HOST_URL_ENV]))
|
|
409
|
+
) || normalizeBaseUrl(_nullishCoalesce(globalEnv[HOST_URL_ENV], () => ( ""))) || PROD_URL;
|
|
410
|
+
}
|
|
411
|
+
function resolveApiKeyForBaseUrl(baseUrl, explicitApiKey) {
|
|
412
|
+
const normalizedBaseUrl = normalizeBaseUrl(baseUrl);
|
|
413
|
+
const projectEnvs = loadProjectEnvCandidates();
|
|
414
|
+
const cliEnv = loadCliEnv(normalizedBaseUrl || baseUrl);
|
|
415
|
+
return firstNonEmpty(
|
|
416
|
+
explicitApiKey,
|
|
417
|
+
process.env[API_KEY_ENV],
|
|
418
|
+
...projectEnvs.map(({ env }) => {
|
|
419
|
+
const projectBaseUrl = normalizeBaseUrl(_nullishCoalesce(env[HOST_URL_ENV], () => ( "")));
|
|
420
|
+
return projectBaseUrl === normalizedBaseUrl ? env[API_KEY_ENV] : "";
|
|
421
|
+
}),
|
|
422
|
+
cliEnv[API_KEY_ENV]
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
function resolveProjectApiKeyForBaseUrl(baseUrl, startDir = process.cwd()) {
|
|
426
|
+
const normalizedBaseUrl = normalizeBaseUrl(baseUrl);
|
|
427
|
+
return firstNonEmpty(
|
|
428
|
+
...loadProjectEnvCandidates(startDir).map(({ env }) => {
|
|
429
|
+
const projectBaseUrl = normalizeBaseUrl(_nullishCoalesce(env[HOST_URL_ENV], () => ( "")));
|
|
430
|
+
return projectBaseUrl === normalizedBaseUrl ? env[API_KEY_ENV] : "";
|
|
431
|
+
})
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
function resolveGlobalApiKeyForBaseUrl(baseUrl) {
|
|
435
|
+
return firstNonEmpty(
|
|
436
|
+
process.env[API_KEY_ENV],
|
|
437
|
+
loadCliEnv(normalizeBaseUrl(baseUrl) || baseUrl)[API_KEY_ENV]
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
function getResolvedProjectAuthSource(baseUrl, apiKey, startDir = process.cwd()) {
|
|
441
|
+
const normalizedBaseUrl = normalizeBaseUrl(baseUrl);
|
|
442
|
+
const normalizedApiKey = apiKey.trim();
|
|
443
|
+
if (!normalizedBaseUrl || !normalizedApiKey) return null;
|
|
444
|
+
return _nullishCoalesce(loadProjectEnvCandidates(startDir).find(({ env }) => {
|
|
445
|
+
const projectBaseUrl = normalizeBaseUrl(_nullishCoalesce(env[HOST_URL_ENV], () => ( "")));
|
|
446
|
+
return projectBaseUrl === normalizedBaseUrl && (_nullishCoalesce(env[API_KEY_ENV], () => ( ""))).trim() === normalizedApiKey;
|
|
447
|
+
}), () => ( null));
|
|
448
|
+
}
|
|
449
|
+
function resolveBaseUrlOnly(options) {
|
|
450
|
+
const baseUrl = normalizeBaseUrl(
|
|
451
|
+
_optionalChain([options, 'optionalAccess', _32 => _32.baseUrl, 'optionalAccess', _33 => _33.trim, 'call', _34 => _34()]) || autoDetectBaseUrl()
|
|
452
|
+
);
|
|
453
|
+
if (!baseUrl) {
|
|
454
|
+
throw new ConfigError(
|
|
455
|
+
`Invalid ${HOST_URL_ENV}. Expected an http(s) URL such as https://code.deepline.com.`
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
return baseUrl;
|
|
459
|
+
}
|
|
460
|
+
function resolveConfig(options) {
|
|
461
|
+
const baseUrl = normalizeBaseUrl(
|
|
462
|
+
_optionalChain([options, 'optionalAccess', _35 => _35.baseUrl, 'optionalAccess', _36 => _36.trim, 'call', _37 => _37()]) || autoDetectBaseUrl()
|
|
463
|
+
);
|
|
464
|
+
if (!baseUrl) {
|
|
465
|
+
throw new ConfigError(
|
|
466
|
+
`Invalid ${HOST_URL_ENV}. Expected an http(s) URL such as https://code.deepline.com.`
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
const apiKey = resolveApiKeyForBaseUrl(baseUrl, _optionalChain([options, 'optionalAccess', _38 => _38.apiKey]));
|
|
470
|
+
if (!apiKey) {
|
|
471
|
+
throw new ConfigError(
|
|
472
|
+
`No API key found. Set ${API_KEY_ENV}, add it to .env.deepline, or run: deepline auth register`
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
return {
|
|
476
|
+
apiKey,
|
|
477
|
+
baseUrl,
|
|
478
|
+
timeout: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _39 => _39.timeout]), () => ( DEFAULT_TIMEOUT)),
|
|
479
|
+
maxRetries: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _40 => _40.maxRetries]), () => ( DEFAULT_MAX_RETRIES)),
|
|
480
|
+
// Pass through untouched: the transport owns case-insensitive merging so
|
|
481
|
+
// there is exactly one place that decides which header wins.
|
|
482
|
+
..._optionalChain([options, 'optionalAccess', _41 => _41.headers]) ? { headers: { ...options.headers } } : {}
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
function mergeProjectEnvFile(filePath, values) {
|
|
486
|
+
const existing = parseEnvFile(filePath);
|
|
487
|
+
const merged = mergePersistedEnvValues(existing, values);
|
|
488
|
+
const dir = _path.dirname.call(void 0, filePath);
|
|
489
|
+
if (!_fs.existsSync.call(void 0, dir)) _fs.mkdirSync.call(void 0, dir, { recursive: true });
|
|
490
|
+
ensureProjectEnvIsIgnored(dir);
|
|
491
|
+
const lines = persistedEnvLines(merged);
|
|
492
|
+
_fs.writeFileSync.call(void 0, filePath, `${lines.join("\n")}
|
|
493
|
+
`, "utf-8");
|
|
494
|
+
}
|
|
495
|
+
function ensureProjectEnvIsIgnored(dir) {
|
|
496
|
+
ensureProjectPrivatePathsIgnored(dir, [
|
|
497
|
+
PROJECT_DEEPLINE_ENV_FILE,
|
|
498
|
+
".deepline/"
|
|
499
|
+
]);
|
|
500
|
+
}
|
|
501
|
+
function ensureProjectPrivatePathsIgnored(dir, entries) {
|
|
502
|
+
const gitDir = findNearestGitCommonDir(dir);
|
|
503
|
+
if (gitDir) {
|
|
504
|
+
const excludePath = _path.join.call(void 0, gitDir, "info", "exclude");
|
|
505
|
+
const existing2 = _fs.existsSync.call(void 0, excludePath) ? _fs.readFileSync.call(void 0, excludePath, "utf-8") : "";
|
|
506
|
+
const existingEntries2 = new Set(
|
|
507
|
+
existing2.split(/\r?\n/).map((line) => line.trim()).filter(Boolean)
|
|
508
|
+
);
|
|
509
|
+
const missing2 = entries.filter(
|
|
510
|
+
(entry) => !existingEntries2.has(entry) && !existingEntries2.has(`/${entry}`)
|
|
511
|
+
);
|
|
512
|
+
if (missing2.length === 0) return;
|
|
513
|
+
_fs.mkdirSync.call(void 0, _path.dirname.call(void 0, excludePath), { recursive: true });
|
|
514
|
+
const prefix2 = existing2 && !existing2.endsWith("\n") ? "\n" : "";
|
|
515
|
+
_fs.writeFileSync.call(void 0,
|
|
516
|
+
excludePath,
|
|
517
|
+
`${existing2}${prefix2}${missing2.join("\n")}
|
|
518
|
+
`,
|
|
519
|
+
"utf-8"
|
|
520
|
+
);
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
const gitignorePath = _path.join.call(void 0, dir, ".gitignore");
|
|
524
|
+
const existing = _fs.existsSync.call(void 0, gitignorePath) ? _fs.readFileSync.call(void 0, gitignorePath, "utf-8") : "";
|
|
525
|
+
const existingEntries = new Set(
|
|
526
|
+
existing.split(/\r?\n/).map((line) => line.trim()).filter(Boolean)
|
|
527
|
+
);
|
|
528
|
+
const missing = entries.filter(
|
|
529
|
+
(entry) => !existingEntries.has(entry) && !existingEntries.has(`/${entry}`)
|
|
530
|
+
);
|
|
531
|
+
if (missing.length === 0) return;
|
|
532
|
+
const prefix = existing && !existing.endsWith("\n") ? "\n" : "";
|
|
533
|
+
_fs.writeFileSync.call(void 0,
|
|
534
|
+
gitignorePath,
|
|
535
|
+
`${existing}${prefix}${missing.join("\n")}
|
|
536
|
+
`,
|
|
537
|
+
"utf-8"
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
function findNearestGitCommonDir(startDir) {
|
|
541
|
+
let current = _path.resolve.call(void 0, startDir);
|
|
542
|
+
while (true) {
|
|
543
|
+
const candidate = _path.join.call(void 0, current, ".git");
|
|
544
|
+
if (_fs.existsSync.call(void 0, candidate)) {
|
|
545
|
+
try {
|
|
546
|
+
const stat = _fs.statSync.call(void 0, candidate);
|
|
547
|
+
if (stat.isDirectory()) return candidate;
|
|
548
|
+
if (stat.isFile()) {
|
|
549
|
+
const match = _fs.readFileSync.call(void 0, candidate, "utf8").match(
|
|
550
|
+
/^gitdir:\s*(.+)$/m
|
|
551
|
+
);
|
|
552
|
+
const rawGitDir = _optionalChain([match, 'optionalAccess', _42 => _42[1], 'optionalAccess', _43 => _43.trim, 'call', _44 => _44()]);
|
|
553
|
+
if (rawGitDir) {
|
|
554
|
+
const gitDir = _path.isAbsolute.call(void 0, rawGitDir) ? rawGitDir : _path.resolve.call(void 0, _path.dirname.call(void 0, candidate), rawGitDir);
|
|
555
|
+
const commonDirPath = _path.join.call(void 0, gitDir, "commondir");
|
|
556
|
+
if (!_fs.existsSync.call(void 0, commonDirPath)) return gitDir;
|
|
557
|
+
const rawCommonDir = _fs.readFileSync.call(void 0, commonDirPath, "utf8").trim();
|
|
558
|
+
return rawCommonDir ? _path.isAbsolute.call(void 0, rawCommonDir) ? rawCommonDir : _path.resolve.call(void 0, gitDir, rawCommonDir) : gitDir;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
} catch (e7) {
|
|
562
|
+
return null;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
const parent = _path.dirname.call(void 0, current);
|
|
566
|
+
if (parent === current) return null;
|
|
567
|
+
current = parent;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
function saveProjectDeeplineEnvValues(values, startDir = process.cwd()) {
|
|
571
|
+
const target = resolveProjectPinTarget(startDir);
|
|
572
|
+
if (!target.ok) {
|
|
573
|
+
throw new ConfigError(
|
|
574
|
+
`Cowork project folder is ambiguous. Candidate folders: ${target.candidates.join(
|
|
575
|
+
", "
|
|
576
|
+
)}. Set CLAUDE_PROJECT_DIR or cd into the intended project folder before running this command.`
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
const filePath = _path.join.call(void 0, target.dir, PROJECT_DEEPLINE_ENV_FILE);
|
|
580
|
+
mergeProjectEnvFile(filePath, values);
|
|
581
|
+
return [filePath];
|
|
582
|
+
}
|
|
583
|
+
function resolveProjectPinTarget(startDir = process.cwd()) {
|
|
584
|
+
const nearestFile = findNearestEnvFile(PROJECT_DEEPLINE_ENV_FILE, startDir);
|
|
585
|
+
if (nearestFile && !isInIgnoredCoworkMount(nearestFile)) {
|
|
586
|
+
return { ok: true, dir: _path.dirname.call(void 0, nearestFile), source: "nearest" };
|
|
587
|
+
}
|
|
588
|
+
const coworkCandidates = listCoworkWorkspaceDirCandidates();
|
|
589
|
+
if (coworkCandidates.length === 1) {
|
|
590
|
+
return { ok: true, dir: coworkCandidates[0], source: "cowork" };
|
|
591
|
+
}
|
|
592
|
+
if (coworkCandidates.length > 1) {
|
|
593
|
+
const resolvedStartDir = canonicalPath(startDir);
|
|
594
|
+
const cwdCandidate = coworkCandidates.find((candidate) => {
|
|
595
|
+
const resolvedCandidate = canonicalPath(candidate);
|
|
596
|
+
return resolvedStartDir === resolvedCandidate || resolvedStartDir.startsWith(`${resolvedCandidate}/`);
|
|
597
|
+
});
|
|
598
|
+
if (cwdCandidate) {
|
|
599
|
+
return { ok: true, dir: cwdCandidate, source: "cowork" };
|
|
600
|
+
}
|
|
601
|
+
return {
|
|
602
|
+
ok: false,
|
|
603
|
+
reason: "ambiguous_cowork_project",
|
|
604
|
+
candidates: coworkCandidates
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
return { ok: true, dir: _path.resolve.call(void 0, startDir), source: "cwd" };
|
|
608
|
+
}
|
|
609
|
+
function getActiveProjectAuthSource(startDir = process.cwd()) {
|
|
610
|
+
return _nullishCoalesce(loadProjectEnvCandidates(startDir)[0], () => ( null));
|
|
611
|
+
}
|
|
612
|
+
function findNearestProjectMarkerDir(startDir) {
|
|
613
|
+
let current = _path.resolve.call(void 0, startDir);
|
|
614
|
+
while (true) {
|
|
615
|
+
if (COWORK_PROJECT_MARKERS.some((marker) => _fs.existsSync.call(void 0, _path.join.call(void 0, current, marker)))) {
|
|
616
|
+
return current;
|
|
617
|
+
}
|
|
618
|
+
const parent = _path.dirname.call(void 0, current);
|
|
619
|
+
if (parent === current) return null;
|
|
620
|
+
current = parent;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
function resolveCliAuthProvenance(config, startDir = process.cwd()) {
|
|
624
|
+
const envApiKey = _optionalChain([process, 'access', _45 => _45.env, 'access', _46 => _46[API_KEY_ENV], 'optionalAccess', _47 => _47.trim, 'call', _48 => _48()]);
|
|
625
|
+
const folderAuth = getResolvedProjectAuthSource(
|
|
626
|
+
config.baseUrl,
|
|
627
|
+
config.apiKey,
|
|
628
|
+
startDir
|
|
629
|
+
);
|
|
630
|
+
const pinTarget = resolveProjectPinTarget(startDir);
|
|
631
|
+
const markerDir = findNearestProjectMarkerDir(startDir);
|
|
632
|
+
const project = !pinTarget.ok ? {
|
|
633
|
+
state: "ambiguous_cowork_project",
|
|
634
|
+
candidates: pinTarget.candidates
|
|
635
|
+
} : folderAuth ? {
|
|
636
|
+
state: "project",
|
|
637
|
+
dir: _path.dirname.call(void 0, folderAuth.filePath),
|
|
638
|
+
pinPath: folderAuth.filePath,
|
|
639
|
+
source: "folder"
|
|
640
|
+
} : pinTarget.source === "cowork" ? {
|
|
641
|
+
state: "project",
|
|
642
|
+
dir: pinTarget.dir,
|
|
643
|
+
pinPath: _path.join.call(void 0, pinTarget.dir, PROJECT_DEEPLINE_ENV_FILE),
|
|
644
|
+
source: "cowork"
|
|
645
|
+
} : markerDir ? {
|
|
646
|
+
state: "project",
|
|
647
|
+
dir: markerDir,
|
|
648
|
+
pinPath: _path.join.call(void 0, markerDir, PROJECT_DEEPLINE_ENV_FILE),
|
|
649
|
+
source: "marker"
|
|
650
|
+
} : { state: "not_project" };
|
|
651
|
+
return {
|
|
652
|
+
scope: envApiKey ? "env" : folderAuth ? "folder" : "global",
|
|
653
|
+
project,
|
|
654
|
+
folderAuthPath: _nullishCoalesce(_optionalChain([folderAuth, 'optionalAccess', _49 => _49.filePath]), () => ( null))
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
function activeOrganizationFromEnv(env) {
|
|
658
|
+
const orgId = _optionalChain([env, 'access', _50 => _50[ACTIVE_ORG_ID_ENV], 'optionalAccess', _51 => _51.trim, 'call', _52 => _52()]);
|
|
659
|
+
if (!orgId) return null;
|
|
660
|
+
const orgName = _optionalChain([env, 'access', _53 => _53[ACTIVE_ORG_NAME_ENV], 'optionalAccess', _54 => _54.trim, 'call', _55 => _55()]) || null;
|
|
661
|
+
return { org_id: orgId, org_name: orgName };
|
|
662
|
+
}
|
|
663
|
+
function resolveCliCommandContext(inputConfig, requestedScope) {
|
|
664
|
+
let config = inputConfig;
|
|
665
|
+
if (!config) {
|
|
666
|
+
try {
|
|
667
|
+
config = resolveConfig();
|
|
668
|
+
} catch (e8) {
|
|
669
|
+
return {
|
|
670
|
+
active_organization: null,
|
|
671
|
+
auth_scope: null,
|
|
672
|
+
metadata_source: null
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
const contextForScope = (scope) => {
|
|
677
|
+
if (scope === "env") {
|
|
678
|
+
const processApiKey = _optionalChain([process, 'access', _56 => _56.env, 'access', _57 => _57[API_KEY_ENV], 'optionalAccess', _58 => _58.trim, 'call', _59 => _59()]);
|
|
679
|
+
return processApiKey && processApiKey === config.apiKey ? {
|
|
680
|
+
active_organization: activeOrganizationFromEnv(process.env),
|
|
681
|
+
auth_scope: "env",
|
|
682
|
+
metadata_source: "process_env"
|
|
683
|
+
} : null;
|
|
684
|
+
}
|
|
685
|
+
if (scope === "folder") {
|
|
686
|
+
const projectAuth = getResolvedProjectAuthSource(
|
|
687
|
+
config.baseUrl,
|
|
688
|
+
config.apiKey
|
|
689
|
+
);
|
|
690
|
+
return projectAuth ? {
|
|
691
|
+
active_organization: activeOrganizationFromEnv(projectAuth.env),
|
|
692
|
+
auth_scope: "folder",
|
|
693
|
+
metadata_source: "folder_env"
|
|
694
|
+
} : null;
|
|
695
|
+
}
|
|
696
|
+
const hostEnv = loadCliEnv(config.baseUrl);
|
|
697
|
+
return (_nullishCoalesce(hostEnv[API_KEY_ENV], () => ( ""))).trim() === config.apiKey ? {
|
|
698
|
+
active_organization: activeOrganizationFromEnv(hostEnv),
|
|
699
|
+
auth_scope: "global",
|
|
700
|
+
metadata_source: "host_env"
|
|
701
|
+
} : null;
|
|
702
|
+
};
|
|
703
|
+
const processContext = contextForScope("env");
|
|
704
|
+
if (processContext) return processContext;
|
|
705
|
+
if (requestedScope) {
|
|
706
|
+
return _nullishCoalesce(contextForScope(requestedScope), () => ( {
|
|
707
|
+
active_organization: null,
|
|
708
|
+
auth_scope: requestedScope,
|
|
709
|
+
metadata_source: null
|
|
710
|
+
}));
|
|
711
|
+
}
|
|
712
|
+
for (const scope of ["folder", "global"]) {
|
|
713
|
+
const context = contextForScope(scope);
|
|
714
|
+
if (context) return context;
|
|
715
|
+
}
|
|
716
|
+
return {
|
|
717
|
+
active_organization: null,
|
|
718
|
+
auth_scope: null,
|
|
719
|
+
metadata_source: null
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
// src/version.ts
|
|
724
|
+
var SDK_VERSION = _chunkD4AZUZO4js.SDK_RELEASE.version;
|
|
725
|
+
var SDK_API_MAJOR = _chunkD4AZUZO4js.SDK_RELEASE.contracts.api.currentMajor;
|
|
726
|
+
var SDK_API_CONTRACT = _nullishCoalesce(_chunkD4AZUZO4js.SDK_RELEASE.contracts.api.legacyWireIds[0], () => ( `api-v${SDK_API_MAJOR}`));
|
|
727
|
+
|
|
728
|
+
// src/agent-runtime.ts
|
|
729
|
+
|
|
730
|
+
var EXPLICIT_AGENT_RUNTIMES = /* @__PURE__ */ new Set([
|
|
731
|
+
"claude_code",
|
|
732
|
+
"claude_cowork",
|
|
733
|
+
"codex",
|
|
734
|
+
"cline",
|
|
735
|
+
"cursor",
|
|
736
|
+
"gemini",
|
|
737
|
+
"antigravity",
|
|
738
|
+
"windsurf",
|
|
739
|
+
"unknown"
|
|
740
|
+
]);
|
|
741
|
+
function truthyEnv(name) {
|
|
742
|
+
return ["1", "true", "yes", "on"].includes(
|
|
743
|
+
String(_nullishCoalesce(process.env[name], () => ( ""))).trim().toLowerCase()
|
|
744
|
+
);
|
|
745
|
+
}
|
|
746
|
+
function normalizeAgentRuntime(value) {
|
|
747
|
+
const explicit = _optionalChain([value, 'optionalAccess', _60 => _60.trim, 'call', _61 => _61(), 'access', _62 => _62.toLowerCase, 'call', _63 => _63(), 'access', _64 => _64.replace, 'call', _65 => _65(/-/g, "_")]);
|
|
748
|
+
if (!explicit) return null;
|
|
749
|
+
if (explicit === "gemini_cli") return "gemini";
|
|
750
|
+
return EXPLICIT_AGENT_RUNTIMES.has(explicit) ? explicit : null;
|
|
751
|
+
}
|
|
752
|
+
function isCoworkLikeSandbox2() {
|
|
753
|
+
const pluginMode = truthyEnv("DEEPLINE_PLUGIN_MODE");
|
|
754
|
+
const claudeRemote = truthyEnv("CLAUDE_CODE_REMOTE");
|
|
755
|
+
const projectDir = Boolean(_optionalChain([process, 'access', _66 => _66.env, 'access', _67 => _67.CLAUDE_PROJECT_DIR, 'optionalAccess', _68 => _68.trim, 'call', _69 => _69()]));
|
|
756
|
+
const pluginRoot = Boolean(_optionalChain([process, 'access', _70 => _70.env, 'access', _71 => _71.DEEPLINE_PLUGIN_ROOT, 'optionalAccess', _72 => _72.trim, 'call', _73 => _73()]));
|
|
757
|
+
const home = _optionalChain([process, 'access', _74 => _74.env, 'access', _75 => _75.HOME, 'optionalAccess', _76 => _76.trim, 'call', _77 => _77()]) || _os.homedir.call(void 0, );
|
|
758
|
+
const sessionHome = home === "/sessions" || home.startsWith("/sessions/");
|
|
759
|
+
return claudeRemote || sessionHome || (pluginMode || pluginRoot) && projectDir;
|
|
760
|
+
}
|
|
761
|
+
function detectAgentRuntime(options = {}) {
|
|
762
|
+
const explicit = normalizeAgentRuntime(process.env.DEEPLINE_AGENT_RUNTIME);
|
|
763
|
+
if (explicit) return explicit;
|
|
764
|
+
if (_optionalChain([process, 'access', _78 => _78.env, 'access', _79 => _79.CODEX_THREAD_ID, 'optionalAccess', _80 => _80.trim, 'call', _81 => _81()])) return "codex";
|
|
765
|
+
if (options.detectCowork !== false && isCoworkLikeSandbox2()) {
|
|
766
|
+
return "claude_cowork";
|
|
767
|
+
}
|
|
768
|
+
if (_optionalChain([process, 'access', _82 => _82.env, 'access', _83 => _83.CLAUDECODE, 'optionalAccess', _84 => _84.trim, 'call', _85 => _85()]) === "1") return "claude_code";
|
|
769
|
+
if (_optionalChain([process, 'access', _86 => _86.env, 'access', _87 => _87.CLINE_ACTIVE, 'optionalAccess', _88 => _88.trim, 'call', _89 => _89(), 'access', _90 => _90.toLowerCase, 'call', _91 => _91()]) === "true") return "cline";
|
|
770
|
+
if (_optionalChain([process, 'access', _92 => _92.env, 'access', _93 => _93.CURSOR_TRACE_ID, 'optionalAccess', _94 => _94.trim, 'call', _95 => _95()]) || _optionalChain([process, 'access', _96 => _96.env, 'access', _97 => _97.CURSOR_AGENT, 'optionalAccess', _98 => _98.trim, 'call', _99 => _99()])) {
|
|
771
|
+
return "cursor";
|
|
772
|
+
}
|
|
773
|
+
if (_optionalChain([process, 'access', _100 => _100.env, 'access', _101 => _101.WINDSURF, 'optionalAccess', _102 => _102.trim, 'call', _103 => _103()]) || _optionalChain([process, 'access', _104 => _104.env, 'access', _105 => _105.CASCADE, 'optionalAccess', _106 => _106.trim, 'call', _107 => _107()])) {
|
|
774
|
+
return "windsurf";
|
|
775
|
+
}
|
|
776
|
+
if (_optionalChain([process, 'access', _108 => _108.env, 'access', _109 => _109.ANTIGRAVITY, 'optionalAccess', _110 => _110.trim, 'call', _111 => _111()]) || _optionalChain([process, 'access', _112 => _112.env, 'access', _113 => _113.ANTIGRAVITY_CLI, 'optionalAccess', _114 => _114.trim, 'call', _115 => _115()]) || _optionalChain([process, 'access', _116 => _116.env, 'access', _117 => _117.ANTIGRAVITY_AGENT, 'optionalAccess', _118 => _118.trim, 'call', _119 => _119()]) || _optionalChain([process, 'access', _120 => _120.env, 'access', _121 => _121.ANTIGRAVITY_WORKSPACE, 'optionalAccess', _122 => _122.trim, 'call', _123 => _123()])) {
|
|
777
|
+
return "antigravity";
|
|
778
|
+
}
|
|
779
|
+
if (_optionalChain([process, 'access', _124 => _124.env, 'access', _125 => _125.GEMINI_CLI, 'optionalAccess', _126 => _126.trim, 'call', _127 => _127()]) || _optionalChain([process, 'access', _128 => _128.env, 'access', _129 => _129.GEMINI_CLI_VERSION, 'optionalAccess', _130 => _130.trim, 'call', _131 => _131()]) || _optionalChain([process, 'access', _132 => _132.env, 'access', _133 => _133.GEMINI_SANDBOX, 'optionalAccess', _134 => _134.trim, 'call', _135 => _135()]) || _optionalChain([process, 'access', _136 => _136.env, 'access', _137 => _137.GEMINI_CONFIG_DIR, 'optionalAccess', _138 => _138.trim, 'call', _139 => _139()])) {
|
|
780
|
+
return "gemini";
|
|
781
|
+
}
|
|
782
|
+
return _nullishCoalesce(options.defaultRuntime, () => ( "unknown"));
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
// src/skills-version.ts
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
function activePluginSkillsDir() {
|
|
789
|
+
const pluginMode = _optionalChain([process, 'access', _140 => _140.env, 'access', _141 => _141.DEEPLINE_PLUGIN_MODE, 'optionalAccess', _142 => _142.trim, 'call', _143 => _143(), 'access', _144 => _144.toLowerCase, 'call', _145 => _145()]);
|
|
790
|
+
if (pluginMode !== "true" && pluginMode !== "1" && pluginMode !== "yes" && pluginMode !== "on") {
|
|
791
|
+
return "";
|
|
792
|
+
}
|
|
793
|
+
const dir = _nullishCoalesce(_optionalChain([process, 'access', _146 => _146.env, 'access', _147 => _147.DEEPLINE_PLUGIN_SKILLS_DIR, 'optionalAccess', _148 => _148.trim, 'call', _149 => _149()]), () => ( ""));
|
|
794
|
+
return dir && _fs.existsSync.call(void 0, dir) ? dir : "";
|
|
795
|
+
}
|
|
796
|
+
function hasActivePluginSkills() {
|
|
797
|
+
return Boolean(activePluginSkillsDir());
|
|
798
|
+
}
|
|
799
|
+
function readPluginSkillsVersion() {
|
|
800
|
+
const dir = activePluginSkillsDir();
|
|
801
|
+
if (!dir) return "";
|
|
802
|
+
try {
|
|
803
|
+
return _fs.readFileSync.call(void 0, _path.join.call(void 0, dir, ".version"), "utf-8").trim();
|
|
804
|
+
} catch (e9) {
|
|
805
|
+
return "";
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
var KNOWN_SKILL_AGENTS = [
|
|
809
|
+
"antigravity",
|
|
810
|
+
"claude-code",
|
|
811
|
+
"cline",
|
|
812
|
+
"codex",
|
|
813
|
+
"cursor",
|
|
814
|
+
"gemini-cli",
|
|
815
|
+
"windsurf"
|
|
816
|
+
];
|
|
817
|
+
var DEFAULT_SKILL_AGENTS = [
|
|
818
|
+
"codex",
|
|
819
|
+
"claude-code",
|
|
820
|
+
"cursor",
|
|
821
|
+
"gemini-cli",
|
|
822
|
+
"antigravity"
|
|
823
|
+
];
|
|
824
|
+
function skillsAgentPathSegment(agent) {
|
|
825
|
+
if (agent === "*") return "all";
|
|
826
|
+
const slug = agent.replace(/[^a-z0-9]+/gi, "-").replace(/^-+|-+$/g, "");
|
|
827
|
+
return slug || "agent";
|
|
828
|
+
}
|
|
829
|
+
function sdkSkillsVersionPath(baseUrl, agents = []) {
|
|
830
|
+
const suffix = agents.length > 0 ? `-${agents.map(skillsAgentPathSegment).join("-")}` : "";
|
|
831
|
+
return _path.join.call(void 0, sdkCliStateDirPath(baseUrl), `skills${suffix}-version`);
|
|
832
|
+
}
|
|
833
|
+
function legacySdkSkillsVersionPath(baseUrl) {
|
|
834
|
+
return _path.join.call(void 0, _path.dirname.call(void 0, sdkCliStateDirPath(baseUrl)), "sdk-skills", ".version");
|
|
835
|
+
}
|
|
836
|
+
function readSkillsVersionFile(path) {
|
|
837
|
+
try {
|
|
838
|
+
return _fs.readFileSync.call(void 0, path, "utf-8").trim();
|
|
839
|
+
} catch (e10) {
|
|
840
|
+
return "";
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
function resolveAutoSyncSkillAgents() {
|
|
844
|
+
switch (detectAgentRuntime()) {
|
|
845
|
+
case "codex":
|
|
846
|
+
return ["codex"];
|
|
847
|
+
case "claude_code":
|
|
848
|
+
return ["claude-code"];
|
|
849
|
+
case "cursor":
|
|
850
|
+
return ["cursor"];
|
|
851
|
+
case "gemini":
|
|
852
|
+
return ["gemini-cli"];
|
|
853
|
+
case "antigravity":
|
|
854
|
+
return ["antigravity"];
|
|
855
|
+
case "unknown":
|
|
856
|
+
return [...DEFAULT_SKILL_AGENTS];
|
|
857
|
+
default:
|
|
858
|
+
return [];
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
function readSdkSkillsLocalVersion(baseUrl) {
|
|
862
|
+
const pluginVersion = readPluginSkillsVersion();
|
|
863
|
+
if (pluginVersion) return pluginVersion;
|
|
864
|
+
const agents = resolveAutoSyncSkillAgents();
|
|
865
|
+
if (agents.length > 1) {
|
|
866
|
+
const versions = agents.map(
|
|
867
|
+
(agent) => readSkillsVersionFile(sdkSkillsVersionPath(baseUrl, [agent]))
|
|
868
|
+
);
|
|
869
|
+
const first = versions[0];
|
|
870
|
+
return first && versions.every((version) => version === first) ? first : "";
|
|
871
|
+
}
|
|
872
|
+
const scopedPath = sdkSkillsVersionPath(baseUrl, agents);
|
|
873
|
+
if (agents.length > 0 && _fs.existsSync.call(void 0, scopedPath)) {
|
|
874
|
+
try {
|
|
875
|
+
return _fs.readFileSync.call(void 0, scopedPath, "utf-8").trim();
|
|
876
|
+
} catch (e11) {
|
|
877
|
+
return "";
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
if (agents.length > 0) {
|
|
881
|
+
const legacyPath = legacySdkSkillsVersionPath(baseUrl);
|
|
882
|
+
if (!_fs.existsSync.call(void 0, legacyPath)) return "";
|
|
883
|
+
try {
|
|
884
|
+
return _fs.readFileSync.call(void 0, legacyPath, "utf-8").trim();
|
|
885
|
+
} catch (e12) {
|
|
886
|
+
return "";
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
const path = _fs.existsSync.call(void 0, sdkSkillsVersionPath(baseUrl)) ? sdkSkillsVersionPath(baseUrl) : legacySdkSkillsVersionPath(baseUrl);
|
|
890
|
+
if (!_fs.existsSync.call(void 0, path)) return "";
|
|
891
|
+
try {
|
|
892
|
+
return _fs.readFileSync.call(void 0, path, "utf-8").trim();
|
|
893
|
+
} catch (e13) {
|
|
894
|
+
return "";
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
function writeSdkSkillsLocalVersion(baseUrl, version, agents) {
|
|
898
|
+
const targets = agents.length > 1 ? agents.map((agent) => [agent]) : [agents];
|
|
899
|
+
let complete = true;
|
|
900
|
+
for (const target of targets) {
|
|
901
|
+
const path = sdkSkillsVersionPath(baseUrl, target);
|
|
902
|
+
try {
|
|
903
|
+
_fs.mkdirSync.call(void 0, _path.dirname.call(void 0, path), { recursive: true });
|
|
904
|
+
_fs.writeFileSync.call(void 0, path, `${version}
|
|
905
|
+
`, "utf-8");
|
|
906
|
+
} catch (e14) {
|
|
907
|
+
complete = false;
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
return complete;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
// ../play-runtime/coordinator-headers.ts
|
|
914
|
+
var COORDINATOR_INTERNAL_TOKEN_HEADER = "x-deepline-internal-token";
|
|
915
|
+
var COORDINATOR_URL_OVERRIDE_HEADER = "x-deepline-coordinator-url";
|
|
916
|
+
var WORKER_CALLBACK_URL_OVERRIDE_HEADER = "x-deepline-worker-callback-url";
|
|
917
|
+
var RUNTIME_SCHEDULER_SCHEMA_OVERRIDE_HEADER = "x-deepline-runtime-scheduler-schema";
|
|
918
|
+
var RUNTIME_ENVIRONMENT_TOKEN_HEADER = "x-deepline-runtime-environment-token";
|
|
919
|
+
var RETAINED_PIPELINE_RECEIVERS_HEADER = "x-deepline-retained-pipeline-receivers";
|
|
920
|
+
var ABSURD_RELEASE_OVERRIDE_HEADER = "x-deepline-absurd-release";
|
|
921
|
+
var PREFERRED_RECEIPT_GATEWAY_MACHINE_ID_HEADER = "x-deepline-preferred-receipt-gateway-machine-id";
|
|
922
|
+
var SYNTHETIC_RUN_HEADER = "x-deepline-synthetic-run";
|
|
923
|
+
|
|
924
|
+
// src/deployment-protection.ts
|
|
925
|
+
function deploymentProtectionHeaders() {
|
|
926
|
+
const token = typeof process !== "undefined" ? _optionalChain([process, 'access', _150 => _150.env, 'optionalAccess', _151 => _151.VERCEL_PROTECTION_BYPASS_TOKEN]) : void 0;
|
|
927
|
+
return token ? { "x-vercel-protection-bypass": token } : {};
|
|
928
|
+
}
|
|
929
|
+
var fetchWithDeploymentProtection = (input, init) => {
|
|
930
|
+
const headers = new Headers(
|
|
931
|
+
input instanceof Request ? input.headers : void 0
|
|
932
|
+
);
|
|
933
|
+
new Headers(_optionalChain([init, 'optionalAccess', _152 => _152.headers])).forEach((value, name) => headers.set(name, value));
|
|
934
|
+
for (const [name, value] of Object.entries(deploymentProtectionHeaders())) {
|
|
935
|
+
headers.set(name, value);
|
|
936
|
+
}
|
|
937
|
+
return fetch(input, { ...init, headers });
|
|
938
|
+
};
|
|
939
|
+
|
|
940
|
+
// ../play-runtime/runtime-incident-drills.ts
|
|
941
|
+
var RUNTIME_TEST_FAULT_IDS = [
|
|
942
|
+
"receipt_complete_write_fail",
|
|
943
|
+
"receipt_fail_write_fail",
|
|
944
|
+
"worker_receipt_complete_write_fail",
|
|
945
|
+
"invocation_response_delivery_abort",
|
|
946
|
+
"execution_upstream_response_loss",
|
|
947
|
+
"receipt_gateway_hold_ms",
|
|
948
|
+
"receipt_claim_query_hold_once_ms",
|
|
949
|
+
"receipt_claim_response_timeout",
|
|
950
|
+
"modal_sandbox_create_resource_exhausted",
|
|
951
|
+
"runtime_sheet_page_tail_hold_ms"
|
|
952
|
+
];
|
|
953
|
+
var LOCAL_TOPOLOGY = ["local_daytona"];
|
|
954
|
+
var LOCAL_AND_PREVIEW_TOPOLOGIES = [
|
|
955
|
+
"local_daytona",
|
|
956
|
+
"preview_fly",
|
|
957
|
+
"preview_direct_modal"
|
|
958
|
+
];
|
|
959
|
+
var MODAL_PREVIEW_TOPOLOGY = ["preview_direct_modal"];
|
|
960
|
+
var RUNTIME_INCIDENT_DRILL_CATALOG = [
|
|
961
|
+
{
|
|
962
|
+
id: "local_worker_process_outage",
|
|
963
|
+
description: "Interrupt the scheduler worker in the selected non-production runtime topology.",
|
|
964
|
+
topologies: LOCAL_AND_PREVIEW_TOPOLOGIES,
|
|
965
|
+
control: {
|
|
966
|
+
kind: "process",
|
|
967
|
+
component: "worker",
|
|
968
|
+
modes: ["pause", "crash"]
|
|
969
|
+
},
|
|
970
|
+
expected: {
|
|
971
|
+
outcome: "The same logical run stays durable through the worker outage and completes after the selected topology recovers.",
|
|
972
|
+
safetyFacts: ["same_logical_run", "no_false_success"]
|
|
973
|
+
},
|
|
974
|
+
verification: {
|
|
975
|
+
kind: "local_black_box",
|
|
976
|
+
target: "local-component-outage-recovery-e2e"
|
|
977
|
+
}
|
|
978
|
+
},
|
|
979
|
+
{
|
|
980
|
+
id: "local_gateway_process_outage",
|
|
981
|
+
description: "Interrupt the receipt gateway in the selected non-production runtime topology.",
|
|
982
|
+
topologies: LOCAL_AND_PREVIEW_TOPOLOGIES,
|
|
983
|
+
control: {
|
|
984
|
+
kind: "process",
|
|
985
|
+
component: "gateway",
|
|
986
|
+
modes: ["pause", "crash"]
|
|
987
|
+
},
|
|
988
|
+
expected: {
|
|
989
|
+
outcome: "In-flight work recovers only at a safe receipt boundary and the same logical run completes after the gateway recovers.",
|
|
990
|
+
safetyFacts: [
|
|
991
|
+
"same_logical_run",
|
|
992
|
+
"no_false_success",
|
|
993
|
+
"bounded_provider_execution"
|
|
994
|
+
]
|
|
995
|
+
},
|
|
996
|
+
verification: {
|
|
997
|
+
kind: "local_black_box",
|
|
998
|
+
target: "local-component-outage-recovery-e2e"
|
|
999
|
+
}
|
|
1000
|
+
},
|
|
1001
|
+
{
|
|
1002
|
+
id: "local_runtime_process_outage",
|
|
1003
|
+
description: "Interrupt both runtime components in the selected non-production topology.",
|
|
1004
|
+
topologies: LOCAL_AND_PREVIEW_TOPOLOGIES,
|
|
1005
|
+
control: { kind: "process", component: "all", modes: ["pause", "crash"] },
|
|
1006
|
+
expected: {
|
|
1007
|
+
outcome: "Durable work waits through the combined outage; it never becomes a false success or creates a second logical run.",
|
|
1008
|
+
safetyFacts: ["same_logical_run", "no_false_success"]
|
|
1009
|
+
},
|
|
1010
|
+
verification: {
|
|
1011
|
+
kind: "local_black_box",
|
|
1012
|
+
target: "local-component-outage-recovery-e2e"
|
|
1013
|
+
}
|
|
1014
|
+
},
|
|
1015
|
+
{
|
|
1016
|
+
id: "receipt_complete_write_fail",
|
|
1017
|
+
description: "Fail the next durable receipt-completion write.",
|
|
1018
|
+
topologies: LOCAL_AND_PREVIEW_TOPOLOGIES,
|
|
1019
|
+
control: {
|
|
1020
|
+
kind: "runtime_test_fault",
|
|
1021
|
+
defaultValue: 1,
|
|
1022
|
+
valueMeaning: "occurrence"
|
|
1023
|
+
},
|
|
1024
|
+
expected: {
|
|
1025
|
+
outcome: "The failed run is loud, and a later bounded recovery may repeat the affected provider operation if its prior completion was not durable.",
|
|
1026
|
+
safetyFacts: ["retry_or_explicit_recovery", "bounded_provider_execution"]
|
|
1027
|
+
},
|
|
1028
|
+
verification: {
|
|
1029
|
+
kind: "local_black_box",
|
|
1030
|
+
target: "receipt-persist-failure-run-fatal-e2e"
|
|
1031
|
+
}
|
|
1032
|
+
},
|
|
1033
|
+
{
|
|
1034
|
+
id: "receipt_fail_write_fail",
|
|
1035
|
+
description: "Fail the next durable receipt-failure write.",
|
|
1036
|
+
topologies: LOCAL_AND_PREVIEW_TOPOLOGIES,
|
|
1037
|
+
control: {
|
|
1038
|
+
kind: "runtime_test_fault",
|
|
1039
|
+
defaultValue: 1,
|
|
1040
|
+
valueMeaning: "occurrence"
|
|
1041
|
+
},
|
|
1042
|
+
expected: {
|
|
1043
|
+
outcome: "The failure is loud; recovery remains bounded and may repeat an operation whose prior outcome was not durably recorded.",
|
|
1044
|
+
safetyFacts: ["retry_or_explicit_recovery", "bounded_provider_execution"]
|
|
1045
|
+
},
|
|
1046
|
+
verification: {
|
|
1047
|
+
kind: "focused_regression",
|
|
1048
|
+
target: "tests/lib/plays/runtime-test-fault-registry.test.ts"
|
|
1049
|
+
}
|
|
1050
|
+
},
|
|
1051
|
+
{
|
|
1052
|
+
id: "worker_receipt_complete_write_fail",
|
|
1053
|
+
description: "Fail the worker-side receipt-completion write once.",
|
|
1054
|
+
topologies: LOCAL_AND_PREVIEW_TOPOLOGIES,
|
|
1055
|
+
control: {
|
|
1056
|
+
kind: "runtime_test_fault",
|
|
1057
|
+
defaultValue: 1,
|
|
1058
|
+
valueMeaning: "occurrence"
|
|
1059
|
+
},
|
|
1060
|
+
expected: {
|
|
1061
|
+
outcome: "The worker reports the persistence failure loudly; bounded recovery may repeat work whose completion was not durable.",
|
|
1062
|
+
safetyFacts: ["retry_or_explicit_recovery", "bounded_provider_execution"]
|
|
1063
|
+
},
|
|
1064
|
+
verification: {
|
|
1065
|
+
kind: "focused_regression",
|
|
1066
|
+
target: "tests/lib/plays/runtime-test-fault-registry.test.ts"
|
|
1067
|
+
}
|
|
1068
|
+
},
|
|
1069
|
+
{
|
|
1070
|
+
id: "invocation_response_delivery_abort",
|
|
1071
|
+
description: "Abort one receipt-gateway response after invocation delivery.",
|
|
1072
|
+
topologies: LOCAL_AND_PREVIEW_TOPOLOGIES,
|
|
1073
|
+
control: {
|
|
1074
|
+
kind: "runtime_test_fault",
|
|
1075
|
+
defaultValue: 1,
|
|
1076
|
+
valueMeaning: "occurrence"
|
|
1077
|
+
},
|
|
1078
|
+
expected: {
|
|
1079
|
+
outcome: "The same logical run completes through terminal-cache replay; any provider retry is governed by its separate operation policy.",
|
|
1080
|
+
safetyFacts: ["same_logical_run", "bounded_provider_execution"]
|
|
1081
|
+
},
|
|
1082
|
+
verification: {
|
|
1083
|
+
kind: "local_black_box",
|
|
1084
|
+
target: "invocation-delivery-replay-e2e"
|
|
1085
|
+
}
|
|
1086
|
+
},
|
|
1087
|
+
{
|
|
1088
|
+
id: "execution_upstream_response_loss",
|
|
1089
|
+
description: "Lose the first response of each keyed execution after the upstream app durably stores it.",
|
|
1090
|
+
topologies: ["preview_fly"],
|
|
1091
|
+
control: {
|
|
1092
|
+
kind: "runtime_test_fault",
|
|
1093
|
+
defaultValue: 1,
|
|
1094
|
+
valueMeaning: "occurrence"
|
|
1095
|
+
},
|
|
1096
|
+
expected: {
|
|
1097
|
+
outcome: "The same invocation recovers the stored response without repeating provider work or customer charges, and every row retains its usable result.",
|
|
1098
|
+
safetyFacts: [
|
|
1099
|
+
"same_logical_run",
|
|
1100
|
+
"bounded_provider_execution",
|
|
1101
|
+
"all_rows_settle_once",
|
|
1102
|
+
"no_false_success"
|
|
1103
|
+
]
|
|
1104
|
+
},
|
|
1105
|
+
verification: {
|
|
1106
|
+
kind: "preview_black_box",
|
|
1107
|
+
target: "101-agent-heavy-gateway-load-e2e"
|
|
1108
|
+
}
|
|
1109
|
+
},
|
|
1110
|
+
{
|
|
1111
|
+
id: "receipt_gateway_hold_ms",
|
|
1112
|
+
description: "Hold one checked-out receipt-gateway scheduler client.",
|
|
1113
|
+
topologies: LOCAL_AND_PREVIEW_TOPOLOGIES,
|
|
1114
|
+
control: {
|
|
1115
|
+
kind: "runtime_test_fault",
|
|
1116
|
+
defaultValue: 500,
|
|
1117
|
+
valueMeaning: "milliseconds"
|
|
1118
|
+
},
|
|
1119
|
+
expected: {
|
|
1120
|
+
outcome: "The request is delayed inside the real gateway pool and either completes within its deadline or follows bounded transport recovery.",
|
|
1121
|
+
safetyFacts: ["bounded_provider_execution"]
|
|
1122
|
+
},
|
|
1123
|
+
verification: {
|
|
1124
|
+
kind: "local_black_box",
|
|
1125
|
+
target: "agent-heavy-gateway-load-e2e"
|
|
1126
|
+
}
|
|
1127
|
+
},
|
|
1128
|
+
{
|
|
1129
|
+
id: "receipt_claim_query_hold_once_ms",
|
|
1130
|
+
description: "Hold one physical receipt-claim query.",
|
|
1131
|
+
topologies: LOCAL_AND_PREVIEW_TOPOLOGIES,
|
|
1132
|
+
control: {
|
|
1133
|
+
kind: "runtime_test_fault",
|
|
1134
|
+
defaultValue: 500,
|
|
1135
|
+
valueMeaning: "milliseconds"
|
|
1136
|
+
},
|
|
1137
|
+
expected: {
|
|
1138
|
+
outcome: "The checked-out claim either completes or times out through bounded recovery; an ambiguous outcome may be retried within its budget.",
|
|
1139
|
+
safetyFacts: ["bounded_provider_execution"]
|
|
1140
|
+
},
|
|
1141
|
+
verification: {
|
|
1142
|
+
kind: "local_black_box",
|
|
1143
|
+
target: "receipt-claim-deadline-recovery-e2e"
|
|
1144
|
+
}
|
|
1145
|
+
},
|
|
1146
|
+
{
|
|
1147
|
+
id: "receipt_claim_response_timeout",
|
|
1148
|
+
description: "Report one fully received receipt-claim response as timed out.",
|
|
1149
|
+
topologies: LOCAL_AND_PREVIEW_TOPOLOGIES,
|
|
1150
|
+
control: {
|
|
1151
|
+
kind: "runtime_test_fault",
|
|
1152
|
+
defaultValue: 1,
|
|
1153
|
+
valueMeaning: "occurrence"
|
|
1154
|
+
},
|
|
1155
|
+
expected: {
|
|
1156
|
+
outcome: "The same logical run completes by replaying the committed receipt response or uses bounded recovery if that response is unavailable.",
|
|
1157
|
+
safetyFacts: ["same_logical_run", "bounded_provider_execution"]
|
|
1158
|
+
},
|
|
1159
|
+
verification: {
|
|
1160
|
+
kind: "local_black_box",
|
|
1161
|
+
target: "receipt-ambiguous-response-recovery-e2e"
|
|
1162
|
+
}
|
|
1163
|
+
},
|
|
1164
|
+
{
|
|
1165
|
+
id: "modal_sandbox_create_resource_exhausted",
|
|
1166
|
+
description: "Make Modal sandbox creation return RESOURCE_EXHAUSTED before user code.",
|
|
1167
|
+
topologies: MODAL_PREVIEW_TOPOLOGY,
|
|
1168
|
+
control: {
|
|
1169
|
+
kind: "runtime_test_fault",
|
|
1170
|
+
defaultValue: 1,
|
|
1171
|
+
valueMeaning: "occurrence"
|
|
1172
|
+
},
|
|
1173
|
+
expected: {
|
|
1174
|
+
outcome: "The same logical run enters bounded pre-code defer/recovery and later retries sandbox startup; no user code or provider call precedes the retry.",
|
|
1175
|
+
safetyFacts: [
|
|
1176
|
+
"same_logical_run",
|
|
1177
|
+
"no_user_code_before_recovery",
|
|
1178
|
+
"bounded_provider_execution"
|
|
1179
|
+
]
|
|
1180
|
+
},
|
|
1181
|
+
verification: {
|
|
1182
|
+
kind: "preview_black_box",
|
|
1183
|
+
target: "modal-sandbox-recovery-e2e"
|
|
1184
|
+
}
|
|
1185
|
+
},
|
|
1186
|
+
{
|
|
1187
|
+
id: "runtime_sheet_page_tail_hold_ms",
|
|
1188
|
+
description: "Hold one runtime-sheet tail-page operation.",
|
|
1189
|
+
topologies: LOCAL_TOPOLOGY,
|
|
1190
|
+
control: {
|
|
1191
|
+
kind: "runtime_test_fault",
|
|
1192
|
+
defaultValue: 500,
|
|
1193
|
+
valueMeaning: "milliseconds"
|
|
1194
|
+
},
|
|
1195
|
+
expected: {
|
|
1196
|
+
outcome: "Page-tail work stays pending during the bounded hold, then completes without losing or duplicating rows.",
|
|
1197
|
+
safetyFacts: ["all_rows_settle_once"]
|
|
1198
|
+
},
|
|
1199
|
+
verification: {
|
|
1200
|
+
kind: "local_black_box",
|
|
1201
|
+
target: "page-tail-sheet-write-hold-e2e"
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
];
|
|
1205
|
+
function isRuntimeTestFaultDrill(drill) {
|
|
1206
|
+
return drill.control.kind === "runtime_test_fault" && RUNTIME_TEST_FAULT_IDS.some((faultId) => faultId === drill.id);
|
|
1207
|
+
}
|
|
1208
|
+
function runtimeTestFaultDrills() {
|
|
1209
|
+
return RUNTIME_INCIDENT_DRILL_CATALOG.filter(isRuntimeTestFaultDrill);
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
// ../play-runtime/test-runtime-seams.ts
|
|
1213
|
+
var PLAY_RUNTIME_TEST_FAULT_HEADER = "x-deepline-test-fault";
|
|
1214
|
+
var SUPPORTED_RUNTIME_TEST_FAULTS = new Set(
|
|
1215
|
+
runtimeTestFaultDrills().map(({ id }) => id)
|
|
1216
|
+
);
|
|
1217
|
+
var MAX_RUNTIME_TEST_POLICY_MS = 10 * 6e4;
|
|
1218
|
+
|
|
1219
|
+
// src/http.ts
|
|
1220
|
+
var MAX_DIAGNOSTIC_HEADER_LENGTH = 120;
|
|
1221
|
+
var COWORK_NETWORK_HINT = "Claude Cowork appears to be running Deepline in a network-restricted sandbox. In Claude Desktop, open Settings > Capabilities, turn on Allow network egress, and set Domain allowlist to All domains for the Cowork session.";
|
|
1222
|
+
var REQUEST_TIMEOUT_MARKER = Symbol("deeplineRequestTimeout");
|
|
1223
|
+
var REQUEST_ABORT_MARKER = Symbol("deeplineRequestAbort");
|
|
1224
|
+
function requestCancelledError(signal) {
|
|
1225
|
+
const error = withErrorCause(new Error("Request aborted"), signal.reason);
|
|
1226
|
+
error[REQUEST_ABORT_MARKER] = true;
|
|
1227
|
+
return error;
|
|
1228
|
+
}
|
|
1229
|
+
function normalizeRequestAbortError(error, input) {
|
|
1230
|
+
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
1231
|
+
const tagged = normalized;
|
|
1232
|
+
if (input.timedOut) {
|
|
1233
|
+
tagged[REQUEST_TIMEOUT_MARKER] = input.timeoutMs;
|
|
1234
|
+
} else if (isAbortLikeError(normalized)) {
|
|
1235
|
+
tagged[REQUEST_ABORT_MARKER] = true;
|
|
1236
|
+
}
|
|
1237
|
+
return normalized;
|
|
1238
|
+
}
|
|
1239
|
+
function applyExplicitHeaders(headers, explicit) {
|
|
1240
|
+
if (!explicit) return headers;
|
|
1241
|
+
for (const [rawName, value] of Object.entries(explicit)) {
|
|
1242
|
+
const name = rawName.trim().toLowerCase();
|
|
1243
|
+
if (!name) continue;
|
|
1244
|
+
for (const existing of Object.keys(headers)) {
|
|
1245
|
+
if (existing.toLowerCase() === name) delete headers[existing];
|
|
1246
|
+
}
|
|
1247
|
+
headers[rawName.trim()] = value;
|
|
1248
|
+
}
|
|
1249
|
+
return headers;
|
|
1250
|
+
}
|
|
1251
|
+
function isAbortLikeError(error) {
|
|
1252
|
+
const name = error.name.toLowerCase();
|
|
1253
|
+
const message = error.message.toLowerCase();
|
|
1254
|
+
return name === "aborterror" || message.includes("operation was aborted") || message === "aborted";
|
|
1255
|
+
}
|
|
1256
|
+
function withErrorCause(error, cause) {
|
|
1257
|
+
if (cause !== null && cause !== void 0) {
|
|
1258
|
+
Object.defineProperty(error, "cause", {
|
|
1259
|
+
value: cause,
|
|
1260
|
+
configurable: true,
|
|
1261
|
+
writable: true
|
|
1262
|
+
});
|
|
1263
|
+
}
|
|
1264
|
+
return error;
|
|
1265
|
+
}
|
|
1266
|
+
function mapNetworkError(baseUrl, error, targetLabel) {
|
|
1267
|
+
const tagged = error;
|
|
1268
|
+
const timeoutMs = _optionalChain([tagged, 'optionalAccess', _153 => _153[REQUEST_TIMEOUT_MARKER]]);
|
|
1269
|
+
if (typeof timeoutMs === "number") {
|
|
1270
|
+
return {
|
|
1271
|
+
message: `Request to ${targetLabel} timed out after ${timeoutMs}ms while waiting for a response.`,
|
|
1272
|
+
code: "NETWORK_TIMEOUT",
|
|
1273
|
+
details: { timeoutMs, target: targetLabel }
|
|
1274
|
+
};
|
|
1275
|
+
}
|
|
1276
|
+
if (_optionalChain([tagged, 'optionalAccess', _154 => _154[REQUEST_ABORT_MARKER]])) {
|
|
1277
|
+
return {
|
|
1278
|
+
message: `Request to ${targetLabel} was aborted before it completed.`,
|
|
1279
|
+
code: "NETWORK_ABORTED"
|
|
1280
|
+
};
|
|
1281
|
+
}
|
|
1282
|
+
return {
|
|
1283
|
+
message: _optionalChain([error, 'optionalAccess', _155 => _155.message]) ? `Unable to connect to ${baseUrl}. ${error.message}` : `Unable to connect to ${baseUrl}. Is the computer able to access the url?`,
|
|
1284
|
+
code: "NETWORK_ERROR"
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1287
|
+
function describeRequestTarget(path) {
|
|
1288
|
+
const toolExecuteMatch = path.match(
|
|
1289
|
+
/^\/api\/v2\/integrations\/([^/?#]+)\/execute(?:[/?#]|$)/
|
|
1290
|
+
);
|
|
1291
|
+
if (toolExecuteMatch) {
|
|
1292
|
+
return providerLabelFromToolId(decodeURIComponent(toolExecuteMatch[1]));
|
|
1293
|
+
}
|
|
1294
|
+
return "Deepline";
|
|
1295
|
+
}
|
|
1296
|
+
function networkDiagnosticUrl(value) {
|
|
1297
|
+
try {
|
|
1298
|
+
const url = new URL(value);
|
|
1299
|
+
if (url.protocol !== "https:" && url.protocol !== "http:") return void 0;
|
|
1300
|
+
return `${url.origin}${url.pathname}`;
|
|
1301
|
+
} catch (e15) {
|
|
1302
|
+
return void 0;
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
function providerLabelFromToolId(toolId) {
|
|
1306
|
+
const normalized = toolId.trim().toLowerCase();
|
|
1307
|
+
const provider = normalized.split(/[_:./-]+/)[0];
|
|
1308
|
+
return provider || normalized || "provider";
|
|
1309
|
+
}
|
|
1310
|
+
function isRecord(value) {
|
|
1311
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
1312
|
+
}
|
|
1313
|
+
var HttpClient = class {
|
|
1314
|
+
constructor(config) {
|
|
1315
|
+
this.config = config;
|
|
1316
|
+
}
|
|
1317
|
+
cleanDiagnosticHeader(value) {
|
|
1318
|
+
const normalized = String(_nullishCoalesce(value, () => ( ""))).replace(/[\u0000-\u001f\u007f]/g, " ").trim().slice(0, MAX_DIAGNOSTIC_HEADER_LENGTH);
|
|
1319
|
+
return normalized || null;
|
|
1320
|
+
}
|
|
1321
|
+
readSkillsVersionHeader() {
|
|
1322
|
+
const explicit = this.cleanDiagnosticHeader(
|
|
1323
|
+
process.env.DEEPLINE_SKILLS_VERSION
|
|
1324
|
+
);
|
|
1325
|
+
if (explicit) return explicit;
|
|
1326
|
+
try {
|
|
1327
|
+
return this.cleanDiagnosticHeader(
|
|
1328
|
+
readSdkSkillsLocalVersion(this.config.baseUrl)
|
|
1329
|
+
);
|
|
1330
|
+
} catch (e16) {
|
|
1331
|
+
return null;
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
authHeaders(extra) {
|
|
1335
|
+
const transportHeaders = {
|
|
1336
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
1337
|
+
"User-Agent": `deepline-ts-sdk/${SDK_VERSION}`,
|
|
1338
|
+
"X-Deepline-Client-Family": "sdk",
|
|
1339
|
+
"X-Deepline-CLI-Family": "sdk",
|
|
1340
|
+
"X-Deepline-Agent-Runtime": detectAgentRuntime(),
|
|
1341
|
+
"X-Deepline-CLI-Version": SDK_VERSION,
|
|
1342
|
+
"X-Deepline-SDK-Version": SDK_VERSION,
|
|
1343
|
+
"X-Deepline-API-Contract": SDK_API_CONTRACT,
|
|
1344
|
+
"X-Deepline-Run-Result-Shape": "canonical"
|
|
1345
|
+
};
|
|
1346
|
+
const headers = deploymentProtectionHeaders();
|
|
1347
|
+
const skillsVersion = this.readSkillsVersionHeader();
|
|
1348
|
+
if (skillsVersion) {
|
|
1349
|
+
headers["X-Deepline-Skills-Version"] = skillsVersion;
|
|
1350
|
+
}
|
|
1351
|
+
const playArtifactR2Prefix = typeof process !== "undefined" ? _optionalChain([process, 'access', _156 => _156.env, 'optionalAccess', _157 => _157.DEEPLINE_PLAY_ARTIFACT_R2_PREFIX]) : void 0;
|
|
1352
|
+
if (playArtifactR2Prefix) {
|
|
1353
|
+
headers["x-deepline-play-artifact-r2-prefix"] = playArtifactR2Prefix;
|
|
1354
|
+
}
|
|
1355
|
+
const coordinatorUrl = typeof process !== "undefined" ? _optionalChain([process, 'access', _158 => _158.env, 'optionalAccess', _159 => _159.DEEPLINE_COORDINATOR_URL]) : void 0;
|
|
1356
|
+
const coordinatorInternalToken = typeof process !== "undefined" ? _optionalChain([process, 'access', _160 => _160.env, 'optionalAccess', _161 => _161.DEEPLINE_INTERNAL_TOKEN]) : void 0;
|
|
1357
|
+
const absurdReleaseOverride = typeof process !== "undefined" ? _optionalChain([process, 'access', _162 => _162.env, 'optionalAccess', _163 => _163.DEEPLINE_ABSURD_RELEASE]) : void 0;
|
|
1358
|
+
const preferredReceiptGatewayMachineId = typeof process !== "undefined" ? _optionalChain([process, 'access', _164 => _164.env, 'optionalAccess', _165 => _165.DEEPLINE_PREFERRED_RECEIPT_GATEWAY_MACHINE_ID]) : void 0;
|
|
1359
|
+
if (_optionalChain([coordinatorUrl, 'optionalAccess', _166 => _166.trim, 'call', _167 => _167()])) {
|
|
1360
|
+
headers[COORDINATOR_URL_OVERRIDE_HEADER] = coordinatorUrl.trim();
|
|
1361
|
+
}
|
|
1362
|
+
const workerCallbackUrl = typeof process !== "undefined" ? _optionalChain([process, 'access', _168 => _168.env, 'optionalAccess', _169 => _169.DEEPLINE_WORKER_CALLBACK_URL]) : void 0;
|
|
1363
|
+
if (_optionalChain([workerCallbackUrl, 'optionalAccess', _170 => _170.trim, 'call', _171 => _171()])) {
|
|
1364
|
+
headers[WORKER_CALLBACK_URL_OVERRIDE_HEADER] = workerCallbackUrl.trim();
|
|
1365
|
+
}
|
|
1366
|
+
const runtimeSchedulerSchema = typeof process !== "undefined" ? _optionalChain([process, 'access', _172 => _172.env, 'optionalAccess', _173 => _173.DEEPLINE_RUNTIME_SCHEDULER_SCHEMA]) : void 0;
|
|
1367
|
+
if (_optionalChain([runtimeSchedulerSchema, 'optionalAccess', _174 => _174.trim, 'call', _175 => _175()])) {
|
|
1368
|
+
headers[RUNTIME_SCHEDULER_SCHEMA_OVERRIDE_HEADER] = runtimeSchedulerSchema.trim();
|
|
1369
|
+
}
|
|
1370
|
+
const syntheticRun = typeof process !== "undefined" ? _optionalChain([process, 'access', _176 => _176.env, 'optionalAccess', _177 => _177.DEEPLINE_SYNTHETIC_RUN]) : void 0;
|
|
1371
|
+
if (syntheticRun && syntheticRun.trim() && syntheticRun.trim() !== "0") {
|
|
1372
|
+
headers[SYNTHETIC_RUN_HEADER] = "1";
|
|
1373
|
+
}
|
|
1374
|
+
const runtimeTestFault = typeof process !== "undefined" ? _optionalChain([process, 'access', _178 => _178.env, 'optionalAccess', _179 => _179.DEEPLINE_TEST_RUNTIME_FAULT]) : void 0;
|
|
1375
|
+
if (_optionalChain([runtimeTestFault, 'optionalAccess', _180 => _180.trim, 'call', _181 => _181()])) {
|
|
1376
|
+
headers[PLAY_RUNTIME_TEST_FAULT_HEADER] = runtimeTestFault.trim();
|
|
1377
|
+
}
|
|
1378
|
+
const retainedReceivers = typeof process !== "undefined" ? _optionalChain([process, 'access', _182 => _182.env, 'optionalAccess', _183 => _183.DEEPLINE_RUNTIME_RETAINED_PIPELINE_RECEIVERS, 'optionalAccess', _184 => _184.trim, 'call', _185 => _185()]) : void 0;
|
|
1379
|
+
if (retainedReceivers && _optionalChain([coordinatorInternalToken, 'optionalAccess', _186 => _186.trim, 'call', _187 => _187()])) {
|
|
1380
|
+
headers[RETAINED_PIPELINE_RECEIVERS_HEADER] = retainedReceivers;
|
|
1381
|
+
headers[COORDINATOR_INTERNAL_TOKEN_HEADER] = coordinatorInternalToken.trim();
|
|
1382
|
+
}
|
|
1383
|
+
if (_optionalChain([absurdReleaseOverride, 'optionalAccess', _188 => _188.trim, 'call', _189 => _189()]) && _optionalChain([coordinatorInternalToken, 'optionalAccess', _190 => _190.trim, 'call', _191 => _191()])) {
|
|
1384
|
+
headers[ABSURD_RELEASE_OVERRIDE_HEADER] = absurdReleaseOverride.trim();
|
|
1385
|
+
}
|
|
1386
|
+
if (_optionalChain([preferredReceiptGatewayMachineId, 'optionalAccess', _192 => _192.trim, 'call', _193 => _193()]) && _optionalChain([coordinatorInternalToken, 'optionalAccess', _194 => _194.trim, 'call', _195 => _195()])) {
|
|
1387
|
+
headers[PREFERRED_RECEIPT_GATEWAY_MACHINE_ID_HEADER] = preferredReceiptGatewayMachineId.trim();
|
|
1388
|
+
}
|
|
1389
|
+
if (_optionalChain([coordinatorInternalToken, 'optionalAccess', _196 => _196.trim, 'call', _197 => _197()]) && (_optionalChain([coordinatorUrl, 'optionalAccess', _198 => _198.trim, 'call', _199 => _199()]) || _optionalChain([workerCallbackUrl, 'optionalAccess', _200 => _200.trim, 'call', _201 => _201()]) || _optionalChain([runtimeTestFault, 'optionalAccess', _202 => _202.trim, 'call', _203 => _203()]) || _optionalChain([absurdReleaseOverride, 'optionalAccess', _204 => _204.trim, 'call', _205 => _205()]) || _optionalChain([preferredReceiptGatewayMachineId, 'optionalAccess', _206 => _206.trim, 'call', _207 => _207()]))) {
|
|
1390
|
+
headers[COORDINATOR_INTERNAL_TOKEN_HEADER] = coordinatorInternalToken.trim();
|
|
1391
|
+
}
|
|
1392
|
+
return applyExplicitHeaders(
|
|
1393
|
+
applyExplicitHeaders(
|
|
1394
|
+
applyExplicitHeaders(transportHeaders, extra),
|
|
1395
|
+
headers
|
|
1396
|
+
),
|
|
1397
|
+
this.config.headers
|
|
1398
|
+
);
|
|
1399
|
+
}
|
|
1400
|
+
/**
|
|
1401
|
+
* Send an HTTP request with automatic retries and error handling.
|
|
1402
|
+
*
|
|
1403
|
+
* @typeParam T - Expected response body type
|
|
1404
|
+
* @param path - API path (e.g. `"/api/v2/tools"`)
|
|
1405
|
+
* @param options - HTTP method, body, headers, and timeout
|
|
1406
|
+
* @returns Parsed JSON response body
|
|
1407
|
+
* @throws {@link AuthError} on Deepline-auth HTTP 401/403 (immediate, no retry)
|
|
1408
|
+
* @throws {@link RateLimitError} on HTTP 429 after all retries exhausted
|
|
1409
|
+
* @throws {@link DeeplineError} on other API errors or connection failures
|
|
1410
|
+
*/
|
|
1411
|
+
async request(path, options) {
|
|
1412
|
+
const baseUrl = this.config.baseUrl;
|
|
1413
|
+
const url = `${baseUrl}${path}`;
|
|
1414
|
+
const method = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _208 => _208.method]), () => ( "GET"));
|
|
1415
|
+
const requestStartedAt = Date.now();
|
|
1416
|
+
let fetchAttempts = 0;
|
|
1417
|
+
let lastRequestUrl = url;
|
|
1418
|
+
let networkFailedAt;
|
|
1419
|
+
let networkPhase = "before_request";
|
|
1420
|
+
const headers = this.authHeaders(_optionalChain([options, 'optionalAccess', _209 => _209.headers]));
|
|
1421
|
+
if (_optionalChain([options, 'optionalAccess', _210 => _210.body]) !== void 0) {
|
|
1422
|
+
applyExplicitHeaders(headers, { "Content-Type": "application/json" });
|
|
1423
|
+
}
|
|
1424
|
+
let lastError = null;
|
|
1425
|
+
const candidateUrls = _optionalChain([options, 'optionalAccess', _211 => _211.exactUrlOnly]) ? [url] : buildCandidateUrls(url);
|
|
1426
|
+
let retryAfterDelayMs = null;
|
|
1427
|
+
const maxRetries = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _212 => _212.maxRetries]), () => ( this.config.maxRetries));
|
|
1428
|
+
requestAttempts: for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
1429
|
+
if (_optionalChain([options, 'optionalAccess', _213 => _213.signal, 'optionalAccess', _214 => _214.aborted])) {
|
|
1430
|
+
lastError = requestCancelledError(options.signal);
|
|
1431
|
+
networkFailedAt = Date.now();
|
|
1432
|
+
break;
|
|
1433
|
+
}
|
|
1434
|
+
if (attempt > 0) {
|
|
1435
|
+
const backoffMs = Math.min(1e3 * Math.pow(2, attempt - 1), 3e4);
|
|
1436
|
+
const delayMs = retryAfterDelayMs === null ? backoffMs : Math.max(backoffMs, retryAfterDelayMs);
|
|
1437
|
+
retryAfterDelayMs = null;
|
|
1438
|
+
networkPhase = "retry_wait";
|
|
1439
|
+
try {
|
|
1440
|
+
await sleep(delayMs, _optionalChain([options, 'optionalAccess', _215 => _215.signal]));
|
|
1441
|
+
} catch (error) {
|
|
1442
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
1443
|
+
networkFailedAt = Date.now();
|
|
1444
|
+
break;
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
for (const candidateUrl of candidateUrls) {
|
|
1448
|
+
if (_optionalChain([options, 'optionalAccess', _216 => _216.signal, 'optionalAccess', _217 => _217.aborted])) {
|
|
1449
|
+
lastError = requestCancelledError(options.signal);
|
|
1450
|
+
networkFailedAt = Date.now();
|
|
1451
|
+
break requestAttempts;
|
|
1452
|
+
}
|
|
1453
|
+
const controller = new AbortController();
|
|
1454
|
+
const timeoutMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _218 => _218.timeout]), () => ( this.config.timeout));
|
|
1455
|
+
let requestTimedOut = false;
|
|
1456
|
+
const timeoutId = setTimeout(() => {
|
|
1457
|
+
requestTimedOut = true;
|
|
1458
|
+
controller.abort();
|
|
1459
|
+
}, timeoutMs);
|
|
1460
|
+
const abortRequest = () => controller.abort();
|
|
1461
|
+
_optionalChain([options, 'optionalAccess', _219 => _219.signal, 'optionalAccess', _220 => _220.addEventListener, 'call', _221 => _221("abort", abortRequest, {
|
|
1462
|
+
once: true
|
|
1463
|
+
})]);
|
|
1464
|
+
networkPhase = "before_request";
|
|
1465
|
+
try {
|
|
1466
|
+
const requestBody = _optionalChain([options, 'optionalAccess', _222 => _222.formData]) !== void 0 ? typeof options.formData === "function" ? options.formData() : options.formData : _optionalChain([options, 'optionalAccess', _223 => _223.body]) !== void 0 ? JSON.stringify(options.body) : void 0;
|
|
1467
|
+
fetchAttempts += 1;
|
|
1468
|
+
lastRequestUrl = candidateUrl;
|
|
1469
|
+
networkPhase = "awaiting_headers";
|
|
1470
|
+
const response = await fetch(candidateUrl, {
|
|
1471
|
+
method,
|
|
1472
|
+
headers,
|
|
1473
|
+
body: requestBody,
|
|
1474
|
+
signal: controller.signal
|
|
1475
|
+
});
|
|
1476
|
+
networkPhase = "reading_body";
|
|
1477
|
+
_optionalChain([options, 'optionalAccess', _224 => _224.onResponse, 'optionalCall', _225 => _225(response)]);
|
|
1478
|
+
if (response.status === 404 && _optionalChain([options, 'optionalAccess', _226 => _226.allowNotFound])) {
|
|
1479
|
+
clearTimeout(timeoutId);
|
|
1480
|
+
return null;
|
|
1481
|
+
}
|
|
1482
|
+
const body = await response.text();
|
|
1483
|
+
clearTimeout(timeoutId);
|
|
1484
|
+
const parsed = parseResponseBody(body);
|
|
1485
|
+
const structuredToolError = _optionalChain([options, 'optionalAccess', _227 => _227.toolId]) && !response.ok ? _chunk7P5AA3SNjs.deserializeToolExecutionFailure.call(void 0,
|
|
1486
|
+
_chunkXNYIZMNQjs.apiErrorMessage.call(void 0, parsed, response.status),
|
|
1487
|
+
isRecord(parsed) ? parsed.tool_error : null,
|
|
1488
|
+
_chunk7P5AA3SNjs.TOOL_EXECUTION_ERROR_SCHEMA_VERSION
|
|
1489
|
+
) : null;
|
|
1490
|
+
if (structuredToolError) {
|
|
1491
|
+
if (response.status === 429) {
|
|
1492
|
+
const retryAfter = parseRetryAfter(response);
|
|
1493
|
+
const failure = _chunk7P5AA3SNjs.serializeToolExecutionFailure.call(void 0, structuredToolError);
|
|
1494
|
+
lastError = failure === null ? structuredToolError : new ToolRateLimitError(structuredToolError.message, {
|
|
1495
|
+
...failure,
|
|
1496
|
+
retryAfterMs: _nullishCoalesce(failure.retryAfterMs, () => ( Math.max(0, retryAfter)))
|
|
1497
|
+
});
|
|
1498
|
+
if (attempt < maxRetries) {
|
|
1499
|
+
retryAfterDelayMs = retryAfter;
|
|
1500
|
+
break;
|
|
1501
|
+
}
|
|
1502
|
+
throw lastError;
|
|
1503
|
+
}
|
|
1504
|
+
throw structuredToolError;
|
|
1505
|
+
}
|
|
1506
|
+
if (response.status === 429) {
|
|
1507
|
+
if (_optionalChain([options, 'optionalAccess', _228 => _228.preserveRateLimitResponse]) && isMonitorRateLimitEnvelope(parsed)) {
|
|
1508
|
+
throw new (0, _chunk7P5AA3SNjs.DeeplineError)(
|
|
1509
|
+
_chunkXNYIZMNQjs.apiErrorMessage.call(void 0, parsed, response.status),
|
|
1510
|
+
response.status,
|
|
1511
|
+
_chunkXNYIZMNQjs.apiErrorCodeFromResponse.call(void 0, parsed),
|
|
1512
|
+
{ response: parsed }
|
|
1513
|
+
);
|
|
1514
|
+
}
|
|
1515
|
+
const retryAfter = parseRetryAfter(response);
|
|
1516
|
+
lastError = new RateLimitError(retryAfter);
|
|
1517
|
+
if (attempt < maxRetries) {
|
|
1518
|
+
retryAfterDelayMs = retryAfter;
|
|
1519
|
+
break;
|
|
1520
|
+
}
|
|
1521
|
+
throw lastError;
|
|
1522
|
+
}
|
|
1523
|
+
if (response.status === 401 && !isProviderOriginatedHttpError(parsed)) {
|
|
1524
|
+
throw new AuthError(_chunkXNYIZMNQjs.apiErrorMessage.call(void 0, parsed, response.status));
|
|
1525
|
+
}
|
|
1526
|
+
if (!response.ok) {
|
|
1527
|
+
const retryableApiError = _optionalChain([options, 'optionalAccess', _229 => _229.retryApiErrors]) === true && isRetryableApiErrorResponse(response.status);
|
|
1528
|
+
const htmlError = detectHtmlErrorBody(
|
|
1529
|
+
body,
|
|
1530
|
+
response.headers.get("content-type")
|
|
1531
|
+
);
|
|
1532
|
+
if (htmlError) {
|
|
1533
|
+
lastError = new (0, _chunk7P5AA3SNjs.DeeplineError)(
|
|
1534
|
+
htmlError.message(response.status),
|
|
1535
|
+
response.status,
|
|
1536
|
+
"API_ERROR",
|
|
1537
|
+
{
|
|
1538
|
+
htmlErrorPage: true,
|
|
1539
|
+
...htmlError.title ? { title: htmlError.title } : {},
|
|
1540
|
+
...htmlError.workerThrewException ? { workerThrewException: true } : {}
|
|
1541
|
+
}
|
|
1542
|
+
);
|
|
1543
|
+
if (retryableApiError && attempt < maxRetries) {
|
|
1544
|
+
retryAfterDelayMs = parseOptionalRetryAfter(response);
|
|
1545
|
+
break;
|
|
1546
|
+
}
|
|
1547
|
+
throw lastError;
|
|
1548
|
+
}
|
|
1549
|
+
const errorValue = typeof parsed === "object" && parsed && "error" in parsed ? parsed.error : void 0;
|
|
1550
|
+
const msg = typeof errorValue === "string" ? errorValue : errorValue && typeof errorValue === "object" && "message" in errorValue && typeof errorValue.message === "string" ? errorValue.message : typeof parsed === "object" && parsed && "message" in parsed && typeof parsed.message === "string" ? parsed.message : `HTTP ${response.status}`;
|
|
1551
|
+
const apiErrorCode = _chunkXNYIZMNQjs.apiErrorCodeFromResponse.call(void 0, parsed);
|
|
1552
|
+
lastError = new (0, _chunk7P5AA3SNjs.DeeplineError)(msg, response.status, apiErrorCode, {
|
|
1553
|
+
response: parsed
|
|
1554
|
+
});
|
|
1555
|
+
if (retryableApiError && attempt < maxRetries) {
|
|
1556
|
+
retryAfterDelayMs = parseOptionalRetryAfter(response);
|
|
1557
|
+
break;
|
|
1558
|
+
}
|
|
1559
|
+
throw lastError;
|
|
1560
|
+
}
|
|
1561
|
+
if (typeof parsed === "string") {
|
|
1562
|
+
const interstitial = detectHtmlErrorBody(
|
|
1563
|
+
body,
|
|
1564
|
+
response.headers.get("content-type")
|
|
1565
|
+
);
|
|
1566
|
+
if (interstitial) {
|
|
1567
|
+
throw new (0, _chunk7P5AA3SNjs.DeeplineError)(
|
|
1568
|
+
`${this.config.baseUrl} returned a deployment-protection page instead of JSON. Set VERCEL_PROTECTION_BYPASS_TOKEN, or run \`vercel login\` if the CLI session expired.`,
|
|
1569
|
+
response.status,
|
|
1570
|
+
"DEPLOYMENT_PROTECTED",
|
|
1571
|
+
{ htmlErrorPage: true }
|
|
1572
|
+
);
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
return parsed;
|
|
1576
|
+
} catch (error) {
|
|
1577
|
+
clearTimeout(timeoutId);
|
|
1578
|
+
networkFailedAt = Date.now();
|
|
1579
|
+
if (_optionalChain([options, 'optionalAccess', _230 => _230.signal, 'optionalAccess', _231 => _231.aborted])) {
|
|
1580
|
+
lastError = requestCancelledError(options.signal);
|
|
1581
|
+
break requestAttempts;
|
|
1582
|
+
}
|
|
1583
|
+
if (error instanceof AuthError || error instanceof _chunk7P5AA3SNjs.DeeplineError) {
|
|
1584
|
+
throw error;
|
|
1585
|
+
}
|
|
1586
|
+
if (error instanceof RateLimitError) {
|
|
1587
|
+
lastError = error;
|
|
1588
|
+
break;
|
|
1589
|
+
}
|
|
1590
|
+
lastError = normalizeRequestAbortError(error, {
|
|
1591
|
+
timeoutMs,
|
|
1592
|
+
timedOut: requestTimedOut
|
|
1593
|
+
});
|
|
1594
|
+
} finally {
|
|
1595
|
+
clearTimeout(timeoutId);
|
|
1596
|
+
_optionalChain([options, 'optionalAccess', _232 => _232.signal, 'optionalAccess', _233 => _233.removeEventListener, 'call', _234 => _234("abort", abortRequest)]);
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
if (attempt < maxRetries) continue;
|
|
1600
|
+
}
|
|
1601
|
+
if (lastError instanceof _chunk7P5AA3SNjs.DeeplineError) {
|
|
1602
|
+
throw lastError;
|
|
1603
|
+
}
|
|
1604
|
+
const mappedNetworkError = mapNetworkError(
|
|
1605
|
+
baseUrl,
|
|
1606
|
+
lastError,
|
|
1607
|
+
describeRequestTarget(path)
|
|
1608
|
+
);
|
|
1609
|
+
const failedAt = _nullishCoalesce(networkFailedAt, () => ( Date.now()));
|
|
1610
|
+
const diagnosticUrl = networkDiagnosticUrl(lastRequestUrl);
|
|
1611
|
+
const networkDetails = {
|
|
1612
|
+
...mappedNetworkError.details,
|
|
1613
|
+
request: {
|
|
1614
|
+
method,
|
|
1615
|
+
...diagnosticUrl === void 0 ? {} : { url: diagnosticUrl },
|
|
1616
|
+
failedAtUtc: new Date(failedAt).toISOString(),
|
|
1617
|
+
// Elapsed time covers the entire logical request, including retries.
|
|
1618
|
+
elapsedMs: Math.max(0, failedAt - requestStartedAt),
|
|
1619
|
+
attempts: fetchAttempts,
|
|
1620
|
+
phase: networkPhase
|
|
1621
|
+
}
|
|
1622
|
+
};
|
|
1623
|
+
if (_optionalChain([options, 'optionalAccess', _235 => _235.toolId])) {
|
|
1624
|
+
const code = mappedNetworkError.code;
|
|
1625
|
+
throw withErrorCause(
|
|
1626
|
+
new (0, _chunk7P5AA3SNjs.ToolExecutionError)(
|
|
1627
|
+
withCoworkNetworkHint(mappedNetworkError.message),
|
|
1628
|
+
{
|
|
1629
|
+
toolId: options.toolId,
|
|
1630
|
+
provider: providerLabelFromToolId(options.toolId),
|
|
1631
|
+
operation: options.toolId,
|
|
1632
|
+
code,
|
|
1633
|
+
origin: "deepline",
|
|
1634
|
+
category: "network",
|
|
1635
|
+
// A direct client timeout has ambiguous delivery. Fail closed unless
|
|
1636
|
+
// the server returns the authoritative action delivery contract.
|
|
1637
|
+
retryable: false,
|
|
1638
|
+
statusCode: null,
|
|
1639
|
+
requestId: null,
|
|
1640
|
+
retryAfterMs: null,
|
|
1641
|
+
networkKind: code === "NETWORK_TIMEOUT" ? "timeout" : code === "NETWORK_ABORTED" ? "unknown" : "unavailable",
|
|
1642
|
+
networkScope: "client_to_deepline",
|
|
1643
|
+
details: networkDetails,
|
|
1644
|
+
publicDetails: options.idempotencyKey ? { idempotencyKey: options.idempotencyKey } : null
|
|
1645
|
+
}
|
|
1646
|
+
),
|
|
1647
|
+
lastError
|
|
1648
|
+
);
|
|
1649
|
+
}
|
|
1650
|
+
throw withErrorCause(
|
|
1651
|
+
new (0, _chunk7P5AA3SNjs.DeeplineError)(
|
|
1652
|
+
withCoworkNetworkHint(mappedNetworkError.message),
|
|
1653
|
+
void 0,
|
|
1654
|
+
mappedNetworkError.code,
|
|
1655
|
+
networkDetails
|
|
1656
|
+
),
|
|
1657
|
+
lastError
|
|
1658
|
+
);
|
|
1659
|
+
}
|
|
1660
|
+
/**
|
|
1661
|
+
* Send a GET request.
|
|
1662
|
+
*
|
|
1663
|
+
* @typeParam T - Expected response body type
|
|
1664
|
+
* @param path - API path (e.g. `"/api/v2/tools"`)
|
|
1665
|
+
*/
|
|
1666
|
+
async get(path, options) {
|
|
1667
|
+
return this.request(path, {
|
|
1668
|
+
method: "GET",
|
|
1669
|
+
retryApiErrors: true,
|
|
1670
|
+
...options
|
|
1671
|
+
});
|
|
1672
|
+
}
|
|
1673
|
+
async *streamSse(path, options) {
|
|
1674
|
+
const url = `${this.config.baseUrl}${path}`;
|
|
1675
|
+
const method = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _236 => _236.method]), () => ( "GET"));
|
|
1676
|
+
const headers = this.authHeaders({
|
|
1677
|
+
Accept: "text/event-stream",
|
|
1678
|
+
..._optionalChain([options, 'optionalAccess', _237 => _237.headers])
|
|
1679
|
+
});
|
|
1680
|
+
if (_optionalChain([options, 'optionalAccess', _238 => _238.body]) !== void 0) {
|
|
1681
|
+
applyExplicitHeaders(headers, { "Content-Type": "application/json" });
|
|
1682
|
+
}
|
|
1683
|
+
let lastError = null;
|
|
1684
|
+
for (const candidateUrl of buildCandidateUrls(url)) {
|
|
1685
|
+
try {
|
|
1686
|
+
const response = await fetch(candidateUrl, {
|
|
1687
|
+
method,
|
|
1688
|
+
headers,
|
|
1689
|
+
body: _optionalChain([options, 'optionalAccess', _239 => _239.body]) !== void 0 ? JSON.stringify(options.body) : void 0,
|
|
1690
|
+
signal: _optionalChain([options, 'optionalAccess', _240 => _240.signal])
|
|
1691
|
+
});
|
|
1692
|
+
if (!response.ok) {
|
|
1693
|
+
const body = await response.text();
|
|
1694
|
+
const parsed = parseResponseBody(body);
|
|
1695
|
+
if (response.status === 401 && !isProviderOriginatedHttpError(parsed)) {
|
|
1696
|
+
throw new AuthError(_chunkXNYIZMNQjs.apiErrorMessage.call(void 0, parsed, response.status));
|
|
1697
|
+
}
|
|
1698
|
+
const htmlError = detectHtmlErrorBody(
|
|
1699
|
+
body,
|
|
1700
|
+
response.headers.get("content-type")
|
|
1701
|
+
);
|
|
1702
|
+
if (htmlError) {
|
|
1703
|
+
throw new (0, _chunk7P5AA3SNjs.DeeplineError)(
|
|
1704
|
+
htmlError.message(response.status),
|
|
1705
|
+
response.status,
|
|
1706
|
+
"API_ERROR",
|
|
1707
|
+
{
|
|
1708
|
+
htmlErrorPage: true,
|
|
1709
|
+
...htmlError.title ? { title: htmlError.title } : {},
|
|
1710
|
+
...htmlError.workerThrewException ? { workerThrewException: true } : {}
|
|
1711
|
+
}
|
|
1712
|
+
);
|
|
1713
|
+
}
|
|
1714
|
+
throw new (0, _chunk7P5AA3SNjs.DeeplineError)(
|
|
1715
|
+
_chunkXNYIZMNQjs.apiErrorMessage.call(void 0, parsed, response.status),
|
|
1716
|
+
response.status,
|
|
1717
|
+
_chunkXNYIZMNQjs.apiErrorCodeFromResponse.call(void 0, parsed),
|
|
1718
|
+
{ response: parsed }
|
|
1719
|
+
);
|
|
1720
|
+
}
|
|
1721
|
+
if (!response.body) {
|
|
1722
|
+
throw new (0, _chunk7P5AA3SNjs.DeeplineError)("SSE response did not include a body.");
|
|
1723
|
+
}
|
|
1724
|
+
yield* decodeSseStream(response.body);
|
|
1725
|
+
return;
|
|
1726
|
+
} catch (error) {
|
|
1727
|
+
if (error instanceof AuthError || error instanceof _chunk7P5AA3SNjs.DeeplineError) {
|
|
1728
|
+
throw error;
|
|
1729
|
+
}
|
|
1730
|
+
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
1731
|
+
if (isAbortLikeError(normalized) && _optionalChain([options, 'optionalAccess', _241 => _241.signal, 'optionalAccess', _242 => _242.aborted])) {
|
|
1732
|
+
throw new (0, _chunk7P5AA3SNjs.DeeplineError)(
|
|
1733
|
+
`Stream from ${this.config.baseUrl} was aborted by the caller.`,
|
|
1734
|
+
void 0,
|
|
1735
|
+
"ABORTED"
|
|
1736
|
+
);
|
|
1737
|
+
}
|
|
1738
|
+
lastError = normalized;
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
if (lastError && isAbortLikeError(lastError)) {
|
|
1742
|
+
throw new (0, _chunk7P5AA3SNjs.DeeplineError)(
|
|
1743
|
+
withCoworkNetworkHint(
|
|
1744
|
+
`Unable to stream from ${this.config.baseUrl}. The remote stream was interrupted.`
|
|
1745
|
+
),
|
|
1746
|
+
void 0,
|
|
1747
|
+
"PLAY_STREAM_NETWORK_ABORTED"
|
|
1748
|
+
);
|
|
1749
|
+
}
|
|
1750
|
+
throw new (0, _chunk7P5AA3SNjs.DeeplineError)(
|
|
1751
|
+
withCoworkNetworkHint(
|
|
1752
|
+
_optionalChain([lastError, 'optionalAccess', _243 => _243.message]) ? `Unable to stream from ${this.config.baseUrl}. ${lastError.message}` : `Unable to stream from ${this.config.baseUrl}.`
|
|
1753
|
+
)
|
|
1754
|
+
);
|
|
1755
|
+
}
|
|
1756
|
+
/**
|
|
1757
|
+
* Send a POST request with a JSON body.
|
|
1758
|
+
*
|
|
1759
|
+
* @typeParam T - Expected response body type
|
|
1760
|
+
* @param path - API path
|
|
1761
|
+
* @param body - Request body (will be JSON-serialized)
|
|
1762
|
+
*/
|
|
1763
|
+
async post(path, body, headers, options) {
|
|
1764
|
+
return this.request(path, {
|
|
1765
|
+
method: "POST",
|
|
1766
|
+
body,
|
|
1767
|
+
headers,
|
|
1768
|
+
...options
|
|
1769
|
+
});
|
|
1770
|
+
}
|
|
1771
|
+
async postFormData(path, formData, headers) {
|
|
1772
|
+
return this.request(path, {
|
|
1773
|
+
method: "POST",
|
|
1774
|
+
formData,
|
|
1775
|
+
headers
|
|
1776
|
+
});
|
|
1777
|
+
}
|
|
1778
|
+
/**
|
|
1779
|
+
* Send a PATCH request with a JSON body.
|
|
1780
|
+
*
|
|
1781
|
+
* @typeParam T - Expected response body type
|
|
1782
|
+
* @param path - API path
|
|
1783
|
+
* @param body - JSON-serializable request body
|
|
1784
|
+
*/
|
|
1785
|
+
async patch(path, body, headers) {
|
|
1786
|
+
return this.request(path, {
|
|
1787
|
+
method: "PATCH",
|
|
1788
|
+
body,
|
|
1789
|
+
headers
|
|
1790
|
+
});
|
|
1791
|
+
}
|
|
1792
|
+
async put(path, body, headers) {
|
|
1793
|
+
return this.request(path, { method: "PUT", body, headers });
|
|
1794
|
+
}
|
|
1795
|
+
/**
|
|
1796
|
+
* Send a DELETE request.
|
|
1797
|
+
*
|
|
1798
|
+
* @typeParam T - Expected response body type
|
|
1799
|
+
* @param path - API path
|
|
1800
|
+
*/
|
|
1801
|
+
async delete(path) {
|
|
1802
|
+
return this.request(path, { method: "DELETE" });
|
|
1803
|
+
}
|
|
1804
|
+
};
|
|
1805
|
+
function parseResponseBody(body) {
|
|
1806
|
+
try {
|
|
1807
|
+
return JSON.parse(body);
|
|
1808
|
+
} catch (e17) {
|
|
1809
|
+
return body;
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
function isProviderOriginatedHttpError(parsed) {
|
|
1813
|
+
const response = asRecord(parsed);
|
|
1814
|
+
const error = asRecord(_optionalChain([response, 'optionalAccess', _244 => _244.error]));
|
|
1815
|
+
const failureOrigin = _nullishCoalesce(_optionalChain([error, 'optionalAccess', _245 => _245.failure_origin]), () => ( _optionalChain([response, 'optionalAccess', _246 => _246.failure_origin])));
|
|
1816
|
+
const code = _nullishCoalesce(_optionalChain([error, 'optionalAccess', _247 => _247.code]), () => ( _optionalChain([response, 'optionalAccess', _248 => _248.code])));
|
|
1817
|
+
return failureOrigin === "provider" || code === "UPSTREAM_BLOCKED";
|
|
1818
|
+
}
|
|
1819
|
+
function isMonitorRateLimitEnvelope(parsed) {
|
|
1820
|
+
const response = asRecord(parsed);
|
|
1821
|
+
const error = asRecord(_optionalChain([response, 'optionalAccess', _249 => _249.error]));
|
|
1822
|
+
return _optionalChain([error, 'optionalAccess', _250 => _250.code]) === "monitor_upstream_rate_limited" && typeof error.message === "string";
|
|
1823
|
+
}
|
|
1824
|
+
function asRecord(value) {
|
|
1825
|
+
return typeof value === "object" && value !== null ? value : null;
|
|
1826
|
+
}
|
|
1827
|
+
function isRetryableApiErrorResponse(status) {
|
|
1828
|
+
return status === 408 || status === 425 || status >= 500 && status < 600;
|
|
1829
|
+
}
|
|
1830
|
+
function detectHtmlErrorBody(body, contentType) {
|
|
1831
|
+
const trimmed = body.trim();
|
|
1832
|
+
const lower = trimmed.toLowerCase();
|
|
1833
|
+
const isHtml = (_nullishCoalesce(contentType, () => ( ""))).toLowerCase().includes("text/html") || lower.startsWith("<!doctype") || lower.startsWith("<html");
|
|
1834
|
+
if (!isHtml) {
|
|
1835
|
+
return null;
|
|
1836
|
+
}
|
|
1837
|
+
const titleMatch = trimmed.match(/<title[^>]*>([\s\S]*?)<\/title>/i);
|
|
1838
|
+
const title = _optionalChain([titleMatch, 'optionalAccess', _251 => _251[1], 'optionalAccess', _252 => _252.replace, 'call', _253 => _253(/\s+/g, " "), 'access', _254 => _254.trim, 'call', _255 => _255()]) || void 0;
|
|
1839
|
+
const workerThrewException = /worker threw exception/i.test(trimmed);
|
|
1840
|
+
return {
|
|
1841
|
+
title,
|
|
1842
|
+
workerThrewException,
|
|
1843
|
+
message: (status) => {
|
|
1844
|
+
const segments = [`HTTP ${status}`];
|
|
1845
|
+
if (workerThrewException) {
|
|
1846
|
+
segments.push("Worker threw exception");
|
|
1847
|
+
}
|
|
1848
|
+
if (title) {
|
|
1849
|
+
segments.push(title);
|
|
1850
|
+
}
|
|
1851
|
+
return `${segments.join(": ")} (Cloudflare HTML error page suppressed)`;
|
|
1852
|
+
}
|
|
1853
|
+
};
|
|
1854
|
+
}
|
|
1855
|
+
function parseRetryAfter(response) {
|
|
1856
|
+
return _nullishCoalesce(parseOptionalRetryAfter(response), () => ( 5e3));
|
|
1857
|
+
}
|
|
1858
|
+
function parseOptionalRetryAfter(response) {
|
|
1859
|
+
const header = response.headers.get("retry-after");
|
|
1860
|
+
if (header) {
|
|
1861
|
+
const seconds = Number(header);
|
|
1862
|
+
if (Number.isFinite(seconds) && seconds > 0) {
|
|
1863
|
+
return seconds * 1e3;
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
return null;
|
|
1867
|
+
}
|
|
1868
|
+
function buildCandidateUrls(url) {
|
|
1869
|
+
try {
|
|
1870
|
+
const parsed = new URL(url);
|
|
1871
|
+
const candidates = [url];
|
|
1872
|
+
if (parsed.hostname === "localhost") {
|
|
1873
|
+
const loopback = new URL(url);
|
|
1874
|
+
loopback.hostname = "127.0.0.1";
|
|
1875
|
+
candidates.push(loopback.toString());
|
|
1876
|
+
}
|
|
1877
|
+
return [...new Set(candidates)];
|
|
1878
|
+
} catch (e18) {
|
|
1879
|
+
return [url];
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
async function* decodeSseStream(body) {
|
|
1883
|
+
const reader = body.getReader();
|
|
1884
|
+
const decoder = new TextDecoder();
|
|
1885
|
+
let buffered = "";
|
|
1886
|
+
try {
|
|
1887
|
+
while (true) {
|
|
1888
|
+
const { value, done } = await reader.read();
|
|
1889
|
+
if (done) break;
|
|
1890
|
+
buffered += decoder.decode(value, { stream: true });
|
|
1891
|
+
const frames = buffered.split(/\r?\n\r?\n/);
|
|
1892
|
+
buffered = _nullishCoalesce(frames.pop(), () => ( ""));
|
|
1893
|
+
for (const frame of frames) {
|
|
1894
|
+
const event2 = decodeSseFrame(frame);
|
|
1895
|
+
if (event2) {
|
|
1896
|
+
yield event2;
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
buffered += decoder.decode();
|
|
1901
|
+
const event = decodeSseFrame(buffered);
|
|
1902
|
+
if (event) {
|
|
1903
|
+
yield event;
|
|
1904
|
+
}
|
|
1905
|
+
} finally {
|
|
1906
|
+
reader.releaseLock();
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
function decodeSseFrame(frame) {
|
|
1910
|
+
const data = frame.split(/\r?\n/).filter((line) => line.startsWith("data:")).map((line) => line.slice("data:".length).trimStart()).join("\n").trim();
|
|
1911
|
+
if (!data) {
|
|
1912
|
+
return null;
|
|
1913
|
+
}
|
|
1914
|
+
const parsed = JSON.parse(data);
|
|
1915
|
+
if (!parsed || typeof parsed !== "object" || typeof parsed.cursor !== "string" || typeof parsed.streamId !== "string" || typeof parsed.scope !== "string" || typeof parsed.type !== "string" || typeof parsed.at !== "string") {
|
|
1916
|
+
return null;
|
|
1917
|
+
}
|
|
1918
|
+
return parsed;
|
|
1919
|
+
}
|
|
1920
|
+
function sleep(ms, signal) {
|
|
1921
|
+
return new Promise((resolve2, reject) => {
|
|
1922
|
+
if (_optionalChain([signal, 'optionalAccess', _256 => _256.aborted])) {
|
|
1923
|
+
reject(requestCancelledError(signal));
|
|
1924
|
+
return;
|
|
1925
|
+
}
|
|
1926
|
+
const timeoutId = setTimeout(() => {
|
|
1927
|
+
_optionalChain([signal, 'optionalAccess', _257 => _257.removeEventListener, 'call', _258 => _258("abort", abort)]);
|
|
1928
|
+
resolve2();
|
|
1929
|
+
}, ms);
|
|
1930
|
+
const abort = () => {
|
|
1931
|
+
clearTimeout(timeoutId);
|
|
1932
|
+
_optionalChain([signal, 'optionalAccess', _259 => _259.removeEventListener, 'call', _260 => _260("abort", abort)]);
|
|
1933
|
+
reject(requestCancelledError(signal));
|
|
1934
|
+
};
|
|
1935
|
+
_optionalChain([signal, 'optionalAccess', _261 => _261.addEventListener, 'call', _262 => _262("abort", abort, { once: true })]);
|
|
1936
|
+
});
|
|
1937
|
+
}
|
|
1938
|
+
function withCoworkNetworkHint(message) {
|
|
1939
|
+
if (!isCoworkLikeSandbox2() || message.includes(COWORK_NETWORK_HINT)) {
|
|
1940
|
+
return message;
|
|
1941
|
+
}
|
|
1942
|
+
return `${message}
|
|
1943
|
+
${COWORK_NETWORK_HINT}`;
|
|
1944
|
+
}
|
|
1945
|
+
|
|
1946
|
+
|
|
1947
|
+
|
|
1948
|
+
|
|
1949
|
+
|
|
1950
|
+
|
|
1951
|
+
|
|
1952
|
+
|
|
1953
|
+
|
|
1954
|
+
|
|
1955
|
+
|
|
1956
|
+
|
|
1957
|
+
|
|
1958
|
+
|
|
1959
|
+
|
|
1960
|
+
|
|
1961
|
+
|
|
1962
|
+
|
|
1963
|
+
|
|
1964
|
+
|
|
1965
|
+
|
|
1966
|
+
|
|
1967
|
+
|
|
1968
|
+
|
|
1969
|
+
|
|
1970
|
+
|
|
1971
|
+
|
|
1972
|
+
|
|
1973
|
+
|
|
1974
|
+
|
|
1975
|
+
|
|
1976
|
+
|
|
1977
|
+
|
|
1978
|
+
|
|
1979
|
+
|
|
1980
|
+
|
|
1981
|
+
|
|
1982
|
+
|
|
1983
|
+
|
|
1984
|
+
|
|
1985
|
+
|
|
1986
|
+
|
|
1987
|
+
|
|
1988
|
+
|
|
1989
|
+
|
|
1990
|
+
|
|
1991
|
+
|
|
1992
|
+
|
|
1993
|
+
|
|
1994
|
+
|
|
1995
|
+
exports.AuthError = AuthError; exports.RateLimitError = RateLimitError; exports.ToolRateLimitError = ToolRateLimitError; exports.ConfigError = ConfigError; exports.HOST_URL_ENV = HOST_URL_ENV; exports.API_KEY_ENV = API_KEY_ENV; exports.ACTIVE_ORG_ID_ENV = ACTIVE_ORG_ID_ENV; exports.ACTIVE_ORG_NAME_ENV = ACTIVE_ORG_NAME_ENV; exports.FEATURES_ENV = FEATURES_ENV; exports.PROD_URL = PROD_URL; exports.featureEnvValues = featureEnvValues; exports.storedHostApiKey = storedHostApiKey; exports.storedHostFeatures = storedHostFeatures; exports.baseUrlSlug = baseUrlSlug; exports.sdkCliStateDirPath = sdkCliStateDirPath; exports.hostConfigDirPath = hostConfigDirPath; exports.hostEnvFilePath = hostEnvFilePath; exports.saveHostEnvValues = saveHostEnvValues; exports.autoDetectBaseUrl = autoDetectBaseUrl; exports.resolveApiKeyForBaseUrl = resolveApiKeyForBaseUrl; exports.resolveProjectApiKeyForBaseUrl = resolveProjectApiKeyForBaseUrl; exports.resolveGlobalApiKeyForBaseUrl = resolveGlobalApiKeyForBaseUrl; exports.getResolvedProjectAuthSource = getResolvedProjectAuthSource; exports.resolveBaseUrlOnly = resolveBaseUrlOnly; exports.resolveConfig = resolveConfig; exports.ensureProjectPrivatePathsIgnored = ensureProjectPrivatePathsIgnored; exports.saveProjectDeeplineEnvValues = saveProjectDeeplineEnvValues; exports.resolveProjectPinTarget = resolveProjectPinTarget; exports.getActiveProjectAuthSource = getActiveProjectAuthSource; exports.resolveCliAuthProvenance = resolveCliAuthProvenance; exports.resolveCliCommandContext = resolveCliCommandContext; exports.SDK_VERSION = SDK_VERSION; exports.SDK_API_MAJOR = SDK_API_MAJOR; exports.SDK_API_CONTRACT = SDK_API_CONTRACT; exports.detectAgentRuntime = detectAgentRuntime; exports.hasActivePluginSkills = hasActivePluginSkills; exports.KNOWN_SKILL_AGENTS = KNOWN_SKILL_AGENTS; exports.DEFAULT_SKILL_AGENTS = DEFAULT_SKILL_AGENTS; exports.skillsAgentPathSegment = skillsAgentPathSegment; exports.resolveAutoSyncSkillAgents = resolveAutoSyncSkillAgents; exports.readSdkSkillsLocalVersion = readSdkSkillsLocalVersion; exports.writeSdkSkillsLocalVersion = writeSdkSkillsLocalVersion; exports.deploymentProtectionHeaders = deploymentProtectionHeaders; exports.fetchWithDeploymentProtection = fetchWithDeploymentProtection; exports.COORDINATOR_INTERNAL_TOKEN_HEADER = COORDINATOR_INTERNAL_TOKEN_HEADER; exports.RUNTIME_ENVIRONMENT_TOKEN_HEADER = RUNTIME_ENVIRONMENT_TOKEN_HEADER; exports.RETAINED_PIPELINE_RECEIVERS_HEADER = RETAINED_PIPELINE_RECEIVERS_HEADER; exports.HttpClient = HttpClient;
|