modal 0.7.5 → 0.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/index.cjs +1816 -369
- package/dist/index.d.cts +320 -4
- package/dist/index.d.ts +320 -4
- package/dist/index.js +1797 -359
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/app.ts
|
|
2
|
-
import { ClientError as
|
|
2
|
+
import { ClientError as ClientError13, Status as Status13 } from "nice-grpc";
|
|
3
3
|
|
|
4
4
|
// node_modules/@bufbuild/protobuf/dist/esm/wire/varint.js
|
|
5
5
|
function varint64read() {
|
|
@@ -1877,6 +1877,36 @@ function endpointInputModalityToJSON(object) {
|
|
|
1877
1877
|
return "UNRECOGNIZED";
|
|
1878
1878
|
}
|
|
1879
1879
|
}
|
|
1880
|
+
function endpointStopSourceFromJSON(object) {
|
|
1881
|
+
switch (object) {
|
|
1882
|
+
case 0:
|
|
1883
|
+
case "ENDPOINT_STOP_SOURCE_UNSPECIFIED":
|
|
1884
|
+
return 0 /* ENDPOINT_STOP_SOURCE_UNSPECIFIED */;
|
|
1885
|
+
case 1:
|
|
1886
|
+
case "ENDPOINT_STOP_SOURCE_CLI":
|
|
1887
|
+
return 1 /* ENDPOINT_STOP_SOURCE_CLI */;
|
|
1888
|
+
case 2:
|
|
1889
|
+
case "ENDPOINT_STOP_SOURCE_WEB":
|
|
1890
|
+
return 2 /* ENDPOINT_STOP_SOURCE_WEB */;
|
|
1891
|
+
case -1:
|
|
1892
|
+
case "UNRECOGNIZED":
|
|
1893
|
+
default:
|
|
1894
|
+
return -1 /* UNRECOGNIZED */;
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
function endpointStopSourceToJSON(object) {
|
|
1898
|
+
switch (object) {
|
|
1899
|
+
case 0 /* ENDPOINT_STOP_SOURCE_UNSPECIFIED */:
|
|
1900
|
+
return "ENDPOINT_STOP_SOURCE_UNSPECIFIED";
|
|
1901
|
+
case 1 /* ENDPOINT_STOP_SOURCE_CLI */:
|
|
1902
|
+
return "ENDPOINT_STOP_SOURCE_CLI";
|
|
1903
|
+
case 2 /* ENDPOINT_STOP_SOURCE_WEB */:
|
|
1904
|
+
return "ENDPOINT_STOP_SOURCE_WEB";
|
|
1905
|
+
case -1 /* UNRECOGNIZED */:
|
|
1906
|
+
default:
|
|
1907
|
+
return "UNRECOGNIZED";
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1880
1910
|
function environmentRoleFromJSON(object) {
|
|
1881
1911
|
switch (object) {
|
|
1882
1912
|
case 0:
|
|
@@ -16079,6 +16109,338 @@ var EndpointHuggingFaceModelSource = {
|
|
|
16079
16109
|
return message;
|
|
16080
16110
|
}
|
|
16081
16111
|
};
|
|
16112
|
+
function createBaseEndpointListItem() {
|
|
16113
|
+
return { endpointId: "", name: "", description: "", activeDeploymentId: "", updatedAt: 0, metadata: void 0 };
|
|
16114
|
+
}
|
|
16115
|
+
var EndpointListItem = {
|
|
16116
|
+
encode(message, writer = new BinaryWriter()) {
|
|
16117
|
+
if (message.endpointId !== "") {
|
|
16118
|
+
writer.uint32(10).string(message.endpointId);
|
|
16119
|
+
}
|
|
16120
|
+
if (message.name !== "") {
|
|
16121
|
+
writer.uint32(18).string(message.name);
|
|
16122
|
+
}
|
|
16123
|
+
if (message.description !== "") {
|
|
16124
|
+
writer.uint32(26).string(message.description);
|
|
16125
|
+
}
|
|
16126
|
+
if (message.activeDeploymentId !== "") {
|
|
16127
|
+
writer.uint32(34).string(message.activeDeploymentId);
|
|
16128
|
+
}
|
|
16129
|
+
if (message.updatedAt !== 0) {
|
|
16130
|
+
writer.uint32(41).double(message.updatedAt);
|
|
16131
|
+
}
|
|
16132
|
+
if (message.metadata !== void 0) {
|
|
16133
|
+
EndpointMetadata.encode(message.metadata, writer.uint32(50).fork()).join();
|
|
16134
|
+
}
|
|
16135
|
+
return writer;
|
|
16136
|
+
},
|
|
16137
|
+
decode(input, length) {
|
|
16138
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
16139
|
+
let end = length === void 0 ? reader.len : reader.pos + length;
|
|
16140
|
+
const message = createBaseEndpointListItem();
|
|
16141
|
+
while (reader.pos < end) {
|
|
16142
|
+
const tag = reader.uint32();
|
|
16143
|
+
switch (tag >>> 3) {
|
|
16144
|
+
case 1: {
|
|
16145
|
+
if (tag !== 10) {
|
|
16146
|
+
break;
|
|
16147
|
+
}
|
|
16148
|
+
message.endpointId = reader.string();
|
|
16149
|
+
continue;
|
|
16150
|
+
}
|
|
16151
|
+
case 2: {
|
|
16152
|
+
if (tag !== 18) {
|
|
16153
|
+
break;
|
|
16154
|
+
}
|
|
16155
|
+
message.name = reader.string();
|
|
16156
|
+
continue;
|
|
16157
|
+
}
|
|
16158
|
+
case 3: {
|
|
16159
|
+
if (tag !== 26) {
|
|
16160
|
+
break;
|
|
16161
|
+
}
|
|
16162
|
+
message.description = reader.string();
|
|
16163
|
+
continue;
|
|
16164
|
+
}
|
|
16165
|
+
case 4: {
|
|
16166
|
+
if (tag !== 34) {
|
|
16167
|
+
break;
|
|
16168
|
+
}
|
|
16169
|
+
message.activeDeploymentId = reader.string();
|
|
16170
|
+
continue;
|
|
16171
|
+
}
|
|
16172
|
+
case 5: {
|
|
16173
|
+
if (tag !== 41) {
|
|
16174
|
+
break;
|
|
16175
|
+
}
|
|
16176
|
+
message.updatedAt = reader.double();
|
|
16177
|
+
continue;
|
|
16178
|
+
}
|
|
16179
|
+
case 6: {
|
|
16180
|
+
if (tag !== 50) {
|
|
16181
|
+
break;
|
|
16182
|
+
}
|
|
16183
|
+
message.metadata = EndpointMetadata.decode(reader, reader.uint32());
|
|
16184
|
+
continue;
|
|
16185
|
+
}
|
|
16186
|
+
}
|
|
16187
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
16188
|
+
break;
|
|
16189
|
+
}
|
|
16190
|
+
reader.skip(tag & 7);
|
|
16191
|
+
}
|
|
16192
|
+
return message;
|
|
16193
|
+
},
|
|
16194
|
+
fromJSON(object) {
|
|
16195
|
+
return {
|
|
16196
|
+
endpointId: isSet5(object.endpointId) ? globalThis.String(object.endpointId) : "",
|
|
16197
|
+
name: isSet5(object.name) ? globalThis.String(object.name) : "",
|
|
16198
|
+
description: isSet5(object.description) ? globalThis.String(object.description) : "",
|
|
16199
|
+
activeDeploymentId: isSet5(object.activeDeploymentId) ? globalThis.String(object.activeDeploymentId) : "",
|
|
16200
|
+
updatedAt: isSet5(object.updatedAt) ? globalThis.Number(object.updatedAt) : 0,
|
|
16201
|
+
metadata: isSet5(object.metadata) ? EndpointMetadata.fromJSON(object.metadata) : void 0
|
|
16202
|
+
};
|
|
16203
|
+
},
|
|
16204
|
+
toJSON(message) {
|
|
16205
|
+
const obj = {};
|
|
16206
|
+
if (message.endpointId !== "") {
|
|
16207
|
+
obj.endpointId = message.endpointId;
|
|
16208
|
+
}
|
|
16209
|
+
if (message.name !== "") {
|
|
16210
|
+
obj.name = message.name;
|
|
16211
|
+
}
|
|
16212
|
+
if (message.description !== "") {
|
|
16213
|
+
obj.description = message.description;
|
|
16214
|
+
}
|
|
16215
|
+
if (message.activeDeploymentId !== "") {
|
|
16216
|
+
obj.activeDeploymentId = message.activeDeploymentId;
|
|
16217
|
+
}
|
|
16218
|
+
if (message.updatedAt !== 0) {
|
|
16219
|
+
obj.updatedAt = message.updatedAt;
|
|
16220
|
+
}
|
|
16221
|
+
if (message.metadata !== void 0) {
|
|
16222
|
+
obj.metadata = EndpointMetadata.toJSON(message.metadata);
|
|
16223
|
+
}
|
|
16224
|
+
return obj;
|
|
16225
|
+
},
|
|
16226
|
+
create(base) {
|
|
16227
|
+
return EndpointListItem.fromPartial(base ?? {});
|
|
16228
|
+
},
|
|
16229
|
+
fromPartial(object) {
|
|
16230
|
+
const message = createBaseEndpointListItem();
|
|
16231
|
+
message.endpointId = object.endpointId ?? "";
|
|
16232
|
+
message.name = object.name ?? "";
|
|
16233
|
+
message.description = object.description ?? "";
|
|
16234
|
+
message.activeDeploymentId = object.activeDeploymentId ?? "";
|
|
16235
|
+
message.updatedAt = object.updatedAt ?? 0;
|
|
16236
|
+
message.metadata = object.metadata !== void 0 && object.metadata !== null ? EndpointMetadata.fromPartial(object.metadata) : void 0;
|
|
16237
|
+
return message;
|
|
16238
|
+
}
|
|
16239
|
+
};
|
|
16240
|
+
function createBaseEndpointListRequest() {
|
|
16241
|
+
return { environmentName: "", pagination: void 0 };
|
|
16242
|
+
}
|
|
16243
|
+
var EndpointListRequest = {
|
|
16244
|
+
encode(message, writer = new BinaryWriter()) {
|
|
16245
|
+
if (message.environmentName !== "") {
|
|
16246
|
+
writer.uint32(10).string(message.environmentName);
|
|
16247
|
+
}
|
|
16248
|
+
if (message.pagination !== void 0) {
|
|
16249
|
+
ListPagination.encode(message.pagination, writer.uint32(18).fork()).join();
|
|
16250
|
+
}
|
|
16251
|
+
return writer;
|
|
16252
|
+
},
|
|
16253
|
+
decode(input, length) {
|
|
16254
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
16255
|
+
let end = length === void 0 ? reader.len : reader.pos + length;
|
|
16256
|
+
const message = createBaseEndpointListRequest();
|
|
16257
|
+
while (reader.pos < end) {
|
|
16258
|
+
const tag = reader.uint32();
|
|
16259
|
+
switch (tag >>> 3) {
|
|
16260
|
+
case 1: {
|
|
16261
|
+
if (tag !== 10) {
|
|
16262
|
+
break;
|
|
16263
|
+
}
|
|
16264
|
+
message.environmentName = reader.string();
|
|
16265
|
+
continue;
|
|
16266
|
+
}
|
|
16267
|
+
case 2: {
|
|
16268
|
+
if (tag !== 18) {
|
|
16269
|
+
break;
|
|
16270
|
+
}
|
|
16271
|
+
message.pagination = ListPagination.decode(reader, reader.uint32());
|
|
16272
|
+
continue;
|
|
16273
|
+
}
|
|
16274
|
+
}
|
|
16275
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
16276
|
+
break;
|
|
16277
|
+
}
|
|
16278
|
+
reader.skip(tag & 7);
|
|
16279
|
+
}
|
|
16280
|
+
return message;
|
|
16281
|
+
},
|
|
16282
|
+
fromJSON(object) {
|
|
16283
|
+
return {
|
|
16284
|
+
environmentName: isSet5(object.environmentName) ? globalThis.String(object.environmentName) : "",
|
|
16285
|
+
pagination: isSet5(object.pagination) ? ListPagination.fromJSON(object.pagination) : void 0
|
|
16286
|
+
};
|
|
16287
|
+
},
|
|
16288
|
+
toJSON(message) {
|
|
16289
|
+
const obj = {};
|
|
16290
|
+
if (message.environmentName !== "") {
|
|
16291
|
+
obj.environmentName = message.environmentName;
|
|
16292
|
+
}
|
|
16293
|
+
if (message.pagination !== void 0) {
|
|
16294
|
+
obj.pagination = ListPagination.toJSON(message.pagination);
|
|
16295
|
+
}
|
|
16296
|
+
return obj;
|
|
16297
|
+
},
|
|
16298
|
+
create(base) {
|
|
16299
|
+
return EndpointListRequest.fromPartial(base ?? {});
|
|
16300
|
+
},
|
|
16301
|
+
fromPartial(object) {
|
|
16302
|
+
const message = createBaseEndpointListRequest();
|
|
16303
|
+
message.environmentName = object.environmentName ?? "";
|
|
16304
|
+
message.pagination = object.pagination !== void 0 && object.pagination !== null ? ListPagination.fromPartial(object.pagination) : void 0;
|
|
16305
|
+
return message;
|
|
16306
|
+
}
|
|
16307
|
+
};
|
|
16308
|
+
function createBaseEndpointListResponse() {
|
|
16309
|
+
return { items: [], environmentName: "" };
|
|
16310
|
+
}
|
|
16311
|
+
var EndpointListResponse = {
|
|
16312
|
+
encode(message, writer = new BinaryWriter()) {
|
|
16313
|
+
for (const v of message.items) {
|
|
16314
|
+
EndpointListItem.encode(v, writer.uint32(10).fork()).join();
|
|
16315
|
+
}
|
|
16316
|
+
if (message.environmentName !== "") {
|
|
16317
|
+
writer.uint32(18).string(message.environmentName);
|
|
16318
|
+
}
|
|
16319
|
+
return writer;
|
|
16320
|
+
},
|
|
16321
|
+
decode(input, length) {
|
|
16322
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
16323
|
+
let end = length === void 0 ? reader.len : reader.pos + length;
|
|
16324
|
+
const message = createBaseEndpointListResponse();
|
|
16325
|
+
while (reader.pos < end) {
|
|
16326
|
+
const tag = reader.uint32();
|
|
16327
|
+
switch (tag >>> 3) {
|
|
16328
|
+
case 1: {
|
|
16329
|
+
if (tag !== 10) {
|
|
16330
|
+
break;
|
|
16331
|
+
}
|
|
16332
|
+
message.items.push(EndpointListItem.decode(reader, reader.uint32()));
|
|
16333
|
+
continue;
|
|
16334
|
+
}
|
|
16335
|
+
case 2: {
|
|
16336
|
+
if (tag !== 18) {
|
|
16337
|
+
break;
|
|
16338
|
+
}
|
|
16339
|
+
message.environmentName = reader.string();
|
|
16340
|
+
continue;
|
|
16341
|
+
}
|
|
16342
|
+
}
|
|
16343
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
16344
|
+
break;
|
|
16345
|
+
}
|
|
16346
|
+
reader.skip(tag & 7);
|
|
16347
|
+
}
|
|
16348
|
+
return message;
|
|
16349
|
+
},
|
|
16350
|
+
fromJSON(object) {
|
|
16351
|
+
return {
|
|
16352
|
+
items: globalThis.Array.isArray(object?.items) ? object.items.map((e) => EndpointListItem.fromJSON(e)) : [],
|
|
16353
|
+
environmentName: isSet5(object.environmentName) ? globalThis.String(object.environmentName) : ""
|
|
16354
|
+
};
|
|
16355
|
+
},
|
|
16356
|
+
toJSON(message) {
|
|
16357
|
+
const obj = {};
|
|
16358
|
+
if (message.items?.length) {
|
|
16359
|
+
obj.items = message.items.map((e) => EndpointListItem.toJSON(e));
|
|
16360
|
+
}
|
|
16361
|
+
if (message.environmentName !== "") {
|
|
16362
|
+
obj.environmentName = message.environmentName;
|
|
16363
|
+
}
|
|
16364
|
+
return obj;
|
|
16365
|
+
},
|
|
16366
|
+
create(base) {
|
|
16367
|
+
return EndpointListResponse.fromPartial(base ?? {});
|
|
16368
|
+
},
|
|
16369
|
+
fromPartial(object) {
|
|
16370
|
+
const message = createBaseEndpointListResponse();
|
|
16371
|
+
message.items = object.items?.map((e) => EndpointListItem.fromPartial(e)) || [];
|
|
16372
|
+
message.environmentName = object.environmentName ?? "";
|
|
16373
|
+
return message;
|
|
16374
|
+
}
|
|
16375
|
+
};
|
|
16376
|
+
function createBaseEndpointMetadata() {
|
|
16377
|
+
return { name: "", creationInfo: void 0 };
|
|
16378
|
+
}
|
|
16379
|
+
var EndpointMetadata = {
|
|
16380
|
+
encode(message, writer = new BinaryWriter()) {
|
|
16381
|
+
if (message.name !== "") {
|
|
16382
|
+
writer.uint32(10).string(message.name);
|
|
16383
|
+
}
|
|
16384
|
+
if (message.creationInfo !== void 0) {
|
|
16385
|
+
CreationInfo.encode(message.creationInfo, writer.uint32(18).fork()).join();
|
|
16386
|
+
}
|
|
16387
|
+
return writer;
|
|
16388
|
+
},
|
|
16389
|
+
decode(input, length) {
|
|
16390
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
16391
|
+
let end = length === void 0 ? reader.len : reader.pos + length;
|
|
16392
|
+
const message = createBaseEndpointMetadata();
|
|
16393
|
+
while (reader.pos < end) {
|
|
16394
|
+
const tag = reader.uint32();
|
|
16395
|
+
switch (tag >>> 3) {
|
|
16396
|
+
case 1: {
|
|
16397
|
+
if (tag !== 10) {
|
|
16398
|
+
break;
|
|
16399
|
+
}
|
|
16400
|
+
message.name = reader.string();
|
|
16401
|
+
continue;
|
|
16402
|
+
}
|
|
16403
|
+
case 2: {
|
|
16404
|
+
if (tag !== 18) {
|
|
16405
|
+
break;
|
|
16406
|
+
}
|
|
16407
|
+
message.creationInfo = CreationInfo.decode(reader, reader.uint32());
|
|
16408
|
+
continue;
|
|
16409
|
+
}
|
|
16410
|
+
}
|
|
16411
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
16412
|
+
break;
|
|
16413
|
+
}
|
|
16414
|
+
reader.skip(tag & 7);
|
|
16415
|
+
}
|
|
16416
|
+
return message;
|
|
16417
|
+
},
|
|
16418
|
+
fromJSON(object) {
|
|
16419
|
+
return {
|
|
16420
|
+
name: isSet5(object.name) ? globalThis.String(object.name) : "",
|
|
16421
|
+
creationInfo: isSet5(object.creationInfo) ? CreationInfo.fromJSON(object.creationInfo) : void 0
|
|
16422
|
+
};
|
|
16423
|
+
},
|
|
16424
|
+
toJSON(message) {
|
|
16425
|
+
const obj = {};
|
|
16426
|
+
if (message.name !== "") {
|
|
16427
|
+
obj.name = message.name;
|
|
16428
|
+
}
|
|
16429
|
+
if (message.creationInfo !== void 0) {
|
|
16430
|
+
obj.creationInfo = CreationInfo.toJSON(message.creationInfo);
|
|
16431
|
+
}
|
|
16432
|
+
return obj;
|
|
16433
|
+
},
|
|
16434
|
+
create(base) {
|
|
16435
|
+
return EndpointMetadata.fromPartial(base ?? {});
|
|
16436
|
+
},
|
|
16437
|
+
fromPartial(object) {
|
|
16438
|
+
const message = createBaseEndpointMetadata();
|
|
16439
|
+
message.name = object.name ?? "";
|
|
16440
|
+
message.creationInfo = object.creationInfo !== void 0 && object.creationInfo !== null ? CreationInfo.fromPartial(object.creationInfo) : void 0;
|
|
16441
|
+
return message;
|
|
16442
|
+
}
|
|
16443
|
+
};
|
|
16082
16444
|
function createBaseEndpointModalVolumeModelSource() {
|
|
16083
16445
|
return { volumeId: "", modelPath: "" };
|
|
16084
16446
|
}
|
|
@@ -16215,6 +16577,111 @@ var EndpointModelSource = {
|
|
|
16215
16577
|
return message;
|
|
16216
16578
|
}
|
|
16217
16579
|
};
|
|
16580
|
+
function createBaseEndpointStopRequest() {
|
|
16581
|
+
return { endpointId: "", source: 0 };
|
|
16582
|
+
}
|
|
16583
|
+
var EndpointStopRequest = {
|
|
16584
|
+
encode(message, writer = new BinaryWriter()) {
|
|
16585
|
+
if (message.endpointId !== "") {
|
|
16586
|
+
writer.uint32(10).string(message.endpointId);
|
|
16587
|
+
}
|
|
16588
|
+
if (message.source !== 0) {
|
|
16589
|
+
writer.uint32(16).int32(message.source);
|
|
16590
|
+
}
|
|
16591
|
+
return writer;
|
|
16592
|
+
},
|
|
16593
|
+
decode(input, length) {
|
|
16594
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
16595
|
+
let end = length === void 0 ? reader.len : reader.pos + length;
|
|
16596
|
+
const message = createBaseEndpointStopRequest();
|
|
16597
|
+
while (reader.pos < end) {
|
|
16598
|
+
const tag = reader.uint32();
|
|
16599
|
+
switch (tag >>> 3) {
|
|
16600
|
+
case 1: {
|
|
16601
|
+
if (tag !== 10) {
|
|
16602
|
+
break;
|
|
16603
|
+
}
|
|
16604
|
+
message.endpointId = reader.string();
|
|
16605
|
+
continue;
|
|
16606
|
+
}
|
|
16607
|
+
case 2: {
|
|
16608
|
+
if (tag !== 16) {
|
|
16609
|
+
break;
|
|
16610
|
+
}
|
|
16611
|
+
message.source = reader.int32();
|
|
16612
|
+
continue;
|
|
16613
|
+
}
|
|
16614
|
+
}
|
|
16615
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
16616
|
+
break;
|
|
16617
|
+
}
|
|
16618
|
+
reader.skip(tag & 7);
|
|
16619
|
+
}
|
|
16620
|
+
return message;
|
|
16621
|
+
},
|
|
16622
|
+
fromJSON(object) {
|
|
16623
|
+
return {
|
|
16624
|
+
endpointId: isSet5(object.endpointId) ? globalThis.String(object.endpointId) : "",
|
|
16625
|
+
source: isSet5(object.source) ? endpointStopSourceFromJSON(object.source) : 0
|
|
16626
|
+
};
|
|
16627
|
+
},
|
|
16628
|
+
toJSON(message) {
|
|
16629
|
+
const obj = {};
|
|
16630
|
+
if (message.endpointId !== "") {
|
|
16631
|
+
obj.endpointId = message.endpointId;
|
|
16632
|
+
}
|
|
16633
|
+
if (message.source !== 0) {
|
|
16634
|
+
obj.source = endpointStopSourceToJSON(message.source);
|
|
16635
|
+
}
|
|
16636
|
+
return obj;
|
|
16637
|
+
},
|
|
16638
|
+
create(base) {
|
|
16639
|
+
return EndpointStopRequest.fromPartial(base ?? {});
|
|
16640
|
+
},
|
|
16641
|
+
fromPartial(object) {
|
|
16642
|
+
const message = createBaseEndpointStopRequest();
|
|
16643
|
+
message.endpointId = object.endpointId ?? "";
|
|
16644
|
+
message.source = object.source ?? 0;
|
|
16645
|
+
return message;
|
|
16646
|
+
}
|
|
16647
|
+
};
|
|
16648
|
+
function createBaseEndpointStopResponse() {
|
|
16649
|
+
return {};
|
|
16650
|
+
}
|
|
16651
|
+
var EndpointStopResponse = {
|
|
16652
|
+
encode(_, writer = new BinaryWriter()) {
|
|
16653
|
+
return writer;
|
|
16654
|
+
},
|
|
16655
|
+
decode(input, length) {
|
|
16656
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
16657
|
+
let end = length === void 0 ? reader.len : reader.pos + length;
|
|
16658
|
+
const message = createBaseEndpointStopResponse();
|
|
16659
|
+
while (reader.pos < end) {
|
|
16660
|
+
const tag = reader.uint32();
|
|
16661
|
+
switch (tag >>> 3) {
|
|
16662
|
+
}
|
|
16663
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
16664
|
+
break;
|
|
16665
|
+
}
|
|
16666
|
+
reader.skip(tag & 7);
|
|
16667
|
+
}
|
|
16668
|
+
return message;
|
|
16669
|
+
},
|
|
16670
|
+
fromJSON(_) {
|
|
16671
|
+
return {};
|
|
16672
|
+
},
|
|
16673
|
+
toJSON(_) {
|
|
16674
|
+
const obj = {};
|
|
16675
|
+
return obj;
|
|
16676
|
+
},
|
|
16677
|
+
create(base) {
|
|
16678
|
+
return EndpointStopResponse.fromPartial(base ?? {});
|
|
16679
|
+
},
|
|
16680
|
+
fromPartial(_) {
|
|
16681
|
+
const message = createBaseEndpointStopResponse();
|
|
16682
|
+
return message;
|
|
16683
|
+
}
|
|
16684
|
+
};
|
|
16218
16685
|
function createBaseEnvironmentCreateRequest() {
|
|
16219
16686
|
return { name: "", isManaged: false };
|
|
16220
16687
|
}
|
|
@@ -34542,7 +35009,8 @@ function createBaseSandbox() {
|
|
|
34542
35009
|
customDomain: "",
|
|
34543
35010
|
includeOidcIdentityToken: false,
|
|
34544
35011
|
readinessProbe: void 0,
|
|
34545
|
-
inboundCidrAllowlist: []
|
|
35012
|
+
inboundCidrAllowlist: [],
|
|
35013
|
+
environmentVariables: void 0
|
|
34546
35014
|
};
|
|
34547
35015
|
}
|
|
34548
35016
|
var Sandbox = {
|
|
@@ -34658,6 +35126,9 @@ var Sandbox = {
|
|
|
34658
35126
|
for (const v of message.inboundCidrAllowlist) {
|
|
34659
35127
|
writer.uint32(314).string(v);
|
|
34660
35128
|
}
|
|
35129
|
+
if (message.environmentVariables !== void 0) {
|
|
35130
|
+
StringMap.encode(message.environmentVariables, writer.uint32(322).fork()).join();
|
|
35131
|
+
}
|
|
34661
35132
|
return writer;
|
|
34662
35133
|
},
|
|
34663
35134
|
decode(input, length) {
|
|
@@ -34929,6 +35400,13 @@ var Sandbox = {
|
|
|
34929
35400
|
message.inboundCidrAllowlist.push(reader.string());
|
|
34930
35401
|
continue;
|
|
34931
35402
|
}
|
|
35403
|
+
case 40: {
|
|
35404
|
+
if (tag !== 322) {
|
|
35405
|
+
break;
|
|
35406
|
+
}
|
|
35407
|
+
message.environmentVariables = StringMap.decode(reader, reader.uint32());
|
|
35408
|
+
continue;
|
|
35409
|
+
}
|
|
34932
35410
|
}
|
|
34933
35411
|
if ((tag & 7) === 4 || tag === 0) {
|
|
34934
35412
|
break;
|
|
@@ -34978,7 +35456,8 @@ var Sandbox = {
|
|
|
34978
35456
|
customDomain: isSet5(object.customDomain) ? globalThis.String(object.customDomain) : "",
|
|
34979
35457
|
includeOidcIdentityToken: isSet5(object.includeOidcIdentityToken) ? globalThis.Boolean(object.includeOidcIdentityToken) : false,
|
|
34980
35458
|
readinessProbe: isSet5(object.readinessProbe) ? Probe.fromJSON(object.readinessProbe) : void 0,
|
|
34981
|
-
inboundCidrAllowlist: globalThis.Array.isArray(object?.inboundCidrAllowlist) ? object.inboundCidrAllowlist.map((e) => globalThis.String(e)) : []
|
|
35459
|
+
inboundCidrAllowlist: globalThis.Array.isArray(object?.inboundCidrAllowlist) ? object.inboundCidrAllowlist.map((e) => globalThis.String(e)) : [],
|
|
35460
|
+
environmentVariables: isSet5(object.environmentVariables) ? StringMap.fromJSON(object.environmentVariables) : void 0
|
|
34982
35461
|
};
|
|
34983
35462
|
},
|
|
34984
35463
|
toJSON(message) {
|
|
@@ -35100,6 +35579,9 @@ var Sandbox = {
|
|
|
35100
35579
|
if (message.inboundCidrAllowlist?.length) {
|
|
35101
35580
|
obj.inboundCidrAllowlist = message.inboundCidrAllowlist;
|
|
35102
35581
|
}
|
|
35582
|
+
if (message.environmentVariables !== void 0) {
|
|
35583
|
+
obj.environmentVariables = StringMap.toJSON(message.environmentVariables);
|
|
35584
|
+
}
|
|
35103
35585
|
return obj;
|
|
35104
35586
|
},
|
|
35105
35587
|
create(base) {
|
|
@@ -35152,6 +35634,7 @@ var Sandbox = {
|
|
|
35152
35634
|
message.includeOidcIdentityToken = object.includeOidcIdentityToken ?? false;
|
|
35153
35635
|
message.readinessProbe = object.readinessProbe !== void 0 && object.readinessProbe !== null ? Probe.fromPartial(object.readinessProbe) : void 0;
|
|
35154
35636
|
message.inboundCidrAllowlist = object.inboundCidrAllowlist?.map((e) => e) || [];
|
|
35637
|
+
message.environmentVariables = object.environmentVariables !== void 0 && object.environmentVariables !== null ? StringMap.fromPartial(object.environmentVariables) : void 0;
|
|
35155
35638
|
return message;
|
|
35156
35639
|
}
|
|
35157
35640
|
};
|
|
@@ -40998,6 +41481,144 @@ var SharedVolumeRemoveFileRequest = {
|
|
|
40998
41481
|
return message;
|
|
40999
41482
|
}
|
|
41000
41483
|
};
|
|
41484
|
+
function createBaseStringMap() {
|
|
41485
|
+
return { contents: {} };
|
|
41486
|
+
}
|
|
41487
|
+
var StringMap = {
|
|
41488
|
+
encode(message, writer = new BinaryWriter()) {
|
|
41489
|
+
Object.entries(message.contents).forEach(([key, value]) => {
|
|
41490
|
+
StringMap_ContentsEntry.encode({ key, value }, writer.uint32(10).fork()).join();
|
|
41491
|
+
});
|
|
41492
|
+
return writer;
|
|
41493
|
+
},
|
|
41494
|
+
decode(input, length) {
|
|
41495
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
41496
|
+
let end = length === void 0 ? reader.len : reader.pos + length;
|
|
41497
|
+
const message = createBaseStringMap();
|
|
41498
|
+
while (reader.pos < end) {
|
|
41499
|
+
const tag = reader.uint32();
|
|
41500
|
+
switch (tag >>> 3) {
|
|
41501
|
+
case 1: {
|
|
41502
|
+
if (tag !== 10) {
|
|
41503
|
+
break;
|
|
41504
|
+
}
|
|
41505
|
+
const entry1 = StringMap_ContentsEntry.decode(reader, reader.uint32());
|
|
41506
|
+
if (entry1.value !== void 0) {
|
|
41507
|
+
message.contents[entry1.key] = entry1.value;
|
|
41508
|
+
}
|
|
41509
|
+
continue;
|
|
41510
|
+
}
|
|
41511
|
+
}
|
|
41512
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
41513
|
+
break;
|
|
41514
|
+
}
|
|
41515
|
+
reader.skip(tag & 7);
|
|
41516
|
+
}
|
|
41517
|
+
return message;
|
|
41518
|
+
},
|
|
41519
|
+
fromJSON(object) {
|
|
41520
|
+
return {
|
|
41521
|
+
contents: isObject2(object.contents) ? Object.entries(object.contents).reduce((acc, [key, value]) => {
|
|
41522
|
+
acc[key] = String(value);
|
|
41523
|
+
return acc;
|
|
41524
|
+
}, {}) : {}
|
|
41525
|
+
};
|
|
41526
|
+
},
|
|
41527
|
+
toJSON(message) {
|
|
41528
|
+
const obj = {};
|
|
41529
|
+
if (message.contents) {
|
|
41530
|
+
const entries = Object.entries(message.contents);
|
|
41531
|
+
if (entries.length > 0) {
|
|
41532
|
+
obj.contents = {};
|
|
41533
|
+
entries.forEach(([k, v]) => {
|
|
41534
|
+
obj.contents[k] = v;
|
|
41535
|
+
});
|
|
41536
|
+
}
|
|
41537
|
+
}
|
|
41538
|
+
return obj;
|
|
41539
|
+
},
|
|
41540
|
+
create(base) {
|
|
41541
|
+
return StringMap.fromPartial(base ?? {});
|
|
41542
|
+
},
|
|
41543
|
+
fromPartial(object) {
|
|
41544
|
+
const message = createBaseStringMap();
|
|
41545
|
+
message.contents = Object.entries(object.contents ?? {}).reduce((acc, [key, value]) => {
|
|
41546
|
+
if (value !== void 0) {
|
|
41547
|
+
acc[key] = globalThis.String(value);
|
|
41548
|
+
}
|
|
41549
|
+
return acc;
|
|
41550
|
+
}, {});
|
|
41551
|
+
return message;
|
|
41552
|
+
}
|
|
41553
|
+
};
|
|
41554
|
+
function createBaseStringMap_ContentsEntry() {
|
|
41555
|
+
return { key: "", value: "" };
|
|
41556
|
+
}
|
|
41557
|
+
var StringMap_ContentsEntry = {
|
|
41558
|
+
encode(message, writer = new BinaryWriter()) {
|
|
41559
|
+
if (message.key !== "") {
|
|
41560
|
+
writer.uint32(10).string(message.key);
|
|
41561
|
+
}
|
|
41562
|
+
if (message.value !== "") {
|
|
41563
|
+
writer.uint32(18).string(message.value);
|
|
41564
|
+
}
|
|
41565
|
+
return writer;
|
|
41566
|
+
},
|
|
41567
|
+
decode(input, length) {
|
|
41568
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
41569
|
+
let end = length === void 0 ? reader.len : reader.pos + length;
|
|
41570
|
+
const message = createBaseStringMap_ContentsEntry();
|
|
41571
|
+
while (reader.pos < end) {
|
|
41572
|
+
const tag = reader.uint32();
|
|
41573
|
+
switch (tag >>> 3) {
|
|
41574
|
+
case 1: {
|
|
41575
|
+
if (tag !== 10) {
|
|
41576
|
+
break;
|
|
41577
|
+
}
|
|
41578
|
+
message.key = reader.string();
|
|
41579
|
+
continue;
|
|
41580
|
+
}
|
|
41581
|
+
case 2: {
|
|
41582
|
+
if (tag !== 18) {
|
|
41583
|
+
break;
|
|
41584
|
+
}
|
|
41585
|
+
message.value = reader.string();
|
|
41586
|
+
continue;
|
|
41587
|
+
}
|
|
41588
|
+
}
|
|
41589
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
41590
|
+
break;
|
|
41591
|
+
}
|
|
41592
|
+
reader.skip(tag & 7);
|
|
41593
|
+
}
|
|
41594
|
+
return message;
|
|
41595
|
+
},
|
|
41596
|
+
fromJSON(object) {
|
|
41597
|
+
return {
|
|
41598
|
+
key: isSet5(object.key) ? globalThis.String(object.key) : "",
|
|
41599
|
+
value: isSet5(object.value) ? globalThis.String(object.value) : ""
|
|
41600
|
+
};
|
|
41601
|
+
},
|
|
41602
|
+
toJSON(message) {
|
|
41603
|
+
const obj = {};
|
|
41604
|
+
if (message.key !== "") {
|
|
41605
|
+
obj.key = message.key;
|
|
41606
|
+
}
|
|
41607
|
+
if (message.value !== "") {
|
|
41608
|
+
obj.value = message.value;
|
|
41609
|
+
}
|
|
41610
|
+
return obj;
|
|
41611
|
+
},
|
|
41612
|
+
create(base) {
|
|
41613
|
+
return StringMap_ContentsEntry.fromPartial(base ?? {});
|
|
41614
|
+
},
|
|
41615
|
+
fromPartial(object) {
|
|
41616
|
+
const message = createBaseStringMap_ContentsEntry();
|
|
41617
|
+
message.key = object.key ?? "";
|
|
41618
|
+
message.value = object.value ?? "";
|
|
41619
|
+
return message;
|
|
41620
|
+
}
|
|
41621
|
+
};
|
|
41001
41622
|
function createBaseSystemErrorMessage() {
|
|
41002
41623
|
return { errorCode: 0, errorMessage: "" };
|
|
41003
41624
|
}
|
|
@@ -48080,6 +48701,22 @@ var ModalClientDefinition = {
|
|
|
48080
48701
|
responseStream: false,
|
|
48081
48702
|
options: {}
|
|
48082
48703
|
},
|
|
48704
|
+
endpointList: {
|
|
48705
|
+
name: "EndpointList",
|
|
48706
|
+
requestType: EndpointListRequest,
|
|
48707
|
+
requestStream: false,
|
|
48708
|
+
responseType: EndpointListResponse,
|
|
48709
|
+
responseStream: false,
|
|
48710
|
+
options: {}
|
|
48711
|
+
},
|
|
48712
|
+
endpointStop: {
|
|
48713
|
+
name: "EndpointStop",
|
|
48714
|
+
requestType: EndpointStopRequest,
|
|
48715
|
+
requestStream: false,
|
|
48716
|
+
responseType: EndpointStopResponse,
|
|
48717
|
+
responseStream: false,
|
|
48718
|
+
options: {}
|
|
48719
|
+
},
|
|
48083
48720
|
/** Environments */
|
|
48084
48721
|
environmentCreate: {
|
|
48085
48722
|
name: "EnvironmentCreate",
|
|
@@ -49272,11 +49909,11 @@ function isSet5(value) {
|
|
|
49272
49909
|
// src/client.ts
|
|
49273
49910
|
import { v4 as uuidv42 } from "uuid";
|
|
49274
49911
|
import {
|
|
49275
|
-
ClientError as
|
|
49912
|
+
ClientError as ClientError12,
|
|
49276
49913
|
createChannel as createChannel2,
|
|
49277
49914
|
createClientFactory as createClientFactory2,
|
|
49278
49915
|
Metadata as Metadata2,
|
|
49279
|
-
Status as
|
|
49916
|
+
Status as Status12
|
|
49280
49917
|
} from "nice-grpc";
|
|
49281
49918
|
|
|
49282
49919
|
// src/cloud_bucket_mount.ts
|
|
@@ -49363,7 +50000,7 @@ var CloudBucketMount2 = class {
|
|
|
49363
50000
|
};
|
|
49364
50001
|
|
|
49365
50002
|
// src/cls.ts
|
|
49366
|
-
import { ClientError as
|
|
50003
|
+
import { ClientError as ClientError4, Status as Status4 } from "nice-grpc";
|
|
49367
50004
|
|
|
49368
50005
|
// src/errors.ts
|
|
49369
50006
|
var TimeoutError = class extends Error {
|
|
@@ -49426,6 +50063,48 @@ var SandboxFilesystemError = class extends Error {
|
|
|
49426
50063
|
this.name = "SandboxFilesystemError";
|
|
49427
50064
|
}
|
|
49428
50065
|
};
|
|
50066
|
+
var SandboxFilesystemDirectoryNotEmptyError = class extends SandboxFilesystemError {
|
|
50067
|
+
constructor(message) {
|
|
50068
|
+
super(message);
|
|
50069
|
+
this.name = "SandboxFilesystemDirectoryNotEmptyError";
|
|
50070
|
+
}
|
|
50071
|
+
};
|
|
50072
|
+
var SandboxFilesystemFileTooLargeError = class extends SandboxFilesystemError {
|
|
50073
|
+
constructor(message) {
|
|
50074
|
+
super(message);
|
|
50075
|
+
this.name = "SandboxFilesystemFileTooLargeError";
|
|
50076
|
+
}
|
|
50077
|
+
};
|
|
50078
|
+
var SandboxFilesystemIsADirectoryError = class extends SandboxFilesystemError {
|
|
50079
|
+
constructor(message) {
|
|
50080
|
+
super(message);
|
|
50081
|
+
this.name = "SandboxFilesystemIsADirectoryError";
|
|
50082
|
+
}
|
|
50083
|
+
};
|
|
50084
|
+
var SandboxFilesystemNotADirectoryError = class extends SandboxFilesystemError {
|
|
50085
|
+
constructor(message) {
|
|
50086
|
+
super(message);
|
|
50087
|
+
this.name = "SandboxFilesystemNotADirectoryError";
|
|
50088
|
+
}
|
|
50089
|
+
};
|
|
50090
|
+
var SandboxFilesystemNotFoundError = class extends SandboxFilesystemError {
|
|
50091
|
+
constructor(message) {
|
|
50092
|
+
super(message);
|
|
50093
|
+
this.name = "SandboxFilesystemNotFoundError";
|
|
50094
|
+
}
|
|
50095
|
+
};
|
|
50096
|
+
var SandboxFilesystemPathAlreadyExistsError = class extends SandboxFilesystemError {
|
|
50097
|
+
constructor(message) {
|
|
50098
|
+
super(message);
|
|
50099
|
+
this.name = "SandboxFilesystemPathAlreadyExistsError";
|
|
50100
|
+
}
|
|
50101
|
+
};
|
|
50102
|
+
var SandboxFilesystemPermissionError = class extends SandboxFilesystemError {
|
|
50103
|
+
constructor(message) {
|
|
50104
|
+
super(message);
|
|
50105
|
+
this.name = "SandboxFilesystemPermissionError";
|
|
50106
|
+
}
|
|
50107
|
+
};
|
|
49429
50108
|
var SandboxTimeoutError = class extends Error {
|
|
49430
50109
|
constructor(message = "Sandbox operation timed out") {
|
|
49431
50110
|
super(message);
|
|
@@ -50136,6 +50815,207 @@ function parseRetries(retries) {
|
|
|
50136
50815
|
);
|
|
50137
50816
|
}
|
|
50138
50817
|
|
|
50818
|
+
// src/volume.ts
|
|
50819
|
+
import { ClientError as ClientError3, Status as Status3 } from "nice-grpc";
|
|
50820
|
+
|
|
50821
|
+
// src/ephemeral.ts
|
|
50822
|
+
var ephemeralObjectHeartbeatSleep = 3e5;
|
|
50823
|
+
var EphemeralHeartbeatManager = class {
|
|
50824
|
+
heartbeatFn;
|
|
50825
|
+
abortController;
|
|
50826
|
+
constructor(heartbeatFn) {
|
|
50827
|
+
this.heartbeatFn = heartbeatFn;
|
|
50828
|
+
this.abortController = new AbortController();
|
|
50829
|
+
this.start();
|
|
50830
|
+
}
|
|
50831
|
+
start() {
|
|
50832
|
+
const signal = this.abortController.signal;
|
|
50833
|
+
(async () => {
|
|
50834
|
+
while (!signal.aborted) {
|
|
50835
|
+
await this.heartbeatFn();
|
|
50836
|
+
await Promise.race([
|
|
50837
|
+
new Promise((resolve) => {
|
|
50838
|
+
setTimeout(resolve, ephemeralObjectHeartbeatSleep).unref();
|
|
50839
|
+
}),
|
|
50840
|
+
new Promise((resolve) => {
|
|
50841
|
+
signal.addEventListener("abort", resolve, { once: true });
|
|
50842
|
+
})
|
|
50843
|
+
]);
|
|
50844
|
+
}
|
|
50845
|
+
})();
|
|
50846
|
+
}
|
|
50847
|
+
stop() {
|
|
50848
|
+
this.abortController.abort();
|
|
50849
|
+
}
|
|
50850
|
+
};
|
|
50851
|
+
|
|
50852
|
+
// src/volume.ts
|
|
50853
|
+
var VolumeService = class {
|
|
50854
|
+
#client;
|
|
50855
|
+
constructor(client2) {
|
|
50856
|
+
this.#client = client2;
|
|
50857
|
+
}
|
|
50858
|
+
/**
|
|
50859
|
+
* Reference a {@link Volume} by its name.
|
|
50860
|
+
*/
|
|
50861
|
+
async fromName(name, params) {
|
|
50862
|
+
try {
|
|
50863
|
+
const resp = await this.#client.cpClient.volumeGetOrCreate({
|
|
50864
|
+
deploymentName: name,
|
|
50865
|
+
environmentName: this.#client.environmentName(params?.environment),
|
|
50866
|
+
objectCreationType: params?.createIfMissing ? 1 /* OBJECT_CREATION_TYPE_CREATE_IF_MISSING */ : 0 /* OBJECT_CREATION_TYPE_UNSPECIFIED */
|
|
50867
|
+
});
|
|
50868
|
+
this.#client.logger.debug(
|
|
50869
|
+
"Retrieved Volume",
|
|
50870
|
+
"volume_id",
|
|
50871
|
+
resp.volumeId,
|
|
50872
|
+
"volume_name",
|
|
50873
|
+
name
|
|
50874
|
+
);
|
|
50875
|
+
return new Volume(resp.volumeId, name);
|
|
50876
|
+
} catch (err) {
|
|
50877
|
+
if (err instanceof ClientError3 && err.code === Status3.NOT_FOUND)
|
|
50878
|
+
throw new NotFoundError(err.details);
|
|
50879
|
+
throw err;
|
|
50880
|
+
}
|
|
50881
|
+
}
|
|
50882
|
+
/**
|
|
50883
|
+
* Create a nameless, temporary {@link Volume}.
|
|
50884
|
+
* It persists until closeEphemeral() is called, or the process exits.
|
|
50885
|
+
*/
|
|
50886
|
+
async ephemeral(params = {}) {
|
|
50887
|
+
const resp = await this.#client.cpClient.volumeGetOrCreate({
|
|
50888
|
+
objectCreationType: 5 /* OBJECT_CREATION_TYPE_EPHEMERAL */,
|
|
50889
|
+
environmentName: this.#client.environmentName(params.environment)
|
|
50890
|
+
});
|
|
50891
|
+
this.#client.logger.debug(
|
|
50892
|
+
"Created ephemeral Volume",
|
|
50893
|
+
"volume_id",
|
|
50894
|
+
resp.volumeId
|
|
50895
|
+
);
|
|
50896
|
+
const ephemeralHbManager = new EphemeralHeartbeatManager(
|
|
50897
|
+
() => this.#client.cpClient.volumeHeartbeat({ volumeId: resp.volumeId })
|
|
50898
|
+
);
|
|
50899
|
+
return new Volume(resp.volumeId, void 0, void 0, ephemeralHbManager);
|
|
50900
|
+
}
|
|
50901
|
+
/**
|
|
50902
|
+
* Delete a named {@link Volume}.
|
|
50903
|
+
*
|
|
50904
|
+
* Warning: Deletion is irreversible and will affect any Apps currently using the Volume.
|
|
50905
|
+
*/
|
|
50906
|
+
async delete(name, params) {
|
|
50907
|
+
try {
|
|
50908
|
+
const volume = await this.fromName(name, {
|
|
50909
|
+
environment: params?.environment,
|
|
50910
|
+
createIfMissing: false
|
|
50911
|
+
});
|
|
50912
|
+
await this.#client.cpClient.volumeDelete({
|
|
50913
|
+
volumeId: volume.volumeId
|
|
50914
|
+
});
|
|
50915
|
+
this.#client.logger.debug(
|
|
50916
|
+
"Deleted Volume",
|
|
50917
|
+
"volume_name",
|
|
50918
|
+
name,
|
|
50919
|
+
"volume_id",
|
|
50920
|
+
volume.volumeId
|
|
50921
|
+
);
|
|
50922
|
+
} catch (err) {
|
|
50923
|
+
const isNotFound = err instanceof NotFoundError || err instanceof ClientError3 && err.code === Status3.NOT_FOUND;
|
|
50924
|
+
if (isNotFound && params?.allowMissing) {
|
|
50925
|
+
return;
|
|
50926
|
+
}
|
|
50927
|
+
throw err;
|
|
50928
|
+
}
|
|
50929
|
+
}
|
|
50930
|
+
};
|
|
50931
|
+
var DEFAULT_MOUNT_OPTIONS = {
|
|
50932
|
+
readOnly: false,
|
|
50933
|
+
subPath: void 0
|
|
50934
|
+
};
|
|
50935
|
+
var Volume = class _Volume {
|
|
50936
|
+
volumeId;
|
|
50937
|
+
name;
|
|
50938
|
+
/**
|
|
50939
|
+
* @hidden
|
|
50940
|
+
* @internal
|
|
50941
|
+
*/
|
|
50942
|
+
_mountOptions = DEFAULT_MOUNT_OPTIONS;
|
|
50943
|
+
#ephemeralHbManager;
|
|
50944
|
+
/** @ignore */
|
|
50945
|
+
constructor(volumeId, name, mountOptions, ephemeralHbManager) {
|
|
50946
|
+
this.volumeId = volumeId;
|
|
50947
|
+
this.name = name;
|
|
50948
|
+
if (mountOptions) {
|
|
50949
|
+
this._mountOptions = mountOptions;
|
|
50950
|
+
}
|
|
50951
|
+
this.#ephemeralHbManager = ephemeralHbManager;
|
|
50952
|
+
}
|
|
50953
|
+
/**
|
|
50954
|
+
* @deprecated Use {@link VolumeService#fromName client.volumes.fromName()} instead.
|
|
50955
|
+
*/
|
|
50956
|
+
static async fromName(name, options) {
|
|
50957
|
+
return getDefaultClient().volumes.fromName(name, options);
|
|
50958
|
+
}
|
|
50959
|
+
/**
|
|
50960
|
+
* Configure Volume to mount as read-only.
|
|
50961
|
+
*
|
|
50962
|
+
* @deprecated Use {@link withMountOptions} with `{ readOnly: true }` instead.
|
|
50963
|
+
*/
|
|
50964
|
+
readOnly() {
|
|
50965
|
+
return this.withMountOptions({ readOnly: true });
|
|
50966
|
+
}
|
|
50967
|
+
/**
|
|
50968
|
+
* Configure options used when mounting this Volume. Fields left undefined preserve their value
|
|
50969
|
+
* from any previous withMountOptions call on the same Volume (stacking).
|
|
50970
|
+
*/
|
|
50971
|
+
withMountOptions(params = {}) {
|
|
50972
|
+
let subPath = this._mountOptions.subPath;
|
|
50973
|
+
if (params.subPath !== void 0) {
|
|
50974
|
+
subPath = params.subPath === "/" ? void 0 : params.subPath;
|
|
50975
|
+
}
|
|
50976
|
+
return new _Volume(
|
|
50977
|
+
this.volumeId,
|
|
50978
|
+
this.name,
|
|
50979
|
+
{
|
|
50980
|
+
readOnly: params.readOnly ?? this._mountOptions.readOnly,
|
|
50981
|
+
subPath
|
|
50982
|
+
},
|
|
50983
|
+
this.#ephemeralHbManager
|
|
50984
|
+
);
|
|
50985
|
+
}
|
|
50986
|
+
/**
|
|
50987
|
+
* @deprecated Inspect mount configuration at the call site that configured it instead.
|
|
50988
|
+
* Future versions of this SDK may remove direct mount-option accessors on Volume.
|
|
50989
|
+
*/
|
|
50990
|
+
get isReadOnly() {
|
|
50991
|
+
return this._mountOptions.readOnly;
|
|
50992
|
+
}
|
|
50993
|
+
/**
|
|
50994
|
+
* @deprecated Use {@link VolumeService#ephemeral client.volumes.ephemeral()} instead.
|
|
50995
|
+
*/
|
|
50996
|
+
static async ephemeral(options = {}) {
|
|
50997
|
+
return getDefaultClient().volumes.ephemeral(options);
|
|
50998
|
+
}
|
|
50999
|
+
/** Delete the ephemeral Volume. Only usable with emphemeral Volumes. */
|
|
51000
|
+
closeEphemeral() {
|
|
51001
|
+
if (this.#ephemeralHbManager) {
|
|
51002
|
+
this.#ephemeralHbManager.stop();
|
|
51003
|
+
} else {
|
|
51004
|
+
throw new InvalidError("Volume is not ephemeral.");
|
|
51005
|
+
}
|
|
51006
|
+
}
|
|
51007
|
+
};
|
|
51008
|
+
function volumeToMountProto(mountPath, volume) {
|
|
51009
|
+
const opts = volume._mountOptions ?? DEFAULT_MOUNT_OPTIONS;
|
|
51010
|
+
return {
|
|
51011
|
+
volumeId: volume.volumeId,
|
|
51012
|
+
mountPath,
|
|
51013
|
+
allowBackgroundCommits: true,
|
|
51014
|
+
readOnly: opts.readOnly,
|
|
51015
|
+
subPath: opts.subPath
|
|
51016
|
+
};
|
|
51017
|
+
}
|
|
51018
|
+
|
|
50139
51019
|
// src/cls.ts
|
|
50140
51020
|
var ClsService = class {
|
|
50141
51021
|
#client;
|
|
@@ -50176,7 +51056,7 @@ var ClsService = class {
|
|
|
50176
51056
|
void 0
|
|
50177
51057
|
);
|
|
50178
51058
|
} catch (err) {
|
|
50179
|
-
if (err instanceof
|
|
51059
|
+
if (err instanceof ClientError4 && err.code === Status4.NOT_FOUND)
|
|
50180
51060
|
throw new NotFoundError(`Class '${appName}/${name}' not found`);
|
|
50181
51061
|
throw err;
|
|
50182
51062
|
}
|
|
@@ -50355,12 +51235,9 @@ async function buildFunctionOptionsProto(options) {
|
|
|
50355
51235
|
gpuConfig
|
|
50356
51236
|
} : void 0;
|
|
50357
51237
|
const secretIds = (o.secrets || []).map((s) => s.secretId);
|
|
50358
|
-
const volumeMounts = o.volumes ? Object.entries(o.volumes).map(
|
|
50359
|
-
|
|
50360
|
-
|
|
50361
|
-
allowBackgroundCommits: true,
|
|
50362
|
-
readOnly: volume.isReadOnly
|
|
50363
|
-
})) : [];
|
|
51238
|
+
const volumeMounts = o.volumes ? Object.entries(o.volumes).map(
|
|
51239
|
+
([mountPath, volume]) => volumeToMountProto(mountPath, volume)
|
|
51240
|
+
) : [];
|
|
50364
51241
|
const parsedRetries = parseRetries(o.retries);
|
|
50365
51242
|
const retryPolicy = parsedRetries ? {
|
|
50366
51243
|
retries: parsedRetries.maxRetries,
|
|
@@ -50457,8 +51334,8 @@ var ClsInstance = class {
|
|
|
50457
51334
|
};
|
|
50458
51335
|
|
|
50459
51336
|
// src/image.ts
|
|
50460
|
-
import { ClientError as
|
|
50461
|
-
import { Status as
|
|
51337
|
+
import { ClientError as ClientError5 } from "nice-grpc";
|
|
51338
|
+
import { Status as Status5 } from "nice-grpc";
|
|
50462
51339
|
var ImageService = class {
|
|
50463
51340
|
#client;
|
|
50464
51341
|
constructor(client2) {
|
|
@@ -50474,9 +51351,9 @@ var ImageService = class {
|
|
|
50474
51351
|
const resp = await this.#client.cpClient.imageFromId({ imageId });
|
|
50475
51352
|
return new Image2(this.#client, resp.imageId, "");
|
|
50476
51353
|
} catch (err) {
|
|
50477
|
-
if (err instanceof
|
|
51354
|
+
if (err instanceof ClientError5 && err.code === Status5.NOT_FOUND)
|
|
50478
51355
|
throw new NotFoundError(err.details);
|
|
50479
|
-
if (err instanceof
|
|
51356
|
+
if (err instanceof ClientError5 && err.code === Status5.FAILED_PRECONDITION && err.details.includes("Could not find image with ID"))
|
|
50480
51357
|
throw new NotFoundError(err.details);
|
|
50481
51358
|
throw err;
|
|
50482
51359
|
}
|
|
@@ -50558,9 +51435,9 @@ var ImageService = class {
|
|
|
50558
51435
|
try {
|
|
50559
51436
|
await this.#client.cpClient.imageDelete({ imageId });
|
|
50560
51437
|
} catch (err) {
|
|
50561
|
-
if (err instanceof
|
|
51438
|
+
if (err instanceof ClientError5 && err.code === Status5.NOT_FOUND)
|
|
50562
51439
|
throw new NotFoundError(err.details);
|
|
50563
|
-
if (err instanceof
|
|
51440
|
+
if (err instanceof ClientError5 && err.code === Status5.FAILED_PRECONDITION && err.details.includes("Could not find image with ID"))
|
|
50564
51441
|
throw new NotFoundError(err.details);
|
|
50565
51442
|
throw err;
|
|
50566
51443
|
}
|
|
@@ -50748,7 +51625,7 @@ ${result.exception}`
|
|
|
50748
51625
|
};
|
|
50749
51626
|
|
|
50750
51627
|
// src/proxy.ts
|
|
50751
|
-
import { ClientError as
|
|
51628
|
+
import { ClientError as ClientError6, Status as Status6 } from "nice-grpc";
|
|
50752
51629
|
var ProxyService = class {
|
|
50753
51630
|
#client;
|
|
50754
51631
|
constructor(client2) {
|
|
@@ -50774,7 +51651,7 @@ var ProxyService = class {
|
|
|
50774
51651
|
}
|
|
50775
51652
|
return new Proxy3(resp.proxy.proxyId);
|
|
50776
51653
|
} catch (err) {
|
|
50777
|
-
if (err instanceof
|
|
51654
|
+
if (err instanceof ClientError6 && err.code === Status6.NOT_FOUND)
|
|
50778
51655
|
throw new NotFoundError(`Proxy '${name}' not found`);
|
|
50779
51656
|
throw err;
|
|
50780
51657
|
}
|
|
@@ -51150,40 +52027,7 @@ function loads(buf) {
|
|
|
51150
52027
|
}
|
|
51151
52028
|
|
|
51152
52029
|
// src/queue.ts
|
|
51153
|
-
import { ClientError as
|
|
51154
|
-
|
|
51155
|
-
// src/ephemeral.ts
|
|
51156
|
-
var ephemeralObjectHeartbeatSleep = 3e5;
|
|
51157
|
-
var EphemeralHeartbeatManager = class {
|
|
51158
|
-
heartbeatFn;
|
|
51159
|
-
abortController;
|
|
51160
|
-
constructor(heartbeatFn) {
|
|
51161
|
-
this.heartbeatFn = heartbeatFn;
|
|
51162
|
-
this.abortController = new AbortController();
|
|
51163
|
-
this.start();
|
|
51164
|
-
}
|
|
51165
|
-
start() {
|
|
51166
|
-
const signal = this.abortController.signal;
|
|
51167
|
-
(async () => {
|
|
51168
|
-
while (!signal.aborted) {
|
|
51169
|
-
await this.heartbeatFn();
|
|
51170
|
-
await Promise.race([
|
|
51171
|
-
new Promise((resolve) => {
|
|
51172
|
-
setTimeout(resolve, ephemeralObjectHeartbeatSleep).unref();
|
|
51173
|
-
}),
|
|
51174
|
-
new Promise((resolve) => {
|
|
51175
|
-
signal.addEventListener("abort", resolve, { once: true });
|
|
51176
|
-
})
|
|
51177
|
-
]);
|
|
51178
|
-
}
|
|
51179
|
-
})();
|
|
51180
|
-
}
|
|
51181
|
-
stop() {
|
|
51182
|
-
this.abortController.abort();
|
|
51183
|
-
}
|
|
51184
|
-
};
|
|
51185
|
-
|
|
51186
|
-
// src/queue.ts
|
|
52030
|
+
import { ClientError as ClientError7, Status as Status7 } from "nice-grpc";
|
|
51187
52031
|
var queueInitialPutBackoffMs = 100;
|
|
51188
52032
|
var queueDefaultPartitionTtlMs = 24 * 3600 * 1e3;
|
|
51189
52033
|
var QueueService = class {
|
|
@@ -51229,7 +52073,7 @@ var QueueService = class {
|
|
|
51229
52073
|
);
|
|
51230
52074
|
return new Queue(this.#client, resp.queueId, name);
|
|
51231
52075
|
} catch (err) {
|
|
51232
|
-
if (err instanceof
|
|
52076
|
+
if (err instanceof ClientError7 && err.code === Status7.NOT_FOUND)
|
|
51233
52077
|
throw new NotFoundError(err.details);
|
|
51234
52078
|
throw err;
|
|
51235
52079
|
}
|
|
@@ -51254,7 +52098,7 @@ var QueueService = class {
|
|
|
51254
52098
|
queue.queueId
|
|
51255
52099
|
);
|
|
51256
52100
|
} catch (err) {
|
|
51257
|
-
const isNotFound = err instanceof NotFoundError || err instanceof
|
|
52101
|
+
const isNotFound = err instanceof NotFoundError || err instanceof ClientError7 && err.code === Status7.NOT_FOUND;
|
|
51258
52102
|
if (isNotFound && params.allowMissing) {
|
|
51259
52103
|
return;
|
|
51260
52104
|
}
|
|
@@ -51392,7 +52236,7 @@ var Queue = class _Queue {
|
|
|
51392
52236
|
});
|
|
51393
52237
|
break;
|
|
51394
52238
|
} catch (e) {
|
|
51395
|
-
if (e instanceof
|
|
52239
|
+
if (e instanceof ClientError7 && e.code === Status7.RESOURCE_EXHAUSTED) {
|
|
51396
52240
|
delay = Math.min(delay * 2, 3e4);
|
|
51397
52241
|
if (deadline !== void 0) {
|
|
51398
52242
|
const remaining = deadline - Date.now();
|
|
@@ -51493,7 +52337,7 @@ var Queue = class _Queue {
|
|
|
51493
52337
|
};
|
|
51494
52338
|
|
|
51495
52339
|
// src/sandbox.ts
|
|
51496
|
-
import { ClientError as
|
|
52340
|
+
import { ClientError as ClientError11, Status as Status11 } from "nice-grpc";
|
|
51497
52341
|
import { setTimeout as setTimeout3 } from "timers/promises";
|
|
51498
52342
|
|
|
51499
52343
|
// proto/modal_proto/task_command_router.ts
|
|
@@ -54656,12 +55500,12 @@ function isSet6(value) {
|
|
|
54656
55500
|
// src/task_command_router_client.ts
|
|
54657
55501
|
import { setTimeout as setTimeout2 } from "timers/promises";
|
|
54658
55502
|
import {
|
|
54659
|
-
ClientError as
|
|
55503
|
+
ClientError as ClientError8,
|
|
54660
55504
|
ChannelCredentials,
|
|
54661
55505
|
createChannel,
|
|
54662
55506
|
createClientFactory,
|
|
54663
55507
|
Metadata,
|
|
54664
|
-
Status as
|
|
55508
|
+
Status as Status8
|
|
54665
55509
|
} from "nice-grpc";
|
|
54666
55510
|
|
|
54667
55511
|
// src/config.ts
|
|
@@ -54731,7 +55575,7 @@ function getProfile(profileName) {
|
|
|
54731
55575
|
}
|
|
54732
55576
|
|
|
54733
55577
|
// src/task_command_router_client.ts
|
|
54734
|
-
function parseJwtExpiration(jwtToken,
|
|
55578
|
+
function parseJwtExpiration(jwtToken, logger2) {
|
|
54735
55579
|
try {
|
|
54736
55580
|
const parts = jwtToken.split(".");
|
|
54737
55581
|
if (parts.length !== 3) {
|
|
@@ -54748,7 +55592,7 @@ function parseJwtExpiration(jwtToken, logger) {
|
|
|
54748
55592
|
return exp;
|
|
54749
55593
|
}
|
|
54750
55594
|
} catch (e) {
|
|
54751
|
-
|
|
55595
|
+
logger2.warn("Failed to parse JWT expiration", "error", e);
|
|
54752
55596
|
}
|
|
54753
55597
|
return null;
|
|
54754
55598
|
}
|
|
@@ -54758,11 +55602,11 @@ async function callWithRetriesOnTransientErrors(func, baseDelayMs = 10, delayFac
|
|
|
54758
55602
|
let delayMs = baseDelayMs;
|
|
54759
55603
|
let numRetries = 0;
|
|
54760
55604
|
const retryableStatusCodes = /* @__PURE__ */ new Set([
|
|
54761
|
-
|
|
54762
|
-
|
|
54763
|
-
|
|
54764
|
-
|
|
54765
|
-
|
|
55605
|
+
Status8.DEADLINE_EXCEEDED,
|
|
55606
|
+
Status8.UNAVAILABLE,
|
|
55607
|
+
Status8.CANCELLED,
|
|
55608
|
+
Status8.INTERNAL,
|
|
55609
|
+
Status8.UNKNOWN
|
|
54766
55610
|
]);
|
|
54767
55611
|
const excluded = new Set(excludeStatusCodes);
|
|
54768
55612
|
while (true) {
|
|
@@ -54772,10 +55616,10 @@ async function callWithRetriesOnTransientErrors(func, baseDelayMs = 10, delayFac
|
|
|
54772
55616
|
try {
|
|
54773
55617
|
return await func();
|
|
54774
55618
|
} catch (err) {
|
|
54775
|
-
if (err instanceof
|
|
55619
|
+
if (err instanceof ClientError8 && err.code === Status8.CANCELLED && isClosed?.()) {
|
|
54776
55620
|
throw new ClientClosedError();
|
|
54777
55621
|
}
|
|
54778
|
-
if (err instanceof
|
|
55622
|
+
if (err instanceof ClientError8 && retryableStatusCodes.has(err.code) && !excluded.has(err.code) && (maxRetries === null || numRetries < maxRetries)) {
|
|
54779
55623
|
let sleepMs = delayMs;
|
|
54780
55624
|
if (deadlineMs !== null) {
|
|
54781
55625
|
sleepMs = Math.min(sleepMs, deadlineMs - Date.now());
|
|
@@ -54803,7 +55647,7 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
|
|
|
54803
55647
|
jwtRefreshLock = Promise.resolve();
|
|
54804
55648
|
logger;
|
|
54805
55649
|
closed = false;
|
|
54806
|
-
static async tryInit(serverClient, taskId, sandboxId, isV2,
|
|
55650
|
+
static async tryInit(serverClient, taskId, sandboxId, isV2, logger2, profile) {
|
|
54807
55651
|
let resp;
|
|
54808
55652
|
try {
|
|
54809
55653
|
resp = await getCommandRouterAccess(
|
|
@@ -54813,8 +55657,8 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
|
|
|
54813
55657
|
isV2
|
|
54814
55658
|
);
|
|
54815
55659
|
} catch (err) {
|
|
54816
|
-
if (err instanceof
|
|
54817
|
-
|
|
55660
|
+
if (err instanceof ClientError8 && err.code === Status8.FAILED_PRECONDITION) {
|
|
55661
|
+
logger2.debug(
|
|
54818
55662
|
"Command router access is not enabled for task",
|
|
54819
55663
|
"task_id",
|
|
54820
55664
|
taskId
|
|
@@ -54823,7 +55667,7 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
|
|
|
54823
55667
|
}
|
|
54824
55668
|
throw err;
|
|
54825
55669
|
}
|
|
54826
|
-
|
|
55670
|
+
logger2.debug(
|
|
54827
55671
|
"Using command router access for task",
|
|
54828
55672
|
"task_id",
|
|
54829
55673
|
taskId,
|
|
@@ -54847,7 +55691,7 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
|
|
|
54847
55691
|
};
|
|
54848
55692
|
let channel;
|
|
54849
55693
|
if (isLocalhost(profile)) {
|
|
54850
|
-
|
|
55694
|
+
logger2.warn(
|
|
54851
55695
|
"Using insecure TLS (skip certificate verification) for task command router"
|
|
54852
55696
|
);
|
|
54853
55697
|
channel = createChannel(
|
|
@@ -54870,24 +55714,24 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
|
|
|
54870
55714
|
resp.url,
|
|
54871
55715
|
resp.jwt,
|
|
54872
55716
|
channel,
|
|
54873
|
-
|
|
55717
|
+
logger2
|
|
54874
55718
|
);
|
|
54875
|
-
|
|
55719
|
+
logger2.debug(
|
|
54876
55720
|
"Successfully initialized command router client",
|
|
54877
55721
|
"task_id",
|
|
54878
55722
|
taskId
|
|
54879
55723
|
);
|
|
54880
55724
|
return client2;
|
|
54881
55725
|
}
|
|
54882
|
-
constructor(serverClient, taskId, sandboxId, isV2, serverUrl, jwt, channel,
|
|
55726
|
+
constructor(serverClient, taskId, sandboxId, isV2, serverUrl, jwt, channel, logger2) {
|
|
54883
55727
|
this.serverClient = serverClient;
|
|
54884
55728
|
this.taskId = taskId;
|
|
54885
55729
|
this.sandboxId = sandboxId;
|
|
54886
55730
|
this.isV2 = isV2;
|
|
54887
55731
|
this.serverUrl = serverUrl;
|
|
54888
55732
|
this.jwt = jwt;
|
|
54889
|
-
this.jwtExp = parseJwtExpiration(jwt,
|
|
54890
|
-
this.logger =
|
|
55733
|
+
this.jwtExp = parseJwtExpiration(jwt, logger2);
|
|
55734
|
+
this.logger = logger2;
|
|
54891
55735
|
this.channel = channel;
|
|
54892
55736
|
const self = this;
|
|
54893
55737
|
const factory = createClientFactory().use(timeoutMiddleware).use(async function* authMiddleware(call, options) {
|
|
@@ -54963,7 +55807,7 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
|
|
|
54963
55807
|
() => this.closed
|
|
54964
55808
|
);
|
|
54965
55809
|
} catch (err) {
|
|
54966
|
-
if (err instanceof
|
|
55810
|
+
if (err instanceof ClientError8 && err.code === Status8.DEADLINE_EXCEEDED) {
|
|
54967
55811
|
throw new Error(`Deadline exceeded while polling for exec ${execId}`);
|
|
54968
55812
|
}
|
|
54969
55813
|
throw err;
|
|
@@ -54992,7 +55836,7 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
|
|
|
54992
55836
|
() => this.closed
|
|
54993
55837
|
);
|
|
54994
55838
|
} catch (err) {
|
|
54995
|
-
if (err instanceof
|
|
55839
|
+
if (err instanceof ClientError8 && err.code === Status8.DEADLINE_EXCEEDED) {
|
|
54996
55840
|
throw new Error(`Deadline exceeded while waiting for exec ${execId}`);
|
|
54997
55841
|
}
|
|
54998
55842
|
throw err;
|
|
@@ -55034,7 +55878,7 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
|
|
|
55034
55878
|
10,
|
|
55035
55879
|
overallDeadlineMs,
|
|
55036
55880
|
() => this.closed,
|
|
55037
|
-
[
|
|
55881
|
+
[Status8.DEADLINE_EXCEEDED, Status8.CANCELLED]
|
|
55038
55882
|
);
|
|
55039
55883
|
} catch (err) {
|
|
55040
55884
|
if (overallDeadlineMs !== null && Date.now() >= overallDeadlineMs) {
|
|
@@ -55092,7 +55936,7 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
|
|
|
55092
55936
|
try {
|
|
55093
55937
|
return await func();
|
|
55094
55938
|
} catch (err) {
|
|
55095
|
-
if (err instanceof
|
|
55939
|
+
if (err instanceof ClientError8 && err.code === Status8.UNAUTHENTICATED) {
|
|
55096
55940
|
await this.refreshJwt();
|
|
55097
55941
|
return await func();
|
|
55098
55942
|
}
|
|
@@ -55106,11 +55950,11 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
|
|
|
55106
55950
|
let numRetriesRemaining = 10;
|
|
55107
55951
|
let didAuthRetry = false;
|
|
55108
55952
|
const retryableStatusCodes = /* @__PURE__ */ new Set([
|
|
55109
|
-
|
|
55110
|
-
|
|
55111
|
-
|
|
55112
|
-
|
|
55113
|
-
|
|
55953
|
+
Status8.DEADLINE_EXCEEDED,
|
|
55954
|
+
Status8.UNAVAILABLE,
|
|
55955
|
+
Status8.CANCELLED,
|
|
55956
|
+
Status8.INTERNAL,
|
|
55957
|
+
Status8.UNKNOWN
|
|
55114
55958
|
]);
|
|
55115
55959
|
while (true) {
|
|
55116
55960
|
try {
|
|
@@ -55135,7 +55979,7 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
|
|
|
55135
55979
|
}
|
|
55136
55980
|
return;
|
|
55137
55981
|
} catch (err) {
|
|
55138
|
-
if (err instanceof
|
|
55982
|
+
if (err instanceof ClientError8 && err.code === Status8.UNAUTHENTICATED && !didAuthRetry) {
|
|
55139
55983
|
await this.refreshJwt();
|
|
55140
55984
|
didAuthRetry = true;
|
|
55141
55985
|
continue;
|
|
@@ -55143,10 +55987,10 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
|
|
|
55143
55987
|
throw err;
|
|
55144
55988
|
}
|
|
55145
55989
|
} catch (err) {
|
|
55146
|
-
if (err instanceof
|
|
55990
|
+
if (err instanceof ClientError8 && err.code === Status8.CANCELLED && this.closed) {
|
|
55147
55991
|
throw new ClientClosedError();
|
|
55148
55992
|
}
|
|
55149
|
-
if (err instanceof
|
|
55993
|
+
if (err instanceof ClientError8 && retryableStatusCodes.has(err.code) && numRetriesRemaining > 0) {
|
|
55150
55994
|
if (deadline && deadline - Date.now() <= delayMs) {
|
|
55151
55995
|
throw new Error(
|
|
55152
55996
|
`Deadline exceeded while streaming stdio for exec ${execId}`
|
|
@@ -55290,6 +56134,760 @@ async function runFilesystemExec(cpClient, request) {
|
|
|
55290
56134
|
return { chunks, response };
|
|
55291
56135
|
}
|
|
55292
56136
|
|
|
56137
|
+
// src/sandbox_fs.ts
|
|
56138
|
+
import { randomBytes } from "node:crypto";
|
|
56139
|
+
import { createReadStream, createWriteStream } from "node:fs";
|
|
56140
|
+
import { mkdir, rename, rm, unlink } from "node:fs/promises";
|
|
56141
|
+
import { Writable } from "node:stream";
|
|
56142
|
+
import { dirname } from "node:path";
|
|
56143
|
+
import { ClientError as ClientError10, Status as Status10 } from "nice-grpc";
|
|
56144
|
+
|
|
56145
|
+
// src/sandbox_fs_utils.ts
|
|
56146
|
+
import { posix } from "node:path";
|
|
56147
|
+
import { ClientError as ClientError9, Status as Status9 } from "nice-grpc";
|
|
56148
|
+
|
|
56149
|
+
// src/logger.ts
|
|
56150
|
+
var LOG_LEVELS = {
|
|
56151
|
+
debug: 0,
|
|
56152
|
+
info: 1,
|
|
56153
|
+
warn: 2,
|
|
56154
|
+
error: 3
|
|
56155
|
+
};
|
|
56156
|
+
function parseLogLevel(level) {
|
|
56157
|
+
if (!level) {
|
|
56158
|
+
return "warn";
|
|
56159
|
+
}
|
|
56160
|
+
const normalized = level.toLowerCase();
|
|
56161
|
+
if (normalized === "debug" || normalized === "info" || normalized === "warn" || normalized === "warning" || normalized === "error") {
|
|
56162
|
+
return normalized === "warning" ? "warn" : normalized;
|
|
56163
|
+
}
|
|
56164
|
+
throw new Error(
|
|
56165
|
+
`Invalid log level value: "${level}" (must be debug, info, warn, or error)`
|
|
56166
|
+
);
|
|
56167
|
+
}
|
|
56168
|
+
var DefaultLogger = class {
|
|
56169
|
+
levelValue;
|
|
56170
|
+
constructor(level = "warn") {
|
|
56171
|
+
this.levelValue = LOG_LEVELS[level];
|
|
56172
|
+
}
|
|
56173
|
+
debug(message, ...args) {
|
|
56174
|
+
if (this.levelValue <= LOG_LEVELS.debug) {
|
|
56175
|
+
console.log(this.formatMessage("DEBUG", message, args));
|
|
56176
|
+
}
|
|
56177
|
+
}
|
|
56178
|
+
info(message, ...args) {
|
|
56179
|
+
if (this.levelValue <= LOG_LEVELS.info) {
|
|
56180
|
+
console.log(this.formatMessage("INFO", message, args));
|
|
56181
|
+
}
|
|
56182
|
+
}
|
|
56183
|
+
warn(message, ...args) {
|
|
56184
|
+
if (this.levelValue <= LOG_LEVELS.warn) {
|
|
56185
|
+
console.warn(this.formatMessage("WARN", message, args));
|
|
56186
|
+
}
|
|
56187
|
+
}
|
|
56188
|
+
error(message, ...args) {
|
|
56189
|
+
if (this.levelValue <= LOG_LEVELS.error) {
|
|
56190
|
+
console.error(this.formatMessage("ERROR", message, args));
|
|
56191
|
+
}
|
|
56192
|
+
}
|
|
56193
|
+
formatMessage(level, message, args) {
|
|
56194
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
56195
|
+
let formatted = `time=${timestamp} level=${level} msg="${message}"`;
|
|
56196
|
+
if (args.length > 0) {
|
|
56197
|
+
for (let i = 0; i < args.length; i += 2) {
|
|
56198
|
+
if (i + 1 < args.length) {
|
|
56199
|
+
const key = args[i];
|
|
56200
|
+
const value = args[i + 1];
|
|
56201
|
+
formatted += ` ${key}=${this.formatValue(value)}`;
|
|
56202
|
+
}
|
|
56203
|
+
}
|
|
56204
|
+
}
|
|
56205
|
+
return formatted;
|
|
56206
|
+
}
|
|
56207
|
+
formatValue(value) {
|
|
56208
|
+
if (typeof value === "string") {
|
|
56209
|
+
return value.includes(" ") ? `"${value}"` : value;
|
|
56210
|
+
}
|
|
56211
|
+
if (value instanceof Error) {
|
|
56212
|
+
return `"${value.message}"`;
|
|
56213
|
+
}
|
|
56214
|
+
if (Array.isArray(value)) {
|
|
56215
|
+
return `[${value.join(",")}]`;
|
|
56216
|
+
}
|
|
56217
|
+
return String(value);
|
|
56218
|
+
}
|
|
56219
|
+
};
|
|
56220
|
+
var FilteredLogger = class {
|
|
56221
|
+
constructor(logger2, level) {
|
|
56222
|
+
this.logger = logger2;
|
|
56223
|
+
this.levelValue = LOG_LEVELS[level];
|
|
56224
|
+
}
|
|
56225
|
+
levelValue;
|
|
56226
|
+
debug(message, ...args) {
|
|
56227
|
+
if (this.levelValue <= LOG_LEVELS.debug) {
|
|
56228
|
+
this.logger.debug(message, ...args);
|
|
56229
|
+
}
|
|
56230
|
+
}
|
|
56231
|
+
info(message, ...args) {
|
|
56232
|
+
if (this.levelValue <= LOG_LEVELS.info) {
|
|
56233
|
+
this.logger.info(message, ...args);
|
|
56234
|
+
}
|
|
56235
|
+
}
|
|
56236
|
+
warn(message, ...args) {
|
|
56237
|
+
if (this.levelValue <= LOG_LEVELS.warn) {
|
|
56238
|
+
this.logger.warn(message, ...args);
|
|
56239
|
+
}
|
|
56240
|
+
}
|
|
56241
|
+
error(message, ...args) {
|
|
56242
|
+
if (this.levelValue <= LOG_LEVELS.error) {
|
|
56243
|
+
this.logger.error(message, ...args);
|
|
56244
|
+
}
|
|
56245
|
+
}
|
|
56246
|
+
};
|
|
56247
|
+
function createLogger(logger2, logLevel = "") {
|
|
56248
|
+
const level = parseLogLevel(logLevel);
|
|
56249
|
+
if (logger2) {
|
|
56250
|
+
return new FilteredLogger(logger2, level);
|
|
56251
|
+
}
|
|
56252
|
+
return new DefaultLogger(level);
|
|
56253
|
+
}
|
|
56254
|
+
function newLogger(logLevel = "") {
|
|
56255
|
+
return createLogger(void 0, logLevel);
|
|
56256
|
+
}
|
|
56257
|
+
|
|
56258
|
+
// src/sandbox_fs_utils.ts
|
|
56259
|
+
var logger = newLogger();
|
|
56260
|
+
var SANDBOX_FS_TOOLS_PATH = "/__modal/.bin/modal-sandbox-fs-tools";
|
|
56261
|
+
function validateAbsoluteRemotePath(remotePath, operation) {
|
|
56262
|
+
if (!posix.isAbsolute(remotePath)) {
|
|
56263
|
+
throw new InvalidError(
|
|
56264
|
+
`Sandbox.filesystem.${operation}() currently only supports absolute remotePath values`
|
|
56265
|
+
);
|
|
56266
|
+
}
|
|
56267
|
+
}
|
|
56268
|
+
function stderrToText(stderr) {
|
|
56269
|
+
if (typeof stderr === "string") return stderr.trim();
|
|
56270
|
+
return new TextDecoder("utf-8", { fatal: false }).decode(stderr).trim();
|
|
56271
|
+
}
|
|
56272
|
+
function tryParseErrorPayload(stderr) {
|
|
56273
|
+
const text = stderrToText(stderr);
|
|
56274
|
+
if (!text) return null;
|
|
56275
|
+
let payload;
|
|
56276
|
+
try {
|
|
56277
|
+
payload = JSON.parse(text);
|
|
56278
|
+
} catch {
|
|
56279
|
+
return null;
|
|
56280
|
+
}
|
|
56281
|
+
if (typeof payload !== "object" || payload === null) return null;
|
|
56282
|
+
const obj = payload;
|
|
56283
|
+
const errorKind = obj.error_kind;
|
|
56284
|
+
const message = obj.message;
|
|
56285
|
+
if (typeof errorKind !== "string") return null;
|
|
56286
|
+
if (typeof message !== "string" || !message.trim()) return null;
|
|
56287
|
+
const detailRaw = obj.detail;
|
|
56288
|
+
const detail = typeof detailRaw === "string" ? detailRaw : "";
|
|
56289
|
+
return { error_kind: errorKind, message, detail };
|
|
56290
|
+
}
|
|
56291
|
+
function raiseListFilesError(returnCode, stderr, remotePath) {
|
|
56292
|
+
const payload = tryParseErrorPayload(stderr);
|
|
56293
|
+
if (payload) {
|
|
56294
|
+
logger.debug(
|
|
56295
|
+
`sandbox-fs-tools listFiles error: path=${remotePath}, error_kind=${payload.error_kind}, message=${payload.message}, detail=${payload.detail}`
|
|
56296
|
+
);
|
|
56297
|
+
if (payload.error_kind === "NotFound")
|
|
56298
|
+
throw new SandboxFilesystemNotFoundError(
|
|
56299
|
+
`${payload.message}: ${remotePath}`
|
|
56300
|
+
);
|
|
56301
|
+
if (payload.error_kind === "IsFile" || payload.error_kind === "NotDirectory")
|
|
56302
|
+
throw new SandboxFilesystemNotADirectoryError(
|
|
56303
|
+
`${payload.message}: ${remotePath}`
|
|
56304
|
+
);
|
|
56305
|
+
if (payload.error_kind === "PermissionDenied")
|
|
56306
|
+
throw new SandboxFilesystemPermissionError(
|
|
56307
|
+
`${payload.message}: ${remotePath}`
|
|
56308
|
+
);
|
|
56309
|
+
throw new SandboxFilesystemError(payload.message);
|
|
56310
|
+
}
|
|
56311
|
+
const text = stderrToText(stderr);
|
|
56312
|
+
if (text) logger.debug(`Unstructured modal-sandbox-fs-tools stderr: ${text}`);
|
|
56313
|
+
throw new SandboxFilesystemError(
|
|
56314
|
+
`Operation on '${remotePath}' failed with exit code ${returnCode}`
|
|
56315
|
+
);
|
|
56316
|
+
}
|
|
56317
|
+
function makeListFilesCommand(remotePath) {
|
|
56318
|
+
return JSON.stringify({ ListFiles: { path: remotePath } });
|
|
56319
|
+
}
|
|
56320
|
+
function raiseMakeDirectoryError(returnCode, stderr, remotePath) {
|
|
56321
|
+
const payload = tryParseErrorPayload(stderr);
|
|
56322
|
+
if (payload) {
|
|
56323
|
+
logger.debug(
|
|
56324
|
+
`sandbox-fs-tools makeDirectory error: path=${remotePath}, error_kind=${payload.error_kind}, message=${payload.message}, detail=${payload.detail}`
|
|
56325
|
+
);
|
|
56326
|
+
if (payload.error_kind === "NotFound")
|
|
56327
|
+
throw new SandboxFilesystemNotFoundError(
|
|
56328
|
+
`${payload.message}: ${remotePath}`
|
|
56329
|
+
);
|
|
56330
|
+
if (payload.error_kind === "PathAlreadyExists")
|
|
56331
|
+
throw new SandboxFilesystemPathAlreadyExistsError(
|
|
56332
|
+
`${payload.message}: ${remotePath}`
|
|
56333
|
+
);
|
|
56334
|
+
if (payload.error_kind === "NotDirectory")
|
|
56335
|
+
throw new SandboxFilesystemNotADirectoryError(
|
|
56336
|
+
`${payload.message}: ${remotePath}`
|
|
56337
|
+
);
|
|
56338
|
+
if (payload.error_kind === "PermissionDenied")
|
|
56339
|
+
throw new SandboxFilesystemPermissionError(
|
|
56340
|
+
`${payload.message}: ${remotePath}`
|
|
56341
|
+
);
|
|
56342
|
+
if (payload.error_kind === "NotSupported")
|
|
56343
|
+
throw new InvalidError(
|
|
56344
|
+
`${payload.message}: ${remotePath} - this operation is not supported for CloudBucketMounts`
|
|
56345
|
+
);
|
|
56346
|
+
throw new SandboxFilesystemError(payload.message);
|
|
56347
|
+
}
|
|
56348
|
+
const text = stderrToText(stderr);
|
|
56349
|
+
if (text) logger.debug(`Unstructured modal-sandbox-fs-tools stderr: ${text}`);
|
|
56350
|
+
throw new SandboxFilesystemError(
|
|
56351
|
+
`Operation on '${remotePath}' failed with exit code ${returnCode}`
|
|
56352
|
+
);
|
|
56353
|
+
}
|
|
56354
|
+
function makeMakeDirectoryCommand(remotePath, createParents) {
|
|
56355
|
+
return JSON.stringify({
|
|
56356
|
+
MakeDirectory: { path: remotePath, parents: createParents }
|
|
56357
|
+
});
|
|
56358
|
+
}
|
|
56359
|
+
function raiseReadFileError(returnCode, stderr, remotePath) {
|
|
56360
|
+
const payload = tryParseErrorPayload(stderr);
|
|
56361
|
+
if (payload) {
|
|
56362
|
+
logger.debug(
|
|
56363
|
+
`sandbox-fs-tools read error: path=${remotePath}, error_kind=${payload.error_kind}, message=${payload.message}, detail=${payload.detail}`
|
|
56364
|
+
);
|
|
56365
|
+
if (payload.error_kind === "NotFound")
|
|
56366
|
+
throw new SandboxFilesystemNotFoundError(
|
|
56367
|
+
`${payload.message}: ${remotePath}`
|
|
56368
|
+
);
|
|
56369
|
+
if (payload.error_kind === "IsDirectory")
|
|
56370
|
+
throw new SandboxFilesystemIsADirectoryError(
|
|
56371
|
+
`${payload.message}: ${remotePath}`
|
|
56372
|
+
);
|
|
56373
|
+
if (payload.error_kind === "PermissionDenied")
|
|
56374
|
+
throw new SandboxFilesystemPermissionError(
|
|
56375
|
+
`${payload.message}: ${remotePath}`
|
|
56376
|
+
);
|
|
56377
|
+
if (payload.error_kind === "FileTooLarge")
|
|
56378
|
+
throw new SandboxFilesystemFileTooLargeError(
|
|
56379
|
+
`${payload.message}: ${remotePath}`
|
|
56380
|
+
);
|
|
56381
|
+
throw new SandboxFilesystemError(payload.message);
|
|
56382
|
+
}
|
|
56383
|
+
const text = stderrToText(stderr);
|
|
56384
|
+
if (text) logger.debug(`Unstructured modal-sandbox-fs-tools stderr: ${text}`);
|
|
56385
|
+
throw new SandboxFilesystemError(
|
|
56386
|
+
`Operation on '${remotePath}' failed with exit code ${returnCode}`
|
|
56387
|
+
);
|
|
56388
|
+
}
|
|
56389
|
+
function makeReadFileCommand(remotePath) {
|
|
56390
|
+
return JSON.stringify({ ReadFile: { path: remotePath } });
|
|
56391
|
+
}
|
|
56392
|
+
function raiseRemoveError(returnCode, stderr, remotePath) {
|
|
56393
|
+
const payload = tryParseErrorPayload(stderr);
|
|
56394
|
+
if (payload) {
|
|
56395
|
+
logger.debug(
|
|
56396
|
+
`sandbox-fs-tools remove error: path=${remotePath}, error_kind=${payload.error_kind}, message=${payload.message}, detail=${payload.detail}`
|
|
56397
|
+
);
|
|
56398
|
+
if (payload.error_kind === "NotFound")
|
|
56399
|
+
throw new SandboxFilesystemNotFoundError(
|
|
56400
|
+
`${payload.message}: ${remotePath}`
|
|
56401
|
+
);
|
|
56402
|
+
if (payload.error_kind === "DirectoryNotEmpty")
|
|
56403
|
+
throw new SandboxFilesystemDirectoryNotEmptyError(
|
|
56404
|
+
`${payload.message}: ${remotePath}`
|
|
56405
|
+
);
|
|
56406
|
+
if (payload.error_kind === "NotSupported")
|
|
56407
|
+
throw new InvalidError(
|
|
56408
|
+
`${payload.message}: ${remotePath} - this operation is not supported for CloudBucketMounts`
|
|
56409
|
+
);
|
|
56410
|
+
if (payload.error_kind === "PermissionDenied")
|
|
56411
|
+
throw new SandboxFilesystemPermissionError(
|
|
56412
|
+
`${payload.message}: ${remotePath}`
|
|
56413
|
+
);
|
|
56414
|
+
throw new SandboxFilesystemError(payload.message);
|
|
56415
|
+
}
|
|
56416
|
+
const text = stderrToText(stderr);
|
|
56417
|
+
if (text) logger.debug(`Unstructured modal-sandbox-fs-tools stderr: ${text}`);
|
|
56418
|
+
throw new SandboxFilesystemError(
|
|
56419
|
+
`Operation on '${remotePath}' failed with exit code ${returnCode}`
|
|
56420
|
+
);
|
|
56421
|
+
}
|
|
56422
|
+
function makeRemoveCommand(remotePath, recursive) {
|
|
56423
|
+
return JSON.stringify({ Remove: { path: remotePath, recursive } });
|
|
56424
|
+
}
|
|
56425
|
+
function raiseStatError(returnCode, stderr, remotePath) {
|
|
56426
|
+
const payload = tryParseErrorPayload(stderr);
|
|
56427
|
+
if (payload) {
|
|
56428
|
+
logger.debug(
|
|
56429
|
+
`sandbox-fs-tools stat error: path=${remotePath}, error_kind=${payload.error_kind}, message=${payload.message}, detail=${payload.detail}`
|
|
56430
|
+
);
|
|
56431
|
+
if (payload.error_kind === "NotFound")
|
|
56432
|
+
throw new SandboxFilesystemNotFoundError(
|
|
56433
|
+
`${payload.message}: ${remotePath}`
|
|
56434
|
+
);
|
|
56435
|
+
if (payload.error_kind === "NotDirectory")
|
|
56436
|
+
throw new SandboxFilesystemNotADirectoryError(
|
|
56437
|
+
`${payload.message}: ${remotePath}`
|
|
56438
|
+
);
|
|
56439
|
+
if (payload.error_kind === "PermissionDenied")
|
|
56440
|
+
throw new SandboxFilesystemPermissionError(
|
|
56441
|
+
`${payload.message}: ${remotePath}`
|
|
56442
|
+
);
|
|
56443
|
+
throw new SandboxFilesystemError(payload.message);
|
|
56444
|
+
}
|
|
56445
|
+
const text = stderrToText(stderr);
|
|
56446
|
+
if (text) logger.debug(`Unstructured modal-sandbox-fs-tools stderr: ${text}`);
|
|
56447
|
+
throw new SandboxFilesystemError(
|
|
56448
|
+
`Operation on '${remotePath}' failed with exit code ${returnCode}`
|
|
56449
|
+
);
|
|
56450
|
+
}
|
|
56451
|
+
function makeStatCommand(remotePath) {
|
|
56452
|
+
return JSON.stringify({ Stat: { path: remotePath } });
|
|
56453
|
+
}
|
|
56454
|
+
function raiseWriteFileError(returnCode, stderr, remotePath) {
|
|
56455
|
+
const payload = tryParseErrorPayload(stderr);
|
|
56456
|
+
if (payload) {
|
|
56457
|
+
logger.debug(
|
|
56458
|
+
`sandbox-fs-tools write error: path=${remotePath}, error_kind=${payload.error_kind}, message=${payload.message}, detail=${payload.detail}`
|
|
56459
|
+
);
|
|
56460
|
+
if (payload.error_kind === "NotDirectory" || payload.error_kind === "AlreadyExists")
|
|
56461
|
+
throw new SandboxFilesystemNotADirectoryError(
|
|
56462
|
+
`${payload.message}: ${remotePath}`
|
|
56463
|
+
);
|
|
56464
|
+
if (payload.error_kind === "IsDirectory")
|
|
56465
|
+
throw new SandboxFilesystemIsADirectoryError(
|
|
56466
|
+
`${payload.message}: ${remotePath}`
|
|
56467
|
+
);
|
|
56468
|
+
if (payload.error_kind === "PermissionDenied")
|
|
56469
|
+
throw new SandboxFilesystemPermissionError(
|
|
56470
|
+
`${payload.message}: ${remotePath}`
|
|
56471
|
+
);
|
|
56472
|
+
throw new SandboxFilesystemError(payload.message);
|
|
56473
|
+
}
|
|
56474
|
+
const text = stderrToText(stderr);
|
|
56475
|
+
if (text) logger.debug(`Unstructured modal-sandbox-fs-tools stderr: ${text}`);
|
|
56476
|
+
throw new SandboxFilesystemError(
|
|
56477
|
+
`Operation on '${remotePath}' failed with exit code ${returnCode}`
|
|
56478
|
+
);
|
|
56479
|
+
}
|
|
56480
|
+
function makeWriteFileCommand(remotePath) {
|
|
56481
|
+
return JSON.stringify({ WriteFile: { path: remotePath } });
|
|
56482
|
+
}
|
|
56483
|
+
var SUPPORT_ERROR_CODE_RE = /Error code:\s*([A-Z0-9]{8})/;
|
|
56484
|
+
function extractSupportErrorCode(err) {
|
|
56485
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
56486
|
+
const match = SUPPORT_ERROR_CODE_RE.exec(message);
|
|
56487
|
+
return match ? match[1] : null;
|
|
56488
|
+
}
|
|
56489
|
+
function describeError(err) {
|
|
56490
|
+
if (err instanceof Error) return `${err.name}: ${err.message}`;
|
|
56491
|
+
return String(err);
|
|
56492
|
+
}
|
|
56493
|
+
function isSandboxUnavailableError(err) {
|
|
56494
|
+
if (err instanceof NotFoundError) return true;
|
|
56495
|
+
if (err instanceof ClientError9) {
|
|
56496
|
+
return err.code === Status9.NOT_FOUND || err.code === Status9.CANCELLED || err.code === Status9.UNKNOWN || err.code === Status9.DEADLINE_EXCEEDED || err.code === Status9.UNAVAILABLE;
|
|
56497
|
+
}
|
|
56498
|
+
return false;
|
|
56499
|
+
}
|
|
56500
|
+
function translateExecSandboxUnavailableError(operation, remotePath, err) {
|
|
56501
|
+
logger.debug(
|
|
56502
|
+
`Sandbox filesystem control-plane error for operation=${operation}, path=${remotePath}: ${describeError(err)}`
|
|
56503
|
+
);
|
|
56504
|
+
return new NotFoundError(
|
|
56505
|
+
"The Sandbox is unavailable. This Sandbox may have already shut down."
|
|
56506
|
+
);
|
|
56507
|
+
}
|
|
56508
|
+
function translateExecUnexpectedError(operation, remotePath, err) {
|
|
56509
|
+
const code = extractSupportErrorCode(err);
|
|
56510
|
+
logger.debug(
|
|
56511
|
+
`Unexpected sandbox filesystem exec error for operation=${operation}, path=${remotePath}: ${describeError(err)}`
|
|
56512
|
+
);
|
|
56513
|
+
const supportSuffix = code ? `please contact support@modal.com (Error code: ${code})` : "please contact support@modal.com";
|
|
56514
|
+
return new SandboxFilesystemError(
|
|
56515
|
+
`An unexpected error occurred, ${supportSuffix}`
|
|
56516
|
+
);
|
|
56517
|
+
}
|
|
56518
|
+
async function translateExecErrors(operation, remotePath, fn) {
|
|
56519
|
+
try {
|
|
56520
|
+
return await fn();
|
|
56521
|
+
} catch (err) {
|
|
56522
|
+
if (isSandboxUnavailableError(err)) {
|
|
56523
|
+
throw translateExecSandboxUnavailableError(operation, remotePath, err);
|
|
56524
|
+
}
|
|
56525
|
+
if (err instanceof ClientError9) {
|
|
56526
|
+
throw translateExecUnexpectedError(operation, remotePath, err);
|
|
56527
|
+
}
|
|
56528
|
+
throw err;
|
|
56529
|
+
}
|
|
56530
|
+
}
|
|
56531
|
+
|
|
56532
|
+
// src/sandbox_fs.ts
|
|
56533
|
+
function parseFileEntry(raw) {
|
|
56534
|
+
return {
|
|
56535
|
+
name: raw.name,
|
|
56536
|
+
path: raw.path,
|
|
56537
|
+
type: raw.type,
|
|
56538
|
+
size: raw.size,
|
|
56539
|
+
mode: raw.mode,
|
|
56540
|
+
permissions: raw.permissions,
|
|
56541
|
+
owner: raw.owner,
|
|
56542
|
+
group: raw.group,
|
|
56543
|
+
modifiedTime: raw.modified_time,
|
|
56544
|
+
symlinkTarget: raw.symlink_target ?? null
|
|
56545
|
+
};
|
|
56546
|
+
}
|
|
56547
|
+
var WRITE_CHUNK_SIZE = 4 * 1024 * 1024;
|
|
56548
|
+
function toUint8Array(data) {
|
|
56549
|
+
if (data instanceof ArrayBuffer) return new Uint8Array(data);
|
|
56550
|
+
if (data instanceof Uint8Array) return data;
|
|
56551
|
+
throw new TypeError(
|
|
56552
|
+
`Expected Uint8Array, ArrayBuffer, or Buffer, got ${typeof data}`
|
|
56553
|
+
);
|
|
56554
|
+
}
|
|
56555
|
+
var SandboxFilesystem = class {
|
|
56556
|
+
/** @ignore */
|
|
56557
|
+
constructor(sandbox) {
|
|
56558
|
+
this.sandbox = sandbox;
|
|
56559
|
+
}
|
|
56560
|
+
/**
|
|
56561
|
+
* Copy a local file into the Sandbox.
|
|
56562
|
+
*
|
|
56563
|
+
* `remotePath` must be an absolute path to a file in the Sandbox.
|
|
56564
|
+
* Parent directories are created if needed. The remote file is overwritten
|
|
56565
|
+
* if it already exists.
|
|
56566
|
+
*
|
|
56567
|
+
* @throws {SandboxFilesystemNotADirectoryError} a parent component of `remotePath` is not a directory.
|
|
56568
|
+
* @throws {SandboxFilesystemIsADirectoryError} `remotePath` points to a directory.
|
|
56569
|
+
* @throws {SandboxFilesystemPermissionError} write permission is denied in the Sandbox.
|
|
56570
|
+
* @throws {SandboxFilesystemError} the command fails for any other reason.
|
|
56571
|
+
* @throws {Error} `localPath` does not exist, is a directory, or cannot be read (`ENOENT`, `EISDIR`, `EACCES`).
|
|
56572
|
+
*/
|
|
56573
|
+
async copyFromLocal(localPath, remotePath) {
|
|
56574
|
+
validateAbsoluteRemotePath(remotePath, "copyFromLocal");
|
|
56575
|
+
await translateExecErrors("copyFromLocal", remotePath, async () => {
|
|
56576
|
+
const process2 = await this.sandbox.exec(
|
|
56577
|
+
[SANDBOX_FS_TOOLS_PATH, makeWriteFileCommand(remotePath)],
|
|
56578
|
+
{ mode: "binary" }
|
|
56579
|
+
);
|
|
56580
|
+
const writer = process2.stdin.getWriter();
|
|
56581
|
+
try {
|
|
56582
|
+
const fileStream = createReadStream(localPath);
|
|
56583
|
+
for await (const chunk of fileStream) {
|
|
56584
|
+
await writer.write(chunk);
|
|
56585
|
+
}
|
|
56586
|
+
await writer.close();
|
|
56587
|
+
} catch (err) {
|
|
56588
|
+
if (err instanceof ClientError10 && (err.code === Status10.FAILED_PRECONDITION || err.code === Status10.ABORTED)) {
|
|
56589
|
+
await process2.closeStdin();
|
|
56590
|
+
} else {
|
|
56591
|
+
await writer.abort(err).catch(() => {
|
|
56592
|
+
});
|
|
56593
|
+
throw err;
|
|
56594
|
+
}
|
|
56595
|
+
} finally {
|
|
56596
|
+
writer.releaseLock();
|
|
56597
|
+
}
|
|
56598
|
+
const returnCode = await process2.wait();
|
|
56599
|
+
if (returnCode !== 0) {
|
|
56600
|
+
const stderr = await process2.stderr.readBytes();
|
|
56601
|
+
raiseWriteFileError(returnCode, stderr, remotePath);
|
|
56602
|
+
}
|
|
56603
|
+
});
|
|
56604
|
+
}
|
|
56605
|
+
/**
|
|
56606
|
+
* Copy a file from the Sandbox to a local path.
|
|
56607
|
+
*
|
|
56608
|
+
* `remotePath` must be an absolute path to a file in the Sandbox.
|
|
56609
|
+
* Parent directories for `localPath` are created if needed. The local file
|
|
56610
|
+
* is overwritten if it already exists.
|
|
56611
|
+
*
|
|
56612
|
+
* @throws {SandboxFilesystemNotFoundError} the remote path does not exist.
|
|
56613
|
+
* @throws {SandboxFilesystemIsADirectoryError} the remote path points to a directory.
|
|
56614
|
+
* @throws {SandboxFilesystemFileTooLargeError} the file exceeds the read size limit.
|
|
56615
|
+
* @throws {SandboxFilesystemPermissionError} read permission is denied in the Sandbox.
|
|
56616
|
+
* @throws {SandboxFilesystemError} the command fails for any other reason.
|
|
56617
|
+
* @throws {Error} `localPath` points to a directory, or writing it is not permitted.
|
|
56618
|
+
*/
|
|
56619
|
+
async copyToLocal(remotePath, localPath) {
|
|
56620
|
+
validateAbsoluteRemotePath(remotePath, "copyToLocal");
|
|
56621
|
+
const dir = dirname(localPath);
|
|
56622
|
+
const createdDir = await mkdir(dir, { recursive: true });
|
|
56623
|
+
const tmpPath = `${dir}/.modal-sandbox-fs-tmp-${randomBytes(8).toString("hex")}`;
|
|
56624
|
+
try {
|
|
56625
|
+
await translateExecErrors("copyToLocal", remotePath, async () => {
|
|
56626
|
+
const process2 = await this.sandbox.exec(
|
|
56627
|
+
[SANDBOX_FS_TOOLS_PATH, makeReadFileCommand(remotePath)],
|
|
56628
|
+
{ mode: "binary" }
|
|
56629
|
+
);
|
|
56630
|
+
const returnCode = await process2.wait();
|
|
56631
|
+
if (returnCode !== 0) {
|
|
56632
|
+
const stderr = await process2.stderr.readBytes();
|
|
56633
|
+
raiseReadFileError(returnCode, stderr, remotePath);
|
|
56634
|
+
}
|
|
56635
|
+
await process2.stdout.pipeTo(Writable.toWeb(createWriteStream(tmpPath)));
|
|
56636
|
+
});
|
|
56637
|
+
await rename(tmpPath, localPath);
|
|
56638
|
+
} catch (err) {
|
|
56639
|
+
await unlink(tmpPath).catch(() => {
|
|
56640
|
+
});
|
|
56641
|
+
if (createdDir !== void 0) {
|
|
56642
|
+
await rm(createdDir, { recursive: true, force: true }).catch(() => {
|
|
56643
|
+
});
|
|
56644
|
+
}
|
|
56645
|
+
throw err;
|
|
56646
|
+
}
|
|
56647
|
+
}
|
|
56648
|
+
/**
|
|
56649
|
+
* List files and directories in a Sandbox directory.
|
|
56650
|
+
*
|
|
56651
|
+
* `remotePath` must be an absolute path to a directory in the Sandbox.
|
|
56652
|
+
* Returns an array of {@link FileInfo} objects sorted by name.
|
|
56653
|
+
*
|
|
56654
|
+
* @throws {SandboxFilesystemNotFoundError} the path does not exist.
|
|
56655
|
+
* @throws {SandboxFilesystemNotADirectoryError} the path is not a directory.
|
|
56656
|
+
* @throws {SandboxFilesystemPermissionError} read permission is denied.
|
|
56657
|
+
* @throws {SandboxFilesystemError} the command fails for any other reason.
|
|
56658
|
+
*/
|
|
56659
|
+
async listFiles(remotePath) {
|
|
56660
|
+
validateAbsoluteRemotePath(remotePath, "listFiles");
|
|
56661
|
+
const json = await translateExecErrors(
|
|
56662
|
+
"listFiles",
|
|
56663
|
+
remotePath,
|
|
56664
|
+
async () => {
|
|
56665
|
+
const process2 = await this.sandbox.exec(
|
|
56666
|
+
[SANDBOX_FS_TOOLS_PATH, makeListFilesCommand(remotePath)],
|
|
56667
|
+
{ mode: "text" }
|
|
56668
|
+
);
|
|
56669
|
+
const returnCode = await process2.wait();
|
|
56670
|
+
if (returnCode !== 0) {
|
|
56671
|
+
const stderr = await process2.stderr.readBytes();
|
|
56672
|
+
raiseListFilesError(returnCode, stderr, remotePath);
|
|
56673
|
+
}
|
|
56674
|
+
return process2.stdout.readText();
|
|
56675
|
+
}
|
|
56676
|
+
);
|
|
56677
|
+
return JSON.parse(json).map(parseFileEntry);
|
|
56678
|
+
}
|
|
56679
|
+
/**
|
|
56680
|
+
* Create a new directory in the Sandbox.
|
|
56681
|
+
*
|
|
56682
|
+
* `remotePath` must be an absolute path in the Sandbox.
|
|
56683
|
+
*
|
|
56684
|
+
* When `createParents` is `true` (the default), any missing parent
|
|
56685
|
+
* directories are created and the call is idempotent (succeeds if the
|
|
56686
|
+
* directory already exists). When `createParents` is `false`, the immediate
|
|
56687
|
+
* parent must already exist and the path must not already exist.
|
|
56688
|
+
*
|
|
56689
|
+
* @throws {SandboxFilesystemNotFoundError} the parent does not exist and `createParents` is `false`.
|
|
56690
|
+
* @throws {SandboxFilesystemPathAlreadyExistsError} the path already exists and `createParents` is `false`.
|
|
56691
|
+
* @throws {SandboxFilesystemNotADirectoryError} a path component is not a directory.
|
|
56692
|
+
* @throws {SandboxFilesystemPermissionError} creation is not permitted.
|
|
56693
|
+
* @throws {InvalidError} the operation is not supported by the mount.
|
|
56694
|
+
* @throws {SandboxFilesystemError} the command fails for any other reason.
|
|
56695
|
+
*/
|
|
56696
|
+
async makeDirectory(remotePath, options) {
|
|
56697
|
+
validateAbsoluteRemotePath(remotePath, "makeDirectory");
|
|
56698
|
+
const createParents = options?.createParents ?? true;
|
|
56699
|
+
await translateExecErrors("makeDirectory", remotePath, async () => {
|
|
56700
|
+
const process2 = await this.sandbox.exec(
|
|
56701
|
+
[
|
|
56702
|
+
SANDBOX_FS_TOOLS_PATH,
|
|
56703
|
+
makeMakeDirectoryCommand(remotePath, createParents)
|
|
56704
|
+
],
|
|
56705
|
+
{ mode: "binary" }
|
|
56706
|
+
);
|
|
56707
|
+
const returnCode = await process2.wait();
|
|
56708
|
+
if (returnCode !== 0) {
|
|
56709
|
+
const stderr = await process2.stderr.readBytes();
|
|
56710
|
+
raiseMakeDirectoryError(returnCode, stderr, remotePath);
|
|
56711
|
+
}
|
|
56712
|
+
});
|
|
56713
|
+
}
|
|
56714
|
+
/**
|
|
56715
|
+
* Read a file from the Sandbox and return its contents as bytes.
|
|
56716
|
+
*
|
|
56717
|
+
* `remotePath` must be an absolute path to a file in the Sandbox.
|
|
56718
|
+
*
|
|
56719
|
+
* @throws {SandboxFilesystemNotFoundError} the path does not exist.
|
|
56720
|
+
* @throws {SandboxFilesystemIsADirectoryError} the path points to a directory.
|
|
56721
|
+
* @throws {SandboxFilesystemFileTooLargeError} the file exceeds the read size limit.
|
|
56722
|
+
* @throws {SandboxFilesystemPermissionError} read permission is denied.
|
|
56723
|
+
* @throws {SandboxFilesystemError} the command fails for any other reason.
|
|
56724
|
+
*/
|
|
56725
|
+
async readBytes(remotePath) {
|
|
56726
|
+
validateAbsoluteRemotePath(remotePath, "readBytes");
|
|
56727
|
+
return translateExecErrors("readBytes", remotePath, async () => {
|
|
56728
|
+
const process2 = await this.sandbox.exec(
|
|
56729
|
+
[SANDBOX_FS_TOOLS_PATH, makeReadFileCommand(remotePath)],
|
|
56730
|
+
{ mode: "binary" }
|
|
56731
|
+
);
|
|
56732
|
+
const returnCode = await process2.wait();
|
|
56733
|
+
if (returnCode !== 0) {
|
|
56734
|
+
const stderr = await process2.stderr.readBytes();
|
|
56735
|
+
raiseReadFileError(returnCode, stderr, remotePath);
|
|
56736
|
+
}
|
|
56737
|
+
return process2.stdout.readBytes();
|
|
56738
|
+
});
|
|
56739
|
+
}
|
|
56740
|
+
/**
|
|
56741
|
+
* Read a file from the Sandbox and return its contents as a UTF-8 string.
|
|
56742
|
+
*
|
|
56743
|
+
* `remotePath` must be an absolute path to a file in the Sandbox.
|
|
56744
|
+
*
|
|
56745
|
+
* @throws {SandboxFilesystemNotFoundError} the path does not exist.
|
|
56746
|
+
* @throws {SandboxFilesystemIsADirectoryError} the path points to a directory.
|
|
56747
|
+
* @throws {SandboxFilesystemFileTooLargeError} the file exceeds the read size limit.
|
|
56748
|
+
* @throws {SandboxFilesystemPermissionError} read permission is denied.
|
|
56749
|
+
* @throws {SandboxFilesystemError} the command fails for any other reason.
|
|
56750
|
+
*/
|
|
56751
|
+
async readText(remotePath) {
|
|
56752
|
+
validateAbsoluteRemotePath(remotePath, "readText");
|
|
56753
|
+
return translateExecErrors("readText", remotePath, async () => {
|
|
56754
|
+
const process2 = await this.sandbox.exec(
|
|
56755
|
+
[SANDBOX_FS_TOOLS_PATH, makeReadFileCommand(remotePath)],
|
|
56756
|
+
{ mode: "text" }
|
|
56757
|
+
);
|
|
56758
|
+
const returnCode = await process2.wait();
|
|
56759
|
+
if (returnCode !== 0) {
|
|
56760
|
+
const stderr = await process2.stderr.readBytes();
|
|
56761
|
+
raiseReadFileError(returnCode, stderr, remotePath);
|
|
56762
|
+
}
|
|
56763
|
+
return process2.stdout.readText();
|
|
56764
|
+
});
|
|
56765
|
+
}
|
|
56766
|
+
/**
|
|
56767
|
+
* Remove a file or directory in the Sandbox.
|
|
56768
|
+
*
|
|
56769
|
+
* `remotePath` must be an absolute path in the Sandbox. When `remotePath`
|
|
56770
|
+
* is a directory and `recursive` is `false` (the default), it is removed
|
|
56771
|
+
* only if empty. When `recursive` is `true`, the directory and all its
|
|
56772
|
+
* contents are removed. Recursive removal is not supported on all mounts —
|
|
56773
|
+
* `CloudBucketMount` does not support it.
|
|
56774
|
+
*
|
|
56775
|
+
* @throws {SandboxFilesystemNotFoundError} the path does not exist.
|
|
56776
|
+
* @throws {SandboxFilesystemDirectoryNotEmptyError} `recursive` is `false` and the directory is not empty.
|
|
56777
|
+
* @throws {SandboxFilesystemPermissionError} removal is not permitted.
|
|
56778
|
+
* @throws {InvalidError} the operation is not supported by the mount.
|
|
56779
|
+
* @throws {SandboxFilesystemError} the command fails for any other reason.
|
|
56780
|
+
*/
|
|
56781
|
+
async remove(remotePath, options) {
|
|
56782
|
+
validateAbsoluteRemotePath(remotePath, "remove");
|
|
56783
|
+
const recursive = options?.recursive ?? false;
|
|
56784
|
+
await translateExecErrors("remove", remotePath, async () => {
|
|
56785
|
+
const process2 = await this.sandbox.exec(
|
|
56786
|
+
[SANDBOX_FS_TOOLS_PATH, makeRemoveCommand(remotePath, recursive)],
|
|
56787
|
+
{ mode: "binary" }
|
|
56788
|
+
);
|
|
56789
|
+
const returnCode = await process2.wait();
|
|
56790
|
+
if (returnCode !== 0) {
|
|
56791
|
+
const stderr = await process2.stderr.readBytes();
|
|
56792
|
+
raiseRemoveError(returnCode, stderr, remotePath);
|
|
56793
|
+
}
|
|
56794
|
+
});
|
|
56795
|
+
}
|
|
56796
|
+
/**
|
|
56797
|
+
* Return metadata for a single file, directory, or symlink in the Sandbox.
|
|
56798
|
+
*
|
|
56799
|
+
* `remotePath` must be an absolute path in the Sandbox. If `remotePath` is
|
|
56800
|
+
* a symlink, the returned {@link FileInfo} describes the symlink itself, not
|
|
56801
|
+
* the target it points to.
|
|
56802
|
+
*
|
|
56803
|
+
* @throws {SandboxFilesystemNotFoundError} the path does not exist.
|
|
56804
|
+
* @throws {SandboxFilesystemNotADirectoryError} a non-leaf component of the path is not a directory.
|
|
56805
|
+
* @throws {SandboxFilesystemPermissionError} a path component is not searchable.
|
|
56806
|
+
* @throws {SandboxFilesystemError} the command fails for any other reason.
|
|
56807
|
+
*/
|
|
56808
|
+
async stat(remotePath) {
|
|
56809
|
+
validateAbsoluteRemotePath(remotePath, "stat");
|
|
56810
|
+
const stdout = await translateExecErrors("stat", remotePath, async () => {
|
|
56811
|
+
const process2 = await this.sandbox.exec(
|
|
56812
|
+
[SANDBOX_FS_TOOLS_PATH, makeStatCommand(remotePath)],
|
|
56813
|
+
{ mode: "text" }
|
|
56814
|
+
);
|
|
56815
|
+
const returnCode = await process2.wait();
|
|
56816
|
+
if (returnCode !== 0) {
|
|
56817
|
+
const stderr = await process2.stderr.readBytes();
|
|
56818
|
+
raiseStatError(returnCode, stderr, remotePath);
|
|
56819
|
+
}
|
|
56820
|
+
return await process2.stdout.readText();
|
|
56821
|
+
});
|
|
56822
|
+
return parseFileEntry(JSON.parse(stdout));
|
|
56823
|
+
}
|
|
56824
|
+
/**
|
|
56825
|
+
* Write binary content to a file in the Sandbox.
|
|
56826
|
+
*
|
|
56827
|
+
* `remotePath` must be an absolute path to a file in the Sandbox.
|
|
56828
|
+
* Parent directories are created if needed. The remote file is overwritten
|
|
56829
|
+
* if it already exists.
|
|
56830
|
+
*
|
|
56831
|
+
* @throws {TypeError} `data` is not a `Uint8Array`, `ArrayBuffer`, or `Buffer`.
|
|
56832
|
+
* @throws {SandboxFilesystemNotADirectoryError} a parent component of `remotePath` is not a directory.
|
|
56833
|
+
* @throws {SandboxFilesystemIsADirectoryError} `remotePath` points to a directory.
|
|
56834
|
+
* @throws {SandboxFilesystemPermissionError} write permission is denied.
|
|
56835
|
+
* @throws {SandboxFilesystemError} the command fails for any other reason.
|
|
56836
|
+
*/
|
|
56837
|
+
async writeBytes(data, remotePath) {
|
|
56838
|
+
validateAbsoluteRemotePath(remotePath, "writeBytes");
|
|
56839
|
+
const bytes = toUint8Array(data);
|
|
56840
|
+
await translateExecErrors("writeBytes", remotePath, async () => {
|
|
56841
|
+
const process2 = await this.sandbox.exec(
|
|
56842
|
+
[SANDBOX_FS_TOOLS_PATH, makeWriteFileCommand(remotePath)],
|
|
56843
|
+
{ mode: "binary" }
|
|
56844
|
+
);
|
|
56845
|
+
const writer = process2.stdin.getWriter();
|
|
56846
|
+
try {
|
|
56847
|
+
const end = Math.max(bytes.length, 1);
|
|
56848
|
+
for (let offset = 0; offset < end; offset += WRITE_CHUNK_SIZE) {
|
|
56849
|
+
await writer.write(bytes.subarray(offset, offset + WRITE_CHUNK_SIZE));
|
|
56850
|
+
}
|
|
56851
|
+
await writer.close();
|
|
56852
|
+
} catch (err) {
|
|
56853
|
+
if (err instanceof ClientError10 && (err.code === Status10.FAILED_PRECONDITION || err.code === Status10.ABORTED)) {
|
|
56854
|
+
await process2.closeStdin();
|
|
56855
|
+
} else {
|
|
56856
|
+
await writer.abort(err).catch(() => {
|
|
56857
|
+
});
|
|
56858
|
+
throw err;
|
|
56859
|
+
}
|
|
56860
|
+
} finally {
|
|
56861
|
+
writer.releaseLock();
|
|
56862
|
+
}
|
|
56863
|
+
const returnCode = await process2.wait();
|
|
56864
|
+
if (returnCode !== 0) {
|
|
56865
|
+
const stderr = await process2.stderr.readBytes();
|
|
56866
|
+
raiseWriteFileError(returnCode, stderr, remotePath);
|
|
56867
|
+
}
|
|
56868
|
+
});
|
|
56869
|
+
}
|
|
56870
|
+
/**
|
|
56871
|
+
* Write UTF-8 text to a file in the Sandbox.
|
|
56872
|
+
*
|
|
56873
|
+
* `remotePath` must be an absolute path to a file in the Sandbox.
|
|
56874
|
+
* Parent directories are created if needed. The remote file is overwritten
|
|
56875
|
+
* if it already exists.
|
|
56876
|
+
*
|
|
56877
|
+
* @throws {TypeError} `data` is not a string.
|
|
56878
|
+
* @throws {SandboxFilesystemNotADirectoryError} a parent component of `remotePath` is not a directory.
|
|
56879
|
+
* @throws {SandboxFilesystemIsADirectoryError} `remotePath` points to a directory.
|
|
56880
|
+
* @throws {SandboxFilesystemPermissionError} write permission is denied.
|
|
56881
|
+
* @throws {SandboxFilesystemError} the command fails for any other reason.
|
|
56882
|
+
*/
|
|
56883
|
+
async writeText(data, remotePath) {
|
|
56884
|
+
validateAbsoluteRemotePath(remotePath, "writeText");
|
|
56885
|
+
if (typeof data !== "string")
|
|
56886
|
+
throw new TypeError(`writeText() expects a string, got ${typeof data}`);
|
|
56887
|
+
await this.writeBytes(new TextEncoder().encode(data), remotePath);
|
|
56888
|
+
}
|
|
56889
|
+
};
|
|
56890
|
+
|
|
55293
56891
|
// src/streams.ts
|
|
55294
56892
|
function toModalReadStream(stream) {
|
|
55295
56893
|
return Object.assign(stream, readMixin);
|
|
@@ -55405,6 +57003,27 @@ var SB_LOGS_INITIAL_DELAY_MS = 10;
|
|
|
55405
57003
|
var SB_LOGS_DELAY_FACTOR = 2;
|
|
55406
57004
|
var SB_LOGS_MAX_RETRIES = 10;
|
|
55407
57005
|
var TTL_NO_EXPIRY_SENTINEL = -1;
|
|
57006
|
+
var V1_SANDBOX_ID_ALPHABET = new Set(
|
|
57007
|
+
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
|
57008
|
+
);
|
|
57009
|
+
var ULID_ALPHABET = new Set("0123456789ABCDEFGHJKMNPQRSTVWXYZ");
|
|
57010
|
+
function isV1SandboxId(sandboxId) {
|
|
57011
|
+
const [prefix, suffix, ...extra] = sandboxId.split("-");
|
|
57012
|
+
return prefix === "sb" && extra.length === 0 && suffix !== void 0 && suffix.length === 22 && Array.from(suffix).every((ch) => V1_SANDBOX_ID_ALPHABET.has(ch));
|
|
57013
|
+
}
|
|
57014
|
+
function isV2SandboxId(sandboxId) {
|
|
57015
|
+
const [prefix, suffix, ...extra] = sandboxId.split("-");
|
|
57016
|
+
return prefix === "sb" && extra.length === 0 && suffix !== void 0 && suffix.length === 26 && "01234567".includes(suffix[0]) && Array.from(suffix).every((ch) => ULID_ALPHABET.has(ch));
|
|
57017
|
+
}
|
|
57018
|
+
function getSandboxVersion(sandboxId) {
|
|
57019
|
+
if (isV2SandboxId(sandboxId)) {
|
|
57020
|
+
return "V2" /* V2 */;
|
|
57021
|
+
}
|
|
57022
|
+
if (isV1SandboxId(sandboxId)) {
|
|
57023
|
+
return "V1" /* V1 */;
|
|
57024
|
+
}
|
|
57025
|
+
throw new InvalidError(`Invalid Sandbox ID: ${sandboxId}`);
|
|
57026
|
+
}
|
|
55408
57027
|
var Probe2 = class _Probe {
|
|
55409
57028
|
#tcpPort;
|
|
55410
57029
|
#execArgv;
|
|
@@ -55506,12 +57125,9 @@ async function buildSandboxCreateRequestProto(appId, imageId, params = {}) {
|
|
|
55506
57125
|
if (params.workdir && !params.workdir.startsWith("/")) {
|
|
55507
57126
|
throw new Error(`workdir must be an absolute path, got: ${params.workdir}`);
|
|
55508
57127
|
}
|
|
55509
|
-
const volumeMounts = params.volumes ? Object.entries(params.volumes).map(
|
|
55510
|
-
|
|
55511
|
-
|
|
55512
|
-
allowBackgroundCommits: true,
|
|
55513
|
-
readOnly: volume.isReadOnly
|
|
55514
|
-
})) : [];
|
|
57128
|
+
const volumeMounts = params.volumes ? Object.entries(params.volumes).map(
|
|
57129
|
+
([mountPath, volume]) => volumeToMountProto(mountPath, volume)
|
|
57130
|
+
) : [];
|
|
55515
57131
|
const cloudBucketMounts = params.cloudBucketMounts ? Object.entries(params.cloudBucketMounts).map(
|
|
55516
57132
|
([mountPath, mount]) => mount.toProto(mountPath)
|
|
55517
57133
|
) : [];
|
|
@@ -55748,7 +57364,7 @@ var SandboxService = class {
|
|
|
55748
57364
|
try {
|
|
55749
57365
|
createResp = await this.#client.cpClient.sandboxCreate(createReq);
|
|
55750
57366
|
} catch (err) {
|
|
55751
|
-
if (err instanceof
|
|
57367
|
+
if (err instanceof ClientError11 && err.code === Status11.ALREADY_EXISTS) {
|
|
55752
57368
|
throw new AlreadyExistsError(err.details || err.message);
|
|
55753
57369
|
}
|
|
55754
57370
|
throw err;
|
|
@@ -55762,6 +57378,20 @@ var SandboxService = class {
|
|
|
55762
57378
|
}
|
|
55763
57379
|
/**
|
|
55764
57380
|
* Create a new {@link Sandbox} using the experimental V2 backend.
|
|
57381
|
+
*
|
|
57382
|
+
* Supported features include exec, encrypted tunnels, wait/poll/terminate,
|
|
57383
|
+
* CPU and memory configuration, and region placement.
|
|
57384
|
+
*
|
|
57385
|
+
* Features like tags, filesystem snapshots, memory snapshots, volumes, cloud
|
|
57386
|
+
* bucket mounts, GPUs, custom domains, OIDC identity tokens, proxies, and
|
|
57387
|
+
* readiness probes are not supported.
|
|
57388
|
+
*
|
|
57389
|
+
* V2 sandboxes created with this method are not currently returned by
|
|
57390
|
+
* {@link SandboxService#list client.sandboxes.list()} and cannot be looked up
|
|
57391
|
+
* with {@link SandboxService#fromName client.sandboxes.fromName()}. Store
|
|
57392
|
+
* {@link Sandbox#sandboxId sandbox.sandboxId} if you need to retrieve the
|
|
57393
|
+
* sandbox later, and use {@link SandboxService#fromId client.sandboxes.fromId()}
|
|
57394
|
+
* to reattach.
|
|
55765
57395
|
*/
|
|
55766
57396
|
async experimentalCreate(app, image, params = {}) {
|
|
55767
57397
|
await image.build(app);
|
|
@@ -55785,7 +57415,7 @@ var SandboxService = class {
|
|
|
55785
57415
|
try {
|
|
55786
57416
|
createResp = await this.#client.cpClient.sandboxCreateV2(createReq);
|
|
55787
57417
|
} catch (err) {
|
|
55788
|
-
if (err instanceof
|
|
57418
|
+
if (err instanceof ClientError11 && err.code === Status11.ALREADY_EXISTS) {
|
|
55789
57419
|
throw new AlreadyExistsError(err.details || err.message);
|
|
55790
57420
|
}
|
|
55791
57421
|
throw err;
|
|
@@ -55812,17 +57442,21 @@ var SandboxService = class {
|
|
|
55812
57442
|
* @returns Sandbox with ID
|
|
55813
57443
|
*/
|
|
55814
57444
|
async fromId(sandboxId) {
|
|
57445
|
+
const sandboxVersion = getSandboxVersion(sandboxId);
|
|
57446
|
+
const isV2 = sandboxVersion === "V2" /* V2 */;
|
|
57447
|
+
const req = { sandboxId, timeout: 0 };
|
|
55815
57448
|
try {
|
|
55816
|
-
|
|
55817
|
-
|
|
55818
|
-
|
|
55819
|
-
|
|
57449
|
+
if (isV2) {
|
|
57450
|
+
await this.#client.cpClient.sandboxWaitV2(req);
|
|
57451
|
+
} else {
|
|
57452
|
+
await this.#client.cpClient.sandboxWait(req);
|
|
57453
|
+
}
|
|
55820
57454
|
} catch (err) {
|
|
55821
|
-
if (err instanceof
|
|
57455
|
+
if (err instanceof ClientError11 && err.code === Status11.NOT_FOUND)
|
|
55822
57456
|
throw new NotFoundError(`Sandbox with id: '${sandboxId}' not found`);
|
|
55823
57457
|
throw err;
|
|
55824
57458
|
}
|
|
55825
|
-
return new Sandbox2(this.#client, sandboxId);
|
|
57459
|
+
return new Sandbox2(this.#client, sandboxId, { isV2 });
|
|
55826
57460
|
}
|
|
55827
57461
|
/** Get a running {@link Sandbox} by name from a deployed {@link App}.
|
|
55828
57462
|
*
|
|
@@ -55843,7 +57477,7 @@ var SandboxService = class {
|
|
|
55843
57477
|
});
|
|
55844
57478
|
return new Sandbox2(this.#client, resp.sandboxId);
|
|
55845
57479
|
} catch (err) {
|
|
55846
|
-
if (err instanceof
|
|
57480
|
+
if (err instanceof ClientError11 && err.code === Status11.NOT_FOUND)
|
|
55847
57481
|
throw new NotFoundError(
|
|
55848
57482
|
`Sandbox with name '${name}' not found in App '${appName}'`
|
|
55849
57483
|
);
|
|
@@ -55878,7 +57512,7 @@ var SandboxService = class {
|
|
|
55878
57512
|
}
|
|
55879
57513
|
beforeTimestamp = resp.sandboxes[resp.sandboxes.length - 1].createdAt;
|
|
55880
57514
|
} catch (err) {
|
|
55881
|
-
if (err instanceof
|
|
57515
|
+
if (err instanceof ClientError11 && err.code === Status11.INVALID_ARGUMENT) {
|
|
55882
57516
|
throw new InvalidError(err.details || err.message);
|
|
55883
57517
|
}
|
|
55884
57518
|
throw err;
|
|
@@ -55998,6 +57632,7 @@ var Sandbox2 = class _Sandbox {
|
|
|
55998
57632
|
#commandRouterClient;
|
|
55999
57633
|
#commandRouterClientPromise;
|
|
56000
57634
|
#attached = true;
|
|
57635
|
+
#filesystem;
|
|
56001
57636
|
/** @ignore */
|
|
56002
57637
|
constructor(client2, sandboxId, params = {}) {
|
|
56003
57638
|
this.#client = client2;
|
|
@@ -56053,6 +57688,13 @@ var Sandbox2 = class _Sandbox {
|
|
|
56053
57688
|
}
|
|
56054
57689
|
return this.#stderr;
|
|
56055
57690
|
}
|
|
57691
|
+
get filesystem() {
|
|
57692
|
+
this.#ensureAttached();
|
|
57693
|
+
if (!this.#filesystem) {
|
|
57694
|
+
this.#filesystem = new SandboxFilesystem(this);
|
|
57695
|
+
}
|
|
57696
|
+
return this.#filesystem;
|
|
57697
|
+
}
|
|
56056
57698
|
/** Set tags (key-value pairs) on the Sandbox. Tags can be used to filter results in {@link SandboxService#list Sandbox.list}. */
|
|
56057
57699
|
async setTags(tags) {
|
|
56058
57700
|
this.#ensureAttached();
|
|
@@ -56068,7 +57710,7 @@ var Sandbox2 = class _Sandbox {
|
|
|
56068
57710
|
tags: tagsList
|
|
56069
57711
|
});
|
|
56070
57712
|
} catch (err) {
|
|
56071
|
-
if (err instanceof
|
|
57713
|
+
if (err instanceof ClientError11 && err.code === Status11.INVALID_ARGUMENT) {
|
|
56072
57714
|
throw new InvalidError(err.details || err.message);
|
|
56073
57715
|
}
|
|
56074
57716
|
throw err;
|
|
@@ -56084,7 +57726,7 @@ var Sandbox2 = class _Sandbox {
|
|
|
56084
57726
|
sandboxId: this.sandboxId
|
|
56085
57727
|
});
|
|
56086
57728
|
} catch (err) {
|
|
56087
|
-
if (err instanceof
|
|
57729
|
+
if (err instanceof ClientError11 && err.code === Status11.INVALID_ARGUMENT) {
|
|
56088
57730
|
throw new InvalidError(err.details || err.message);
|
|
56089
57731
|
}
|
|
56090
57732
|
throw err;
|
|
@@ -56111,6 +57753,10 @@ var Sandbox2 = class _Sandbox {
|
|
|
56111
57753
|
}
|
|
56112
57754
|
/**
|
|
56113
57755
|
* Open a file in the Sandbox filesystem.
|
|
57756
|
+
*
|
|
57757
|
+
* @deprecated Use {@link SandboxFilesystem} methods: `sandbox.filesystem.readBytes()`,
|
|
57758
|
+
* `writeBytes()`, or `copyToLocal()` instead for improved reliability.
|
|
57759
|
+
*
|
|
56114
57760
|
* @param path - Path to the file to open
|
|
56115
57761
|
* @param mode - File open mode (r, w, a, r+, w+, a+)
|
|
56116
57762
|
* @returns Promise that resolves to a {@link SandboxFile}
|
|
@@ -56352,7 +57998,7 @@ var Sandbox2 = class _Sandbox {
|
|
|
56352
57998
|
return;
|
|
56353
57999
|
}
|
|
56354
58000
|
} catch (err) {
|
|
56355
|
-
if (err instanceof
|
|
58001
|
+
if (err instanceof ClientError11 && err.code === Status11.DEADLINE_EXCEEDED)
|
|
56356
58002
|
continue;
|
|
56357
58003
|
throw err;
|
|
56358
58004
|
}
|
|
@@ -56561,6 +58207,16 @@ var ContainerProcess = class {
|
|
|
56561
58207
|
this.stderr = toModalReadStream(stderrStream);
|
|
56562
58208
|
}
|
|
56563
58209
|
}
|
|
58210
|
+
/**
|
|
58211
|
+
* @ignore
|
|
58212
|
+
* Send stdin EOF directly, bypassing the WritableStream state machine.
|
|
58213
|
+
*
|
|
58214
|
+
* Useful for when an stdin write has failed.
|
|
58215
|
+
*/
|
|
58216
|
+
async closeStdin() {
|
|
58217
|
+
await this.#commandRouterClient.execStdinWrite(this.#taskId, this.#execId, 0, new Uint8Array(0), true).catch(() => {
|
|
58218
|
+
});
|
|
58219
|
+
}
|
|
56564
58220
|
/** Wait for process completion and return the exit code. */
|
|
56565
58221
|
async wait() {
|
|
56566
58222
|
const resp = await this.#commandRouterClient.execWait(
|
|
@@ -56686,127 +58342,6 @@ function encodeIfString(chunk) {
|
|
|
56686
58342
|
return typeof chunk === "string" ? new TextEncoder().encode(chunk) : chunk;
|
|
56687
58343
|
}
|
|
56688
58344
|
|
|
56689
|
-
// src/volume.ts
|
|
56690
|
-
import { ClientError as ClientError9, Status as Status9 } from "nice-grpc";
|
|
56691
|
-
var VolumeService = class {
|
|
56692
|
-
#client;
|
|
56693
|
-
constructor(client2) {
|
|
56694
|
-
this.#client = client2;
|
|
56695
|
-
}
|
|
56696
|
-
/**
|
|
56697
|
-
* Reference a {@link Volume} by its name.
|
|
56698
|
-
*/
|
|
56699
|
-
async fromName(name, params) {
|
|
56700
|
-
try {
|
|
56701
|
-
const resp = await this.#client.cpClient.volumeGetOrCreate({
|
|
56702
|
-
deploymentName: name,
|
|
56703
|
-
environmentName: this.#client.environmentName(params?.environment),
|
|
56704
|
-
objectCreationType: params?.createIfMissing ? 1 /* OBJECT_CREATION_TYPE_CREATE_IF_MISSING */ : 0 /* OBJECT_CREATION_TYPE_UNSPECIFIED */
|
|
56705
|
-
});
|
|
56706
|
-
this.#client.logger.debug(
|
|
56707
|
-
"Retrieved Volume",
|
|
56708
|
-
"volume_id",
|
|
56709
|
-
resp.volumeId,
|
|
56710
|
-
"volume_name",
|
|
56711
|
-
name
|
|
56712
|
-
);
|
|
56713
|
-
return new Volume(resp.volumeId, name);
|
|
56714
|
-
} catch (err) {
|
|
56715
|
-
if (err instanceof ClientError9 && err.code === Status9.NOT_FOUND)
|
|
56716
|
-
throw new NotFoundError(err.details);
|
|
56717
|
-
throw err;
|
|
56718
|
-
}
|
|
56719
|
-
}
|
|
56720
|
-
/**
|
|
56721
|
-
* Create a nameless, temporary {@link Volume}.
|
|
56722
|
-
* It persists until closeEphemeral() is called, or the process exits.
|
|
56723
|
-
*/
|
|
56724
|
-
async ephemeral(params = {}) {
|
|
56725
|
-
const resp = await this.#client.cpClient.volumeGetOrCreate({
|
|
56726
|
-
objectCreationType: 5 /* OBJECT_CREATION_TYPE_EPHEMERAL */,
|
|
56727
|
-
environmentName: this.#client.environmentName(params.environment)
|
|
56728
|
-
});
|
|
56729
|
-
this.#client.logger.debug(
|
|
56730
|
-
"Created ephemeral Volume",
|
|
56731
|
-
"volume_id",
|
|
56732
|
-
resp.volumeId
|
|
56733
|
-
);
|
|
56734
|
-
const ephemeralHbManager = new EphemeralHeartbeatManager(
|
|
56735
|
-
() => this.#client.cpClient.volumeHeartbeat({ volumeId: resp.volumeId })
|
|
56736
|
-
);
|
|
56737
|
-
return new Volume(resp.volumeId, void 0, false, ephemeralHbManager);
|
|
56738
|
-
}
|
|
56739
|
-
/**
|
|
56740
|
-
* Delete a named {@link Volume}.
|
|
56741
|
-
*
|
|
56742
|
-
* Warning: Deletion is irreversible and will affect any Apps currently using the Volume.
|
|
56743
|
-
*/
|
|
56744
|
-
async delete(name, params) {
|
|
56745
|
-
try {
|
|
56746
|
-
const volume = await this.fromName(name, {
|
|
56747
|
-
environment: params?.environment,
|
|
56748
|
-
createIfMissing: false
|
|
56749
|
-
});
|
|
56750
|
-
await this.#client.cpClient.volumeDelete({
|
|
56751
|
-
volumeId: volume.volumeId
|
|
56752
|
-
});
|
|
56753
|
-
this.#client.logger.debug(
|
|
56754
|
-
"Deleted Volume",
|
|
56755
|
-
"volume_name",
|
|
56756
|
-
name,
|
|
56757
|
-
"volume_id",
|
|
56758
|
-
volume.volumeId
|
|
56759
|
-
);
|
|
56760
|
-
} catch (err) {
|
|
56761
|
-
const isNotFound = err instanceof NotFoundError || err instanceof ClientError9 && err.code === Status9.NOT_FOUND;
|
|
56762
|
-
if (isNotFound && params?.allowMissing) {
|
|
56763
|
-
return;
|
|
56764
|
-
}
|
|
56765
|
-
throw err;
|
|
56766
|
-
}
|
|
56767
|
-
}
|
|
56768
|
-
};
|
|
56769
|
-
var Volume = class _Volume {
|
|
56770
|
-
volumeId;
|
|
56771
|
-
name;
|
|
56772
|
-
_readOnly = false;
|
|
56773
|
-
#ephemeralHbManager;
|
|
56774
|
-
/** @ignore */
|
|
56775
|
-
constructor(volumeId, name, readOnly = false, ephemeralHbManager) {
|
|
56776
|
-
this.volumeId = volumeId;
|
|
56777
|
-
this.name = name;
|
|
56778
|
-
this._readOnly = readOnly;
|
|
56779
|
-
this.#ephemeralHbManager = ephemeralHbManager;
|
|
56780
|
-
}
|
|
56781
|
-
/**
|
|
56782
|
-
* @deprecated Use {@link VolumeService#fromName client.volumes.fromName()} instead.
|
|
56783
|
-
*/
|
|
56784
|
-
static async fromName(name, options) {
|
|
56785
|
-
return getDefaultClient().volumes.fromName(name, options);
|
|
56786
|
-
}
|
|
56787
|
-
/** Configure Volume to mount as read-only. */
|
|
56788
|
-
readOnly() {
|
|
56789
|
-
return new _Volume(this.volumeId, this.name, true, this.#ephemeralHbManager);
|
|
56790
|
-
}
|
|
56791
|
-
get isReadOnly() {
|
|
56792
|
-
return this._readOnly;
|
|
56793
|
-
}
|
|
56794
|
-
/**
|
|
56795
|
-
* @deprecated Use {@link VolumeService#ephemeral client.volumes.ephemeral()} instead.
|
|
56796
|
-
*/
|
|
56797
|
-
static async ephemeral(options = {}) {
|
|
56798
|
-
return getDefaultClient().volumes.ephemeral(options);
|
|
56799
|
-
}
|
|
56800
|
-
/** Delete the ephemeral Volume. Only usable with emphemeral Volumes. */
|
|
56801
|
-
closeEphemeral() {
|
|
56802
|
-
if (this.#ephemeralHbManager) {
|
|
56803
|
-
this.#ephemeralHbManager.stop();
|
|
56804
|
-
} else {
|
|
56805
|
-
throw new InvalidError("Volume is not ephemeral.");
|
|
56806
|
-
}
|
|
56807
|
-
}
|
|
56808
|
-
};
|
|
56809
|
-
|
|
56810
58345
|
// src/auth_token_manager.ts
|
|
56811
58346
|
var REFRESH_WINDOW = 5 * 60;
|
|
56812
58347
|
var DEFAULT_EXPIRY_OFFSET = 20 * 60;
|
|
@@ -56816,9 +58351,9 @@ var AuthTokenManager = class {
|
|
|
56816
58351
|
currentToken = "";
|
|
56817
58352
|
tokenExpiry = 0;
|
|
56818
58353
|
refreshPromise = null;
|
|
56819
|
-
constructor(client2,
|
|
58354
|
+
constructor(client2, logger2) {
|
|
56820
58355
|
this.client = client2;
|
|
56821
|
-
this.logger =
|
|
58356
|
+
this.logger = logger2;
|
|
56822
58357
|
}
|
|
56823
58358
|
/**
|
|
56824
58359
|
* Returns a valid auth token.
|
|
@@ -56926,113 +58461,7 @@ var AuthTokenManager = class {
|
|
|
56926
58461
|
|
|
56927
58462
|
// src/version.ts
|
|
56928
58463
|
function getSDKVersion() {
|
|
56929
|
-
return true ? "0.7.
|
|
56930
|
-
}
|
|
56931
|
-
|
|
56932
|
-
// src/logger.ts
|
|
56933
|
-
var LOG_LEVELS = {
|
|
56934
|
-
debug: 0,
|
|
56935
|
-
info: 1,
|
|
56936
|
-
warn: 2,
|
|
56937
|
-
error: 3
|
|
56938
|
-
};
|
|
56939
|
-
function parseLogLevel(level) {
|
|
56940
|
-
if (!level) {
|
|
56941
|
-
return "warn";
|
|
56942
|
-
}
|
|
56943
|
-
const normalized = level.toLowerCase();
|
|
56944
|
-
if (normalized === "debug" || normalized === "info" || normalized === "warn" || normalized === "warning" || normalized === "error") {
|
|
56945
|
-
return normalized === "warning" ? "warn" : normalized;
|
|
56946
|
-
}
|
|
56947
|
-
throw new Error(
|
|
56948
|
-
`Invalid log level value: "${level}" (must be debug, info, warn, or error)`
|
|
56949
|
-
);
|
|
56950
|
-
}
|
|
56951
|
-
var DefaultLogger = class {
|
|
56952
|
-
levelValue;
|
|
56953
|
-
constructor(level = "warn") {
|
|
56954
|
-
this.levelValue = LOG_LEVELS[level];
|
|
56955
|
-
}
|
|
56956
|
-
debug(message, ...args) {
|
|
56957
|
-
if (this.levelValue <= LOG_LEVELS.debug) {
|
|
56958
|
-
console.log(this.formatMessage("DEBUG", message, args));
|
|
56959
|
-
}
|
|
56960
|
-
}
|
|
56961
|
-
info(message, ...args) {
|
|
56962
|
-
if (this.levelValue <= LOG_LEVELS.info) {
|
|
56963
|
-
console.log(this.formatMessage("INFO", message, args));
|
|
56964
|
-
}
|
|
56965
|
-
}
|
|
56966
|
-
warn(message, ...args) {
|
|
56967
|
-
if (this.levelValue <= LOG_LEVELS.warn) {
|
|
56968
|
-
console.warn(this.formatMessage("WARN", message, args));
|
|
56969
|
-
}
|
|
56970
|
-
}
|
|
56971
|
-
error(message, ...args) {
|
|
56972
|
-
if (this.levelValue <= LOG_LEVELS.error) {
|
|
56973
|
-
console.error(this.formatMessage("ERROR", message, args));
|
|
56974
|
-
}
|
|
56975
|
-
}
|
|
56976
|
-
formatMessage(level, message, args) {
|
|
56977
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
56978
|
-
let formatted = `time=${timestamp} level=${level} msg="${message}"`;
|
|
56979
|
-
if (args.length > 0) {
|
|
56980
|
-
for (let i = 0; i < args.length; i += 2) {
|
|
56981
|
-
if (i + 1 < args.length) {
|
|
56982
|
-
const key = args[i];
|
|
56983
|
-
const value = args[i + 1];
|
|
56984
|
-
formatted += ` ${key}=${this.formatValue(value)}`;
|
|
56985
|
-
}
|
|
56986
|
-
}
|
|
56987
|
-
}
|
|
56988
|
-
return formatted;
|
|
56989
|
-
}
|
|
56990
|
-
formatValue(value) {
|
|
56991
|
-
if (typeof value === "string") {
|
|
56992
|
-
return value.includes(" ") ? `"${value}"` : value;
|
|
56993
|
-
}
|
|
56994
|
-
if (value instanceof Error) {
|
|
56995
|
-
return `"${value.message}"`;
|
|
56996
|
-
}
|
|
56997
|
-
if (Array.isArray(value)) {
|
|
56998
|
-
return `[${value.join(",")}]`;
|
|
56999
|
-
}
|
|
57000
|
-
return String(value);
|
|
57001
|
-
}
|
|
57002
|
-
};
|
|
57003
|
-
var FilteredLogger = class {
|
|
57004
|
-
constructor(logger, level) {
|
|
57005
|
-
this.logger = logger;
|
|
57006
|
-
this.levelValue = LOG_LEVELS[level];
|
|
57007
|
-
}
|
|
57008
|
-
levelValue;
|
|
57009
|
-
debug(message, ...args) {
|
|
57010
|
-
if (this.levelValue <= LOG_LEVELS.debug) {
|
|
57011
|
-
this.logger.debug(message, ...args);
|
|
57012
|
-
}
|
|
57013
|
-
}
|
|
57014
|
-
info(message, ...args) {
|
|
57015
|
-
if (this.levelValue <= LOG_LEVELS.info) {
|
|
57016
|
-
this.logger.info(message, ...args);
|
|
57017
|
-
}
|
|
57018
|
-
}
|
|
57019
|
-
warn(message, ...args) {
|
|
57020
|
-
if (this.levelValue <= LOG_LEVELS.warn) {
|
|
57021
|
-
this.logger.warn(message, ...args);
|
|
57022
|
-
}
|
|
57023
|
-
}
|
|
57024
|
-
error(message, ...args) {
|
|
57025
|
-
if (this.levelValue <= LOG_LEVELS.error) {
|
|
57026
|
-
this.logger.error(message, ...args);
|
|
57027
|
-
}
|
|
57028
|
-
}
|
|
57029
|
-
};
|
|
57030
|
-
function createLogger(logger, logLevel = "") {
|
|
57031
|
-
const level = parseLogLevel(logLevel);
|
|
57032
|
-
if (logger) {
|
|
57033
|
-
return new FilteredLogger(logger, level);
|
|
57034
|
-
}
|
|
57035
|
-
return new DefaultLogger(level);
|
|
58464
|
+
return true ? "0.7.6" : "0.0.0";
|
|
57036
58465
|
}
|
|
57037
58466
|
|
|
57038
58467
|
// src/client.ts
|
|
@@ -57135,7 +58564,7 @@ var ModalClient2 = class {
|
|
|
57135
58564
|
}
|
|
57136
58565
|
/** Middleware to retry transient errors and timeouts for unary requests. */
|
|
57137
58566
|
retryMiddleware() {
|
|
57138
|
-
const
|
|
58567
|
+
const logger2 = this.logger;
|
|
57139
58568
|
const maxThrottleWaitSecs = this.profile.maxThrottleWaitSecs;
|
|
57140
58569
|
return async function* retryMiddleware(call, options) {
|
|
57141
58570
|
const {
|
|
@@ -57161,7 +58590,7 @@ var ModalClient2 = class {
|
|
|
57161
58590
|
let delayMs = baseDelay;
|
|
57162
58591
|
let throttleRetries = 0;
|
|
57163
58592
|
let lastServerRetryWarnTime = 0;
|
|
57164
|
-
|
|
58593
|
+
logger2.debug("Sending gRPC request", "method", call.method.path);
|
|
57165
58594
|
while (true) {
|
|
57166
58595
|
const metadata = new Metadata2(restOptions.metadata ?? {});
|
|
57167
58596
|
metadata.set("x-idempotency-key", idempotencyKey);
|
|
@@ -57202,7 +58631,7 @@ var ModalClient2 = class {
|
|
|
57202
58631
|
const serverDelaySecs = serverDelayMs / 1e3;
|
|
57203
58632
|
const elapsedSecs = (Date.now() - startTime) / 1e3;
|
|
57204
58633
|
if (maxThrottleWaitSecs && elapsedSecs + serverDelaySecs >= maxThrottleWaitSecs) {
|
|
57205
|
-
|
|
58634
|
+
logger2.debug(
|
|
57206
58635
|
"Max throttle wait exceeded, not retrying",
|
|
57207
58636
|
"method",
|
|
57208
58637
|
call.method.path,
|
|
@@ -57217,7 +58646,7 @@ var ModalClient2 = class {
|
|
|
57217
58646
|
);
|
|
57218
58647
|
throw err;
|
|
57219
58648
|
}
|
|
57220
|
-
|
|
58649
|
+
logger2.debug(
|
|
57221
58650
|
"Server requested retry delay",
|
|
57222
58651
|
"method",
|
|
57223
58652
|
call.method.path,
|
|
@@ -57233,8 +58662,8 @@ var ModalClient2 = class {
|
|
|
57233
58662
|
const now = Date.now();
|
|
57234
58663
|
if (!lastServerRetryWarnTime || now - lastServerRetryWarnTime >= SERVER_RETRY_WARNING_INTERVAL_MS) {
|
|
57235
58664
|
lastServerRetryWarnTime = now;
|
|
57236
|
-
const clientError2 = err instanceof
|
|
57237
|
-
|
|
58665
|
+
const clientError2 = err instanceof ClientError12 ? err : null;
|
|
58666
|
+
logger2.warn(
|
|
57238
58667
|
"Server requested retry delay. Retrying...",
|
|
57239
58668
|
"status",
|
|
57240
58669
|
clientError2?.code ?? "unknown",
|
|
@@ -57248,10 +58677,10 @@ var ModalClient2 = class {
|
|
|
57248
58677
|
await sleep(serverDelayMs, signal);
|
|
57249
58678
|
continue;
|
|
57250
58679
|
}
|
|
57251
|
-
const clientError = err instanceof
|
|
58680
|
+
const clientError = err instanceof ClientError12 ? err : null;
|
|
57252
58681
|
if (!clientError || !retryableCodes.has(clientError.code) || attempt >= retries) {
|
|
57253
58682
|
if (attempt === retries && attempt > 0) {
|
|
57254
|
-
|
|
58683
|
+
logger2.debug(
|
|
57255
58684
|
"Final retry attempt failed",
|
|
57256
58685
|
"error",
|
|
57257
58686
|
err,
|
|
@@ -57268,7 +58697,7 @@ var ModalClient2 = class {
|
|
|
57268
58697
|
throw err;
|
|
57269
58698
|
}
|
|
57270
58699
|
if (attempt > 0) {
|
|
57271
|
-
|
|
58700
|
+
logger2.debug(
|
|
57272
58701
|
"Retryable failure",
|
|
57273
58702
|
"error",
|
|
57274
58703
|
err,
|
|
@@ -57351,20 +58780,20 @@ var timeoutMiddleware = async function* timeoutMiddleware2(call, options) {
|
|
|
57351
58780
|
origSignal?.removeEventListener("abort", abortListener);
|
|
57352
58781
|
clearTimeout(timer);
|
|
57353
58782
|
if (timedOut) {
|
|
57354
|
-
throw new
|
|
58783
|
+
throw new ClientError12(
|
|
57355
58784
|
call.method.path,
|
|
57356
|
-
|
|
58785
|
+
Status12.DEADLINE_EXCEEDED,
|
|
57357
58786
|
`Timed out after ${timeoutMs}ms`
|
|
57358
58787
|
);
|
|
57359
58788
|
}
|
|
57360
58789
|
}
|
|
57361
58790
|
};
|
|
57362
58791
|
var retryableGrpcStatusCodes = /* @__PURE__ */ new Set([
|
|
57363
|
-
|
|
57364
|
-
|
|
57365
|
-
|
|
57366
|
-
|
|
57367
|
-
|
|
58792
|
+
Status12.DEADLINE_EXCEEDED,
|
|
58793
|
+
Status12.UNAVAILABLE,
|
|
58794
|
+
Status12.CANCELLED,
|
|
58795
|
+
Status12.INTERNAL,
|
|
58796
|
+
Status12.UNKNOWN
|
|
57368
58797
|
]);
|
|
57369
58798
|
var SERVER_RETRY_WARNING_INTERVAL_MS = 3e4;
|
|
57370
58799
|
function getServerRetryPolicy(statusDetails) {
|
|
@@ -57381,7 +58810,7 @@ function getServerRetryPolicy(statusDetails) {
|
|
|
57381
58810
|
return null;
|
|
57382
58811
|
}
|
|
57383
58812
|
function isRetryableGrpc(err) {
|
|
57384
|
-
if (err instanceof
|
|
58813
|
+
if (err instanceof ClientError12) {
|
|
57385
58814
|
return retryableGrpcStatusCodes.has(err.code);
|
|
57386
58815
|
}
|
|
57387
58816
|
return false;
|
|
@@ -57450,7 +58879,7 @@ var AppService = class {
|
|
|
57450
58879
|
);
|
|
57451
58880
|
return new App2(resp.appId, name);
|
|
57452
58881
|
} catch (err) {
|
|
57453
|
-
if (err instanceof
|
|
58882
|
+
if (err instanceof ClientError13 && err.code === Status13.NOT_FOUND)
|
|
57454
58883
|
throw new NotFoundError(`App '${name}' not found`);
|
|
57455
58884
|
throw err;
|
|
57456
58885
|
}
|
|
@@ -57550,6 +58979,15 @@ export {
|
|
|
57550
58979
|
Retries,
|
|
57551
58980
|
Sandbox2 as Sandbox,
|
|
57552
58981
|
SandboxFile,
|
|
58982
|
+
SandboxFilesystem,
|
|
58983
|
+
SandboxFilesystemDirectoryNotEmptyError,
|
|
58984
|
+
SandboxFilesystemError,
|
|
58985
|
+
SandboxFilesystemFileTooLargeError,
|
|
58986
|
+
SandboxFilesystemIsADirectoryError,
|
|
58987
|
+
SandboxFilesystemNotADirectoryError,
|
|
58988
|
+
SandboxFilesystemNotFoundError,
|
|
58989
|
+
SandboxFilesystemPathAlreadyExistsError,
|
|
58990
|
+
SandboxFilesystemPermissionError,
|
|
57553
58991
|
SandboxService,
|
|
57554
58992
|
SandboxTimeoutError,
|
|
57555
58993
|
Secret,
|