commonswarm 0.1.49 → 0.1.51
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/cswarm.cjs +1153 -965
- package/package.json +1 -1
package/cswarm.cjs
CHANGED
|
@@ -44,7 +44,7 @@ var __toESM = (mod, isNodeMode, target2) => (target2 = mod != null ? __create(__
|
|
|
44
44
|
));
|
|
45
45
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
46
46
|
|
|
47
|
-
// node_modules/tslib/tslib.es6.mjs
|
|
47
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/tslib/tslib.es6.mjs
|
|
48
48
|
var tslib_es6_exports = {};
|
|
49
49
|
__export(tslib_es6_exports, {
|
|
50
50
|
__addDisposableResource: () => __addDisposableResource,
|
|
@@ -483,7 +483,7 @@ function __rewriteRelativeImportExtension(path, preserveJsx) {
|
|
|
483
483
|
}
|
|
484
484
|
var extendStatics, __assign, __createBinding, __setModuleDefault, ownKeys, _SuppressedError, tslib_es6_default;
|
|
485
485
|
var init_tslib_es6 = __esm({
|
|
486
|
-
"node_modules/tslib/tslib.es6.mjs"() {
|
|
486
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/tslib/tslib.es6.mjs"() {
|
|
487
487
|
extendStatics = function(d, b2) {
|
|
488
488
|
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b3) {
|
|
489
489
|
d2.__proto__ = b3;
|
|
@@ -569,9 +569,9 @@ var init_tslib_es6 = __esm({
|
|
|
569
569
|
}
|
|
570
570
|
});
|
|
571
571
|
|
|
572
|
-
// node_modules/@supabase/functions-js/dist/main/helper.js
|
|
572
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/functions-js/dist/main/helper.js
|
|
573
573
|
var require_helper = __commonJS({
|
|
574
|
-
"node_modules/@supabase/functions-js/dist/main/helper.js"(exports2) {
|
|
574
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/functions-js/dist/main/helper.js"(exports2) {
|
|
575
575
|
"use strict";
|
|
576
576
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
577
577
|
exports2.resolveFetch = void 0;
|
|
@@ -585,9 +585,9 @@ var require_helper = __commonJS({
|
|
|
585
585
|
}
|
|
586
586
|
});
|
|
587
587
|
|
|
588
|
-
// node_modules/@supabase/functions-js/dist/main/types.js
|
|
588
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/functions-js/dist/main/types.js
|
|
589
589
|
var require_types = __commonJS({
|
|
590
|
-
"node_modules/@supabase/functions-js/dist/main/types.js"(exports2) {
|
|
590
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/functions-js/dist/main/types.js"(exports2) {
|
|
591
591
|
"use strict";
|
|
592
592
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
593
593
|
exports2.FunctionRegion = exports2.FunctionsHttpError = exports2.FunctionsRelayError = exports2.FunctionsFetchError = exports2.FunctionsError = void 0;
|
|
@@ -645,9 +645,9 @@ var require_types = __commonJS({
|
|
|
645
645
|
}
|
|
646
646
|
});
|
|
647
647
|
|
|
648
|
-
// node_modules/@supabase/functions-js/dist/main/FunctionsClient.js
|
|
648
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/functions-js/dist/main/FunctionsClient.js
|
|
649
649
|
var require_FunctionsClient = __commonJS({
|
|
650
|
-
"node_modules/@supabase/functions-js/dist/main/FunctionsClient.js"(exports2) {
|
|
650
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/functions-js/dist/main/FunctionsClient.js"(exports2) {
|
|
651
651
|
"use strict";
|
|
652
652
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
653
653
|
exports2.FunctionsClient = void 0;
|
|
@@ -931,9 +931,9 @@ var require_FunctionsClient = __commonJS({
|
|
|
931
931
|
}
|
|
932
932
|
});
|
|
933
933
|
|
|
934
|
-
// node_modules/@supabase/functions-js/dist/main/index.js
|
|
934
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/functions-js/dist/main/index.js
|
|
935
935
|
var require_main = __commonJS({
|
|
936
|
-
"node_modules/@supabase/functions-js/dist/main/index.js"(exports2) {
|
|
936
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/functions-js/dist/main/index.js"(exports2) {
|
|
937
937
|
"use strict";
|
|
938
938
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
939
939
|
exports2.FunctionRegion = exports2.FunctionsRelayError = exports2.FunctionsHttpError = exports2.FunctionsFetchError = exports2.FunctionsError = exports2.FunctionsClient = void 0;
|
|
@@ -960,9 +960,9 @@ var require_main = __commonJS({
|
|
|
960
960
|
}
|
|
961
961
|
});
|
|
962
962
|
|
|
963
|
-
// node_modules/@supabase/realtime-js/dist/main/lib/websocket-factory.js
|
|
963
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/websocket-factory.js
|
|
964
964
|
var require_websocket_factory = __commonJS({
|
|
965
|
-
"node_modules/@supabase/realtime-js/dist/main/lib/websocket-factory.js"(exports2) {
|
|
965
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/websocket-factory.js"(exports2) {
|
|
966
966
|
"use strict";
|
|
967
967
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
968
968
|
exports2.WebSocketFactory = void 0;
|
|
@@ -1071,9 +1071,9 @@ Suggested solution: ${env.workaround}`;
|
|
|
1071
1071
|
}
|
|
1072
1072
|
});
|
|
1073
1073
|
|
|
1074
|
-
// node_modules/@supabase/realtime-js/dist/main/lib/version.js
|
|
1074
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/version.js
|
|
1075
1075
|
var require_version = __commonJS({
|
|
1076
|
-
"node_modules/@supabase/realtime-js/dist/main/lib/version.js"(exports2) {
|
|
1076
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/version.js"(exports2) {
|
|
1077
1077
|
"use strict";
|
|
1078
1078
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1079
1079
|
exports2.version = void 0;
|
|
@@ -1081,9 +1081,9 @@ var require_version = __commonJS({
|
|
|
1081
1081
|
}
|
|
1082
1082
|
});
|
|
1083
1083
|
|
|
1084
|
-
// node_modules/@supabase/realtime-js/dist/main/lib/constants.js
|
|
1084
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/constants.js
|
|
1085
1085
|
var require_constants = __commonJS({
|
|
1086
|
-
"node_modules/@supabase/realtime-js/dist/main/lib/constants.js"(exports2) {
|
|
1086
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/constants.js"(exports2) {
|
|
1087
1087
|
"use strict";
|
|
1088
1088
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1089
1089
|
exports2.CONNECTION_STATE = exports2.TRANSPORTS = exports2.CHANNEL_EVENTS = exports2.CHANNEL_STATES = exports2.SOCKET_STATES = exports2.MAX_PUSH_BUFFER_SIZE = exports2.WS_CLOSE_NORMAL = exports2.DEFAULT_TIMEOUT = exports2.VERSION = exports2.DEFAULT_VSN = exports2.VSN_2_0_0 = exports2.VSN_1_0_0 = exports2.DEFAULT_VERSION = void 0;
|
|
@@ -1129,9 +1129,9 @@ var require_constants = __commonJS({
|
|
|
1129
1129
|
}
|
|
1130
1130
|
});
|
|
1131
1131
|
|
|
1132
|
-
// node_modules/@supabase/realtime-js/dist/main/lib/serializer.js
|
|
1132
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/serializer.js
|
|
1133
1133
|
var require_serializer = __commonJS({
|
|
1134
|
-
"node_modules/@supabase/realtime-js/dist/main/lib/serializer.js"(exports2) {
|
|
1134
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/serializer.js"(exports2) {
|
|
1135
1135
|
"use strict";
|
|
1136
1136
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1137
1137
|
var Serializer = class {
|
|
@@ -1283,9 +1283,9 @@ var require_serializer = __commonJS({
|
|
|
1283
1283
|
}
|
|
1284
1284
|
});
|
|
1285
1285
|
|
|
1286
|
-
// node_modules/@supabase/realtime-js/dist/main/lib/transformers.js
|
|
1286
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/transformers.js
|
|
1287
1287
|
var require_transformers = __commonJS({
|
|
1288
|
-
"node_modules/@supabase/realtime-js/dist/main/lib/transformers.js"(exports2) {
|
|
1288
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/transformers.js"(exports2) {
|
|
1289
1289
|
"use strict";
|
|
1290
1290
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1291
1291
|
exports2.httpEndpointURL = exports2.toTimestampString = exports2.toArray = exports2.toJson = exports2.toNumber = exports2.toBoolean = exports2.convertCell = exports2.convertColumn = exports2.convertChangeData = exports2.PostgresTypes = void 0;
|
|
@@ -1462,9 +1462,9 @@ var require_transformers = __commonJS({
|
|
|
1462
1462
|
}
|
|
1463
1463
|
});
|
|
1464
1464
|
|
|
1465
|
-
// node_modules/@supabase/phoenix/priv/static/phoenix.cjs.js
|
|
1465
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/phoenix/priv/static/phoenix.cjs.js
|
|
1466
1466
|
var require_phoenix_cjs = __commonJS({
|
|
1467
|
-
"node_modules/@supabase/phoenix/priv/static/phoenix.cjs.js"(exports2, module2) {
|
|
1467
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/phoenix/priv/static/phoenix.cjs.js"(exports2, module2) {
|
|
1468
1468
|
"use strict";
|
|
1469
1469
|
var __defProp2 = Object.defineProperty;
|
|
1470
1470
|
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
@@ -3314,9 +3314,9 @@ var require_phoenix_cjs = __commonJS({
|
|
|
3314
3314
|
}
|
|
3315
3315
|
});
|
|
3316
3316
|
|
|
3317
|
-
// node_modules/@supabase/realtime-js/dist/main/phoenix/presenceAdapter.js
|
|
3317
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/phoenix/presenceAdapter.js
|
|
3318
3318
|
var require_presenceAdapter = __commonJS({
|
|
3319
|
-
"node_modules/@supabase/realtime-js/dist/main/phoenix/presenceAdapter.js"(exports2) {
|
|
3319
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/phoenix/presenceAdapter.js"(exports2) {
|
|
3320
3320
|
"use strict";
|
|
3321
3321
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3322
3322
|
var phoenix_1 = require_phoenix_cjs();
|
|
@@ -3412,9 +3412,9 @@ var require_presenceAdapter = __commonJS({
|
|
|
3412
3412
|
}
|
|
3413
3413
|
});
|
|
3414
3414
|
|
|
3415
|
-
// node_modules/@supabase/realtime-js/dist/main/RealtimePresence.js
|
|
3415
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/RealtimePresence.js
|
|
3416
3416
|
var require_RealtimePresence = __commonJS({
|
|
3417
|
-
"node_modules/@supabase/realtime-js/dist/main/RealtimePresence.js"(exports2) {
|
|
3417
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/RealtimePresence.js"(exports2) {
|
|
3418
3418
|
"use strict";
|
|
3419
3419
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3420
3420
|
exports2.REALTIME_PRESENCE_LISTEN_EVENTS = void 0;
|
|
@@ -3456,9 +3456,9 @@ var require_RealtimePresence = __commonJS({
|
|
|
3456
3456
|
}
|
|
3457
3457
|
});
|
|
3458
3458
|
|
|
3459
|
-
// node_modules/@supabase/realtime-js/dist/main/lib/normalizeChannelError.js
|
|
3459
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/normalizeChannelError.js
|
|
3460
3460
|
var require_normalizeChannelError = __commonJS({
|
|
3461
|
-
"node_modules/@supabase/realtime-js/dist/main/lib/normalizeChannelError.js"(exports2) {
|
|
3461
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/normalizeChannelError.js"(exports2) {
|
|
3462
3462
|
"use strict";
|
|
3463
3463
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3464
3464
|
exports2.normalizeChannelError = normalizeChannelError;
|
|
@@ -3482,9 +3482,9 @@ var require_normalizeChannelError = __commonJS({
|
|
|
3482
3482
|
}
|
|
3483
3483
|
});
|
|
3484
3484
|
|
|
3485
|
-
// node_modules/@supabase/realtime-js/dist/main/phoenix/channelAdapter.js
|
|
3485
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/phoenix/channelAdapter.js
|
|
3486
3486
|
var require_channelAdapter = __commonJS({
|
|
3487
|
-
"node_modules/@supabase/realtime-js/dist/main/phoenix/channelAdapter.js"(exports2) {
|
|
3487
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/phoenix/channelAdapter.js"(exports2) {
|
|
3488
3488
|
"use strict";
|
|
3489
3489
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3490
3490
|
var constants_1 = require_constants();
|
|
@@ -3589,9 +3589,9 @@ var require_channelAdapter = __commonJS({
|
|
|
3589
3589
|
}
|
|
3590
3590
|
});
|
|
3591
3591
|
|
|
3592
|
-
// node_modules/@supabase/realtime-js/dist/main/RealtimePostgresFilterBuilder.js
|
|
3592
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/RealtimePostgresFilterBuilder.js
|
|
3593
3593
|
var require_RealtimePostgresFilterBuilder = __commonJS({
|
|
3594
|
-
"node_modules/@supabase/realtime-js/dist/main/RealtimePostgresFilterBuilder.js"(exports2) {
|
|
3594
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/RealtimePostgresFilterBuilder.js"(exports2) {
|
|
3595
3595
|
"use strict";
|
|
3596
3596
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3597
3597
|
exports2.postgresChangesFilter = exports2.RealtimePostgresFilterBuilder = void 0;
|
|
@@ -3713,9 +3713,9 @@ var require_RealtimePostgresFilterBuilder = __commonJS({
|
|
|
3713
3713
|
}
|
|
3714
3714
|
});
|
|
3715
3715
|
|
|
3716
|
-
// node_modules/@supabase/realtime-js/dist/main/RealtimeChannel.js
|
|
3716
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/RealtimeChannel.js
|
|
3717
3717
|
var require_RealtimeChannel = __commonJS({
|
|
3718
|
-
"node_modules/@supabase/realtime-js/dist/main/RealtimeChannel.js"(exports2) {
|
|
3718
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/RealtimeChannel.js"(exports2) {
|
|
3719
3719
|
"use strict";
|
|
3720
3720
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3721
3721
|
exports2.REALTIME_CHANNEL_STATES = exports2.REALTIME_SUBSCRIBE_STATES = exports2.REALTIME_LISTEN_TYPES = exports2.REALTIME_POSTGRES_CHANGES_LISTEN_EVENT = exports2.postgresChangesFilter = exports2.RealtimePostgresFilterBuilder = void 0;
|
|
@@ -4444,9 +4444,9 @@ var require_RealtimeChannel = __commonJS({
|
|
|
4444
4444
|
}
|
|
4445
4445
|
});
|
|
4446
4446
|
|
|
4447
|
-
// node_modules/@supabase/realtime-js/dist/main/phoenix/socketAdapter.js
|
|
4447
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/phoenix/socketAdapter.js
|
|
4448
4448
|
var require_socketAdapter = __commonJS({
|
|
4449
|
-
"node_modules/@supabase/realtime-js/dist/main/phoenix/socketAdapter.js"(exports2) {
|
|
4449
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/phoenix/socketAdapter.js"(exports2) {
|
|
4450
4450
|
"use strict";
|
|
4451
4451
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
4452
4452
|
var phoenix_1 = require_phoenix_cjs();
|
|
@@ -4562,9 +4562,9 @@ var require_socketAdapter = __commonJS({
|
|
|
4562
4562
|
}
|
|
4563
4563
|
});
|
|
4564
4564
|
|
|
4565
|
-
// node_modules/@supabase/realtime-js/dist/main/RealtimeClient.js
|
|
4565
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/RealtimeClient.js
|
|
4566
4566
|
var require_RealtimeClient = __commonJS({
|
|
4567
|
-
"node_modules/@supabase/realtime-js/dist/main/RealtimeClient.js"(exports2) {
|
|
4567
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/RealtimeClient.js"(exports2) {
|
|
4568
4568
|
"use strict";
|
|
4569
4569
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
4570
4570
|
var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports));
|
|
@@ -5216,9 +5216,9 @@ var require_RealtimeClient = __commonJS({
|
|
|
5216
5216
|
}
|
|
5217
5217
|
});
|
|
5218
5218
|
|
|
5219
|
-
// node_modules/@supabase/realtime-js/dist/main/index.js
|
|
5219
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/index.js
|
|
5220
5220
|
var require_main2 = __commonJS({
|
|
5221
|
-
"node_modules/@supabase/realtime-js/dist/main/index.js"(exports2) {
|
|
5221
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/index.js"(exports2) {
|
|
5222
5222
|
"use strict";
|
|
5223
5223
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
5224
5224
|
exports2.WebSocketFactory = exports2.REALTIME_CHANNEL_STATES = exports2.REALTIME_SUBSCRIBE_STATES = exports2.REALTIME_PRESENCE_LISTEN_EVENTS = exports2.REALTIME_POSTGRES_CHANGES_LISTEN_EVENT = exports2.REALTIME_LISTEN_TYPES = exports2.postgresChangesFilter = exports2.RealtimePostgresFilterBuilder = exports2.RealtimeClient = exports2.RealtimeChannel = exports2.RealtimePresence = void 0;
|
|
@@ -5255,9 +5255,9 @@ var require_main2 = __commonJS({
|
|
|
5255
5255
|
}
|
|
5256
5256
|
});
|
|
5257
5257
|
|
|
5258
|
-
// node_modules/@supabase/auth-js/dist/main/lib/version.js
|
|
5258
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/version.js
|
|
5259
5259
|
var require_version2 = __commonJS({
|
|
5260
|
-
"node_modules/@supabase/auth-js/dist/main/lib/version.js"(exports2) {
|
|
5260
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/version.js"(exports2) {
|
|
5261
5261
|
"use strict";
|
|
5262
5262
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
5263
5263
|
exports2.version = void 0;
|
|
@@ -5265,9 +5265,9 @@ var require_version2 = __commonJS({
|
|
|
5265
5265
|
}
|
|
5266
5266
|
});
|
|
5267
5267
|
|
|
5268
|
-
// node_modules/@supabase/auth-js/dist/main/lib/constants.js
|
|
5268
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/constants.js
|
|
5269
5269
|
var require_constants2 = __commonJS({
|
|
5270
|
-
"node_modules/@supabase/auth-js/dist/main/lib/constants.js"(exports2) {
|
|
5270
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/constants.js"(exports2) {
|
|
5271
5271
|
"use strict";
|
|
5272
5272
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
5273
5273
|
exports2.JWKS_TTL = exports2.BASE64URL_REGEX = exports2.API_VERSIONS = exports2.API_VERSION_HEADER_NAME = exports2.NETWORK_FAILURE = exports2.DEFAULT_HEADERS = exports2.AUDIENCE = exports2.STORAGE_KEY = exports2.GOTRUE_URL = exports2.REFRESH_FAILURE_COOLDOWN_MS = exports2.EXPIRY_MARGIN_MS = exports2.AUTO_REFRESH_TICK_THRESHOLD = exports2.AUTO_REFRESH_TICK_DURATION_MS = void 0;
|
|
@@ -5297,9 +5297,9 @@ var require_constants2 = __commonJS({
|
|
|
5297
5297
|
}
|
|
5298
5298
|
});
|
|
5299
5299
|
|
|
5300
|
-
// node_modules/@supabase/auth-js/dist/main/lib/errors.js
|
|
5300
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/errors.js
|
|
5301
5301
|
var require_errors = __commonJS({
|
|
5302
|
-
"node_modules/@supabase/auth-js/dist/main/lib/errors.js"(exports2) {
|
|
5302
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/errors.js"(exports2) {
|
|
5303
5303
|
"use strict";
|
|
5304
5304
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
5305
5305
|
exports2.AuthInvalidJwtError = exports2.AuthWeakPasswordError = exports2.AuthRefreshDiscardedError = exports2.AuthRetryableFetchError = exports2.AuthPKCECodeVerifierMissingError = exports2.AuthPKCEGrantCodeExchangeError = exports2.AuthImplicitGrantRedirectError = exports2.AuthInvalidCredentialsError = exports2.AuthInvalidTokenResponseError = exports2.AuthSessionMissingError = exports2.CustomAuthError = exports2.AuthUnknownError = exports2.AuthApiError = exports2.AuthError = void 0;
|
|
@@ -5455,9 +5455,9 @@ var require_errors = __commonJS({
|
|
|
5455
5455
|
}
|
|
5456
5456
|
});
|
|
5457
5457
|
|
|
5458
|
-
// node_modules/@supabase/auth-js/dist/main/lib/base64url.js
|
|
5458
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/base64url.js
|
|
5459
5459
|
var require_base64url = __commonJS({
|
|
5460
|
-
"node_modules/@supabase/auth-js/dist/main/lib/base64url.js"(exports2) {
|
|
5460
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/base64url.js"(exports2) {
|
|
5461
5461
|
"use strict";
|
|
5462
5462
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
5463
5463
|
exports2.byteToBase64URL = byteToBase64URL;
|
|
@@ -5645,9 +5645,9 @@ var require_base64url = __commonJS({
|
|
|
5645
5645
|
}
|
|
5646
5646
|
});
|
|
5647
5647
|
|
|
5648
|
-
// node_modules/@supabase/auth-js/dist/main/lib/helpers.js
|
|
5648
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/helpers.js
|
|
5649
5649
|
var require_helpers = __commonJS({
|
|
5650
|
-
"node_modules/@supabase/auth-js/dist/main/lib/helpers.js"(exports2) {
|
|
5650
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/helpers.js"(exports2) {
|
|
5651
5651
|
"use strict";
|
|
5652
5652
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
5653
5653
|
exports2.Deferred = exports2.removeItemAsync = exports2.getItemAsync = exports2.setItemAsync = exports2.looksLikeFetchResponse = exports2.resolveFetch = exports2.supportsLocalStorage = exports2.isBrowser = void 0;
|
|
@@ -5967,9 +5967,9 @@ var require_helpers = __commonJS({
|
|
|
5967
5967
|
}
|
|
5968
5968
|
});
|
|
5969
5969
|
|
|
5970
|
-
// node_modules/@supabase/auth-js/dist/main/lib/fetch.js
|
|
5970
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/fetch.js
|
|
5971
5971
|
var require_fetch = __commonJS({
|
|
5972
|
-
"node_modules/@supabase/auth-js/dist/main/lib/fetch.js"(exports2) {
|
|
5972
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/fetch.js"(exports2) {
|
|
5973
5973
|
"use strict";
|
|
5974
5974
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
5975
5975
|
exports2.handleError = handleError2;
|
|
@@ -6151,9 +6151,9 @@ var require_fetch = __commonJS({
|
|
|
6151
6151
|
}
|
|
6152
6152
|
});
|
|
6153
6153
|
|
|
6154
|
-
// node_modules/@supabase/auth-js/dist/main/lib/types.js
|
|
6154
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/types.js
|
|
6155
6155
|
var require_types2 = __commonJS({
|
|
6156
|
-
"node_modules/@supabase/auth-js/dist/main/lib/types.js"(exports2) {
|
|
6156
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/types.js"(exports2) {
|
|
6157
6157
|
"use strict";
|
|
6158
6158
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
6159
6159
|
exports2.SIGN_OUT_SCOPES = void 0;
|
|
@@ -6161,9 +6161,9 @@ var require_types2 = __commonJS({
|
|
|
6161
6161
|
}
|
|
6162
6162
|
});
|
|
6163
6163
|
|
|
6164
|
-
// node_modules/@supabase/auth-js/dist/main/GoTrueAdminApi.js
|
|
6164
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/GoTrueAdminApi.js
|
|
6165
6165
|
var require_GoTrueAdminApi = __commonJS({
|
|
6166
|
-
"node_modules/@supabase/auth-js/dist/main/GoTrueAdminApi.js"(exports2) {
|
|
6166
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/GoTrueAdminApi.js"(exports2) {
|
|
6167
6167
|
"use strict";
|
|
6168
6168
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
6169
6169
|
var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports));
|
|
@@ -7247,9 +7247,9 @@ var require_GoTrueAdminApi = __commonJS({
|
|
|
7247
7247
|
}
|
|
7248
7248
|
});
|
|
7249
7249
|
|
|
7250
|
-
// node_modules/@supabase/auth-js/dist/main/lib/local-storage.js
|
|
7250
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/local-storage.js
|
|
7251
7251
|
var require_local_storage = __commonJS({
|
|
7252
|
-
"node_modules/@supabase/auth-js/dist/main/lib/local-storage.js"(exports2) {
|
|
7252
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/local-storage.js"(exports2) {
|
|
7253
7253
|
"use strict";
|
|
7254
7254
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
7255
7255
|
exports2.memoryLocalStorageAdapter = memoryLocalStorageAdapter;
|
|
@@ -7269,9 +7269,9 @@ var require_local_storage = __commonJS({
|
|
|
7269
7269
|
}
|
|
7270
7270
|
});
|
|
7271
7271
|
|
|
7272
|
-
// node_modules/@supabase/auth-js/dist/main/lib/locks.js
|
|
7272
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/locks.js
|
|
7273
7273
|
var require_locks = __commonJS({
|
|
7274
|
-
"node_modules/@supabase/auth-js/dist/main/lib/locks.js"(exports2) {
|
|
7274
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/locks.js"(exports2) {
|
|
7275
7275
|
"use strict";
|
|
7276
7276
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
7277
7277
|
exports2.ProcessLockAcquireTimeoutError = exports2.NavigatorLockAcquireTimeoutError = exports2.LockAcquireTimeoutError = exports2.internals = void 0;
|
|
@@ -7447,9 +7447,9 @@ var require_locks = __commonJS({
|
|
|
7447
7447
|
}
|
|
7448
7448
|
});
|
|
7449
7449
|
|
|
7450
|
-
// node_modules/@supabase/auth-js/dist/main/lib/polyfills.js
|
|
7450
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/polyfills.js
|
|
7451
7451
|
var require_polyfills = __commonJS({
|
|
7452
|
-
"node_modules/@supabase/auth-js/dist/main/lib/polyfills.js"(exports2) {
|
|
7452
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/polyfills.js"(exports2) {
|
|
7453
7453
|
"use strict";
|
|
7454
7454
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
7455
7455
|
exports2.polyfillGlobalThis = polyfillGlobalThis;
|
|
@@ -7474,9 +7474,9 @@ var require_polyfills = __commonJS({
|
|
|
7474
7474
|
}
|
|
7475
7475
|
});
|
|
7476
7476
|
|
|
7477
|
-
// node_modules/@supabase/auth-js/dist/main/lib/web3/ethereum.js
|
|
7477
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/web3/ethereum.js
|
|
7478
7478
|
var require_ethereum = __commonJS({
|
|
7479
|
-
"node_modules/@supabase/auth-js/dist/main/lib/web3/ethereum.js"(exports2) {
|
|
7479
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/web3/ethereum.js"(exports2) {
|
|
7480
7480
|
"use strict";
|
|
7481
7481
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
7482
7482
|
exports2.getAddress = getAddress;
|
|
@@ -7552,9 +7552,9 @@ ${suffix}`;
|
|
|
7552
7552
|
}
|
|
7553
7553
|
});
|
|
7554
7554
|
|
|
7555
|
-
// node_modules/@supabase/auth-js/dist/main/lib/webauthn.errors.js
|
|
7555
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/webauthn.errors.js
|
|
7556
7556
|
var require_webauthn_errors = __commonJS({
|
|
7557
|
-
"node_modules/@supabase/auth-js/dist/main/lib/webauthn.errors.js"(exports2) {
|
|
7557
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/webauthn.errors.js"(exports2) {
|
|
7558
7558
|
"use strict";
|
|
7559
7559
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
7560
7560
|
exports2.WebAuthnUnknownError = exports2.WebAuthnError = void 0;
|
|
@@ -7743,9 +7743,9 @@ var require_webauthn_errors = __commonJS({
|
|
|
7743
7743
|
}
|
|
7744
7744
|
});
|
|
7745
7745
|
|
|
7746
|
-
// node_modules/@supabase/auth-js/dist/main/lib/webauthn.js
|
|
7746
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/webauthn.js
|
|
7747
7747
|
var require_webauthn = __commonJS({
|
|
7748
|
-
"node_modules/@supabase/auth-js/dist/main/lib/webauthn.js"(exports2) {
|
|
7748
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/webauthn.js"(exports2) {
|
|
7749
7749
|
"use strict";
|
|
7750
7750
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
7751
7751
|
exports2.WebAuthnApi = exports2.DEFAULT_REQUEST_OPTIONS = exports2.DEFAULT_CREATION_OPTIONS = exports2.webAuthnAbortService = exports2.WebAuthnAbortService = exports2.identifyAuthenticationError = exports2.identifyRegistrationError = exports2.isWebAuthnError = exports2.WebAuthnError = void 0;
|
|
@@ -8302,9 +8302,9 @@ var require_webauthn = __commonJS({
|
|
|
8302
8302
|
}
|
|
8303
8303
|
});
|
|
8304
8304
|
|
|
8305
|
-
// node_modules/@supabase/auth-js/dist/main/GoTrueClient.js
|
|
8305
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/GoTrueClient.js
|
|
8306
8306
|
var require_GoTrueClient = __commonJS({
|
|
8307
|
-
"node_modules/@supabase/auth-js/dist/main/GoTrueClient.js"(exports2) {
|
|
8307
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/GoTrueClient.js"(exports2) {
|
|
8308
8308
|
"use strict";
|
|
8309
8309
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
8310
8310
|
var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports));
|
|
@@ -13442,9 +13442,9 @@ var require_GoTrueClient = __commonJS({
|
|
|
13442
13442
|
}
|
|
13443
13443
|
});
|
|
13444
13444
|
|
|
13445
|
-
// node_modules/@supabase/auth-js/dist/main/AuthAdminApi.js
|
|
13445
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/AuthAdminApi.js
|
|
13446
13446
|
var require_AuthAdminApi = __commonJS({
|
|
13447
|
-
"node_modules/@supabase/auth-js/dist/main/AuthAdminApi.js"(exports2) {
|
|
13447
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/AuthAdminApi.js"(exports2) {
|
|
13448
13448
|
"use strict";
|
|
13449
13449
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
13450
13450
|
var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports));
|
|
@@ -13454,9 +13454,9 @@ var require_AuthAdminApi = __commonJS({
|
|
|
13454
13454
|
}
|
|
13455
13455
|
});
|
|
13456
13456
|
|
|
13457
|
-
// node_modules/@supabase/auth-js/dist/main/AuthClient.js
|
|
13457
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/AuthClient.js
|
|
13458
13458
|
var require_AuthClient = __commonJS({
|
|
13459
|
-
"node_modules/@supabase/auth-js/dist/main/AuthClient.js"(exports2) {
|
|
13459
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/AuthClient.js"(exports2) {
|
|
13460
13460
|
"use strict";
|
|
13461
13461
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
13462
13462
|
var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports));
|
|
@@ -13466,9 +13466,9 @@ var require_AuthClient = __commonJS({
|
|
|
13466
13466
|
}
|
|
13467
13467
|
});
|
|
13468
13468
|
|
|
13469
|
-
// node_modules/@supabase/auth-js/dist/main/index.js
|
|
13469
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/index.js
|
|
13470
13470
|
var require_main3 = __commonJS({
|
|
13471
|
-
"node_modules/@supabase/auth-js/dist/main/index.js"(exports2) {
|
|
13471
|
+
"../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/index.js"(exports2) {
|
|
13472
13472
|
"use strict";
|
|
13473
13473
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
13474
13474
|
exports2.processLock = exports2.lockInternals = exports2.NavigatorLockAcquireTimeoutError = exports2.navigatorLock = exports2.AuthClient = exports2.AuthAdminApi = exports2.GoTrueClient = exports2.GoTrueAdminApi = void 0;
|
|
@@ -13535,7 +13535,7 @@ var import_node_crypto2 = require("node:crypto");
|
|
|
13535
13535
|
var import_node_http = require("node:http");
|
|
13536
13536
|
var import_node_child_process = require("node:child_process");
|
|
13537
13537
|
|
|
13538
|
-
// node_modules/@supabase/supabase-js/dist/index.mjs
|
|
13538
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/supabase-js/dist/index.mjs
|
|
13539
13539
|
var dist_exports = {};
|
|
13540
13540
|
__export(dist_exports, {
|
|
13541
13541
|
FunctionRegion: () => import_functions_js.FunctionRegion,
|
|
@@ -13550,7 +13550,7 @@ __export(dist_exports, {
|
|
|
13550
13550
|
});
|
|
13551
13551
|
var import_functions_js = __toESM(require_main(), 1);
|
|
13552
13552
|
|
|
13553
|
-
// node_modules/@supabase/postgrest-js/dist/index.mjs
|
|
13553
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/postgrest-js/dist/index.mjs
|
|
13554
13554
|
var DEFAULT_MAX_RETRIES = 3;
|
|
13555
13555
|
var getRetryDelay = (attemptIndex) => Math.min(1e3 * 2 ** attemptIndex, 3e4);
|
|
13556
13556
|
var RETRYABLE_STATUS_CODES = [520, 503];
|
|
@@ -17328,10 +17328,10 @@ var PostgrestClient = class PostgrestClient2 {
|
|
|
17328
17328
|
}
|
|
17329
17329
|
};
|
|
17330
17330
|
|
|
17331
|
-
// node_modules/@supabase/supabase-js/dist/index.mjs
|
|
17331
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/supabase-js/dist/index.mjs
|
|
17332
17332
|
var import_realtime_js = __toESM(require_main2(), 1);
|
|
17333
17333
|
|
|
17334
|
-
// node_modules/iceberg-js/dist/index.mjs
|
|
17334
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/iceberg-js/dist/index.mjs
|
|
17335
17335
|
var IcebergError = class extends Error {
|
|
17336
17336
|
constructor(message, opts) {
|
|
17337
17337
|
super(message);
|
|
@@ -17864,7 +17864,7 @@ var IcebergRestCatalog = class {
|
|
|
17864
17864
|
}
|
|
17865
17865
|
};
|
|
17866
17866
|
|
|
17867
|
-
// node_modules/@supabase/storage-js/dist/index.mjs
|
|
17867
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/storage-js/dist/index.mjs
|
|
17868
17868
|
function _typeof2(o) {
|
|
17869
17869
|
"@babel/helpers - typeof";
|
|
17870
17870
|
return _typeof2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
@@ -20656,7 +20656,7 @@ var StorageClient = class extends StorageBucketApi {
|
|
|
20656
20656
|
}
|
|
20657
20657
|
};
|
|
20658
20658
|
|
|
20659
|
-
// node_modules/@supabase/supabase-js/dist/index.mjs
|
|
20659
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/supabase-js/dist/index.mjs
|
|
20660
20660
|
var import_auth_js = __toESM(require_main3(), 1);
|
|
20661
20661
|
__reExport(dist_exports, __toESM(require_main2(), 1));
|
|
20662
20662
|
__reExport(dist_exports, __toESM(require_main3(), 1));
|
|
@@ -21470,6 +21470,14 @@ var MemoryStorage = class {
|
|
|
21470
21470
|
this.values.delete(key2);
|
|
21471
21471
|
}
|
|
21472
21472
|
};
|
|
21473
|
+
var HumanSessionError = class extends Error {
|
|
21474
|
+
constructor(code, message) {
|
|
21475
|
+
super(message);
|
|
21476
|
+
this.code = code;
|
|
21477
|
+
}
|
|
21478
|
+
code;
|
|
21479
|
+
name = "HumanSessionError";
|
|
21480
|
+
};
|
|
21473
21481
|
function base64Url(bytes) {
|
|
21474
21482
|
return bytes.toString("base64url");
|
|
21475
21483
|
}
|
|
@@ -21848,7 +21856,12 @@ async function refreshedCredential(target2, store2) {
|
|
|
21848
21856
|
return await store2.withLock(async () => {
|
|
21849
21857
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
21850
21858
|
const before = await store2.read();
|
|
21851
|
-
if (!before)
|
|
21859
|
+
if (!before) {
|
|
21860
|
+
throw new HumanSessionError(
|
|
21861
|
+
"human_session_missing",
|
|
21862
|
+
"not logged in; run cswarm login"
|
|
21863
|
+
);
|
|
21864
|
+
}
|
|
21852
21865
|
const memory = new MemoryStorage();
|
|
21853
21866
|
const client = authClient(target2, memory);
|
|
21854
21867
|
const refreshed = await client.auth.refreshSession({
|
|
@@ -21857,7 +21870,10 @@ async function refreshedCredential(target2, store2) {
|
|
|
21857
21870
|
if (refreshed.error) {
|
|
21858
21871
|
const afterFailure = await store2.read();
|
|
21859
21872
|
if (afterFailure && afterFailure.generation !== before.generation) continue;
|
|
21860
|
-
throw new
|
|
21873
|
+
throw new HumanSessionError(
|
|
21874
|
+
"human_session_refresh_failed",
|
|
21875
|
+
"could not refresh your session; run cswarm login to sign in again"
|
|
21876
|
+
);
|
|
21861
21877
|
}
|
|
21862
21878
|
const session = requireSession(refreshed.data.session);
|
|
21863
21879
|
const current = await store2.read();
|
|
@@ -24045,11 +24061,11 @@ async function resolveCloudTarget(options) {
|
|
|
24045
24061
|
// src/cloud/seed.ts
|
|
24046
24062
|
var import_node_crypto7 = require("node:crypto");
|
|
24047
24063
|
|
|
24048
|
-
// node_modules/postgres/src/index.js
|
|
24064
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/index.js
|
|
24049
24065
|
var import_os = __toESM(require("os"), 1);
|
|
24050
24066
|
var import_fs = __toESM(require("fs"), 1);
|
|
24051
24067
|
|
|
24052
|
-
// node_modules/postgres/src/query.js
|
|
24068
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/query.js
|
|
24053
24069
|
var originCache = /* @__PURE__ */ new Map();
|
|
24054
24070
|
var originStackCache = /* @__PURE__ */ new Map();
|
|
24055
24071
|
var originError = /* @__PURE__ */ Symbol("OriginError");
|
|
@@ -24186,7 +24202,7 @@ function cachedError(xs) {
|
|
|
24186
24202
|
return originCache.get(xs);
|
|
24187
24203
|
}
|
|
24188
24204
|
|
|
24189
|
-
// node_modules/postgres/src/errors.js
|
|
24205
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/errors.js
|
|
24190
24206
|
var PostgresError = class extends Error {
|
|
24191
24207
|
constructor(x) {
|
|
24192
24208
|
super(x.message);
|
|
@@ -24236,7 +24252,7 @@ function notSupported(x) {
|
|
|
24236
24252
|
return error;
|
|
24237
24253
|
}
|
|
24238
24254
|
|
|
24239
|
-
// node_modules/postgres/src/types.js
|
|
24255
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/types.js
|
|
24240
24256
|
var types = {
|
|
24241
24257
|
string: {
|
|
24242
24258
|
to: 25,
|
|
@@ -24522,14 +24538,14 @@ fromKebab.column = { to: fromKebab };
|
|
|
24522
24538
|
var kebab = { ...toKebab };
|
|
24523
24539
|
kebab.column.to = fromKebab;
|
|
24524
24540
|
|
|
24525
|
-
// node_modules/postgres/src/connection.js
|
|
24541
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/connection.js
|
|
24526
24542
|
var import_net = __toESM(require("net"), 1);
|
|
24527
24543
|
var import_tls = __toESM(require("tls"), 1);
|
|
24528
24544
|
var import_crypto = __toESM(require("crypto"), 1);
|
|
24529
24545
|
var import_stream = __toESM(require("stream"), 1);
|
|
24530
24546
|
var import_perf_hooks = require("perf_hooks");
|
|
24531
24547
|
|
|
24532
|
-
// node_modules/postgres/src/result.js
|
|
24548
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/result.js
|
|
24533
24549
|
var Result = class extends Array {
|
|
24534
24550
|
constructor() {
|
|
24535
24551
|
super();
|
|
@@ -24546,7 +24562,7 @@ var Result = class extends Array {
|
|
|
24546
24562
|
}
|
|
24547
24563
|
};
|
|
24548
24564
|
|
|
24549
|
-
// node_modules/postgres/src/queue.js
|
|
24565
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/queue.js
|
|
24550
24566
|
var queue_default = Queue;
|
|
24551
24567
|
function Queue(initial = []) {
|
|
24552
24568
|
let xs = initial.slice();
|
|
@@ -24573,7 +24589,7 @@ function Queue(initial = []) {
|
|
|
24573
24589
|
};
|
|
24574
24590
|
}
|
|
24575
24591
|
|
|
24576
|
-
// node_modules/postgres/src/bytes.js
|
|
24592
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/bytes.js
|
|
24577
24593
|
var size = 256;
|
|
24578
24594
|
var buffer = Buffer.allocUnsafe(size);
|
|
24579
24595
|
var messages = "BCcDdEFfHPpQSX".split("").reduce((acc, x) => {
|
|
@@ -24646,7 +24662,7 @@ function reset() {
|
|
|
24646
24662
|
return b;
|
|
24647
24663
|
}
|
|
24648
24664
|
|
|
24649
|
-
// node_modules/postgres/src/connection.js
|
|
24665
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/connection.js
|
|
24650
24666
|
var connection_default = Connection;
|
|
24651
24667
|
var uid = 1;
|
|
24652
24668
|
var Sync = bytes_default().S().end();
|
|
@@ -25486,7 +25502,7 @@ function timer(fn, seconds) {
|
|
|
25486
25502
|
}
|
|
25487
25503
|
}
|
|
25488
25504
|
|
|
25489
|
-
// node_modules/postgres/src/subscribe.js
|
|
25505
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/subscribe.js
|
|
25490
25506
|
var noop2 = () => {
|
|
25491
25507
|
};
|
|
25492
25508
|
function Subscribe(postgres2, options) {
|
|
@@ -25698,7 +25714,7 @@ function parseEvent(x) {
|
|
|
25698
25714
|
return (command2 || "*") + (path ? ":" + (path.indexOf(".") === -1 ? "public." + path : path) : "") + (key2 ? "=" + key2 : "");
|
|
25699
25715
|
}
|
|
25700
25716
|
|
|
25701
|
-
// node_modules/postgres/src/large.js
|
|
25717
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/large.js
|
|
25702
25718
|
var import_stream2 = __toESM(require("stream"), 1);
|
|
25703
25719
|
function largeObject(sql, oid, mode3 = 131072 | 262144) {
|
|
25704
25720
|
return new Promise(async (resolve3, reject) => {
|
|
@@ -25764,7 +25780,7 @@ function largeObject(sql, oid, mode3 = 131072 | 262144) {
|
|
|
25764
25780
|
});
|
|
25765
25781
|
}
|
|
25766
25782
|
|
|
25767
|
-
// node_modules/postgres/src/index.js
|
|
25783
|
+
// ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/index.js
|
|
25768
25784
|
Object.assign(Postgres, {
|
|
25769
25785
|
PostgresError,
|
|
25770
25786
|
toPascal,
|
|
@@ -26463,6 +26479,149 @@ async function agentCredentialStore(options) {
|
|
|
26463
26479
|
};
|
|
26464
26480
|
}
|
|
26465
26481
|
|
|
26482
|
+
// src/cloud/agent-credential-input.ts
|
|
26483
|
+
var UUID_RE4 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
26484
|
+
var AGENT_TOKEN_RE3 = /^swm_agt_[A-Za-z0-9_-]{43}$/;
|
|
26485
|
+
var AGENT_CREDENTIAL_MESSAGE = "Agent credential minted. It is bound to this task and run so the agent's work stays scoped and attributable.";
|
|
26486
|
+
var AGENT_CREDENTIAL_MESSAGE_D088 = "Agent credential minted. It is bound to this run, so the agent's work is attributable to it.";
|
|
26487
|
+
var ACCEPTED_AGENT_CREDENTIAL_MESSAGES = [
|
|
26488
|
+
AGENT_CREDENTIAL_MESSAGE,
|
|
26489
|
+
AGENT_CREDENTIAL_MESSAGE_D088
|
|
26490
|
+
];
|
|
26491
|
+
var AgentCredentialInputError = class extends Error {
|
|
26492
|
+
constructor(code, message) {
|
|
26493
|
+
super(`[${code}] ${message}`);
|
|
26494
|
+
this.code = code;
|
|
26495
|
+
}
|
|
26496
|
+
code;
|
|
26497
|
+
name = "AgentCredentialInputError";
|
|
26498
|
+
};
|
|
26499
|
+
var AGENT_CREDENTIAL_REQUIRED_FIELDS = [
|
|
26500
|
+
"message",
|
|
26501
|
+
"status",
|
|
26502
|
+
"principal_id",
|
|
26503
|
+
"token_id",
|
|
26504
|
+
"run_id",
|
|
26505
|
+
"agent_token"
|
|
26506
|
+
];
|
|
26507
|
+
var AGENT_CREDENTIAL_OPTIONAL_FIELDS = ["expires_at"];
|
|
26508
|
+
var ALLOWED_ARTIFACT_KEYS = /* @__PURE__ */ new Set([
|
|
26509
|
+
...AGENT_CREDENTIAL_REQUIRED_FIELDS,
|
|
26510
|
+
...AGENT_CREDENTIAL_OPTIONAL_FIELDS
|
|
26511
|
+
]);
|
|
26512
|
+
function sourceName(source) {
|
|
26513
|
+
return source.kind === "file" ? `agent credential file ${source.path}` : "agent credential input from stdin";
|
|
26514
|
+
}
|
|
26515
|
+
function nextStep(source) {
|
|
26516
|
+
return source.kind === "file" ? `Next step: copy the minted JSON line again and replace ${source.path}.` : "Next step: copy the minted JSON line again and send that line to stdin.";
|
|
26517
|
+
}
|
|
26518
|
+
function credentialInputError(code, source, found) {
|
|
26519
|
+
return new AgentCredentialInputError(
|
|
26520
|
+
code,
|
|
26521
|
+
`${sourceName(source)} ${found}. It must be the JSON line CommonSwarm minted, copied unchanged: ${AGENT_CREDENTIAL_REQUIRED_FIELDS.join(", ")} (${AGENT_CREDENTIAL_OPTIONAL_FIELDS.join(", ")} is optional). ${nextStep(source)}`
|
|
26522
|
+
);
|
|
26523
|
+
}
|
|
26524
|
+
function jsonKind(value) {
|
|
26525
|
+
if (value === null) return "JSON null";
|
|
26526
|
+
if (Array.isArray(value)) return "a JSON array";
|
|
26527
|
+
return `a JSON ${typeof value}`;
|
|
26528
|
+
}
|
|
26529
|
+
function parseAgentCredentialInput(value, source) {
|
|
26530
|
+
if (AGENT_TOKEN_RE3.test(value)) {
|
|
26531
|
+
return {
|
|
26532
|
+
token: value,
|
|
26533
|
+
principalId: null,
|
|
26534
|
+
tokenId: null,
|
|
26535
|
+
runId: null,
|
|
26536
|
+
expiresAt: null,
|
|
26537
|
+
durable: false
|
|
26538
|
+
};
|
|
26539
|
+
}
|
|
26540
|
+
let parsed;
|
|
26541
|
+
try {
|
|
26542
|
+
parsed = JSON.parse(value);
|
|
26543
|
+
} catch {
|
|
26544
|
+
throw credentialInputError(
|
|
26545
|
+
"agent_credential_invalid_json",
|
|
26546
|
+
source,
|
|
26547
|
+
"contains text that is not valid JSON"
|
|
26548
|
+
);
|
|
26549
|
+
}
|
|
26550
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
26551
|
+
throw credentialInputError(
|
|
26552
|
+
"agent_credential_not_object",
|
|
26553
|
+
source,
|
|
26554
|
+
`contains ${jsonKind(parsed)} instead of a JSON object`
|
|
26555
|
+
);
|
|
26556
|
+
}
|
|
26557
|
+
const artifact = parsed;
|
|
26558
|
+
if (!Object.hasOwn(artifact, "agent_token")) {
|
|
26559
|
+
throw credentialInputError(
|
|
26560
|
+
"agent_credential_missing_agent_token",
|
|
26561
|
+
source,
|
|
26562
|
+
'is missing "agent_token"'
|
|
26563
|
+
);
|
|
26564
|
+
}
|
|
26565
|
+
if (typeof artifact.agent_token !== "string" || !AGENT_TOKEN_RE3.test(artifact.agent_token)) {
|
|
26566
|
+
const found = typeof artifact.agent_token === "string" ? 'has "agent_token" as a string that is not a swm_agt_ credential' : `has "agent_token" as ${jsonKind(artifact.agent_token)}`;
|
|
26567
|
+
throw credentialInputError(
|
|
26568
|
+
"agent_credential_invalid_agent_token",
|
|
26569
|
+
source,
|
|
26570
|
+
found
|
|
26571
|
+
);
|
|
26572
|
+
}
|
|
26573
|
+
const actualKeys = Object.keys(artifact);
|
|
26574
|
+
const missingKeys = AGENT_CREDENTIAL_REQUIRED_FIELDS.filter(
|
|
26575
|
+
(key2) => !Object.hasOwn(artifact, key2)
|
|
26576
|
+
);
|
|
26577
|
+
const unknownCount = actualKeys.filter(
|
|
26578
|
+
(key2) => !ALLOWED_ARTIFACT_KEYS.has(key2)
|
|
26579
|
+
).length;
|
|
26580
|
+
const invalidKeys = [];
|
|
26581
|
+
if (Object.hasOwn(artifact, "message") && !ACCEPTED_AGENT_CREDENTIAL_MESSAGES.includes(artifact.message)) {
|
|
26582
|
+
invalidKeys.push("message");
|
|
26583
|
+
}
|
|
26584
|
+
if (Object.hasOwn(artifact, "status") && artifact.status !== "accepted") {
|
|
26585
|
+
invalidKeys.push("status");
|
|
26586
|
+
}
|
|
26587
|
+
for (const key2 of ["principal_id", "token_id", "run_id"]) {
|
|
26588
|
+
if (Object.hasOwn(artifact, key2) && (typeof artifact[key2] !== "string" || !UUID_RE4.test(artifact[key2]))) {
|
|
26589
|
+
invalidKeys.push(key2);
|
|
26590
|
+
}
|
|
26591
|
+
}
|
|
26592
|
+
if (artifact.expires_at !== void 0) {
|
|
26593
|
+
if (typeof artifact.expires_at !== "string" || Number.isNaN(Date.parse(artifact.expires_at))) {
|
|
26594
|
+
invalidKeys.push("expires_at");
|
|
26595
|
+
}
|
|
26596
|
+
}
|
|
26597
|
+
if (missingKeys.length > 0 || unknownCount > 0 || invalidKeys.length > 0) {
|
|
26598
|
+
const faults = [];
|
|
26599
|
+
if (unknownCount > 0) {
|
|
26600
|
+
faults.push(`has ${unknownCount} unrecognized ${unknownCount === 1 ? "field" : "fields"}`);
|
|
26601
|
+
}
|
|
26602
|
+
if (missingKeys.length > 0) {
|
|
26603
|
+
faults.push(`is missing required ${missingKeys.length === 1 ? "field" : "fields"} ${missingKeys.map((key2) => `"${key2}"`).join(", ")}`);
|
|
26604
|
+
}
|
|
26605
|
+
if (invalidKeys.length > 0) {
|
|
26606
|
+
faults.push(`has invalid ${invalidKeys.length === 1 ? "field" : "fields"} ${invalidKeys.map((key2) => `"${key2}"`).join(", ")}`);
|
|
26607
|
+
}
|
|
26608
|
+
throw credentialInputError(
|
|
26609
|
+
"agent_credential_fields_invalid",
|
|
26610
|
+
source,
|
|
26611
|
+
faults.join(" and ")
|
|
26612
|
+
);
|
|
26613
|
+
}
|
|
26614
|
+
const expiresAt = artifact.expires_at === void 0 ? null : Date.parse(artifact.expires_at);
|
|
26615
|
+
return {
|
|
26616
|
+
token: artifact.agent_token,
|
|
26617
|
+
principalId: artifact.principal_id.toLowerCase(),
|
|
26618
|
+
tokenId: artifact.token_id.toLowerCase(),
|
|
26619
|
+
runId: artifact.run_id.toLowerCase(),
|
|
26620
|
+
expiresAt,
|
|
26621
|
+
durable: true
|
|
26622
|
+
};
|
|
26623
|
+
}
|
|
26624
|
+
|
|
26466
26625
|
// src/cloud/renewal.ts
|
|
26467
26626
|
var import_node_crypto9 = require("node:crypto");
|
|
26468
26627
|
var AGENT_TOKEN_DEFAULT_TTL_MS2 = 60 * 60 * 1e3;
|
|
@@ -26485,8 +26644,8 @@ var RENEWAL_LEAD_FLOOR_MS = 5 * 6e4;
|
|
|
26485
26644
|
var RENEWAL_LEAD_CEILING_MS = 15 * 6e4;
|
|
26486
26645
|
var RENEWAL_PENDING_RECOVERY_MS = 60 * 6e4;
|
|
26487
26646
|
var RENEW_TIMEOUT_MS = 3e4;
|
|
26488
|
-
var
|
|
26489
|
-
var
|
|
26647
|
+
var UUID_RE5 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
26648
|
+
var AGENT_TOKEN_RE4 = /^swm_agt_[A-Za-z0-9_-]{43}$/;
|
|
26490
26649
|
function renewalDueAt(issuedAt, expiresAt) {
|
|
26491
26650
|
const lifetime = Math.max(0, expiresAt - issuedAt);
|
|
26492
26651
|
const lead = Math.min(
|
|
@@ -26644,7 +26803,7 @@ async function requestSuccessor(options) {
|
|
|
26644
26803
|
} catch {
|
|
26645
26804
|
body = {};
|
|
26646
26805
|
}
|
|
26647
|
-
const principalId = typeof body.principal_id === "string" &&
|
|
26806
|
+
const principalId = typeof body.principal_id === "string" && UUID_RE5.test(body.principal_id) ? body.principal_id.toLowerCase() : null;
|
|
26648
26807
|
if (response.status === 400 || response.status === 404) {
|
|
26649
26808
|
throw new RenewalUnsupported(
|
|
26650
26809
|
"this deployment does not offer credential renewal yet, so a credential here still has to be re-issued by hand when it expires"
|
|
@@ -26732,7 +26891,7 @@ async function requestSuccessor(options) {
|
|
|
26732
26891
|
if (!token) {
|
|
26733
26892
|
return null;
|
|
26734
26893
|
}
|
|
26735
|
-
if (!
|
|
26894
|
+
if (!AGENT_TOKEN_RE4.test(token)) {
|
|
26736
26895
|
throw new RenewalRefused(
|
|
26737
26896
|
response.status,
|
|
26738
26897
|
"malformed_successor",
|
|
@@ -26741,7 +26900,7 @@ async function requestSuccessor(options) {
|
|
|
26741
26900
|
}
|
|
26742
26901
|
const tokenId = typeof body.token_id === "string" ? body.token_id : "";
|
|
26743
26902
|
const runId = typeof body.run_id === "string" ? body.run_id : "";
|
|
26744
|
-
if (!
|
|
26903
|
+
if (!UUID_RE5.test(tokenId) || !UUID_RE5.test(runId) || principalId === null) {
|
|
26745
26904
|
throw new RenewalRefused(
|
|
26746
26905
|
response.status,
|
|
26747
26906
|
"incomplete_successor",
|
|
@@ -27250,7 +27409,7 @@ var MAX_LINK_PAYLOAD_BYTES = 8 * 1024;
|
|
|
27250
27409
|
var MAX_LABEL_INPUT_LENGTH = 1024;
|
|
27251
27410
|
var CONTROL_GLOBAL_RE = /[\u0000-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/g;
|
|
27252
27411
|
var ANSI_ESCAPE_GLOBAL_RE = /\u001b\[[0-?]*[ -/]*[@-~]/g;
|
|
27253
|
-
var
|
|
27412
|
+
var UUID_RE6 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
27254
27413
|
var STRICT_BASE64URL_RE = /^[A-Za-z0-9_-]+$/;
|
|
27255
27414
|
var RAW_BASE64_PAYLOAD_CANDIDATE_RE = /^[A-Za-z0-9+/_=-]+$/;
|
|
27256
27415
|
var CURRENT_INVITE_SCHEME = "cswarm://accept/";
|
|
@@ -27301,7 +27460,7 @@ function validatedPayload(value) {
|
|
|
27301
27460
|
throw new Error("invite link target is malformed");
|
|
27302
27461
|
}
|
|
27303
27462
|
cloudTarget(value.url, value.anon_key);
|
|
27304
|
-
if (typeof value.workspace_id !== "string" || !
|
|
27463
|
+
if (typeof value.workspace_id !== "string" || !UUID_RE6.test(value.workspace_id)) {
|
|
27305
27464
|
throw new Error("invite link workspace_id must be a UUID");
|
|
27306
27465
|
}
|
|
27307
27466
|
if (typeof value.invitation_token !== "string") {
|
|
@@ -27311,7 +27470,7 @@ function validatedPayload(value) {
|
|
|
27311
27470
|
if (typeof value.workspace_name !== "string" || typeof value.inviter_display_name !== "string" || value.workspace_name.length > MAX_LABEL_INPUT_LENGTH || value.inviter_display_name.length > MAX_LABEL_INPUT_LENGTH) {
|
|
27312
27471
|
throw new Error("invite link display labels are malformed");
|
|
27313
27472
|
}
|
|
27314
|
-
if (value.inviter_user_id !== void 0 && (typeof value.inviter_user_id !== "string" || !
|
|
27473
|
+
if (value.inviter_user_id !== void 0 && (typeof value.inviter_user_id !== "string" || !UUID_RE6.test(value.inviter_user_id))) {
|
|
27315
27474
|
throw new Error("invite link inviter_user_id must be a UUID");
|
|
27316
27475
|
}
|
|
27317
27476
|
return value;
|
|
@@ -27969,7 +28128,7 @@ function renderCapabilityRevoke(capabilityId, revokedAt) {
|
|
|
27969
28128
|
}
|
|
27970
28129
|
|
|
27971
28130
|
// src/cloud/renewal-grants.ts
|
|
27972
|
-
var
|
|
28131
|
+
var UUID_RE7 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
27973
28132
|
function nullableString(value, field) {
|
|
27974
28133
|
if (value === null) return null;
|
|
27975
28134
|
if (typeof value !== "string") {
|
|
@@ -27985,7 +28144,7 @@ function nullableTimestamp(value, field) {
|
|
|
27985
28144
|
return text;
|
|
27986
28145
|
}
|
|
27987
28146
|
function uuid3(value, field) {
|
|
27988
|
-
if (typeof value !== "string" || !
|
|
28147
|
+
if (typeof value !== "string" || !UUID_RE7.test(value)) {
|
|
27989
28148
|
throw new Error(`renewal grant read returned malformed ${field}`);
|
|
27990
28149
|
}
|
|
27991
28150
|
return value.toLowerCase();
|
|
@@ -28076,7 +28235,7 @@ function describeRenewalGrant(grant) {
|
|
|
28076
28235
|
}
|
|
28077
28236
|
|
|
28078
28237
|
// src/cloud/workspaces.ts
|
|
28079
|
-
var
|
|
28238
|
+
var UUID_RE8 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
28080
28239
|
var ROLES = /* @__PURE__ */ new Set(["owner", "admin", "member"]);
|
|
28081
28240
|
var MemberSelectionError = class extends Error {
|
|
28082
28241
|
constructor(code, message, matches = []) {
|
|
@@ -28089,7 +28248,7 @@ var MemberSelectionError = class extends Error {
|
|
|
28089
28248
|
matches;
|
|
28090
28249
|
};
|
|
28091
28250
|
function resolveWorkspaceMember(selector, members) {
|
|
28092
|
-
if (
|
|
28251
|
+
if (UUID_RE8.test(selector)) {
|
|
28093
28252
|
const selected = members.find(
|
|
28094
28253
|
(member) => member.user_id === selector.toLowerCase()
|
|
28095
28254
|
);
|
|
@@ -28188,7 +28347,7 @@ var WorkspaceAmbiguousNameError = class extends WorkspaceCliError {
|
|
|
28188
28347
|
}
|
|
28189
28348
|
};
|
|
28190
28349
|
function checkedUuid(value, field) {
|
|
28191
|
-
if (typeof value !== "string" || !
|
|
28350
|
+
if (typeof value !== "string" || !UUID_RE8.test(value)) {
|
|
28192
28351
|
throw new Error(`workspace read returned a malformed ${field}`);
|
|
28193
28352
|
}
|
|
28194
28353
|
return value.toLowerCase();
|
|
@@ -28507,13 +28666,13 @@ async function updateWorkspaceDefaultAfterClose(store2, userId, closedWorkspaceI
|
|
|
28507
28666
|
}
|
|
28508
28667
|
function workspaceOverride(explicit, environmental) {
|
|
28509
28668
|
if (explicit !== void 0) {
|
|
28510
|
-
if (!
|
|
28669
|
+
if (!UUID_RE8.test(explicit)) {
|
|
28511
28670
|
throw new Error("--workspace-id must be a UUID");
|
|
28512
28671
|
}
|
|
28513
28672
|
return explicit.toLowerCase();
|
|
28514
28673
|
}
|
|
28515
28674
|
if (environmental) {
|
|
28516
|
-
if (!
|
|
28675
|
+
if (!UUID_RE8.test(environmental)) {
|
|
28517
28676
|
throw new Error("SWARM_CLOUD_WORKSPACE_ID must be a UUID");
|
|
28518
28677
|
}
|
|
28519
28678
|
return environmental.toLowerCase();
|
|
@@ -28573,7 +28732,7 @@ async function selectWorkspace(selector, workspaces, store2, userId) {
|
|
|
28573
28732
|
function resolveWorkspaceSelector(selector, workspaces) {
|
|
28574
28733
|
const sorted = sortWorkspaces(workspaces);
|
|
28575
28734
|
let selected;
|
|
28576
|
-
if (
|
|
28735
|
+
if (UUID_RE8.test(selector)) {
|
|
28577
28736
|
const normalized = selector.toLowerCase();
|
|
28578
28737
|
selected = sorted.find(
|
|
28579
28738
|
(workspace) => workspace.workspace_id === normalized
|
|
@@ -28723,7 +28882,7 @@ function describeServerError(prefix, envelope) {
|
|
|
28723
28882
|
|
|
28724
28883
|
// src/cloud/attachments.ts
|
|
28725
28884
|
var SIGNAL_ATTACHMENT_MAX = 8;
|
|
28726
|
-
var
|
|
28885
|
+
var UUID_RE9 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
28727
28886
|
function parseSignalAttachments(value, options = {}) {
|
|
28728
28887
|
if (options.enabled === false || value === void 0) return [];
|
|
28729
28888
|
if (!Array.isArray(value) || value.length > SIGNAL_ATTACHMENT_MAX) {
|
|
@@ -28736,7 +28895,7 @@ function parseSignalAttachments(value, options = {}) {
|
|
|
28736
28895
|
throw new Error("signal read returned a malformed attachment");
|
|
28737
28896
|
}
|
|
28738
28897
|
const row = valueAtPosition;
|
|
28739
|
-
if (typeof row.file_id !== "string" || !
|
|
28898
|
+
if (typeof row.file_id !== "string" || !UUID_RE9.test(row.file_id) || typeof row.version_n !== "number" || !Number.isSafeInteger(row.version_n) || row.version_n < 1 || typeof row.name !== "string" || row.name.length < 1 || row.name.length > 255 || typeof row.content_type !== "string" || row.content_type.length < 1 || typeof row.size_bytes !== "number" || !Number.isSafeInteger(row.size_bytes) || row.size_bytes < 0) {
|
|
28740
28899
|
throw new Error("signal read returned malformed attachment metadata");
|
|
28741
28900
|
}
|
|
28742
28901
|
const fileId = row.file_id.toLowerCase();
|
|
@@ -28756,7 +28915,7 @@ function parseSignalAttachments(value, options = {}) {
|
|
|
28756
28915
|
return attachments;
|
|
28757
28916
|
}
|
|
28758
28917
|
function attachmentRetrievalCommand(workspaceId2, attachment) {
|
|
28759
|
-
if (!
|
|
28918
|
+
if (!UUID_RE9.test(workspaceId2) || !UUID_RE9.test(attachment.file_id)) {
|
|
28760
28919
|
throw new Error("attachment retrieval command needs UUID identifiers");
|
|
28761
28920
|
}
|
|
28762
28921
|
if (!Number.isSafeInteger(attachment.version_n) || attachment.version_n < 1) {
|
|
@@ -28772,7 +28931,7 @@ function formatAttachmentSize(bytes) {
|
|
|
28772
28931
|
}
|
|
28773
28932
|
|
|
28774
28933
|
// src/cloud/signals.ts
|
|
28775
|
-
var
|
|
28934
|
+
var UUID_RE10 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
28776
28935
|
var SIGNAL_KINDS = /* @__PURE__ */ new Set(["working-on", "note", "ask"]);
|
|
28777
28936
|
var SIGNAL_BODY_DISPLAY_MAX = 8e3;
|
|
28778
28937
|
var SIGNAL_ABOUT_DISPLAY_MAX = 500;
|
|
@@ -28843,7 +29002,7 @@ function plainMalformedError(message) {
|
|
|
28843
29002
|
return error;
|
|
28844
29003
|
}
|
|
28845
29004
|
function checkedUuid2(value, field) {
|
|
28846
|
-
if (typeof value !== "string" || !
|
|
29005
|
+
if (typeof value !== "string" || !UUID_RE10.test(value)) {
|
|
28847
29006
|
throw new Error(`signal read returned a malformed ${field}`);
|
|
28848
29007
|
}
|
|
28849
29008
|
return value.toLowerCase();
|
|
@@ -29474,7 +29633,7 @@ async function readAgentSignalDirectory(target2, token, workspaceId2, fetcherOrO
|
|
|
29474
29633
|
}
|
|
29475
29634
|
function resolveSignalRecipient(selector, directory) {
|
|
29476
29635
|
const resolved = Array.isArray(directory) ? { members: directory, agents: [] } : directory;
|
|
29477
|
-
if (
|
|
29636
|
+
if (UUID_RE10.test(selector)) {
|
|
29478
29637
|
const normalized = selector.toLowerCase();
|
|
29479
29638
|
const member = resolved.members.find((row) => row.user_id === normalized);
|
|
29480
29639
|
const agent = resolved.agents.find(
|
|
@@ -29560,10 +29719,10 @@ async function pollForSignals(options) {
|
|
|
29560
29719
|
return { signals: [], timedOut: true };
|
|
29561
29720
|
}
|
|
29562
29721
|
function normalizedSignalQuery(query) {
|
|
29563
|
-
if (!
|
|
29722
|
+
if (!UUID_RE10.test(query.workspaceId)) {
|
|
29564
29723
|
throw new Error("--workspace-id must be a UUID");
|
|
29565
29724
|
}
|
|
29566
|
-
if (query.in_reply_to !== void 0 && !
|
|
29725
|
+
if (query.in_reply_to !== void 0 && !UUID_RE10.test(query.in_reply_to)) {
|
|
29567
29726
|
throw new Error("in_reply_to must be a signal UUID");
|
|
29568
29727
|
}
|
|
29569
29728
|
const after = checkedAfter(query.after);
|
|
@@ -30081,7 +30240,7 @@ async function runInboxFollow(options) {
|
|
|
30081
30240
|
// src/cloud/arrival-watch.ts
|
|
30082
30241
|
var import_node_os4 = require("node:os");
|
|
30083
30242
|
var import_node_path4 = require("node:path");
|
|
30084
|
-
var
|
|
30243
|
+
var UUID_RE11 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
30085
30244
|
var CURSOR_MAX_BYTES = 4 * 1024;
|
|
30086
30245
|
var ARRIVAL_SNIPPET_MAX = 180;
|
|
30087
30246
|
var ARRIVAL_WATCH_POLL_MS = 25e3;
|
|
@@ -30149,7 +30308,7 @@ function parseCursor(raw, workspaceId2, principalId) {
|
|
|
30149
30308
|
}
|
|
30150
30309
|
const row = value;
|
|
30151
30310
|
const cursor = row.cursor;
|
|
30152
|
-
if (row.version !== 1 || row.workspace_id !== workspaceId2.toLowerCase() || row.principal_id !== principalId.toLowerCase() || !(cursor === null || typeof cursor === "object" && !Array.isArray(cursor) && typeof cursor.created_at === "string" && Number.isFinite(Date.parse(cursor.created_at)) && typeof cursor.id === "string" &&
|
|
30311
|
+
if (row.version !== 1 || row.workspace_id !== workspaceId2.toLowerCase() || row.principal_id !== principalId.toLowerCase() || !(cursor === null || typeof cursor === "object" && !Array.isArray(cursor) && typeof cursor.created_at === "string" && Number.isFinite(Date.parse(cursor.created_at)) && typeof cursor.id === "string" && UUID_RE11.test(cursor.id))) {
|
|
30153
30312
|
throw new Error("stored arrival cursor is malformed");
|
|
30154
30313
|
}
|
|
30155
30314
|
if (cursor === null) return null;
|
|
@@ -30161,7 +30320,7 @@ function parseCursor(raw, workspaceId2, principalId) {
|
|
|
30161
30320
|
function fileArrivalCursorStore(options) {
|
|
30162
30321
|
const workspaceId2 = options.workspaceId.toLowerCase();
|
|
30163
30322
|
const principalId = options.principalId.toLowerCase();
|
|
30164
|
-
if (!
|
|
30323
|
+
if (!UUID_RE11.test(workspaceId2) || !UUID_RE11.test(principalId)) {
|
|
30165
30324
|
throw new Error("arrival cursor identity must use workspace and principal UUIDs");
|
|
30166
30325
|
}
|
|
30167
30326
|
const location2 = arrivalCursorPath(
|
|
@@ -30343,7 +30502,7 @@ async function runArrivalWatch(options) {
|
|
|
30343
30502
|
}
|
|
30344
30503
|
|
|
30345
30504
|
// src/cloud/delivery-receipts.ts
|
|
30346
|
-
var
|
|
30505
|
+
var UUID_RE12 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
30347
30506
|
var DeliveryReceiptReadError = class extends Error {
|
|
30348
30507
|
constructor(code, message, status = null) {
|
|
30349
30508
|
super(message);
|
|
@@ -30362,7 +30521,7 @@ var ACK_OUTCOMES = /* @__PURE__ */ new Set([
|
|
|
30362
30521
|
"failed_terminal"
|
|
30363
30522
|
]);
|
|
30364
30523
|
function uuid4(value, field) {
|
|
30365
|
-
if (typeof value !== "string" || !
|
|
30524
|
+
if (typeof value !== "string" || !UUID_RE12.test(value)) {
|
|
30366
30525
|
throw new DeliveryReceiptReadError(
|
|
30367
30526
|
"protocol",
|
|
30368
30527
|
`delivery receipt returned a malformed ${field}`
|
|
@@ -30919,161 +31078,753 @@ function signalReceiptJsonPayload(report, nowMs = Date.now()) {
|
|
|
30919
31078
|
};
|
|
30920
31079
|
}
|
|
30921
31080
|
|
|
30922
|
-
// src/cloud/
|
|
30923
|
-
var
|
|
30924
|
-
var
|
|
30925
|
-
var
|
|
30926
|
-
|
|
31081
|
+
// src/cloud/delivery.ts
|
|
31082
|
+
var UUID_RE13 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
31083
|
+
var RFC3339_TIMESTAMP_RE = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:Z|([+-]\d{2}):(\d{2}))$/i;
|
|
31084
|
+
var DELIVERY_KINDS = /* @__PURE__ */ new Set(["ask", "note"]);
|
|
31085
|
+
var SENDER_OWNER_RELATIONS2 = /* @__PURE__ */ new Set([
|
|
31086
|
+
"same_owner",
|
|
31087
|
+
"cross_owner",
|
|
31088
|
+
"unknown"
|
|
31089
|
+
]);
|
|
31090
|
+
var DELIVERY_ACK_OUTCOMES = /* @__PURE__ */ new Set([
|
|
31091
|
+
"replied",
|
|
31092
|
+
"observed",
|
|
31093
|
+
"queued",
|
|
31094
|
+
"expired",
|
|
31095
|
+
"failed_terminal"
|
|
31096
|
+
]);
|
|
31097
|
+
var DELIVERY_HANDLED_OUTCOMES = new Set(
|
|
31098
|
+
[...DELIVERY_ACK_OUTCOMES].filter(
|
|
31099
|
+
(outcome) => outcome === "replied" || outcome === "observed"
|
|
31100
|
+
)
|
|
31101
|
+
);
|
|
31102
|
+
var DELIVERY_PROVIDER_PROVEN_OUTCOMES = new Set(
|
|
31103
|
+
[...DELIVERY_ACK_OUTCOMES].filter((outcome) => outcome === "replied")
|
|
31104
|
+
);
|
|
31105
|
+
function orList(values2) {
|
|
31106
|
+
return values2.length <= 1 ? values2.join("") : `${values2.slice(0, -1).join(", ")}, or ${values2[values2.length - 1]}`;
|
|
31107
|
+
}
|
|
31108
|
+
var DELIVERY_REQUEST_TIMEOUT_MS = 3e4;
|
|
31109
|
+
var COMMAND_ID_VALIDATOR_RE = /^[A-Za-z0-9_-]{8,72}$/;
|
|
31110
|
+
var FAILED_TERMINAL_CODES_SET = /* @__PURE__ */ new Set([
|
|
31111
|
+
"provider_refused",
|
|
31112
|
+
"local_effect_failed",
|
|
31113
|
+
"host_session_failed",
|
|
31114
|
+
"credential_unavailable"
|
|
31115
|
+
]);
|
|
31116
|
+
var SERVER_ERROR_CODES_SET = /* @__PURE__ */ new Set([
|
|
31117
|
+
"unauthenticated",
|
|
31118
|
+
"fresh_auth_required",
|
|
31119
|
+
"invalid_request",
|
|
31120
|
+
"payload_too_large",
|
|
31121
|
+
"forbidden",
|
|
31122
|
+
"delivery_unavailable",
|
|
31123
|
+
"delivery_ack_conflict",
|
|
31124
|
+
"command_id_conflict",
|
|
31125
|
+
"rate_limited",
|
|
31126
|
+
"upgrade_required",
|
|
31127
|
+
"temporarily_unavailable",
|
|
31128
|
+
"internal_error"
|
|
31129
|
+
]);
|
|
31130
|
+
var DELIVERY_FAILED_TERMINAL_CODES = Object.freeze([
|
|
31131
|
+
"provider_refused",
|
|
31132
|
+
"local_effect_failed",
|
|
31133
|
+
"host_session_failed",
|
|
31134
|
+
"credential_unavailable"
|
|
31135
|
+
]);
|
|
31136
|
+
var DELIVERY_SERVER_ERROR_CODES = Object.freeze([
|
|
31137
|
+
"unauthenticated",
|
|
31138
|
+
"fresh_auth_required",
|
|
31139
|
+
"invalid_request",
|
|
31140
|
+
"payload_too_large",
|
|
31141
|
+
"forbidden",
|
|
31142
|
+
"delivery_unavailable",
|
|
31143
|
+
"delivery_ack_conflict",
|
|
31144
|
+
"command_id_conflict",
|
|
31145
|
+
"rate_limited",
|
|
31146
|
+
"upgrade_required",
|
|
31147
|
+
"temporarily_unavailable",
|
|
31148
|
+
"internal_error"
|
|
31149
|
+
]);
|
|
31150
|
+
var DELIVERY_UNKNOWN_ERROR_CODE = "unknown_error";
|
|
31151
|
+
function observationCommandId(signalId) {
|
|
31152
|
+
checkedUuidRequest(signalId, "signalId");
|
|
31153
|
+
return `observe_${signalId.toLowerCase().replaceAll("-", "")}`;
|
|
31154
|
+
}
|
|
31155
|
+
var DeliveryTransportError = class extends Error {
|
|
31156
|
+
constructor(message) {
|
|
31157
|
+
super(message);
|
|
31158
|
+
this.name = "DeliveryTransportError";
|
|
31159
|
+
}
|
|
31160
|
+
};
|
|
31161
|
+
var DeliveryHttpError = class extends Error {
|
|
31162
|
+
constructor(status, code, message, retryAfterMs = null) {
|
|
30927
31163
|
super(message);
|
|
30928
|
-
this.code = code;
|
|
30929
31164
|
this.status = status;
|
|
30930
|
-
this.
|
|
31165
|
+
this.code = code;
|
|
31166
|
+
this.retryAfterMs = retryAfterMs;
|
|
31167
|
+
this.name = "DeliveryHttpError";
|
|
30931
31168
|
}
|
|
30932
|
-
code;
|
|
30933
31169
|
status;
|
|
31170
|
+
code;
|
|
31171
|
+
retryAfterMs;
|
|
30934
31172
|
};
|
|
30935
|
-
|
|
30936
|
-
|
|
30937
|
-
(
|
|
30938
|
-
|
|
31173
|
+
var DeliveryProtocolError = class extends Error {
|
|
31174
|
+
constructor(message) {
|
|
31175
|
+
super(message);
|
|
31176
|
+
this.name = "DeliveryProtocolError";
|
|
31177
|
+
}
|
|
31178
|
+
};
|
|
31179
|
+
function checkedUuid3(value, field) {
|
|
31180
|
+
if (typeof value !== "string" || !UUID_RE13.test(value)) {
|
|
31181
|
+
throw new DeliveryProtocolError(
|
|
31182
|
+
`delivery response returned a malformed ${field}`
|
|
31183
|
+
);
|
|
31184
|
+
}
|
|
31185
|
+
return value.toLowerCase();
|
|
30939
31186
|
}
|
|
30940
|
-
function
|
|
30941
|
-
|
|
30942
|
-
|
|
30943
|
-
|
|
30944
|
-
|
|
31187
|
+
function isLeapYear(year) {
|
|
31188
|
+
return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
31189
|
+
}
|
|
31190
|
+
function daysInMonth(year, month) {
|
|
31191
|
+
switch (month) {
|
|
31192
|
+
case 1:
|
|
31193
|
+
case 3:
|
|
31194
|
+
case 5:
|
|
31195
|
+
case 7:
|
|
31196
|
+
case 8:
|
|
31197
|
+
case 10:
|
|
31198
|
+
case 12:
|
|
31199
|
+
return 31;
|
|
31200
|
+
case 4:
|
|
31201
|
+
case 6:
|
|
31202
|
+
case 9:
|
|
31203
|
+
case 11:
|
|
31204
|
+
return 30;
|
|
31205
|
+
case 2:
|
|
31206
|
+
return isLeapYear(year) ? 29 : 28;
|
|
31207
|
+
default:
|
|
31208
|
+
return 0;
|
|
30945
31209
|
}
|
|
30946
|
-
return batches;
|
|
30947
31210
|
}
|
|
30948
|
-
|
|
30949
|
-
|
|
30950
|
-
|
|
30951
|
-
|
|
30952
|
-
try {
|
|
30953
|
-
response = await fetcher(commandEndpoint(target2), {
|
|
30954
|
-
method: "POST",
|
|
30955
|
-
headers: {
|
|
30956
|
-
authorization: `Bearer ${token}`,
|
|
30957
|
-
apikey: target2.anonKey,
|
|
30958
|
-
"content-type": "application/json"
|
|
30959
|
-
},
|
|
30960
|
-
body: JSON.stringify({
|
|
30961
|
-
command_id: newCommandId(),
|
|
30962
|
-
client_version: CLIENT_PROTOCOL_VERSION,
|
|
30963
|
-
workspace_id: workspaceId2,
|
|
30964
|
-
stream: { kind: "workspace" },
|
|
30965
|
-
command: { kind: "signals_seen", signal_ids: signalIds }
|
|
30966
|
-
}),
|
|
30967
|
-
signal: controller.signal
|
|
30968
|
-
});
|
|
30969
|
-
} catch {
|
|
30970
|
-
throw new AgentSeenReportError(
|
|
30971
|
-
"transport",
|
|
30972
|
-
"agent seen report did not reach the command service"
|
|
31211
|
+
function checkedRfc3339Timestamp(value, field) {
|
|
31212
|
+
if (typeof value !== "string") {
|
|
31213
|
+
throw new DeliveryProtocolError(
|
|
31214
|
+
`delivery response returned a malformed ${field}`
|
|
30973
31215
|
);
|
|
30974
|
-
} finally {
|
|
30975
|
-
clearTimeout(timer2);
|
|
30976
31216
|
}
|
|
30977
|
-
|
|
30978
|
-
|
|
30979
|
-
|
|
30980
|
-
`
|
|
30981
|
-
response.status
|
|
31217
|
+
const match = RFC3339_TIMESTAMP_RE.exec(value);
|
|
31218
|
+
if (!match) {
|
|
31219
|
+
throw new DeliveryProtocolError(
|
|
31220
|
+
`delivery response returned a malformed ${field}`
|
|
30982
31221
|
);
|
|
30983
31222
|
}
|
|
30984
|
-
|
|
30985
|
-
|
|
30986
|
-
|
|
30987
|
-
|
|
30988
|
-
|
|
30989
|
-
|
|
30990
|
-
|
|
30991
|
-
|
|
31223
|
+
const year = parseInt(match[1], 10);
|
|
31224
|
+
const month = parseInt(match[2], 10);
|
|
31225
|
+
const day = parseInt(match[3], 10);
|
|
31226
|
+
const hour = parseInt(match[4], 10);
|
|
31227
|
+
const minute = parseInt(match[5], 10);
|
|
31228
|
+
const second = parseInt(match[6], 10);
|
|
31229
|
+
if (month < 1 || month > 12 || day < 1 || day > daysInMonth(year, month) || hour < 0 || hour > 23 || minute < 0 || minute > 59 || second < 0 || second > 59) {
|
|
31230
|
+
throw new DeliveryProtocolError(
|
|
31231
|
+
`delivery response returned a malformed ${field}`
|
|
30992
31232
|
);
|
|
30993
31233
|
}
|
|
30994
|
-
if (
|
|
30995
|
-
|
|
30996
|
-
|
|
30997
|
-
|
|
30998
|
-
|
|
31234
|
+
if (match[7] !== void 0 && match[8] !== void 0) {
|
|
31235
|
+
const offsetHour = Math.abs(parseInt(match[7], 10));
|
|
31236
|
+
const offsetMin = parseInt(match[8], 10);
|
|
31237
|
+
if (offsetHour > 23 || offsetMin < 0 || offsetMin > 59) {
|
|
31238
|
+
throw new DeliveryProtocolError(
|
|
31239
|
+
`delivery response returned a malformed ${field}`
|
|
31240
|
+
);
|
|
31241
|
+
}
|
|
31242
|
+
}
|
|
31243
|
+
if (!Number.isFinite(Date.parse(value))) {
|
|
31244
|
+
throw new DeliveryProtocolError(
|
|
31245
|
+
`delivery response returned a malformed ${field}`
|
|
30999
31246
|
);
|
|
31000
31247
|
}
|
|
31248
|
+
return value;
|
|
31001
31249
|
}
|
|
31002
|
-
|
|
31003
|
-
|
|
31004
|
-
|
|
31005
|
-
|
|
31006
|
-
|
|
31007
|
-
|
|
31008
|
-
|
|
31009
|
-
|
|
31010
|
-
|
|
31011
|
-
|
|
31012
|
-
|
|
31250
|
+
function checkedLiveLease(leasedUntil, now) {
|
|
31251
|
+
if (Date.parse(leasedUntil) <= now()) {
|
|
31252
|
+
throw new DeliveryProtocolError(
|
|
31253
|
+
"delivery claim response returned an already expired lease"
|
|
31254
|
+
);
|
|
31255
|
+
}
|
|
31256
|
+
}
|
|
31257
|
+
function checkedRelation(value) {
|
|
31258
|
+
if (typeof value !== "string" || !SENDER_OWNER_RELATIONS2.has(value)) {
|
|
31259
|
+
throw new DeliveryProtocolError(
|
|
31260
|
+
"delivery response returned a malformed sender_owner_relation"
|
|
31261
|
+
);
|
|
31262
|
+
}
|
|
31263
|
+
return value;
|
|
31264
|
+
}
|
|
31265
|
+
function checkedNonNegativeCount(value, field) {
|
|
31266
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
|
|
31267
|
+
throw new DeliveryProtocolError(
|
|
31268
|
+
`delivery response returned a malformed ${field}`
|
|
31269
|
+
);
|
|
31270
|
+
}
|
|
31271
|
+
return value;
|
|
31272
|
+
}
|
|
31273
|
+
function checkedClaimCapabilities(value) {
|
|
31274
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
31275
|
+
throw new DeliveryProtocolError(
|
|
31276
|
+
"delivery claim response is missing delivery capabilities"
|
|
31277
|
+
);
|
|
31278
|
+
}
|
|
31279
|
+
const row = value;
|
|
31280
|
+
for (const marker of ["delivery_claim", "delivery_ack", "sender_owner_relation"]) {
|
|
31281
|
+
if (row[marker] !== 1) {
|
|
31282
|
+
throw new DeliveryProtocolError(
|
|
31283
|
+
`delivery claim response is missing the ${marker} capability`
|
|
31013
31284
|
);
|
|
31014
31285
|
}
|
|
31015
31286
|
}
|
|
31016
|
-
return {
|
|
31287
|
+
return { deliveryClaim: true, deliveryAck: true, senderOwnerRelation: true };
|
|
31017
31288
|
}
|
|
31018
|
-
|
|
31019
|
-
|
|
31020
|
-
|
|
31021
|
-
|
|
31022
|
-
|
|
31023
|
-
|
|
31024
|
-
|
|
31025
|
-
var SEPARATOR_CLASS_SOURCE = "\\t\\n\\x0b\\f\\r " + EXOTIC_SEPARATORS;
|
|
31026
|
-
var ANSI_ESCAPE_GLOBAL_RE2 = new RegExp("\\u001b\\[[0-?]*[ -\\/]*[@-~]", "g");
|
|
31027
|
-
var CONTROL_AND_SEPARATOR_STRIP_RE = new RegExp(
|
|
31028
|
-
"[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f" + EXOTIC_SEPARATORS + "]",
|
|
31029
|
-
"g"
|
|
31030
|
-
);
|
|
31031
|
-
var CREDENTIAL_PREFIX_RE = new RegExp(
|
|
31032
|
-
`swm_(?:agt|inv|cap)_[^${SEPARATOR_CLASS_SOURCE}]*`,
|
|
31033
|
-
"gi"
|
|
31034
|
-
);
|
|
31035
|
-
function redactCredentialText(value) {
|
|
31036
|
-
return value.replace(ANSI_ESCAPE_GLOBAL_RE2, "").replace(CONTROL_AND_SEPARATOR_STRIP_RE, "").replace(CREDENTIAL_PREFIX_RE, "[redacted-credential]");
|
|
31289
|
+
function checkedOptionalUuidArray(value, field) {
|
|
31290
|
+
if (value === void 0) return;
|
|
31291
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== "string" || !UUID_RE13.test(item))) {
|
|
31292
|
+
throw new DeliveryProtocolError(
|
|
31293
|
+
`delivery response returned a malformed ${field}`
|
|
31294
|
+
);
|
|
31295
|
+
}
|
|
31037
31296
|
}
|
|
31038
|
-
|
|
31039
|
-
|
|
31040
|
-
|
|
31041
|
-
|
|
31042
|
-
|
|
31043
|
-
|
|
31044
|
-
|
|
31045
|
-
return redactCredentialText(raw).slice(-TAIL_MAX_CHARS).trim();
|
|
31297
|
+
function checkedOptionalArray(value, field) {
|
|
31298
|
+
if (value === void 0) return;
|
|
31299
|
+
if (!Array.isArray(value)) {
|
|
31300
|
+
throw new DeliveryProtocolError(
|
|
31301
|
+
`delivery response returned a malformed ${field}`
|
|
31302
|
+
);
|
|
31303
|
+
}
|
|
31046
31304
|
}
|
|
31047
|
-
function
|
|
31048
|
-
|
|
31049
|
-
|
|
31050
|
-
|
|
31051
|
-
|
|
31052
|
-
|
|
31053
|
-
|
|
31054
|
-
|
|
31055
|
-
|
|
31056
|
-
|
|
31057
|
-
|
|
31058
|
-
|
|
31059
|
-
|
|
31060
|
-
|
|
31061
|
-
|
|
31062
|
-
|
|
31063
|
-
|
|
31064
|
-
|
|
31065
|
-
|
|
31305
|
+
function parseDeliveryRow(value, expected, index, now) {
|
|
31306
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
31307
|
+
throw new DeliveryProtocolError(
|
|
31308
|
+
"delivery claim response returned a malformed delivery row"
|
|
31309
|
+
);
|
|
31310
|
+
}
|
|
31311
|
+
const row = value;
|
|
31312
|
+
let signal;
|
|
31313
|
+
try {
|
|
31314
|
+
signal = parseSignalRecord(row.signal);
|
|
31315
|
+
} catch {
|
|
31316
|
+
throw new DeliveryProtocolError(
|
|
31317
|
+
`delivery claim response returned a malformed signal at ${index}`
|
|
31318
|
+
);
|
|
31319
|
+
}
|
|
31320
|
+
if (signal.workspace_id !== expected.workspaceId) {
|
|
31321
|
+
throw new DeliveryProtocolError(
|
|
31322
|
+
"delivery claim response returned a signal for another workspace"
|
|
31323
|
+
);
|
|
31324
|
+
}
|
|
31325
|
+
if (signal.to_agent !== expected.principalId) {
|
|
31326
|
+
throw new DeliveryProtocolError(
|
|
31327
|
+
"delivery claim response returned a signal addressed to another agent"
|
|
31328
|
+
);
|
|
31329
|
+
}
|
|
31330
|
+
if (!DELIVERY_KINDS.has(signal.kind)) {
|
|
31331
|
+
throw new DeliveryProtocolError(
|
|
31332
|
+
"delivery claim response returned a non-direct signal kind"
|
|
31333
|
+
);
|
|
31334
|
+
}
|
|
31335
|
+
const senderOwnerRelation = checkedRelation(row.sender_owner_relation);
|
|
31336
|
+
const leaseId = checkedUuid3(row.lease_id, "lease_id");
|
|
31337
|
+
const leasedUntil = checkedRfc3339Timestamp(row.leased_until, "leased_until");
|
|
31338
|
+
checkedLiveLease(leasedUntil, now);
|
|
31339
|
+
signal.sender_owner_relation = senderOwnerRelation;
|
|
31340
|
+
return { signal, leaseId, leasedUntil, senderOwnerRelation };
|
|
31341
|
+
}
|
|
31342
|
+
function parseClaimSuccess(body, expected, now) {
|
|
31343
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) {
|
|
31344
|
+
throw new DeliveryProtocolError("delivery claim response was not an object");
|
|
31345
|
+
}
|
|
31346
|
+
const row = body;
|
|
31347
|
+
if (row.status !== "accepted" || row.ok !== true) {
|
|
31348
|
+
throw new DeliveryProtocolError(
|
|
31349
|
+
"delivery claim response did not report accepted ok"
|
|
31350
|
+
);
|
|
31351
|
+
}
|
|
31352
|
+
const capabilities = checkedClaimCapabilities(row.capabilities);
|
|
31353
|
+
checkedOptionalUuidArray(row.event_ids, "event_ids");
|
|
31354
|
+
checkedOptionalArray(row.events, "events");
|
|
31355
|
+
if (!Array.isArray(row.deliveries)) {
|
|
31356
|
+
throw new DeliveryProtocolError(
|
|
31357
|
+
"delivery claim response is missing its deliveries array"
|
|
31358
|
+
);
|
|
31359
|
+
}
|
|
31360
|
+
const deliveries = row.deliveries.map(
|
|
31361
|
+
(item, index) => parseDeliveryRow(item, expected, index, now)
|
|
31362
|
+
);
|
|
31363
|
+
const signalIds = /* @__PURE__ */ new Set();
|
|
31364
|
+
const leaseIds = /* @__PURE__ */ new Set();
|
|
31365
|
+
for (const delivery of deliveries) {
|
|
31366
|
+
if (signalIds.has(delivery.signal.id)) {
|
|
31367
|
+
throw new DeliveryProtocolError(
|
|
31368
|
+
"delivery claim response repeats a signal id"
|
|
31369
|
+
);
|
|
31066
31370
|
}
|
|
31067
|
-
|
|
31068
|
-
|
|
31069
|
-
|
|
31070
|
-
|
|
31071
|
-
|
|
31072
|
-
|
|
31073
|
-
|
|
31074
|
-
|
|
31075
|
-
|
|
31076
|
-
|
|
31371
|
+
signalIds.add(delivery.signal.id);
|
|
31372
|
+
if (leaseIds.has(delivery.leaseId)) {
|
|
31373
|
+
throw new DeliveryProtocolError(
|
|
31374
|
+
"delivery claim response repeats a lease id"
|
|
31375
|
+
);
|
|
31376
|
+
}
|
|
31377
|
+
leaseIds.add(delivery.leaseId);
|
|
31378
|
+
}
|
|
31379
|
+
if (deliveries.length > 1) {
|
|
31380
|
+
throw new DeliveryProtocolError(
|
|
31381
|
+
"delivery claim response returned more than one delivery"
|
|
31382
|
+
);
|
|
31383
|
+
}
|
|
31384
|
+
const pendingDeliveryCount = checkedNonNegativeCount(
|
|
31385
|
+
row.pending_delivery_count,
|
|
31386
|
+
"pending_delivery_count"
|
|
31387
|
+
);
|
|
31388
|
+
const terminalDeliveryFailureCount = checkedNonNegativeCount(
|
|
31389
|
+
row.terminal_delivery_failure_count,
|
|
31390
|
+
"terminal_delivery_failure_count"
|
|
31391
|
+
);
|
|
31392
|
+
if (deliveries.length > pendingDeliveryCount) {
|
|
31393
|
+
throw new DeliveryProtocolError(
|
|
31394
|
+
"delivery claim response returned more deliveries than its pending count"
|
|
31395
|
+
);
|
|
31396
|
+
}
|
|
31397
|
+
return {
|
|
31398
|
+
capabilities,
|
|
31399
|
+
deliveries,
|
|
31400
|
+
pendingDeliveryCount,
|
|
31401
|
+
terminalDeliveryFailureCount
|
|
31402
|
+
};
|
|
31403
|
+
}
|
|
31404
|
+
function parseAckSuccess(body, expected) {
|
|
31405
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) {
|
|
31406
|
+
throw new DeliveryProtocolError(
|
|
31407
|
+
"delivery acknowledgement response was not an object"
|
|
31408
|
+
);
|
|
31409
|
+
}
|
|
31410
|
+
const row = body;
|
|
31411
|
+
if (row.status !== "accepted" || row.ok !== true) {
|
|
31412
|
+
throw new DeliveryProtocolError(
|
|
31413
|
+
"delivery acknowledgement response did not report accepted ok"
|
|
31414
|
+
);
|
|
31415
|
+
}
|
|
31416
|
+
checkedOptionalUuidArray(row.event_ids, "event_ids");
|
|
31417
|
+
checkedOptionalArray(row.events, "events");
|
|
31418
|
+
if (row.signal_id !== expected.signalId) {
|
|
31419
|
+
throw new DeliveryProtocolError(
|
|
31420
|
+
"delivery acknowledgement response echoed a different signal id"
|
|
31421
|
+
);
|
|
31422
|
+
}
|
|
31423
|
+
if (row.outcome !== expected.outcome) {
|
|
31424
|
+
throw new DeliveryProtocolError(
|
|
31425
|
+
"delivery acknowledgement response echoed a different outcome"
|
|
31426
|
+
);
|
|
31427
|
+
}
|
|
31428
|
+
}
|
|
31429
|
+
function checkedCommandId(value) {
|
|
31430
|
+
if (typeof value !== "string" || !COMMAND_ID_VALIDATOR_RE.test(value)) {
|
|
31431
|
+
throw new Error(
|
|
31432
|
+
"a delivery command id must be 8..72 characters of [A-Za-z0-9_-]"
|
|
31433
|
+
);
|
|
31434
|
+
}
|
|
31435
|
+
return value;
|
|
31436
|
+
}
|
|
31437
|
+
function checkedUuidRequest(value, field) {
|
|
31438
|
+
if (!UUID_RE13.test(value)) {
|
|
31439
|
+
throw new Error(`${field} must be a UUID for an agent delivery command`);
|
|
31440
|
+
}
|
|
31441
|
+
}
|
|
31442
|
+
function assertAckRequest(request) {
|
|
31443
|
+
checkedCommandId(request.commandId);
|
|
31444
|
+
assertAgentToken(request.credential);
|
|
31445
|
+
checkedUuidRequest(request.workspaceId, "workspaceId");
|
|
31446
|
+
checkedUuidRequest(request.signalId, "signalId");
|
|
31447
|
+
checkedUuidRequest(request.leaseId, "leaseId");
|
|
31448
|
+
checkedUuidRequest(request.listenerInstanceId, "listenerInstanceId");
|
|
31449
|
+
if (!DELIVERY_ACK_OUTCOMES.has(request.outcome)) {
|
|
31450
|
+
throw new Error(
|
|
31451
|
+
`a delivery outcome must be ${orList([...DELIVERY_ACK_OUTCOMES])}`
|
|
31452
|
+
);
|
|
31453
|
+
}
|
|
31454
|
+
if (request.outcome === "failed_terminal") {
|
|
31455
|
+
if (typeof request.lastErrorCode !== "string" || !FAILED_TERMINAL_CODES_SET.has(request.lastErrorCode)) {
|
|
31456
|
+
throw new Error(
|
|
31457
|
+
`a failed_terminal acknowledgement requires one of ${orList([...FAILED_TERMINAL_CODES_SET])}`
|
|
31458
|
+
);
|
|
31459
|
+
}
|
|
31460
|
+
} else if (request.lastErrorCode !== null) {
|
|
31461
|
+
throw new Error(
|
|
31462
|
+
"a non-failed acknowledgement must send lastErrorCode null"
|
|
31463
|
+
);
|
|
31464
|
+
}
|
|
31465
|
+
}
|
|
31466
|
+
function boundedDeliveryErrorCode(body) {
|
|
31467
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) {
|
|
31468
|
+
return DELIVERY_UNKNOWN_ERROR_CODE;
|
|
31469
|
+
}
|
|
31470
|
+
const error = body.error;
|
|
31471
|
+
if (typeof error === "string" && SERVER_ERROR_CODES_SET.has(error)) {
|
|
31472
|
+
return error;
|
|
31473
|
+
}
|
|
31474
|
+
return DELIVERY_UNKNOWN_ERROR_CODE;
|
|
31475
|
+
}
|
|
31476
|
+
function refusal(response, text) {
|
|
31477
|
+
let code = DELIVERY_UNKNOWN_ERROR_CODE;
|
|
31478
|
+
try {
|
|
31479
|
+
code = boundedDeliveryErrorCode(JSON.parse(text));
|
|
31480
|
+
} catch {
|
|
31481
|
+
}
|
|
31482
|
+
const retryAfterMs = parseRetryAfterMs(response.headers.get("retry-after"));
|
|
31483
|
+
return new DeliveryHttpError(
|
|
31484
|
+
response.status,
|
|
31485
|
+
code,
|
|
31486
|
+
`delivery command failed (HTTP ${response.status}): ${code}`,
|
|
31487
|
+
retryAfterMs
|
|
31488
|
+
);
|
|
31489
|
+
}
|
|
31490
|
+
function successBody(response, text, verb) {
|
|
31491
|
+
try {
|
|
31492
|
+
return JSON.parse(text);
|
|
31493
|
+
} catch {
|
|
31494
|
+
throw new DeliveryProtocolError(
|
|
31495
|
+
`${verb} response was not JSON (HTTP ${response.status})`
|
|
31496
|
+
);
|
|
31497
|
+
}
|
|
31498
|
+
}
|
|
31499
|
+
var DeliveryCommandClient = class {
|
|
31500
|
+
constructor(target2, fetcher = fetch, options = {}) {
|
|
31501
|
+
this.target = target2;
|
|
31502
|
+
this.fetcher = fetcher;
|
|
31503
|
+
this.deadlineMs = options.deadlineMs ?? DELIVERY_REQUEST_TIMEOUT_MS;
|
|
31504
|
+
this.now = options.now ?? Date.now;
|
|
31505
|
+
this.clearTimeoutFn = options.clearTimeout ?? ((timer2) => clearTimeout(timer2));
|
|
31506
|
+
this.createAbortControllerFn = options.createAbortController ?? (() => new AbortController());
|
|
31507
|
+
}
|
|
31508
|
+
target;
|
|
31509
|
+
fetcher;
|
|
31510
|
+
deadlineMs;
|
|
31511
|
+
now;
|
|
31512
|
+
clearTimeoutFn;
|
|
31513
|
+
createAbortControllerFn;
|
|
31514
|
+
async post(request, command2, verb) {
|
|
31515
|
+
if (this.deadlineMs <= 0) {
|
|
31516
|
+
throw new DeliveryTransportError(`${verb} request timed out`);
|
|
31517
|
+
}
|
|
31518
|
+
const deadlineController = this.createAbortControllerFn();
|
|
31519
|
+
let timedOut = false;
|
|
31520
|
+
const signal = deadlineController.signal;
|
|
31521
|
+
let onAbort = () => {
|
|
31522
|
+
};
|
|
31523
|
+
const aborted = new Promise((resolve3) => {
|
|
31524
|
+
onAbort = () => resolve3("timeout");
|
|
31525
|
+
if (signal.aborted) {
|
|
31526
|
+
onAbort();
|
|
31527
|
+
} else {
|
|
31528
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
31529
|
+
}
|
|
31530
|
+
});
|
|
31531
|
+
const timer2 = setTimeout(() => {
|
|
31532
|
+
timedOut = true;
|
|
31533
|
+
deadlineController.abort();
|
|
31534
|
+
}, this.deadlineMs);
|
|
31535
|
+
try {
|
|
31536
|
+
if (signal.aborted) {
|
|
31537
|
+
throw new DeliveryTransportError(`${verb} request timed out`);
|
|
31538
|
+
}
|
|
31539
|
+
const read = (async () => {
|
|
31540
|
+
let response;
|
|
31541
|
+
try {
|
|
31542
|
+
response = await this.fetcher(commandEndpoint(this.target), {
|
|
31543
|
+
method: "POST",
|
|
31544
|
+
headers: {
|
|
31545
|
+
authorization: `Bearer ${request.credential}`,
|
|
31546
|
+
apikey: this.target.anonKey,
|
|
31547
|
+
"content-type": "application/json"
|
|
31548
|
+
},
|
|
31549
|
+
body: JSON.stringify({
|
|
31550
|
+
command_id: request.commandId,
|
|
31551
|
+
client_version: CLIENT_PROTOCOL_VERSION,
|
|
31552
|
+
workspace_id: request.workspaceId.toLowerCase(),
|
|
31553
|
+
stream: { kind: "workspace" },
|
|
31554
|
+
command: command2
|
|
31555
|
+
}),
|
|
31556
|
+
signal
|
|
31557
|
+
});
|
|
31558
|
+
} catch (error) {
|
|
31559
|
+
if (signal.aborted || timedOut || error?.name === "AbortError") {
|
|
31560
|
+
return "timeout";
|
|
31561
|
+
}
|
|
31562
|
+
throw new DeliveryTransportError(
|
|
31563
|
+
`${verb} request failed before a response`
|
|
31564
|
+
);
|
|
31565
|
+
}
|
|
31566
|
+
if (signal.aborted || timedOut) return "timeout";
|
|
31567
|
+
let text;
|
|
31568
|
+
try {
|
|
31569
|
+
text = await response.text();
|
|
31570
|
+
} catch {
|
|
31571
|
+
if (signal.aborted || timedOut) return "timeout";
|
|
31572
|
+
throw new DeliveryTransportError(
|
|
31573
|
+
`${verb} response body was interrupted`
|
|
31574
|
+
);
|
|
31575
|
+
}
|
|
31576
|
+
if (signal.aborted || timedOut) return "timeout";
|
|
31577
|
+
return { response, text };
|
|
31578
|
+
})();
|
|
31579
|
+
const raced = await Promise.race([read, aborted]);
|
|
31580
|
+
if (raced === "timeout") {
|
|
31581
|
+
throw new DeliveryTransportError(`${verb} request timed out`);
|
|
31582
|
+
}
|
|
31583
|
+
return raced;
|
|
31584
|
+
} finally {
|
|
31585
|
+
this.clearTimeoutFn(timer2);
|
|
31586
|
+
signal.removeEventListener("abort", onAbort);
|
|
31587
|
+
}
|
|
31588
|
+
}
|
|
31589
|
+
/** Claim the caller's own single unacked direct-signal delivery row. */
|
|
31590
|
+
async claimAgentInbox(request) {
|
|
31591
|
+
checkedCommandId(request.commandId);
|
|
31592
|
+
assertAgentToken(request.credential);
|
|
31593
|
+
checkedUuidRequest(request.workspaceId, "workspaceId");
|
|
31594
|
+
checkedUuidRequest(request.listenerInstanceId, "listenerInstanceId");
|
|
31595
|
+
checkedUuidRequest(request.expectedPrincipalId, "expectedPrincipalId");
|
|
31596
|
+
const { response, text } = await this.post(request, {
|
|
31597
|
+
kind: "claim_agent_inbox",
|
|
31598
|
+
listener_instance_id: request.listenerInstanceId.toLowerCase(),
|
|
31599
|
+
limit: 1
|
|
31600
|
+
}, "delivery claim");
|
|
31601
|
+
if (!response.ok) throw refusal(response, text);
|
|
31602
|
+
const parsed = parseClaimSuccess(
|
|
31603
|
+
successBody(response, text, "delivery claim"),
|
|
31604
|
+
{
|
|
31605
|
+
workspaceId: request.workspaceId.toLowerCase(),
|
|
31606
|
+
principalId: request.expectedPrincipalId.toLowerCase()
|
|
31607
|
+
},
|
|
31608
|
+
this.now
|
|
31609
|
+
);
|
|
31610
|
+
return {
|
|
31611
|
+
httpStatus: response.status,
|
|
31612
|
+
capabilities: parsed.capabilities,
|
|
31613
|
+
deliveries: parsed.deliveries,
|
|
31614
|
+
pendingDeliveryCount: parsed.pendingDeliveryCount,
|
|
31615
|
+
terminalDeliveryFailureCount: parsed.terminalDeliveryFailureCount
|
|
31616
|
+
};
|
|
31617
|
+
}
|
|
31618
|
+
/** Acknowledge one leased delivery with an exact terminal outcome. */
|
|
31619
|
+
async ackAgentDelivery(request) {
|
|
31620
|
+
assertAckRequest(request);
|
|
31621
|
+
const { response, text } = await this.post(request, {
|
|
31622
|
+
kind: "ack_agent_delivery",
|
|
31623
|
+
signal_id: request.signalId.toLowerCase(),
|
|
31624
|
+
lease_id: request.leaseId.toLowerCase(),
|
|
31625
|
+
listener_instance_id: request.listenerInstanceId.toLowerCase(),
|
|
31626
|
+
outcome: request.outcome,
|
|
31627
|
+
last_error_code: request.lastErrorCode
|
|
31628
|
+
}, "delivery acknowledgement");
|
|
31629
|
+
if (!response.ok) throw refusal(response, text);
|
|
31630
|
+
parseAckSuccess(
|
|
31631
|
+
successBody(response, text, "delivery acknowledgement"),
|
|
31632
|
+
{
|
|
31633
|
+
signalId: request.signalId.toLowerCase(),
|
|
31634
|
+
outcome: request.outcome
|
|
31635
|
+
}
|
|
31636
|
+
);
|
|
31637
|
+
return {
|
|
31638
|
+
httpStatus: response.status,
|
|
31639
|
+
signalId: request.signalId.toLowerCase(),
|
|
31640
|
+
outcome: request.outcome
|
|
31641
|
+
};
|
|
31642
|
+
}
|
|
31643
|
+
/** Mark a queued delivery observed only after the interactive hook surfaced it. */
|
|
31644
|
+
async observeQueuedAgentDelivery(request) {
|
|
31645
|
+
checkedCommandId(request.commandId);
|
|
31646
|
+
assertAgentToken(request.credential);
|
|
31647
|
+
checkedUuidRequest(request.workspaceId, "workspaceId");
|
|
31648
|
+
checkedUuidRequest(request.signalId, "signalId");
|
|
31649
|
+
const { response, text } = await this.post(request, {
|
|
31650
|
+
kind: "ack_agent_delivery",
|
|
31651
|
+
signal_id: request.signalId.toLowerCase(),
|
|
31652
|
+
lease_id: null,
|
|
31653
|
+
listener_instance_id: null,
|
|
31654
|
+
outcome: "observed",
|
|
31655
|
+
last_error_code: null
|
|
31656
|
+
}, "delivery observation");
|
|
31657
|
+
if (!response.ok) throw refusal(response, text);
|
|
31658
|
+
parseAckSuccess(
|
|
31659
|
+
successBody(response, text, "delivery observation"),
|
|
31660
|
+
{
|
|
31661
|
+
signalId: request.signalId.toLowerCase(),
|
|
31662
|
+
outcome: "observed"
|
|
31663
|
+
}
|
|
31664
|
+
);
|
|
31665
|
+
return {
|
|
31666
|
+
httpStatus: response.status,
|
|
31667
|
+
signalId: request.signalId.toLowerCase(),
|
|
31668
|
+
outcome: "observed"
|
|
31669
|
+
};
|
|
31670
|
+
}
|
|
31671
|
+
};
|
|
31672
|
+
|
|
31673
|
+
// src/cloud/agent-signal-receipts.ts
|
|
31674
|
+
var AGENT_SEEN_BATCH_MAX = 50;
|
|
31675
|
+
var AGENT_SEEN_TIMEOUT_MS = 5e3;
|
|
31676
|
+
var AgentSeenReportError = class extends Error {
|
|
31677
|
+
constructor(code, message, status = null) {
|
|
31678
|
+
super(message);
|
|
31679
|
+
this.code = code;
|
|
31680
|
+
this.status = status;
|
|
31681
|
+
this.name = "AgentSeenReportError";
|
|
31682
|
+
}
|
|
31683
|
+
code;
|
|
31684
|
+
status;
|
|
31685
|
+
};
|
|
31686
|
+
function renderedBroadcastIds(rows3) {
|
|
31687
|
+
return [...new Set(rows3.filter(
|
|
31688
|
+
(row) => row.to === null && row.to_agent === null
|
|
31689
|
+
).map((row) => row.id))];
|
|
31690
|
+
}
|
|
31691
|
+
function agentSeenBatches(ids) {
|
|
31692
|
+
const unique = [...new Set(ids)];
|
|
31693
|
+
const batches = [];
|
|
31694
|
+
for (let offset = 0; offset < unique.length; offset += AGENT_SEEN_BATCH_MAX) {
|
|
31695
|
+
batches.push(unique.slice(offset, offset + AGENT_SEEN_BATCH_MAX));
|
|
31696
|
+
}
|
|
31697
|
+
return batches;
|
|
31698
|
+
}
|
|
31699
|
+
async function postAgentSeenBatch(target2, token, workspaceId2, signalIds, fetcher) {
|
|
31700
|
+
const controller = new AbortController();
|
|
31701
|
+
const timer2 = setTimeout(() => controller.abort(), AGENT_SEEN_TIMEOUT_MS);
|
|
31702
|
+
let response;
|
|
31703
|
+
try {
|
|
31704
|
+
response = await fetcher(commandEndpoint(target2), {
|
|
31705
|
+
method: "POST",
|
|
31706
|
+
headers: {
|
|
31707
|
+
authorization: `Bearer ${token}`,
|
|
31708
|
+
apikey: target2.anonKey,
|
|
31709
|
+
"content-type": "application/json"
|
|
31710
|
+
},
|
|
31711
|
+
body: JSON.stringify({
|
|
31712
|
+
command_id: newCommandId(),
|
|
31713
|
+
client_version: CLIENT_PROTOCOL_VERSION,
|
|
31714
|
+
workspace_id: workspaceId2,
|
|
31715
|
+
stream: { kind: "workspace" },
|
|
31716
|
+
command: { kind: "signals_seen", signal_ids: signalIds }
|
|
31717
|
+
}),
|
|
31718
|
+
signal: controller.signal
|
|
31719
|
+
});
|
|
31720
|
+
} catch {
|
|
31721
|
+
throw new AgentSeenReportError(
|
|
31722
|
+
"transport",
|
|
31723
|
+
"agent seen report did not reach the command service"
|
|
31724
|
+
);
|
|
31725
|
+
} finally {
|
|
31726
|
+
clearTimeout(timer2);
|
|
31727
|
+
}
|
|
31728
|
+
if (!response.ok) {
|
|
31729
|
+
throw new AgentSeenReportError(
|
|
31730
|
+
"http",
|
|
31731
|
+
`agent seen report was refused with HTTP ${response.status}`,
|
|
31732
|
+
response.status
|
|
31733
|
+
);
|
|
31734
|
+
}
|
|
31735
|
+
let body;
|
|
31736
|
+
try {
|
|
31737
|
+
body = await response.json();
|
|
31738
|
+
} catch {
|
|
31739
|
+
throw new AgentSeenReportError(
|
|
31740
|
+
"protocol",
|
|
31741
|
+
"agent seen report returned malformed JSON",
|
|
31742
|
+
response.status
|
|
31743
|
+
);
|
|
31744
|
+
}
|
|
31745
|
+
if (!body || typeof body !== "object" || Array.isArray(body) || body.ok !== true) {
|
|
31746
|
+
throw new AgentSeenReportError(
|
|
31747
|
+
"protocol",
|
|
31748
|
+
"agent seen report returned a malformed acknowledgement",
|
|
31749
|
+
response.status
|
|
31750
|
+
);
|
|
31751
|
+
}
|
|
31752
|
+
}
|
|
31753
|
+
async function reportRenderedBroadcasts(target2, token, workspaceId2, signalIds, fetcher = fetch) {
|
|
31754
|
+
const batches = agentSeenBatches(signalIds);
|
|
31755
|
+
const failures = [];
|
|
31756
|
+
let reported = 0;
|
|
31757
|
+
for (const batch of batches) {
|
|
31758
|
+
try {
|
|
31759
|
+
await postAgentSeenBatch(target2, token, workspaceId2, batch, fetcher);
|
|
31760
|
+
reported += batch.length;
|
|
31761
|
+
} catch (error) {
|
|
31762
|
+
failures.push(
|
|
31763
|
+
error instanceof AgentSeenReportError ? error.code : "transport"
|
|
31764
|
+
);
|
|
31765
|
+
}
|
|
31766
|
+
}
|
|
31767
|
+
return { attempted: new Set(signalIds).size, reported, failures };
|
|
31768
|
+
}
|
|
31769
|
+
|
|
31770
|
+
// src/host/opencode.ts
|
|
31771
|
+
var import_node_child_process3 = require("node:child_process");
|
|
31772
|
+
var import_node_crypto12 = require("node:crypto");
|
|
31773
|
+
|
|
31774
|
+
// src/host/credential-redaction.ts
|
|
31775
|
+
var EXOTIC_SEPARATORS = "\\u00a0\\u1680\\u2000-\\u200d\\u2028\\u2029\\u202a-\\u202e\\u2060\\u2066-\\u2069\\u202f\\u205f\\u3000\\ufeff";
|
|
31776
|
+
var SEPARATOR_CLASS_SOURCE = "\\t\\n\\x0b\\f\\r " + EXOTIC_SEPARATORS;
|
|
31777
|
+
var ANSI_ESCAPE_GLOBAL_RE2 = new RegExp("\\u001b\\[[0-?]*[ -\\/]*[@-~]", "g");
|
|
31778
|
+
var CONTROL_AND_SEPARATOR_STRIP_RE = new RegExp(
|
|
31779
|
+
"[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f" + EXOTIC_SEPARATORS + "]",
|
|
31780
|
+
"g"
|
|
31781
|
+
);
|
|
31782
|
+
var CREDENTIAL_PREFIX_RE = new RegExp(
|
|
31783
|
+
`swm_(?:agt|inv|cap)_[^${SEPARATOR_CLASS_SOURCE}]*`,
|
|
31784
|
+
"gi"
|
|
31785
|
+
);
|
|
31786
|
+
function redactCredentialText(value) {
|
|
31787
|
+
return value.replace(ANSI_ESCAPE_GLOBAL_RE2, "").replace(CONTROL_AND_SEPARATOR_STRIP_RE, "").replace(CREDENTIAL_PREFIX_RE, "[redacted-credential]");
|
|
31788
|
+
}
|
|
31789
|
+
|
|
31790
|
+
// src/host/stderr-tail.ts
|
|
31791
|
+
var RING_CAPACITY_BYTES = 4096;
|
|
31792
|
+
var TAIL_MAX_CHARS = 2048;
|
|
31793
|
+
var STDERR_EXIT_GRACE_MS = 100;
|
|
31794
|
+
var STDERR_READABLE_END_GRACE_MS = STDERR_EXIT_GRACE_MS + 50;
|
|
31795
|
+
function sanitizeStderrTail(raw) {
|
|
31796
|
+
return redactCredentialText(raw).slice(-TAIL_MAX_CHARS).trim();
|
|
31797
|
+
}
|
|
31798
|
+
function attachStderrTailRing(stderr) {
|
|
31799
|
+
const chunks = [];
|
|
31800
|
+
let total = 0;
|
|
31801
|
+
let evicted = false;
|
|
31802
|
+
stderr.on("data", (chunk) => {
|
|
31803
|
+
const buffer2 = typeof chunk === "string" ? Buffer.from(chunk) : chunk;
|
|
31804
|
+
chunks.push(buffer2);
|
|
31805
|
+
total += buffer2.length;
|
|
31806
|
+
while (total > RING_CAPACITY_BYTES && chunks.length > 0) {
|
|
31807
|
+
evicted = true;
|
|
31808
|
+
const head2 = chunks[0];
|
|
31809
|
+
const excess = total - RING_CAPACITY_BYTES;
|
|
31810
|
+
if (head2.length <= excess) {
|
|
31811
|
+
chunks.shift();
|
|
31812
|
+
total -= head2.length;
|
|
31813
|
+
} else {
|
|
31814
|
+
chunks[0] = head2.subarray(excess);
|
|
31815
|
+
total -= excess;
|
|
31816
|
+
}
|
|
31817
|
+
}
|
|
31818
|
+
});
|
|
31819
|
+
stderr.resume();
|
|
31820
|
+
return {
|
|
31821
|
+
read() {
|
|
31822
|
+
let text = Buffer.concat(chunks).toString("utf8");
|
|
31823
|
+
if (evicted) {
|
|
31824
|
+
const newline = text.indexOf("\n");
|
|
31825
|
+
text = newline === -1 ? "" : text.slice(newline + 1);
|
|
31826
|
+
}
|
|
31827
|
+
return sanitizeStderrTail(text);
|
|
31077
31828
|
}
|
|
31078
31829
|
};
|
|
31079
31830
|
}
|
|
@@ -33739,7 +34490,7 @@ async function resolveBudgetAndPrompt(session, prompt, budget) {
|
|
|
33739
34490
|
}
|
|
33740
34491
|
|
|
33741
34492
|
// src/listener/engine.ts
|
|
33742
|
-
var
|
|
34493
|
+
var UUID_RE14 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
33743
34494
|
var TERMINAL_STATES = /* @__PURE__ */ new Set(["done", "expired", "failed"]);
|
|
33744
34495
|
var REPLY_MAX_CODE_UNITS = 2e3;
|
|
33745
34496
|
var TRUNCATION_SUFFIX = "\n[Reply truncated by CommonSwarm]";
|
|
@@ -33747,7 +34498,7 @@ var UNSAFE_CONTROLS_RE = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f\u
|
|
|
33747
34498
|
var LISTENER_MAX_PROMPT_ATTEMPTS = 3;
|
|
33748
34499
|
var LISTENER_MAX_POST_ATTEMPTS = 5;
|
|
33749
34500
|
function listenerReplyCommandId(signalId, effectOrdinal = 0) {
|
|
33750
|
-
if (!
|
|
34501
|
+
if (!UUID_RE14.test(signalId)) {
|
|
33751
34502
|
throw new Error("listener signal id must be a UUID");
|
|
33752
34503
|
}
|
|
33753
34504
|
if (!Number.isSafeInteger(effectOrdinal) || effectOrdinal < 0) {
|
|
@@ -34240,7 +34991,7 @@ var import_node_crypto13 = require("node:crypto");
|
|
|
34240
34991
|
var import_node_os6 = require("node:os");
|
|
34241
34992
|
var import_node_path9 = require("node:path");
|
|
34242
34993
|
var import_node_util = require("node:util");
|
|
34243
|
-
var
|
|
34994
|
+
var UUID_RE15 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
34244
34995
|
var COMMAND_ID_RE2 = /^[A-Za-z0-9_-]{8,72}$/;
|
|
34245
34996
|
var MAX_EFFECT_BYTES = 1024 * 1024;
|
|
34246
34997
|
var STATES = /* @__PURE__ */ new Set([
|
|
@@ -34290,7 +35041,7 @@ function defaultListenerStateDirectory() {
|
|
|
34290
35041
|
return process.env.XDG_STATE_HOME ? (0, import_node_path9.join)(process.env.XDG_STATE_HOME, "cswarm", "listeners") : (0, import_node_path9.join)((0, import_node_os6.homedir)(), ".cswarm", "listeners");
|
|
34291
35042
|
}
|
|
34292
35043
|
function listenerInstanceKey(input) {
|
|
34293
|
-
if (!
|
|
35044
|
+
if (!UUID_RE15.test(input.workspaceId) || !UUID_RE15.test(input.principalId)) {
|
|
34294
35045
|
throw new Error("listener workspace and principal ids must be UUIDs");
|
|
34295
35046
|
}
|
|
34296
35047
|
if (!input.profileId || input.profileId.includes("\0")) {
|
|
@@ -34323,7 +35074,7 @@ function parseListenerEffectRecord(raw, expectedId) {
|
|
|
34323
35074
|
}
|
|
34324
35075
|
const row = value;
|
|
34325
35076
|
rejectSensitiveKeys(row);
|
|
34326
|
-
if (typeof row.version !== "number" || row.version !== 1 && row.version !== 2 || typeof row.signalId !== "string" || row.signalId.toLowerCase() !== expectedId || !
|
|
35077
|
+
if (typeof row.version !== "number" || row.version !== 1 && row.version !== 2 || typeof row.signalId !== "string" || row.signalId.toLowerCase() !== expectedId || !UUID_RE15.test(row.signalId)) {
|
|
34327
35078
|
throw new Error("stored listener effect is malformed");
|
|
34328
35079
|
}
|
|
34329
35080
|
if (row.version === 1) {
|
|
@@ -34338,7 +35089,7 @@ function upcastV1Ask(row) {
|
|
|
34338
35089
|
if (row.effectOrdinal !== 0 || typeof row.commandId !== "string" || !COMMAND_ID_RE2.test(row.commandId) || typeof row.askBody !== "string" || row.askBody.length < 1 || typeof row.askUntil !== "string" || !Number.isFinite(Date.parse(row.askUntil)) || typeof row.senderOwnerRelation !== "string" || !RELATIONS.has(row.senderOwnerRelation) || typeof row.state !== "string" || !STATES.has(row.state) || !integer(row.promptAttempts) || !integer(row.postAttempts) || !nullableString2(row.replyBody, 2e3) || typeof row.replyTruncated !== "boolean" || !nullableString2(row.replySignalId, 64) || !nullableString2(row.failureCode, 96) || typeof row.updatedAt !== "string" || !Number.isFinite(Date.parse(row.updatedAt))) {
|
|
34339
35090
|
throw new Error("stored listener effect is malformed");
|
|
34340
35091
|
}
|
|
34341
|
-
if (row.replySignalId !== null && !
|
|
35092
|
+
if (row.replySignalId !== null && !UUID_RE15.test(row.replySignalId)) {
|
|
34342
35093
|
throw new Error("stored listener effect is malformed");
|
|
34343
35094
|
}
|
|
34344
35095
|
return {
|
|
@@ -34377,7 +35128,7 @@ function parseV2Record(row) {
|
|
|
34377
35128
|
if (typeof row.commandId !== "string" || !COMMAND_ID_RE2.test(row.commandId) || row.state === "observed") {
|
|
34378
35129
|
throw new Error("stored listener effect is malformed");
|
|
34379
35130
|
}
|
|
34380
|
-
if (row.replySignalId !== null && !
|
|
35131
|
+
if (row.replySignalId !== null && !UUID_RE15.test(row.replySignalId)) {
|
|
34381
35132
|
throw new Error("stored listener effect is malformed");
|
|
34382
35133
|
}
|
|
34383
35134
|
}
|
|
@@ -34401,7 +35152,7 @@ function parseV2Record(row) {
|
|
|
34401
35152
|
};
|
|
34402
35153
|
}
|
|
34403
35154
|
function newObservedNoteRecord(input) {
|
|
34404
|
-
if (!
|
|
35155
|
+
if (!UUID_RE15.test(input.signalId)) {
|
|
34405
35156
|
throw new Error("listener note signal id must be a UUID");
|
|
34406
35157
|
}
|
|
34407
35158
|
if (input.body.length < 1) {
|
|
@@ -34535,7 +35286,7 @@ var FileListenerEffectStore = class {
|
|
|
34535
35286
|
);
|
|
34536
35287
|
}
|
|
34537
35288
|
checkedId(signalId) {
|
|
34538
|
-
if (!
|
|
35289
|
+
if (!UUID_RE15.test(signalId)) {
|
|
34539
35290
|
throw new Error("listener signal id must be a UUID");
|
|
34540
35291
|
}
|
|
34541
35292
|
return signalId.toLowerCase();
|
|
@@ -35767,590 +36518,9 @@ var CodexListenerModel = class {
|
|
|
35767
36518
|
// src/listener/runtime.ts
|
|
35768
36519
|
var import_node_crypto18 = require("node:crypto");
|
|
35769
36520
|
|
|
35770
|
-
// src/cloud/delivery.ts
|
|
35771
|
-
var UUID_RE14 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
35772
|
-
var RFC3339_TIMESTAMP_RE = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:Z|([+-]\d{2}):(\d{2}))$/i;
|
|
35773
|
-
var DELIVERY_KINDS = /* @__PURE__ */ new Set(["ask", "note"]);
|
|
35774
|
-
var SENDER_OWNER_RELATIONS2 = /* @__PURE__ */ new Set([
|
|
35775
|
-
"same_owner",
|
|
35776
|
-
"cross_owner",
|
|
35777
|
-
"unknown"
|
|
35778
|
-
]);
|
|
35779
|
-
var DELIVERY_ACK_OUTCOMES = /* @__PURE__ */ new Set([
|
|
35780
|
-
"replied",
|
|
35781
|
-
"observed",
|
|
35782
|
-
"queued",
|
|
35783
|
-
"expired",
|
|
35784
|
-
"failed_terminal"
|
|
35785
|
-
]);
|
|
35786
|
-
var DELIVERY_REQUEST_TIMEOUT_MS = 3e4;
|
|
35787
|
-
var COMMAND_ID_VALIDATOR_RE = /^[A-Za-z0-9_-]{8,72}$/;
|
|
35788
|
-
var FAILED_TERMINAL_CODES_SET = /* @__PURE__ */ new Set([
|
|
35789
|
-
"provider_refused",
|
|
35790
|
-
"local_effect_failed",
|
|
35791
|
-
"host_session_failed",
|
|
35792
|
-
"credential_unavailable"
|
|
35793
|
-
]);
|
|
35794
|
-
var SERVER_ERROR_CODES_SET = /* @__PURE__ */ new Set([
|
|
35795
|
-
"unauthenticated",
|
|
35796
|
-
"fresh_auth_required",
|
|
35797
|
-
"invalid_request",
|
|
35798
|
-
"payload_too_large",
|
|
35799
|
-
"forbidden",
|
|
35800
|
-
"delivery_unavailable",
|
|
35801
|
-
"delivery_ack_conflict",
|
|
35802
|
-
"command_id_conflict",
|
|
35803
|
-
"rate_limited",
|
|
35804
|
-
"upgrade_required",
|
|
35805
|
-
"temporarily_unavailable",
|
|
35806
|
-
"internal_error"
|
|
35807
|
-
]);
|
|
35808
|
-
var DELIVERY_FAILED_TERMINAL_CODES = Object.freeze([
|
|
35809
|
-
"provider_refused",
|
|
35810
|
-
"local_effect_failed",
|
|
35811
|
-
"host_session_failed",
|
|
35812
|
-
"credential_unavailable"
|
|
35813
|
-
]);
|
|
35814
|
-
var DELIVERY_SERVER_ERROR_CODES = Object.freeze([
|
|
35815
|
-
"unauthenticated",
|
|
35816
|
-
"fresh_auth_required",
|
|
35817
|
-
"invalid_request",
|
|
35818
|
-
"payload_too_large",
|
|
35819
|
-
"forbidden",
|
|
35820
|
-
"delivery_unavailable",
|
|
35821
|
-
"delivery_ack_conflict",
|
|
35822
|
-
"command_id_conflict",
|
|
35823
|
-
"rate_limited",
|
|
35824
|
-
"upgrade_required",
|
|
35825
|
-
"temporarily_unavailable",
|
|
35826
|
-
"internal_error"
|
|
35827
|
-
]);
|
|
35828
|
-
var DELIVERY_UNKNOWN_ERROR_CODE = "unknown_error";
|
|
35829
|
-
function observationCommandId(signalId) {
|
|
35830
|
-
checkedUuidRequest(signalId, "signalId");
|
|
35831
|
-
return `observe_${signalId.toLowerCase().replaceAll("-", "")}`;
|
|
35832
|
-
}
|
|
35833
|
-
var DeliveryTransportError = class extends Error {
|
|
35834
|
-
constructor(message) {
|
|
35835
|
-
super(message);
|
|
35836
|
-
this.name = "DeliveryTransportError";
|
|
35837
|
-
}
|
|
35838
|
-
};
|
|
35839
|
-
var DeliveryHttpError = class extends Error {
|
|
35840
|
-
constructor(status, code, message, retryAfterMs = null) {
|
|
35841
|
-
super(message);
|
|
35842
|
-
this.status = status;
|
|
35843
|
-
this.code = code;
|
|
35844
|
-
this.retryAfterMs = retryAfterMs;
|
|
35845
|
-
this.name = "DeliveryHttpError";
|
|
35846
|
-
}
|
|
35847
|
-
status;
|
|
35848
|
-
code;
|
|
35849
|
-
retryAfterMs;
|
|
35850
|
-
};
|
|
35851
|
-
var DeliveryProtocolError = class extends Error {
|
|
35852
|
-
constructor(message) {
|
|
35853
|
-
super(message);
|
|
35854
|
-
this.name = "DeliveryProtocolError";
|
|
35855
|
-
}
|
|
35856
|
-
};
|
|
35857
|
-
function checkedUuid3(value, field) {
|
|
35858
|
-
if (typeof value !== "string" || !UUID_RE14.test(value)) {
|
|
35859
|
-
throw new DeliveryProtocolError(
|
|
35860
|
-
`delivery response returned a malformed ${field}`
|
|
35861
|
-
);
|
|
35862
|
-
}
|
|
35863
|
-
return value.toLowerCase();
|
|
35864
|
-
}
|
|
35865
|
-
function isLeapYear(year) {
|
|
35866
|
-
return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
35867
|
-
}
|
|
35868
|
-
function daysInMonth(year, month) {
|
|
35869
|
-
switch (month) {
|
|
35870
|
-
case 1:
|
|
35871
|
-
case 3:
|
|
35872
|
-
case 5:
|
|
35873
|
-
case 7:
|
|
35874
|
-
case 8:
|
|
35875
|
-
case 10:
|
|
35876
|
-
case 12:
|
|
35877
|
-
return 31;
|
|
35878
|
-
case 4:
|
|
35879
|
-
case 6:
|
|
35880
|
-
case 9:
|
|
35881
|
-
case 11:
|
|
35882
|
-
return 30;
|
|
35883
|
-
case 2:
|
|
35884
|
-
return isLeapYear(year) ? 29 : 28;
|
|
35885
|
-
default:
|
|
35886
|
-
return 0;
|
|
35887
|
-
}
|
|
35888
|
-
}
|
|
35889
|
-
function checkedRfc3339Timestamp(value, field) {
|
|
35890
|
-
if (typeof value !== "string") {
|
|
35891
|
-
throw new DeliveryProtocolError(
|
|
35892
|
-
`delivery response returned a malformed ${field}`
|
|
35893
|
-
);
|
|
35894
|
-
}
|
|
35895
|
-
const match = RFC3339_TIMESTAMP_RE.exec(value);
|
|
35896
|
-
if (!match) {
|
|
35897
|
-
throw new DeliveryProtocolError(
|
|
35898
|
-
`delivery response returned a malformed ${field}`
|
|
35899
|
-
);
|
|
35900
|
-
}
|
|
35901
|
-
const year = parseInt(match[1], 10);
|
|
35902
|
-
const month = parseInt(match[2], 10);
|
|
35903
|
-
const day = parseInt(match[3], 10);
|
|
35904
|
-
const hour = parseInt(match[4], 10);
|
|
35905
|
-
const minute = parseInt(match[5], 10);
|
|
35906
|
-
const second = parseInt(match[6], 10);
|
|
35907
|
-
if (month < 1 || month > 12 || day < 1 || day > daysInMonth(year, month) || hour < 0 || hour > 23 || minute < 0 || minute > 59 || second < 0 || second > 59) {
|
|
35908
|
-
throw new DeliveryProtocolError(
|
|
35909
|
-
`delivery response returned a malformed ${field}`
|
|
35910
|
-
);
|
|
35911
|
-
}
|
|
35912
|
-
if (match[7] !== void 0 && match[8] !== void 0) {
|
|
35913
|
-
const offsetHour = Math.abs(parseInt(match[7], 10));
|
|
35914
|
-
const offsetMin = parseInt(match[8], 10);
|
|
35915
|
-
if (offsetHour > 23 || offsetMin < 0 || offsetMin > 59) {
|
|
35916
|
-
throw new DeliveryProtocolError(
|
|
35917
|
-
`delivery response returned a malformed ${field}`
|
|
35918
|
-
);
|
|
35919
|
-
}
|
|
35920
|
-
}
|
|
35921
|
-
if (!Number.isFinite(Date.parse(value))) {
|
|
35922
|
-
throw new DeliveryProtocolError(
|
|
35923
|
-
`delivery response returned a malformed ${field}`
|
|
35924
|
-
);
|
|
35925
|
-
}
|
|
35926
|
-
return value;
|
|
35927
|
-
}
|
|
35928
|
-
function checkedLiveLease(leasedUntil, now) {
|
|
35929
|
-
if (Date.parse(leasedUntil) <= now()) {
|
|
35930
|
-
throw new DeliveryProtocolError(
|
|
35931
|
-
"delivery claim response returned an already expired lease"
|
|
35932
|
-
);
|
|
35933
|
-
}
|
|
35934
|
-
}
|
|
35935
|
-
function checkedRelation(value) {
|
|
35936
|
-
if (typeof value !== "string" || !SENDER_OWNER_RELATIONS2.has(value)) {
|
|
35937
|
-
throw new DeliveryProtocolError(
|
|
35938
|
-
"delivery response returned a malformed sender_owner_relation"
|
|
35939
|
-
);
|
|
35940
|
-
}
|
|
35941
|
-
return value;
|
|
35942
|
-
}
|
|
35943
|
-
function checkedNonNegativeCount(value, field) {
|
|
35944
|
-
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
|
|
35945
|
-
throw new DeliveryProtocolError(
|
|
35946
|
-
`delivery response returned a malformed ${field}`
|
|
35947
|
-
);
|
|
35948
|
-
}
|
|
35949
|
-
return value;
|
|
35950
|
-
}
|
|
35951
|
-
function checkedClaimCapabilities(value) {
|
|
35952
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
35953
|
-
throw new DeliveryProtocolError(
|
|
35954
|
-
"delivery claim response is missing delivery capabilities"
|
|
35955
|
-
);
|
|
35956
|
-
}
|
|
35957
|
-
const row = value;
|
|
35958
|
-
for (const marker of ["delivery_claim", "delivery_ack", "sender_owner_relation"]) {
|
|
35959
|
-
if (row[marker] !== 1) {
|
|
35960
|
-
throw new DeliveryProtocolError(
|
|
35961
|
-
`delivery claim response is missing the ${marker} capability`
|
|
35962
|
-
);
|
|
35963
|
-
}
|
|
35964
|
-
}
|
|
35965
|
-
return { deliveryClaim: true, deliveryAck: true, senderOwnerRelation: true };
|
|
35966
|
-
}
|
|
35967
|
-
function checkedOptionalUuidArray(value, field) {
|
|
35968
|
-
if (value === void 0) return;
|
|
35969
|
-
if (!Array.isArray(value) || value.some((item) => typeof item !== "string" || !UUID_RE14.test(item))) {
|
|
35970
|
-
throw new DeliveryProtocolError(
|
|
35971
|
-
`delivery response returned a malformed ${field}`
|
|
35972
|
-
);
|
|
35973
|
-
}
|
|
35974
|
-
}
|
|
35975
|
-
function checkedOptionalArray(value, field) {
|
|
35976
|
-
if (value === void 0) return;
|
|
35977
|
-
if (!Array.isArray(value)) {
|
|
35978
|
-
throw new DeliveryProtocolError(
|
|
35979
|
-
`delivery response returned a malformed ${field}`
|
|
35980
|
-
);
|
|
35981
|
-
}
|
|
35982
|
-
}
|
|
35983
|
-
function parseDeliveryRow(value, expected, index, now) {
|
|
35984
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
35985
|
-
throw new DeliveryProtocolError(
|
|
35986
|
-
"delivery claim response returned a malformed delivery row"
|
|
35987
|
-
);
|
|
35988
|
-
}
|
|
35989
|
-
const row = value;
|
|
35990
|
-
let signal;
|
|
35991
|
-
try {
|
|
35992
|
-
signal = parseSignalRecord(row.signal);
|
|
35993
|
-
} catch {
|
|
35994
|
-
throw new DeliveryProtocolError(
|
|
35995
|
-
`delivery claim response returned a malformed signal at ${index}`
|
|
35996
|
-
);
|
|
35997
|
-
}
|
|
35998
|
-
if (signal.workspace_id !== expected.workspaceId) {
|
|
35999
|
-
throw new DeliveryProtocolError(
|
|
36000
|
-
"delivery claim response returned a signal for another workspace"
|
|
36001
|
-
);
|
|
36002
|
-
}
|
|
36003
|
-
if (signal.to_agent !== expected.principalId) {
|
|
36004
|
-
throw new DeliveryProtocolError(
|
|
36005
|
-
"delivery claim response returned a signal addressed to another agent"
|
|
36006
|
-
);
|
|
36007
|
-
}
|
|
36008
|
-
if (!DELIVERY_KINDS.has(signal.kind)) {
|
|
36009
|
-
throw new DeliveryProtocolError(
|
|
36010
|
-
"delivery claim response returned a non-direct signal kind"
|
|
36011
|
-
);
|
|
36012
|
-
}
|
|
36013
|
-
const senderOwnerRelation = checkedRelation(row.sender_owner_relation);
|
|
36014
|
-
const leaseId = checkedUuid3(row.lease_id, "lease_id");
|
|
36015
|
-
const leasedUntil = checkedRfc3339Timestamp(row.leased_until, "leased_until");
|
|
36016
|
-
checkedLiveLease(leasedUntil, now);
|
|
36017
|
-
signal.sender_owner_relation = senderOwnerRelation;
|
|
36018
|
-
return { signal, leaseId, leasedUntil, senderOwnerRelation };
|
|
36019
|
-
}
|
|
36020
|
-
function parseClaimSuccess(body, expected, now) {
|
|
36021
|
-
if (!body || typeof body !== "object" || Array.isArray(body)) {
|
|
36022
|
-
throw new DeliveryProtocolError("delivery claim response was not an object");
|
|
36023
|
-
}
|
|
36024
|
-
const row = body;
|
|
36025
|
-
if (row.status !== "accepted" || row.ok !== true) {
|
|
36026
|
-
throw new DeliveryProtocolError(
|
|
36027
|
-
"delivery claim response did not report accepted ok"
|
|
36028
|
-
);
|
|
36029
|
-
}
|
|
36030
|
-
const capabilities = checkedClaimCapabilities(row.capabilities);
|
|
36031
|
-
checkedOptionalUuidArray(row.event_ids, "event_ids");
|
|
36032
|
-
checkedOptionalArray(row.events, "events");
|
|
36033
|
-
if (!Array.isArray(row.deliveries)) {
|
|
36034
|
-
throw new DeliveryProtocolError(
|
|
36035
|
-
"delivery claim response is missing its deliveries array"
|
|
36036
|
-
);
|
|
36037
|
-
}
|
|
36038
|
-
const deliveries = row.deliveries.map(
|
|
36039
|
-
(item, index) => parseDeliveryRow(item, expected, index, now)
|
|
36040
|
-
);
|
|
36041
|
-
const signalIds = /* @__PURE__ */ new Set();
|
|
36042
|
-
const leaseIds = /* @__PURE__ */ new Set();
|
|
36043
|
-
for (const delivery of deliveries) {
|
|
36044
|
-
if (signalIds.has(delivery.signal.id)) {
|
|
36045
|
-
throw new DeliveryProtocolError(
|
|
36046
|
-
"delivery claim response repeats a signal id"
|
|
36047
|
-
);
|
|
36048
|
-
}
|
|
36049
|
-
signalIds.add(delivery.signal.id);
|
|
36050
|
-
if (leaseIds.has(delivery.leaseId)) {
|
|
36051
|
-
throw new DeliveryProtocolError(
|
|
36052
|
-
"delivery claim response repeats a lease id"
|
|
36053
|
-
);
|
|
36054
|
-
}
|
|
36055
|
-
leaseIds.add(delivery.leaseId);
|
|
36056
|
-
}
|
|
36057
|
-
if (deliveries.length > 1) {
|
|
36058
|
-
throw new DeliveryProtocolError(
|
|
36059
|
-
"delivery claim response returned more than one delivery"
|
|
36060
|
-
);
|
|
36061
|
-
}
|
|
36062
|
-
const pendingDeliveryCount = checkedNonNegativeCount(
|
|
36063
|
-
row.pending_delivery_count,
|
|
36064
|
-
"pending_delivery_count"
|
|
36065
|
-
);
|
|
36066
|
-
const terminalDeliveryFailureCount = checkedNonNegativeCount(
|
|
36067
|
-
row.terminal_delivery_failure_count,
|
|
36068
|
-
"terminal_delivery_failure_count"
|
|
36069
|
-
);
|
|
36070
|
-
if (deliveries.length > pendingDeliveryCount) {
|
|
36071
|
-
throw new DeliveryProtocolError(
|
|
36072
|
-
"delivery claim response returned more deliveries than its pending count"
|
|
36073
|
-
);
|
|
36074
|
-
}
|
|
36075
|
-
return {
|
|
36076
|
-
capabilities,
|
|
36077
|
-
deliveries,
|
|
36078
|
-
pendingDeliveryCount,
|
|
36079
|
-
terminalDeliveryFailureCount
|
|
36080
|
-
};
|
|
36081
|
-
}
|
|
36082
|
-
function parseAckSuccess(body, expected) {
|
|
36083
|
-
if (!body || typeof body !== "object" || Array.isArray(body)) {
|
|
36084
|
-
throw new DeliveryProtocolError(
|
|
36085
|
-
"delivery acknowledgement response was not an object"
|
|
36086
|
-
);
|
|
36087
|
-
}
|
|
36088
|
-
const row = body;
|
|
36089
|
-
if (row.status !== "accepted" || row.ok !== true) {
|
|
36090
|
-
throw new DeliveryProtocolError(
|
|
36091
|
-
"delivery acknowledgement response did not report accepted ok"
|
|
36092
|
-
);
|
|
36093
|
-
}
|
|
36094
|
-
checkedOptionalUuidArray(row.event_ids, "event_ids");
|
|
36095
|
-
checkedOptionalArray(row.events, "events");
|
|
36096
|
-
if (row.signal_id !== expected.signalId) {
|
|
36097
|
-
throw new DeliveryProtocolError(
|
|
36098
|
-
"delivery acknowledgement response echoed a different signal id"
|
|
36099
|
-
);
|
|
36100
|
-
}
|
|
36101
|
-
if (row.outcome !== expected.outcome) {
|
|
36102
|
-
throw new DeliveryProtocolError(
|
|
36103
|
-
"delivery acknowledgement response echoed a different outcome"
|
|
36104
|
-
);
|
|
36105
|
-
}
|
|
36106
|
-
}
|
|
36107
|
-
function checkedCommandId(value) {
|
|
36108
|
-
if (typeof value !== "string" || !COMMAND_ID_VALIDATOR_RE.test(value)) {
|
|
36109
|
-
throw new Error(
|
|
36110
|
-
"a delivery command id must be 8..72 characters of [A-Za-z0-9_-]"
|
|
36111
|
-
);
|
|
36112
|
-
}
|
|
36113
|
-
return value;
|
|
36114
|
-
}
|
|
36115
|
-
function checkedUuidRequest(value, field) {
|
|
36116
|
-
if (!UUID_RE14.test(value)) {
|
|
36117
|
-
throw new Error(`${field} must be a UUID for an agent delivery command`);
|
|
36118
|
-
}
|
|
36119
|
-
}
|
|
36120
|
-
function assertAckRequest(request) {
|
|
36121
|
-
checkedCommandId(request.commandId);
|
|
36122
|
-
assertAgentToken(request.credential);
|
|
36123
|
-
checkedUuidRequest(request.workspaceId, "workspaceId");
|
|
36124
|
-
checkedUuidRequest(request.signalId, "signalId");
|
|
36125
|
-
checkedUuidRequest(request.leaseId, "leaseId");
|
|
36126
|
-
checkedUuidRequest(request.listenerInstanceId, "listenerInstanceId");
|
|
36127
|
-
if (!DELIVERY_ACK_OUTCOMES.has(request.outcome)) {
|
|
36128
|
-
throw new Error(
|
|
36129
|
-
"a delivery outcome must be replied, observed, queued, expired, or failed_terminal"
|
|
36130
|
-
);
|
|
36131
|
-
}
|
|
36132
|
-
if (request.outcome === "failed_terminal") {
|
|
36133
|
-
if (typeof request.lastErrorCode !== "string" || !FAILED_TERMINAL_CODES_SET.has(request.lastErrorCode)) {
|
|
36134
|
-
throw new Error(
|
|
36135
|
-
"a failed_terminal acknowledgement requires one of provider_refused, local_effect_failed, host_session_failed, credential_unavailable"
|
|
36136
|
-
);
|
|
36137
|
-
}
|
|
36138
|
-
} else if (request.lastErrorCode !== null) {
|
|
36139
|
-
throw new Error(
|
|
36140
|
-
"a non-failed acknowledgement must send lastErrorCode null"
|
|
36141
|
-
);
|
|
36142
|
-
}
|
|
36143
|
-
}
|
|
36144
|
-
function boundedDeliveryErrorCode(body) {
|
|
36145
|
-
if (!body || typeof body !== "object" || Array.isArray(body)) {
|
|
36146
|
-
return DELIVERY_UNKNOWN_ERROR_CODE;
|
|
36147
|
-
}
|
|
36148
|
-
const error = body.error;
|
|
36149
|
-
if (typeof error === "string" && SERVER_ERROR_CODES_SET.has(error)) {
|
|
36150
|
-
return error;
|
|
36151
|
-
}
|
|
36152
|
-
return DELIVERY_UNKNOWN_ERROR_CODE;
|
|
36153
|
-
}
|
|
36154
|
-
function refusal(response, text) {
|
|
36155
|
-
let code = DELIVERY_UNKNOWN_ERROR_CODE;
|
|
36156
|
-
try {
|
|
36157
|
-
code = boundedDeliveryErrorCode(JSON.parse(text));
|
|
36158
|
-
} catch {
|
|
36159
|
-
}
|
|
36160
|
-
const retryAfterMs = parseRetryAfterMs(response.headers.get("retry-after"));
|
|
36161
|
-
return new DeliveryHttpError(
|
|
36162
|
-
response.status,
|
|
36163
|
-
code,
|
|
36164
|
-
`delivery command failed (HTTP ${response.status}): ${code}`,
|
|
36165
|
-
retryAfterMs
|
|
36166
|
-
);
|
|
36167
|
-
}
|
|
36168
|
-
function successBody(response, text, verb) {
|
|
36169
|
-
try {
|
|
36170
|
-
return JSON.parse(text);
|
|
36171
|
-
} catch {
|
|
36172
|
-
throw new DeliveryProtocolError(
|
|
36173
|
-
`${verb} response was not JSON (HTTP ${response.status})`
|
|
36174
|
-
);
|
|
36175
|
-
}
|
|
36176
|
-
}
|
|
36177
|
-
var DeliveryCommandClient = class {
|
|
36178
|
-
constructor(target2, fetcher = fetch, options = {}) {
|
|
36179
|
-
this.target = target2;
|
|
36180
|
-
this.fetcher = fetcher;
|
|
36181
|
-
this.deadlineMs = options.deadlineMs ?? DELIVERY_REQUEST_TIMEOUT_MS;
|
|
36182
|
-
this.now = options.now ?? Date.now;
|
|
36183
|
-
this.clearTimeoutFn = options.clearTimeout ?? ((timer2) => clearTimeout(timer2));
|
|
36184
|
-
this.createAbortControllerFn = options.createAbortController ?? (() => new AbortController());
|
|
36185
|
-
}
|
|
36186
|
-
target;
|
|
36187
|
-
fetcher;
|
|
36188
|
-
deadlineMs;
|
|
36189
|
-
now;
|
|
36190
|
-
clearTimeoutFn;
|
|
36191
|
-
createAbortControllerFn;
|
|
36192
|
-
async post(request, command2, verb) {
|
|
36193
|
-
if (this.deadlineMs <= 0) {
|
|
36194
|
-
throw new DeliveryTransportError(`${verb} request timed out`);
|
|
36195
|
-
}
|
|
36196
|
-
const deadlineController = this.createAbortControllerFn();
|
|
36197
|
-
let timedOut = false;
|
|
36198
|
-
const signal = deadlineController.signal;
|
|
36199
|
-
let onAbort = () => {
|
|
36200
|
-
};
|
|
36201
|
-
const aborted = new Promise((resolve3) => {
|
|
36202
|
-
onAbort = () => resolve3("timeout");
|
|
36203
|
-
if (signal.aborted) {
|
|
36204
|
-
onAbort();
|
|
36205
|
-
} else {
|
|
36206
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
36207
|
-
}
|
|
36208
|
-
});
|
|
36209
|
-
const timer2 = setTimeout(() => {
|
|
36210
|
-
timedOut = true;
|
|
36211
|
-
deadlineController.abort();
|
|
36212
|
-
}, this.deadlineMs);
|
|
36213
|
-
try {
|
|
36214
|
-
if (signal.aborted) {
|
|
36215
|
-
throw new DeliveryTransportError(`${verb} request timed out`);
|
|
36216
|
-
}
|
|
36217
|
-
const read = (async () => {
|
|
36218
|
-
let response;
|
|
36219
|
-
try {
|
|
36220
|
-
response = await this.fetcher(commandEndpoint(this.target), {
|
|
36221
|
-
method: "POST",
|
|
36222
|
-
headers: {
|
|
36223
|
-
authorization: `Bearer ${request.credential}`,
|
|
36224
|
-
apikey: this.target.anonKey,
|
|
36225
|
-
"content-type": "application/json"
|
|
36226
|
-
},
|
|
36227
|
-
body: JSON.stringify({
|
|
36228
|
-
command_id: request.commandId,
|
|
36229
|
-
client_version: CLIENT_PROTOCOL_VERSION,
|
|
36230
|
-
workspace_id: request.workspaceId.toLowerCase(),
|
|
36231
|
-
stream: { kind: "workspace" },
|
|
36232
|
-
command: command2
|
|
36233
|
-
}),
|
|
36234
|
-
signal
|
|
36235
|
-
});
|
|
36236
|
-
} catch (error) {
|
|
36237
|
-
if (signal.aborted || timedOut || error?.name === "AbortError") {
|
|
36238
|
-
return "timeout";
|
|
36239
|
-
}
|
|
36240
|
-
throw new DeliveryTransportError(
|
|
36241
|
-
`${verb} request failed before a response`
|
|
36242
|
-
);
|
|
36243
|
-
}
|
|
36244
|
-
if (signal.aborted || timedOut) return "timeout";
|
|
36245
|
-
let text;
|
|
36246
|
-
try {
|
|
36247
|
-
text = await response.text();
|
|
36248
|
-
} catch {
|
|
36249
|
-
if (signal.aborted || timedOut) return "timeout";
|
|
36250
|
-
throw new DeliveryTransportError(
|
|
36251
|
-
`${verb} response body was interrupted`
|
|
36252
|
-
);
|
|
36253
|
-
}
|
|
36254
|
-
if (signal.aborted || timedOut) return "timeout";
|
|
36255
|
-
return { response, text };
|
|
36256
|
-
})();
|
|
36257
|
-
const raced = await Promise.race([read, aborted]);
|
|
36258
|
-
if (raced === "timeout") {
|
|
36259
|
-
throw new DeliveryTransportError(`${verb} request timed out`);
|
|
36260
|
-
}
|
|
36261
|
-
return raced;
|
|
36262
|
-
} finally {
|
|
36263
|
-
this.clearTimeoutFn(timer2);
|
|
36264
|
-
signal.removeEventListener("abort", onAbort);
|
|
36265
|
-
}
|
|
36266
|
-
}
|
|
36267
|
-
/** Claim the caller's own single unacked direct-signal delivery row. */
|
|
36268
|
-
async claimAgentInbox(request) {
|
|
36269
|
-
checkedCommandId(request.commandId);
|
|
36270
|
-
assertAgentToken(request.credential);
|
|
36271
|
-
checkedUuidRequest(request.workspaceId, "workspaceId");
|
|
36272
|
-
checkedUuidRequest(request.listenerInstanceId, "listenerInstanceId");
|
|
36273
|
-
checkedUuidRequest(request.expectedPrincipalId, "expectedPrincipalId");
|
|
36274
|
-
const { response, text } = await this.post(request, {
|
|
36275
|
-
kind: "claim_agent_inbox",
|
|
36276
|
-
listener_instance_id: request.listenerInstanceId.toLowerCase(),
|
|
36277
|
-
limit: 1
|
|
36278
|
-
}, "delivery claim");
|
|
36279
|
-
if (!response.ok) throw refusal(response, text);
|
|
36280
|
-
const parsed = parseClaimSuccess(
|
|
36281
|
-
successBody(response, text, "delivery claim"),
|
|
36282
|
-
{
|
|
36283
|
-
workspaceId: request.workspaceId.toLowerCase(),
|
|
36284
|
-
principalId: request.expectedPrincipalId.toLowerCase()
|
|
36285
|
-
},
|
|
36286
|
-
this.now
|
|
36287
|
-
);
|
|
36288
|
-
return {
|
|
36289
|
-
httpStatus: response.status,
|
|
36290
|
-
capabilities: parsed.capabilities,
|
|
36291
|
-
deliveries: parsed.deliveries,
|
|
36292
|
-
pendingDeliveryCount: parsed.pendingDeliveryCount,
|
|
36293
|
-
terminalDeliveryFailureCount: parsed.terminalDeliveryFailureCount
|
|
36294
|
-
};
|
|
36295
|
-
}
|
|
36296
|
-
/** Acknowledge one leased delivery with an exact terminal outcome. */
|
|
36297
|
-
async ackAgentDelivery(request) {
|
|
36298
|
-
assertAckRequest(request);
|
|
36299
|
-
const { response, text } = await this.post(request, {
|
|
36300
|
-
kind: "ack_agent_delivery",
|
|
36301
|
-
signal_id: request.signalId.toLowerCase(),
|
|
36302
|
-
lease_id: request.leaseId.toLowerCase(),
|
|
36303
|
-
listener_instance_id: request.listenerInstanceId.toLowerCase(),
|
|
36304
|
-
outcome: request.outcome,
|
|
36305
|
-
last_error_code: request.lastErrorCode
|
|
36306
|
-
}, "delivery acknowledgement");
|
|
36307
|
-
if (!response.ok) throw refusal(response, text);
|
|
36308
|
-
parseAckSuccess(
|
|
36309
|
-
successBody(response, text, "delivery acknowledgement"),
|
|
36310
|
-
{
|
|
36311
|
-
signalId: request.signalId.toLowerCase(),
|
|
36312
|
-
outcome: request.outcome
|
|
36313
|
-
}
|
|
36314
|
-
);
|
|
36315
|
-
return {
|
|
36316
|
-
httpStatus: response.status,
|
|
36317
|
-
signalId: request.signalId.toLowerCase(),
|
|
36318
|
-
outcome: request.outcome
|
|
36319
|
-
};
|
|
36320
|
-
}
|
|
36321
|
-
/** Mark a queued delivery observed only after the interactive hook surfaced it. */
|
|
36322
|
-
async observeQueuedAgentDelivery(request) {
|
|
36323
|
-
checkedCommandId(request.commandId);
|
|
36324
|
-
assertAgentToken(request.credential);
|
|
36325
|
-
checkedUuidRequest(request.workspaceId, "workspaceId");
|
|
36326
|
-
checkedUuidRequest(request.signalId, "signalId");
|
|
36327
|
-
const { response, text } = await this.post(request, {
|
|
36328
|
-
kind: "ack_agent_delivery",
|
|
36329
|
-
signal_id: request.signalId.toLowerCase(),
|
|
36330
|
-
lease_id: null,
|
|
36331
|
-
listener_instance_id: null,
|
|
36332
|
-
outcome: "observed",
|
|
36333
|
-
last_error_code: null
|
|
36334
|
-
}, "delivery observation");
|
|
36335
|
-
if (!response.ok) throw refusal(response, text);
|
|
36336
|
-
parseAckSuccess(
|
|
36337
|
-
successBody(response, text, "delivery observation"),
|
|
36338
|
-
{
|
|
36339
|
-
signalId: request.signalId.toLowerCase(),
|
|
36340
|
-
outcome: "observed"
|
|
36341
|
-
}
|
|
36342
|
-
);
|
|
36343
|
-
return {
|
|
36344
|
-
httpStatus: response.status,
|
|
36345
|
-
signalId: request.signalId.toLowerCase(),
|
|
36346
|
-
outcome: "observed"
|
|
36347
|
-
};
|
|
36348
|
-
}
|
|
36349
|
-
};
|
|
36350
|
-
|
|
36351
36521
|
// src/listener/main-routing.ts
|
|
36352
36522
|
var import_node_path15 = require("node:path");
|
|
36353
|
-
var
|
|
36523
|
+
var UUID_RE16 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
36354
36524
|
var MAX_QUEUE_BYTES = 1024 * 1024;
|
|
36355
36525
|
var QUEUE_FILE = "pending-for-main.json";
|
|
36356
36526
|
var QUEUE_LOCK = "pending-for-main";
|
|
@@ -36407,7 +36577,7 @@ function parseEntry(value, rejectUnknownKeys) {
|
|
|
36407
36577
|
if (rejectUnknownKeys && Object.keys(row).some((key2) => !ENTRY_KEYS.has(key2))) {
|
|
36408
36578
|
throw new Error("stored pending-for-main entry is malformed");
|
|
36409
36579
|
}
|
|
36410
|
-
if (typeof row.signalId !== "string" || !
|
|
36580
|
+
if (typeof row.signalId !== "string" || !UUID_RE16.test(row.signalId) || typeof row.workspaceId !== "string" || !UUID_RE16.test(row.workspaceId) || typeof row.principalId !== "string" || !UUID_RE16.test(row.principalId) || typeof row.fromId !== "string" || !UUID_RE16.test(row.fromId) || row.fromKind !== "user" && row.fromKind !== "agent" || !(row.kind === void 0 || row.kind === "ask" || row.kind === "note") || !(row.senderName === null || typeof row.senderName === "string" && row.senderName.length <= 200) || typeof row.body !== "string" || row.body.length < 1 || !(row.attachmentCount === void 0 || typeof row.attachmentCount === "number" && Number.isSafeInteger(row.attachmentCount) && row.attachmentCount >= 1 && row.attachmentCount <= 8) || !checkedTimestamp2(row.createdAt) || !checkedTimestamp2(row.queuedAt) || !(row.observationPending === void 0 || row.observationPending === true)) {
|
|
36411
36581
|
throw new Error("stored pending-for-main entry is malformed");
|
|
36412
36582
|
}
|
|
36413
36583
|
return {
|
|
@@ -36547,7 +36717,7 @@ var LISTENER_PROMPT_START_MINIMUM_MS = SIGNAL_READ_TIMEOUT_MS + ACP_DEFAULT_REQU
|
|
|
36547
36717
|
var LISTENER_DELIVERY_RETRY_INITIAL_MS = 500;
|
|
36548
36718
|
var LISTENER_DELIVERY_RETRY_MAX_MS = 3e4;
|
|
36549
36719
|
var LISTENER_HOST_PORTS_PROBE_MS = 6e4;
|
|
36550
|
-
var
|
|
36720
|
+
var UUID_RE17 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
36551
36721
|
var ListenerCapabilityError = class extends Error {
|
|
36552
36722
|
code;
|
|
36553
36723
|
constructor(code, message) {
|
|
@@ -36825,7 +36995,7 @@ async function runListenerRuntime(options) {
|
|
|
36825
36995
|
new Error("listener instance id and delivery journal must be configured together")
|
|
36826
36996
|
);
|
|
36827
36997
|
}
|
|
36828
|
-
if (hasInstanceId && !
|
|
36998
|
+
if (hasInstanceId && !UUID_RE17.test(options.listenerInstanceId)) {
|
|
36829
36999
|
return await closeBeforeStart(
|
|
36830
37000
|
options.model,
|
|
36831
37001
|
new Error("listener instance id must be a UUID")
|
|
@@ -37937,13 +38107,14 @@ var import_node_crypto19 = require("node:crypto");
|
|
|
37937
38107
|
var import_node_net = require("node:net");
|
|
37938
38108
|
var import_promises9 = require("node:fs/promises");
|
|
37939
38109
|
var import_node_path16 = require("node:path");
|
|
37940
|
-
var
|
|
38110
|
+
var UUID_RE18 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
37941
38111
|
var SEMVER_RE2 = /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|[A-Za-z-][0-9A-Za-z-]*))*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
|
|
37942
38112
|
var MAX_STATUS_BYTES = 32 * 1024;
|
|
37943
38113
|
var MAX_CONTROL_BYTES = 8 * 1024;
|
|
37944
38114
|
var CONTROL_TIMEOUT_MS = 2e3;
|
|
37945
38115
|
var START_LOCK_WAIT_MS = 2e3;
|
|
37946
38116
|
var START_LOCK_STALE_MS = 1e4;
|
|
38117
|
+
var LISTENER_DELIVERY_FAILING_THRESHOLD = 3;
|
|
37947
38118
|
var ListenerAlreadyRunningError = class extends Error {
|
|
37948
38119
|
constructor() {
|
|
37949
38120
|
super("a listener is already running for this agent principal");
|
|
@@ -38006,6 +38177,9 @@ var STATUS_ALLOWED_KEYS = /* @__PURE__ */ new Set([
|
|
|
38006
38177
|
"lastTerminalDeliveryFailureAt",
|
|
38007
38178
|
"lastClaimAt",
|
|
38008
38179
|
"lastAckAt",
|
|
38180
|
+
"lastAckOutcome",
|
|
38181
|
+
"consecutiveAckFailureCount",
|
|
38182
|
+
"lastAckSignalId",
|
|
38009
38183
|
"routeMode",
|
|
38010
38184
|
"deferOverChars",
|
|
38011
38185
|
"pendingForMainCount",
|
|
@@ -38045,8 +38219,11 @@ var STATUS_DELIVERY_KEYS = [
|
|
|
38045
38219
|
"lastTerminalDeliveryFailureCount",
|
|
38046
38220
|
"lastTerminalDeliveryFailureAt",
|
|
38047
38221
|
"lastClaimAt",
|
|
38048
|
-
"lastAckAt"
|
|
38222
|
+
"lastAckAt",
|
|
38223
|
+
"lastAckOutcome",
|
|
38224
|
+
"consecutiveAckFailureCount"
|
|
38049
38225
|
];
|
|
38226
|
+
var deliveryOutcomes = DELIVERY_ACK_OUTCOMES;
|
|
38050
38227
|
function parseStatus(raw, rejectUnknownKeys = false) {
|
|
38051
38228
|
let value;
|
|
38052
38229
|
try {
|
|
@@ -38066,11 +38243,11 @@ function parseStatus(raw, rejectUnknownKeys = false) {
|
|
|
38066
38243
|
throw new Error("stored listener status is malformed");
|
|
38067
38244
|
}
|
|
38068
38245
|
}
|
|
38069
|
-
const nullableUuid3 = (candidate) => candidate === null || typeof candidate === "string" &&
|
|
38246
|
+
const nullableUuid3 = (candidate) => candidate === null || typeof candidate === "string" && UUID_RE18.test(candidate);
|
|
38070
38247
|
const nullableCount = (candidate) => candidate === null || typeof candidate === "number" && Number.isSafeInteger(candidate) && candidate >= 0;
|
|
38071
38248
|
const nullableTimestamp3 = (candidate) => candidate === null || typeof candidate === "string" && Number.isFinite(Date.parse(candidate));
|
|
38072
38249
|
const readHealth = row.readHealth === void 0 ? void 0 : parseListenerReadHealth(row.readHealth, rejectUnknownKeys);
|
|
38073
|
-
if (row.version !== 1 || typeof row.instanceId !== "string" || !
|
|
38250
|
+
if (row.version !== 1 || typeof row.instanceId !== "string" || !UUID_RE18.test(row.instanceId) || row.provider !== "grok" && row.provider !== "opencode" && row.provider !== "claude" && row.provider !== "codex" || typeof row.profileId !== "string" || typeof row.workspaceId !== "string" || !UUID_RE18.test(row.workspaceId) || typeof row.principalId !== "string" || !UUID_RE18.test(row.principalId) || !Number.isSafeInteger(row.pid) || row.pid < 1 || typeof row.state !== "string" || !["starting", "ready", "stopping", "stopped", "failed"].includes(row.state) || typeof row.startedAt !== "string" || !Number.isFinite(Date.parse(row.startedAt)) || !(row.readyAt === null || typeof row.readyAt === "string" && Number.isFinite(Date.parse(row.readyAt))) || typeof row.updatedAt !== "string" || !Number.isFinite(Date.parse(row.updatedAt)) || !(row.stoppedAt === null || typeof row.stoppedAt === "string" && Number.isFinite(Date.parse(row.stoppedAt))) || !nullableUuid3(row.lastSignalId) || !(row.lastErrorCode === null || typeof row.lastErrorCode === "string" && /^[a-z0-9_-]{1,96}$/.test(row.lastErrorCode)) || !(row.lastErrorDetail === void 0 || row.lastErrorDetail === null || typeof row.lastErrorDetail === "string" && row.lastErrorDetail.length > 0 && row.lastErrorDetail.length <= 2048 && !/swm_(?:agt|inv|cap)_/i.test(row.lastErrorDetail)) || !(row.lastErrorReasonCode === void 0 || row.lastErrorReasonCode === null || typeof row.lastErrorReasonCode === "string" && /^[a-z0-9_-]{1,96}$/.test(row.lastErrorReasonCode)) || !(row.providerExecutable === void 0 || row.providerExecutable === null || typeof row.providerExecutable === "string" && (0, import_node_path16.isAbsolute)(row.providerExecutable)) || !(row.providerVersion === void 0 || row.providerVersion === null || typeof row.providerVersion === "string" && SEMVER_RE2.test(row.providerVersion)) || !(row.providerLastMeasuredVersion === void 0 || row.providerLastMeasuredVersion === null || typeof row.providerLastMeasuredVersion === "string" && SEMVER_RE2.test(row.providerLastMeasuredVersion)) || !(row.providerBundledAgentSdkVersion === void 0 || row.providerBundledAgentSdkVersion === null || typeof row.providerBundledAgentSdkVersion === "string" && SEMVER_RE2.test(row.providerBundledAgentSdkVersion)) || !(row.providerBundledClaudeCodeVersion === void 0 || row.providerBundledClaudeCodeVersion === null || typeof row.providerBundledClaudeCodeVersion === "string" && SEMVER_RE2.test(row.providerBundledClaudeCodeVersion)) || !(row.providerMinimumRequiredVersion === void 0 || row.providerMinimumRequiredVersion === null || typeof row.providerMinimumRequiredVersion === "string" && SEMVER_RE2.test(row.providerMinimumRequiredVersion)) || !(row.cswarmVersion === void 0 || row.cswarmVersion === null || typeof row.cswarmVersion === "string" && SEMVER_RE2.test(row.cswarmVersion)) || (row.providerVersion === null || row.providerVersion === void 0) !== (row.providerLastMeasuredVersion === null || row.providerLastMeasuredVersion === void 0) || !(row.lastWorkerStderrTail === void 0 || row.lastWorkerStderrTail === null || typeof row.lastWorkerStderrTail === "string" && row.lastWorkerStderrTail.length > 0 && row.lastWorkerStderrTail.length <= 2048 && !/swm_(?:agt|inv|cap)_/i.test(row.lastWorkerStderrTail)) || typeof row.logPath !== "string" || !(0, import_node_path16.isAbsolute)(row.logPath) || !(row.deliveryMode === void 0 || row.deliveryMode === null || typeof row.deliveryMode === "string" && STATUS_DELIVERY_MODES.has(row.deliveryMode)) || !(row.pendingDeliveryCount === void 0 || nullableCount(row.pendingDeliveryCount)) || !(row.lastTerminalDeliveryFailureCount === void 0 || nullableCount(row.lastTerminalDeliveryFailureCount)) || !(row.lastTerminalDeliveryFailureAt === void 0 || nullableTimestamp3(row.lastTerminalDeliveryFailureAt)) || !(row.lastClaimAt === void 0 || nullableTimestamp3(row.lastClaimAt)) || !(row.lastAckAt === void 0 || nullableTimestamp3(row.lastAckAt)) || !(row.lastAckOutcome === void 0 || row.lastAckOutcome === null || typeof row.lastAckOutcome === "string" && deliveryOutcomes.has(row.lastAckOutcome)) || !(row.consecutiveAckFailureCount === void 0 || nullableCount(row.consecutiveAckFailureCount)) || !(row.lastAckSignalId === void 0 || row.lastAckSignalId === null || typeof row.lastAckSignalId === "string" && UUID_RE18.test(row.lastAckSignalId)) || !(row.routeMode === void 0 || row.routeMode === "worker" || row.routeMode === "main" || row.routeMode === "split") || !(row.deferOverChars === void 0 || row.deferOverChars === null || typeof row.deferOverChars === "number" && Number.isSafeInteger(row.deferOverChars) && row.deferOverChars >= 1 && row.deferOverChars <= 1e4) || !(row.pendingForMainCount === void 0 || typeof row.pendingForMainCount === "number" && Number.isSafeInteger(row.pendingForMainCount) && row.pendingForMainCount >= 0) || !(row.droppedForMainCount === void 0 || typeof row.droppedForMainCount === "number" && Number.isSafeInteger(row.droppedForMainCount) && row.droppedForMainCount >= 0) || readHealth === null || !(row.connectionsOpened === void 0 || typeof row.connectionsOpened === "number" && Number.isSafeInteger(row.connectionsOpened) && row.connectionsOpened >= 0) || !(row.connectionReuseRatio === void 0 || typeof row.connectionReuseRatio === "number" && Number.isFinite(row.connectionReuseRatio) && row.connectionReuseRatio >= 0) || !(row.activityPublishFailures === void 0 || typeof row.activityPublishFailures === "number" && Number.isSafeInteger(row.activityPublishFailures) && row.activityPublishFailures >= 0) || !(row.activityLastErrorCode === void 0 || row.activityLastErrorCode === null || typeof row.activityLastErrorCode === "string" && STATUS_ACTIVITY_ERROR_CODES.has(
|
|
38074
38251
|
row.activityLastErrorCode
|
|
38075
38252
|
))) {
|
|
38076
38253
|
throw new Error("stored listener status is malformed");
|
|
@@ -38091,6 +38268,11 @@ function parseStatus(raw, rejectUnknownKeys = false) {
|
|
|
38091
38268
|
lastTerminalDeliveryFailureAt: row.lastTerminalDeliveryFailureAt ?? null,
|
|
38092
38269
|
lastClaimAt: row.lastClaimAt ?? null,
|
|
38093
38270
|
lastAckAt: row.lastAckAt ?? null,
|
|
38271
|
+
lastAckOutcome: row.lastAckOutcome ?? null,
|
|
38272
|
+
consecutiveAckFailureCount: row.consecutiveAckFailureCount ?? null,
|
|
38273
|
+
// Optional key: present only when the file carried it, so a status written
|
|
38274
|
+
// without it round-trips byte-for-byte (the routeMode pattern).
|
|
38275
|
+
...row.lastAckSignalId === void 0 ? {} : { lastAckSignalId: row.lastAckSignalId ?? null },
|
|
38094
38276
|
lastErrorDetail: row.lastErrorDetail ?? null,
|
|
38095
38277
|
lastWorkerStderrTail: row.lastWorkerStderrTail ?? null,
|
|
38096
38278
|
providerVersion: row.providerVersion ?? null,
|
|
@@ -38170,13 +38352,6 @@ async function appendListenerEvent(paths, event) {
|
|
|
38170
38352
|
"dropped_count"
|
|
38171
38353
|
]);
|
|
38172
38354
|
const deliveryModes = /* @__PURE__ */ new Set(["durable_claim", "cursor_fallback"]);
|
|
38173
|
-
const deliveryOutcomes = /* @__PURE__ */ new Set([
|
|
38174
|
-
"replied",
|
|
38175
|
-
"observed",
|
|
38176
|
-
"queued",
|
|
38177
|
-
"expired",
|
|
38178
|
-
"failed_terminal"
|
|
38179
|
-
]);
|
|
38180
38355
|
const routeModes = /* @__PURE__ */ new Set(["worker", "main", "split"]);
|
|
38181
38356
|
const routeDecisions = /* @__PURE__ */ new Set(["worker", "main"]);
|
|
38182
38357
|
for (const [key2, value] of Object.entries(event)) {
|
|
@@ -38488,7 +38663,7 @@ async function queryListenerControl(paths, command2, timeoutMs = CONTROL_TIMEOUT
|
|
|
38488
38663
|
|
|
38489
38664
|
// src/listener/supervisor.ts
|
|
38490
38665
|
var import_node_crypto20 = require("node:crypto");
|
|
38491
|
-
var
|
|
38666
|
+
var UUID_RE19 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
38492
38667
|
var LISTENER_RESTART_MAX_ATTEMPTS = 5;
|
|
38493
38668
|
var LISTENER_RESTART_INITIAL_MS = 1e3;
|
|
38494
38669
|
var LISTENER_RESTART_MAX_MS = 6e4;
|
|
@@ -38586,6 +38761,7 @@ async function runListenerSupervisor(options) {
|
|
|
38586
38761
|
const startedAt = iso2(now);
|
|
38587
38762
|
const controller = new AbortController();
|
|
38588
38763
|
const proposedInstanceId = (0, import_node_crypto20.randomUUID)();
|
|
38764
|
+
const carried = await readListenerStatus(options.paths).catch(() => null);
|
|
38589
38765
|
let status = {
|
|
38590
38766
|
version: 1,
|
|
38591
38767
|
instanceId: proposedInstanceId,
|
|
@@ -38601,7 +38777,7 @@ async function runListenerSupervisor(options) {
|
|
|
38601
38777
|
readyAt: null,
|
|
38602
38778
|
updatedAt: startedAt,
|
|
38603
38779
|
stoppedAt: null,
|
|
38604
|
-
lastSignalId: null,
|
|
38780
|
+
lastSignalId: carried?.lastSignalId ?? null,
|
|
38605
38781
|
lastErrorCode: null,
|
|
38606
38782
|
lastErrorDetail: null,
|
|
38607
38783
|
lastErrorReasonCode: null,
|
|
@@ -38617,7 +38793,14 @@ async function runListenerSupervisor(options) {
|
|
|
38617
38793
|
lastTerminalDeliveryFailureCount: null,
|
|
38618
38794
|
lastTerminalDeliveryFailureAt: null,
|
|
38619
38795
|
lastClaimAt: null,
|
|
38620
|
-
|
|
38796
|
+
/* The ack record is carried WHOLE. Carrying the outcome and the run without
|
|
38797
|
+
their timestamp and signal id rendered a screen whose own sentences
|
|
38798
|
+
disagreed -- "the newest delivery acknowledgement was replied" above
|
|
38799
|
+
"No signal has been handled yet." */
|
|
38800
|
+
lastAckAt: carried?.lastAckAt ?? null,
|
|
38801
|
+
lastAckOutcome: carried?.lastAckOutcome ?? null,
|
|
38802
|
+
consecutiveAckFailureCount: carried?.consecutiveAckFailureCount ?? null,
|
|
38803
|
+
lastAckSignalId: carried?.lastAckSignalId ?? null,
|
|
38621
38804
|
routeMode: options.routeMode ?? "worker",
|
|
38622
38805
|
deferOverChars: options.deferOverChars ?? null,
|
|
38623
38806
|
pendingForMainCount: 0,
|
|
@@ -38672,7 +38855,7 @@ async function runListenerSupervisor(options) {
|
|
|
38672
38855
|
// before the socket can answer, before any status/event persistence.
|
|
38673
38856
|
initialize: prepare ? async () => {
|
|
38674
38857
|
const selected = await prepare(proposedInstanceId);
|
|
38675
|
-
if (!selected || typeof selected !== "object" || typeof selected.instanceId !== "string" || !
|
|
38858
|
+
if (!selected || typeof selected !== "object" || typeof selected.instanceId !== "string" || !UUID_RE19.test(selected.instanceId)) {
|
|
38676
38859
|
throw new Error("listener prepare returned an invalid instance id");
|
|
38677
38860
|
}
|
|
38678
38861
|
status = { ...status, instanceId: selected.instanceId };
|
|
@@ -38698,6 +38881,17 @@ async function runListenerSupervisor(options) {
|
|
|
38698
38881
|
const versionNotice = options.getProviderVersionNotice?.() ?? null;
|
|
38699
38882
|
transition("ready", {
|
|
38700
38883
|
readyAt: event.ts,
|
|
38884
|
+
// Deliberately does NOT clear consecutiveAckFailureCount. Reaching
|
|
38885
|
+
// `ready` is not provider proof: the permission canary is its own
|
|
38886
|
+
// prompt, and a provider can answer it and fail every real one --
|
|
38887
|
+
// tests/listener-cli-process.test.ts builds such a child, whose
|
|
38888
|
+
// `failPrompts` trips only non-canary prompts (that test does not
|
|
38889
|
+
// restart it, so it does not by itself exercise this path). Clearing
|
|
38890
|
+
// the run here while `lastAckOutcome` still held a stale `observed`
|
|
38891
|
+
// put `HANDLED: yes` back on the incident screen after any restartable
|
|
38892
|
+
// blip. Only a `replied` ack clears the run; the pin is in
|
|
38893
|
+
// tests/listener-runtime.test.ts, which fires `ready` after the
|
|
38894
|
+
// measured incident and asserts the run survives it.
|
|
38701
38895
|
lastErrorCode: null,
|
|
38702
38896
|
lastErrorDetail: null,
|
|
38703
38897
|
lastErrorReasonCode: null,
|
|
@@ -38882,9 +39076,14 @@ async function runListenerSupervisor(options) {
|
|
|
38882
39076
|
return;
|
|
38883
39077
|
}
|
|
38884
39078
|
if (event.type === "delivery_ack") {
|
|
39079
|
+
const failed = event.outcome === "failed_terminal";
|
|
39080
|
+
const providerProven = DELIVERY_PROVIDER_PROVEN_OUTCOMES.has(event.outcome);
|
|
38885
39081
|
status = {
|
|
38886
39082
|
...status,
|
|
38887
39083
|
lastAckAt: event.ts,
|
|
39084
|
+
lastAckOutcome: event.outcome,
|
|
39085
|
+
lastAckSignalId: event.signalId,
|
|
39086
|
+
consecutiveAckFailureCount: failed ? (status.consecutiveAckFailureCount ?? 0) + 1 : providerProven ? 0 : status.consecutiveAckFailureCount,
|
|
38888
39087
|
pendingDeliveryCount: null,
|
|
38889
39088
|
lastSignalId: event.signalId,
|
|
38890
39089
|
updatedAt: event.ts
|
|
@@ -39117,7 +39316,7 @@ async function waitForListenerReady(paths, options = {}) {
|
|
|
39117
39316
|
// src/listener/delivery-journal.ts
|
|
39118
39317
|
var import_node_path17 = require("node:path");
|
|
39119
39318
|
var import_node_util2 = require("node:util");
|
|
39120
|
-
var
|
|
39319
|
+
var UUID_RE20 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
39121
39320
|
var COMMAND_ID_RE3 = /^[A-Za-z0-9_-]{8,72}$/;
|
|
39122
39321
|
var SIGNAL_FINGERPRINT_RE = /^[0-9a-f]{64}$/;
|
|
39123
39322
|
var MAX_JOURNAL_BYTES = 8192;
|
|
@@ -39212,7 +39411,7 @@ var ALLOWED_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
|
39212
39411
|
"credential_unavailable"
|
|
39213
39412
|
]);
|
|
39214
39413
|
function claimCommandId(listenerInstanceId, claimOrdinal) {
|
|
39215
|
-
if (!
|
|
39414
|
+
if (!UUID_RE20.test(listenerInstanceId)) {
|
|
39216
39415
|
throw new Error("stored delivery journal is malformed");
|
|
39217
39416
|
}
|
|
39218
39417
|
if (!Number.isSafeInteger(claimOrdinal) || claimOrdinal < 0) {
|
|
@@ -39227,7 +39426,7 @@ function claimCommandId(listenerInstanceId, claimOrdinal) {
|
|
|
39227
39426
|
return id;
|
|
39228
39427
|
}
|
|
39229
39428
|
function ackCommandId(leaseId) {
|
|
39230
|
-
if (!
|
|
39429
|
+
if (!UUID_RE20.test(leaseId)) {
|
|
39231
39430
|
throw new Error("stored delivery journal is malformed");
|
|
39232
39431
|
}
|
|
39233
39432
|
const cleanLease = leaseId.toLowerCase().replace(/-/g, "");
|
|
@@ -39310,19 +39509,19 @@ function parseJournalRecord(raw, expectedWorkspaceId, expectedPrincipalId, rejec
|
|
|
39310
39509
|
if (row.version !== 1) {
|
|
39311
39510
|
throw new Error("stored delivery journal is malformed");
|
|
39312
39511
|
}
|
|
39313
|
-
if (typeof row.workspaceId !== "string" || !
|
|
39512
|
+
if (typeof row.workspaceId !== "string" || !UUID_RE20.test(row.workspaceId) || row.workspaceId !== row.workspaceId.toLowerCase()) {
|
|
39314
39513
|
throw new Error("stored delivery journal is malformed");
|
|
39315
39514
|
}
|
|
39316
39515
|
if (expectedWorkspaceId && row.workspaceId !== expectedWorkspaceId.toLowerCase()) {
|
|
39317
39516
|
throw new Error("stored delivery journal is malformed");
|
|
39318
39517
|
}
|
|
39319
|
-
if (typeof row.principalId !== "string" || !
|
|
39518
|
+
if (typeof row.principalId !== "string" || !UUID_RE20.test(row.principalId) || row.principalId !== row.principalId.toLowerCase()) {
|
|
39320
39519
|
throw new Error("stored delivery journal is malformed");
|
|
39321
39520
|
}
|
|
39322
39521
|
if (expectedPrincipalId && row.principalId !== expectedPrincipalId.toLowerCase()) {
|
|
39323
39522
|
throw new Error("stored delivery journal is malformed");
|
|
39324
39523
|
}
|
|
39325
|
-
if (typeof row.listenerInstanceId !== "string" || !
|
|
39524
|
+
if (typeof row.listenerInstanceId !== "string" || !UUID_RE20.test(row.listenerInstanceId) || row.listenerInstanceId !== row.listenerInstanceId.toLowerCase()) {
|
|
39326
39525
|
throw new Error("stored delivery journal is malformed");
|
|
39327
39526
|
}
|
|
39328
39527
|
if (!Number.isSafeInteger(row.nextClaimOrdinal) || row.nextClaimOrdinal < 0) {
|
|
@@ -39396,10 +39595,10 @@ function parseJournalRecord(raw, expectedWorkspaceId, expectedPrincipalId, rejec
|
|
|
39396
39595
|
if (active.claimLastAttemptAt === null) {
|
|
39397
39596
|
throw new Error("stored delivery journal is malformed");
|
|
39398
39597
|
}
|
|
39399
|
-
if (typeof active.signalId !== "string" || !
|
|
39598
|
+
if (typeof active.signalId !== "string" || !UUID_RE20.test(active.signalId) || active.signalId !== active.signalId.toLowerCase()) {
|
|
39400
39599
|
throw new Error("stored delivery journal is malformed");
|
|
39401
39600
|
}
|
|
39402
|
-
if (typeof active.leaseId !== "string" || !
|
|
39601
|
+
if (typeof active.leaseId !== "string" || !UUID_RE20.test(active.leaseId) || active.leaseId !== active.leaseId.toLowerCase()) {
|
|
39403
39602
|
throw new Error("stored delivery journal is malformed");
|
|
39404
39603
|
}
|
|
39405
39604
|
if (!isValidIsoTimestamp(active.leasedUntil) || Date.parse(active.leasedUntil) <= Date.parse(active.claimCreatedAt)) {
|
|
@@ -39491,7 +39690,7 @@ var FileListenerDeliveryJournal = class {
|
|
|
39491
39690
|
["profileId", "workspaceId", "principalId"],
|
|
39492
39691
|
"delivery journal configuration rejected"
|
|
39493
39692
|
);
|
|
39494
|
-
if (typeof options.profileId !== "string" || !options.profileId || options.profileId.includes("\0") || typeof options.workspaceId !== "string" || !
|
|
39693
|
+
if (typeof options.profileId !== "string" || !options.profileId || options.profileId.includes("\0") || typeof options.workspaceId !== "string" || !UUID_RE20.test(options.workspaceId) || typeof options.principalId !== "string" || !UUID_RE20.test(options.principalId)) {
|
|
39495
39694
|
throw new Error("delivery journal configuration rejected");
|
|
39496
39695
|
}
|
|
39497
39696
|
if (options.stateDirectory !== void 0) {
|
|
@@ -39613,7 +39812,7 @@ var FileListenerDeliveryJournal = class {
|
|
|
39613
39812
|
["signalId", "leaseId", "leasedUntil"],
|
|
39614
39813
|
"delivery journal mutation rejected"
|
|
39615
39814
|
);
|
|
39616
|
-
if (typeof input.signalId !== "string" || !
|
|
39815
|
+
if (typeof input.signalId !== "string" || !UUID_RE20.test(input.signalId) || typeof input.leaseId !== "string" || !UUID_RE20.test(input.leaseId) || !isValidIsoTimestamp(input.leasedUntil) || input.signalFingerprint !== void 0 && (typeof input.signalFingerprint !== "string" || !SIGNAL_FINGERPRINT_RE.test(input.signalFingerprint))) {
|
|
39617
39816
|
throw new Error("delivery journal mutation rejected");
|
|
39618
39817
|
}
|
|
39619
39818
|
const canonicalSignalId = input.signalId.toLowerCase();
|
|
@@ -39745,7 +39944,7 @@ async function openListenerDeliveryJournal(options) {
|
|
|
39745
39944
|
["profileId", "workspaceId", "principalId", "proposedListenerInstanceId"],
|
|
39746
39945
|
"delivery journal configuration rejected"
|
|
39747
39946
|
);
|
|
39748
|
-
if (typeof options.profileId !== "string" || !options.profileId || options.profileId.includes("\0") || typeof options.workspaceId !== "string" || !
|
|
39947
|
+
if (typeof options.profileId !== "string" || !options.profileId || options.profileId.includes("\0") || typeof options.workspaceId !== "string" || !UUID_RE20.test(options.workspaceId) || typeof options.principalId !== "string" || !UUID_RE20.test(options.principalId) || typeof options.proposedListenerInstanceId !== "string" || !UUID_RE20.test(options.proposedListenerInstanceId)) {
|
|
39749
39948
|
throw new Error("delivery journal configuration rejected");
|
|
39750
39949
|
}
|
|
39751
39950
|
if (options.stateDirectory !== void 0) {
|
|
@@ -39965,7 +40164,7 @@ var import_node_path20 = require("node:path");
|
|
|
39965
40164
|
|
|
39966
40165
|
// src/listener/brain-digest.ts
|
|
39967
40166
|
var import_node_path19 = require("node:path");
|
|
39968
|
-
var
|
|
40167
|
+
var UUID_RE21 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
39969
40168
|
var TOPIC_RE = /^[a-z0-9][a-z0-9._-]*$/;
|
|
39970
40169
|
var BRAIN_DIGEST_FILE = "brain-digest.json";
|
|
39971
40170
|
var BRAIN_DIGEST_LOCK = "brain-digest";
|
|
@@ -39985,7 +40184,7 @@ function parseState(raw) {
|
|
|
39985
40184
|
}
|
|
39986
40185
|
const row = value;
|
|
39987
40186
|
const topicVersions = row.topicVersions;
|
|
39988
|
-
if (row.version !== 1 || typeof row.principalId !== "string" || !
|
|
40187
|
+
if (row.version !== 1 || typeof row.principalId !== "string" || !UUID_RE21.test(row.principalId) || !topicVersions || typeof topicVersions !== "object" || Array.isArray(topicVersions) || Object.keys(topicVersions).length > MAX_BRAIN_DIGEST_TOPICS) {
|
|
39989
40188
|
throw new Error("stored brain digest state is malformed");
|
|
39990
40189
|
}
|
|
39991
40190
|
for (const [topic, version3] of Object.entries(topicVersions)) {
|
|
@@ -40028,7 +40227,7 @@ function renderBrainDigest(topicCount, topics) {
|
|
|
40028
40227
|
var FileBrainDigestStore = class {
|
|
40029
40228
|
constructor(instanceDirectory, principalId) {
|
|
40030
40229
|
this.instanceDirectory = instanceDirectory;
|
|
40031
|
-
if (!(0, import_node_path19.isAbsolute)(instanceDirectory) || !
|
|
40230
|
+
if (!(0, import_node_path19.isAbsolute)(instanceDirectory) || !UUID_RE21.test(principalId)) {
|
|
40032
40231
|
throw new Error("brain digest state needs an absolute listener directory and principal UUID");
|
|
40033
40232
|
}
|
|
40034
40233
|
this.principalId = principalId.toLowerCase();
|
|
@@ -40075,7 +40274,7 @@ var FileBrainDigestStore = class {
|
|
|
40075
40274
|
};
|
|
40076
40275
|
|
|
40077
40276
|
// src/listener/hook.ts
|
|
40078
|
-
var
|
|
40277
|
+
var UUID_RE22 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
40079
40278
|
var TOKEN_RE = /^swm_agt_[A-Za-z0-9_-]{43}$/;
|
|
40080
40279
|
var INSTANCE_KEY_RE = /^[0-9a-f]{64}$/;
|
|
40081
40280
|
var MAX_HOOK_CREDENTIAL_BYTES = 8 * 1024;
|
|
@@ -40127,7 +40326,7 @@ function parseListenerCredential(raw, rejectUnknownKeys = false) {
|
|
|
40127
40326
|
throw new Error("stored listener hook credential is malformed");
|
|
40128
40327
|
}
|
|
40129
40328
|
const row = value;
|
|
40130
|
-
if (!(rejectUnknownKeys ? exactKeys2(row, LISTENER_CREDENTIAL_KEYS) : hasRequiredKeys(row, LISTENER_CREDENTIAL_KEYS)) || row.version !== 1 || typeof row.profileId !== "string" || !/^[0-9a-f]{24}$/.test(row.profileId) || typeof row.targetUrl !== "string" || typeof row.anonKey !== "string" || row.anonKey.length < 1 || row.anonKey.length > 4096 || typeof row.workspaceId !== "string" || !
|
|
40329
|
+
if (!(rejectUnknownKeys ? exactKeys2(row, LISTENER_CREDENTIAL_KEYS) : hasRequiredKeys(row, LISTENER_CREDENTIAL_KEYS)) || row.version !== 1 || typeof row.profileId !== "string" || !/^[0-9a-f]{24}$/.test(row.profileId) || typeof row.targetUrl !== "string" || typeof row.anonKey !== "string" || row.anonKey.length < 1 || row.anonKey.length > 4096 || typeof row.workspaceId !== "string" || !UUID_RE22.test(row.workspaceId) || typeof row.principalId !== "string" || !UUID_RE22.test(row.principalId) || typeof row.credential !== "string" || !TOKEN_RE.test(row.credential) || typeof row.updatedAt !== "string" || !Number.isFinite(Date.parse(row.updatedAt))) {
|
|
40131
40330
|
throw new Error("stored listener hook credential is malformed");
|
|
40132
40331
|
}
|
|
40133
40332
|
const target2 = cloudTarget(row.targetUrl, row.anonKey);
|
|
@@ -40185,7 +40384,7 @@ function parseSurface(raw, rejectUnknownKeys = false) {
|
|
|
40185
40384
|
throw new Error("stored listener hook surface state is malformed");
|
|
40186
40385
|
}
|
|
40187
40386
|
const row = value;
|
|
40188
|
-
if (rejectUnknownKeys && Object.keys(row).some((key2) => !HOOK_SURFACE_KEYS.has(key2)) || row.version !== 1 || !Array.isArray(row.surfacedSignalIds) || row.surfacedSignalIds.length > HOOK_SURFACED_IDS_MAX || row.surfacedSignalIds.some((id) => typeof id !== "string" || !
|
|
40387
|
+
if (rejectUnknownKeys && Object.keys(row).some((key2) => !HOOK_SURFACE_KEYS.has(key2)) || row.version !== 1 || !Array.isArray(row.surfacedSignalIds) || row.surfacedSignalIds.length > HOOK_SURFACED_IDS_MAX || row.surfacedSignalIds.some((id) => typeof id !== "string" || !UUID_RE22.test(id)) || !(row.reportedDroppedCount === void 0 || typeof row.reportedDroppedCount === "number" && Number.isSafeInteger(row.reportedDroppedCount) && row.reportedDroppedCount >= 0) || !(row.credentialFailureReported === void 0 || typeof row.credentialFailureReported === "boolean")) {
|
|
40189
40388
|
throw new Error("stored listener hook surface state is malformed");
|
|
40190
40389
|
}
|
|
40191
40390
|
const ids = row.surfacedSignalIds.map((id) => String(id).toLowerCase());
|
|
@@ -40216,7 +40415,7 @@ var FileHookSurfaceStore = class {
|
|
|
40216
40415
|
const unseen = [];
|
|
40217
40416
|
for (const item of items) {
|
|
40218
40417
|
const signalId = item.signalId.toLowerCase();
|
|
40219
|
-
if (!
|
|
40418
|
+
if (!UUID_RE22.test(signalId) || seen.has(signalId)) continue;
|
|
40220
40419
|
seen.add(signalId);
|
|
40221
40420
|
unseen.push(item);
|
|
40222
40421
|
}
|
|
@@ -40247,7 +40446,7 @@ var FileHookSurfaceStore = class {
|
|
|
40247
40446
|
const unseen = [];
|
|
40248
40447
|
for (const item of items) {
|
|
40249
40448
|
const signalId = item.signalId.toLowerCase();
|
|
40250
|
-
if (!
|
|
40449
|
+
if (!UUID_RE22.test(signalId) || seen.has(signalId)) continue;
|
|
40251
40450
|
seen.add(signalId);
|
|
40252
40451
|
unseen.push(item);
|
|
40253
40452
|
}
|
|
@@ -40270,7 +40469,7 @@ var FileHookSurfaceStore = class {
|
|
|
40270
40469
|
const seen = new Set(state.surfacedSignalIds);
|
|
40271
40470
|
for (const signalId of options.signalIds ?? []) {
|
|
40272
40471
|
const checked = signalId.toLowerCase();
|
|
40273
|
-
if (
|
|
40472
|
+
if (UUID_RE22.test(checked)) seen.add(checked);
|
|
40274
40473
|
}
|
|
40275
40474
|
await writeSecureJsonFile(
|
|
40276
40475
|
this.path,
|
|
@@ -40399,7 +40598,7 @@ async function discoverContexts(stateDirectory2, principalIds, isListenerLive =
|
|
|
40399
40598
|
}
|
|
40400
40599
|
selectedPrincipals = availablePrincipals;
|
|
40401
40600
|
} else {
|
|
40402
|
-
if (principalIds.some((principalId) => !
|
|
40601
|
+
if (principalIds.some((principalId) => !UUID_RE22.test(principalId))) {
|
|
40403
40602
|
return { contexts: [], requiresPrincipalScope: false };
|
|
40404
40603
|
}
|
|
40405
40604
|
selectedPrincipals = new Set(principalIds.map((principalId) => principalId.toLowerCase()));
|
|
@@ -41828,16 +42027,10 @@ var BOOLEAN_FLAGS = /* @__PURE__ */ new Set([
|
|
|
41828
42027
|
"user",
|
|
41829
42028
|
"write"
|
|
41830
42029
|
]);
|
|
41831
|
-
var
|
|
41832
|
-
var AGENT_CREDENTIAL_MESSAGE = "Agent credential minted. It is bound to this task and run so the agent's work stays scoped and attributable.";
|
|
41833
|
-
var AGENT_CREDENTIAL_MESSAGE_D088 = "Agent credential minted. It is bound to this run, so the agent's work is attributable to it.";
|
|
41834
|
-
var ACCEPTED_AGENT_CREDENTIAL_MESSAGES = [
|
|
41835
|
-
AGENT_CREDENTIAL_MESSAGE,
|
|
41836
|
-
AGENT_CREDENTIAL_MESSAGE_D088
|
|
41837
|
-
];
|
|
42030
|
+
var UUID_RE23 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
41838
42031
|
function packageVersion() {
|
|
41839
|
-
if ("0.1.
|
|
41840
|
-
return "0.1.
|
|
42032
|
+
if ("0.1.51".length > 0) {
|
|
42033
|
+
return "0.1.51";
|
|
41841
42034
|
}
|
|
41842
42035
|
try {
|
|
41843
42036
|
const value = JSON.parse(
|
|
@@ -42182,58 +42375,6 @@ function agentCredentialArtifact(input) {
|
|
|
42182
42375
|
...input.expiresAt === void 0 || input.expiresAt === null ? {} : { expires_at: new Date(input.expiresAt).toISOString() }
|
|
42183
42376
|
};
|
|
42184
42377
|
}
|
|
42185
|
-
function parsedAgentCredential(value) {
|
|
42186
|
-
if (!value.startsWith("{")) {
|
|
42187
|
-
assertAgentToken(value);
|
|
42188
|
-
return {
|
|
42189
|
-
token: value,
|
|
42190
|
-
principalId: null,
|
|
42191
|
-
tokenId: null,
|
|
42192
|
-
runId: null,
|
|
42193
|
-
expiresAt: null,
|
|
42194
|
-
durable: false
|
|
42195
|
-
};
|
|
42196
|
-
}
|
|
42197
|
-
const parsed = JSON.parse(value);
|
|
42198
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
42199
|
-
throw new Error("agent credential JSON is malformed");
|
|
42200
|
-
}
|
|
42201
|
-
const artifact = parsed;
|
|
42202
|
-
const requiredKeys = [
|
|
42203
|
-
"agent_token",
|
|
42204
|
-
"message",
|
|
42205
|
-
"principal_id",
|
|
42206
|
-
"run_id",
|
|
42207
|
-
"status",
|
|
42208
|
-
"token_id"
|
|
42209
|
-
];
|
|
42210
|
-
const withExpiry = [...requiredKeys, "expires_at"].sort();
|
|
42211
|
-
const actualKeys = Object.keys(artifact).sort();
|
|
42212
|
-
const shape = actualKeys.length === requiredKeys.length ? requiredKeys : withExpiry;
|
|
42213
|
-
if (actualKeys.length !== shape.length || !actualKeys.every((key2, index) => key2 === shape[index]) || !ACCEPTED_AGENT_CREDENTIAL_MESSAGES.includes(artifact.message) || artifact.status !== "accepted" || typeof artifact.principal_id !== "string" || !UUID_RE22.test(artifact.principal_id) || typeof artifact.token_id !== "string" || !UUID_RE22.test(artifact.token_id) || typeof artifact.run_id !== "string" || !UUID_RE22.test(artifact.run_id) || typeof artifact.agent_token !== "string") {
|
|
42214
|
-
throw new Error("agent credential JSON is malformed");
|
|
42215
|
-
}
|
|
42216
|
-
let expiresAt = null;
|
|
42217
|
-
if (artifact.expires_at !== void 0) {
|
|
42218
|
-
if (typeof artifact.expires_at !== "string") {
|
|
42219
|
-
throw new Error("agent credential JSON is malformed");
|
|
42220
|
-
}
|
|
42221
|
-
const parsedExpiry = Date.parse(artifact.expires_at);
|
|
42222
|
-
if (Number.isNaN(parsedExpiry)) {
|
|
42223
|
-
throw new Error("agent credential JSON is malformed");
|
|
42224
|
-
}
|
|
42225
|
-
expiresAt = parsedExpiry;
|
|
42226
|
-
}
|
|
42227
|
-
assertAgentToken(artifact.agent_token);
|
|
42228
|
-
return {
|
|
42229
|
-
token: artifact.agent_token,
|
|
42230
|
-
principalId: artifact.principal_id.toLowerCase(),
|
|
42231
|
-
tokenId: artifact.token_id.toLowerCase(),
|
|
42232
|
-
runId: artifact.run_id.toLowerCase(),
|
|
42233
|
-
expiresAt,
|
|
42234
|
-
durable: true
|
|
42235
|
-
};
|
|
42236
|
-
}
|
|
42237
42378
|
async function stdinCredential() {
|
|
42238
42379
|
if (process.stdin.isTTY) {
|
|
42239
42380
|
throw new Error(
|
|
@@ -42248,7 +42389,7 @@ async function stdinCredential() {
|
|
|
42248
42389
|
}
|
|
42249
42390
|
}
|
|
42250
42391
|
const credential = value.trim();
|
|
42251
|
-
return
|
|
42392
|
+
return parseAgentCredentialInput(credential, { kind: "stdin" });
|
|
42252
42393
|
}
|
|
42253
42394
|
var AgentTokenFileError = class extends Error {
|
|
42254
42395
|
constructor(code, message) {
|
|
@@ -42286,7 +42427,10 @@ async function agentCredential(args, options = {}) {
|
|
|
42286
42427
|
`--agent-token-file does not exist: ${fromFile}`
|
|
42287
42428
|
);
|
|
42288
42429
|
}
|
|
42289
|
-
return
|
|
42430
|
+
return parseAgentCredentialInput(value.trim(), {
|
|
42431
|
+
kind: "file",
|
|
42432
|
+
path: fromFile
|
|
42433
|
+
});
|
|
42290
42434
|
}
|
|
42291
42435
|
if (fromStdin || options.implicitStdin === true) {
|
|
42292
42436
|
return await stdinCredential();
|
|
@@ -42354,6 +42498,18 @@ async function humanCredential(args, cloud) {
|
|
|
42354
42498
|
store: credentials
|
|
42355
42499
|
};
|
|
42356
42500
|
}
|
|
42501
|
+
async function dualAuthHumanCredential(args, cloud) {
|
|
42502
|
+
try {
|
|
42503
|
+
return await humanCredential(args, cloud);
|
|
42504
|
+
} catch (error) {
|
|
42505
|
+
if (!(error instanceof HumanSessionError)) throw error;
|
|
42506
|
+
const personPath = error.code === "human_session_missing" ? "not signed in. If you are a person, run cswarm login." : "could not refresh your session. If you are a person, run cswarm login to sign in again.";
|
|
42507
|
+
throw new HumanSessionError(
|
|
42508
|
+
error.code,
|
|
42509
|
+
`${personPath} If you are an agent, pass --agent-token-file <path to the credential CommonSwarm minted for you> (or --agent-token-stdin).`
|
|
42510
|
+
);
|
|
42511
|
+
}
|
|
42512
|
+
}
|
|
42357
42513
|
function writeWorkspaceWarning(warning) {
|
|
42358
42514
|
process.stderr.write(`cswarm: ${warning.message}
|
|
42359
42515
|
`);
|
|
@@ -42493,7 +42649,7 @@ async function runNew(args) {
|
|
|
42493
42649
|
project: {
|
|
42494
42650
|
workspace_id: created,
|
|
42495
42651
|
name,
|
|
42496
|
-
stream_id: typeof response.stream_id === "string" &&
|
|
42652
|
+
stream_id: typeof response.stream_id === "string" && UUID_RE23.test(response.stream_id) ? response.stream_id : null
|
|
42497
42653
|
}
|
|
42498
42654
|
});
|
|
42499
42655
|
return;
|
|
@@ -43235,7 +43391,7 @@ async function runTokenRevoke(args) {
|
|
|
43235
43391
|
2
|
|
43236
43392
|
);
|
|
43237
43393
|
const cloud = await target(args);
|
|
43238
|
-
const human = await
|
|
43394
|
+
const human = await dualAuthHumanCredential(args, cloud);
|
|
43239
43395
|
const workspace = await workspaceId(args, cloud, human);
|
|
43240
43396
|
const tokenId = args.required("token-id");
|
|
43241
43397
|
const response = (await sendConnectWithPending(
|
|
@@ -43302,7 +43458,7 @@ async function runLinkNew(args) {
|
|
|
43302
43458
|
2
|
|
43303
43459
|
);
|
|
43304
43460
|
const taskId = args.required("task-id");
|
|
43305
|
-
if (!
|
|
43461
|
+
if (!UUID_RE23.test(taskId)) {
|
|
43306
43462
|
throw new Error("--task-id must be the work item's UUID");
|
|
43307
43463
|
}
|
|
43308
43464
|
const site = capabilitySiteOrigin(
|
|
@@ -43362,7 +43518,7 @@ async function runLinkRevoke(args) {
|
|
|
43362
43518
|
2
|
|
43363
43519
|
);
|
|
43364
43520
|
const capabilityId = args.required("capability-id");
|
|
43365
|
-
if (!
|
|
43521
|
+
if (!UUID_RE23.test(capabilityId)) {
|
|
43366
43522
|
throw new Error(
|
|
43367
43523
|
"--capability-id must be the id printed when the link was created"
|
|
43368
43524
|
);
|
|
@@ -43535,7 +43691,7 @@ async function commandWorkspaceAndCredential(args, cloud, options = {}) {
|
|
|
43535
43691
|
session
|
|
43536
43692
|
};
|
|
43537
43693
|
}
|
|
43538
|
-
const human = await
|
|
43694
|
+
const human = await dualAuthHumanCredential(args, cloud);
|
|
43539
43695
|
return {
|
|
43540
43696
|
selectedWorkspace: await workspaceId(args, cloud, human, {
|
|
43541
43697
|
validateOverride: options.validateHumanWorkspace ?? false
|
|
@@ -44037,7 +44193,7 @@ async function runReply(args) {
|
|
|
44037
44193
|
"json"
|
|
44038
44194
|
], 3);
|
|
44039
44195
|
const signalId = args.positionals[1];
|
|
44040
|
-
if (signalId === void 0 || !
|
|
44196
|
+
if (signalId === void 0 || !UUID_RE23.test(signalId)) {
|
|
44041
44197
|
throw new Error("reply requires the signal UUID being answered");
|
|
44042
44198
|
}
|
|
44043
44199
|
const body = args.positionals[2];
|
|
@@ -44582,7 +44738,7 @@ async function runReceipt(args) {
|
|
|
44582
44738
|
"json"
|
|
44583
44739
|
], 2);
|
|
44584
44740
|
const signalId = args.positionals[1];
|
|
44585
|
-
if (!
|
|
44741
|
+
if (!UUID_RE23.test(signalId)) {
|
|
44586
44742
|
throw new Error("signal-id must be a UUID");
|
|
44587
44743
|
}
|
|
44588
44744
|
if (!hasAgentCredential(args)) {
|
|
@@ -44742,7 +44898,7 @@ async function runInboxFollowCommand(args) {
|
|
|
44742
44898
|
}
|
|
44743
44899
|
}
|
|
44744
44900
|
function listenerUuid(value, flag) {
|
|
44745
|
-
if (!value || !
|
|
44901
|
+
if (!value || !UUID_RE23.test(value)) {
|
|
44746
44902
|
throw new Error(`--${flag} must be a UUID`);
|
|
44747
44903
|
}
|
|
44748
44904
|
return value.toLowerCase();
|
|
@@ -44911,7 +45067,9 @@ function listenerAttendanceState(status, evidence) {
|
|
|
44911
45067
|
const connected = status.state === "ready";
|
|
44912
45068
|
const attendanceState = routeMode === "worker" ? "not_required" : pending > 0 ? "unattended" : evidence.hookSurfaceAdvanced ? "attended" : "unproven";
|
|
44913
45069
|
const attended = attendanceState === "attended" ? true : attendanceState === "unattended" ? false : null;
|
|
44914
|
-
const
|
|
45070
|
+
const lastAckOutcome = status.lastAckOutcome ?? null;
|
|
45071
|
+
const deliveryFailing = (status.consecutiveAckFailureCount ?? 0) >= LISTENER_DELIVERY_FAILING_THRESHOLD;
|
|
45072
|
+
const handled = pending > 0 ? false : routeMode !== "worker" || lastAckOutcome === null ? null : deliveryFailing ? false : DELIVERY_HANDLED_OUTCOMES.has(lastAckOutcome) ? true : lastAckOutcome === "failed_terminal" ? false : null;
|
|
44915
45073
|
return {
|
|
44916
45074
|
connected,
|
|
44917
45075
|
attended,
|
|
@@ -44952,10 +45110,36 @@ function listenerLapseNotices(status, summary) {
|
|
|
44952
45110
|
}
|
|
44953
45111
|
if (summary.throughputLapseHours.length > 0) {
|
|
44954
45112
|
const latest = summary.throughputLapseHours.at(-1);
|
|
45113
|
+
const pending = status.pendingDeliveryCount;
|
|
45114
|
+
const pendingClause = pending === null ? " No pending count was recorded." : ` Pending deliveries now: ${pending}.`;
|
|
45115
|
+
const lapseRetries = summary.retryHours.find((hour) => hour.hourStart === latest.hourStart)?.retries ?? 0;
|
|
44955
45116
|
notices.push({
|
|
44956
45117
|
code: "listener_claim_throughput_lapse",
|
|
44957
|
-
message: `Claim throughput fell below
|
|
44958
|
-
nextStep: "
|
|
45118
|
+
message: `Claim throughput fell below ${LISTENER_THROUGHPUT_LAPSE_RATIO.toFixed(2)} for the full hour at ${latest.hourStart}: ${latest.claims}/${Math.round(latest.expectedClaims)} expected (${latest.ratio.toFixed(3)}).${pendingClause}`,
|
|
45119
|
+
nextStep: lapseRetries > 0 ? `Reads also failed in that hour: ${lapseRetries} ${lapseRetries === 1 ? "retry" : "retries"} recorded. Read those failures first; any notice above names the code. A retry does not say where the fault was \u2014 host_ports_exhausted is a retry AND a host fault.` : "No read retries were recorded in that hour, so the reads were not FAILING. That does not settle whether they were SLOW: a read that succeeds slowly records nothing here, and a claim retry sleeps in the claim loop without recording either. This notice measured nothing else about that hour, and nothing about the host \u2014 read any other notice above before looking further. Cheapest checks first: load average (uptime), process count, memory pressure (sysctl kern.memorystatus_vm_pressure_level, 1 is normal), sockets (netstat -an | grep -c TIME_WAIT)."
|
|
45120
|
+
});
|
|
45121
|
+
}
|
|
45122
|
+
const consecutive = status.consecutiveAckFailureCount ?? 0;
|
|
45123
|
+
if (consecutive >= LISTENER_DELIVERY_FAILING_THRESHOLD) {
|
|
45124
|
+
notices.push({
|
|
45125
|
+
code: "listener_delivery_failing",
|
|
45126
|
+
message: (
|
|
45127
|
+
// Do not assert "messages are not being answered": a notes-only listener
|
|
45128
|
+
// acks `observed` and is fine. State only what the run records.
|
|
45129
|
+
`The listener recorded ${consecutive} terminal delivery ${consecutive === 1 ? "failure" : "failures"} with no reply since. The newest acknowledgement was ${status.lastAckOutcome ?? "not recorded"} at ${status.lastAckAt ?? "an unknown time"}. The most recent listener error code is ${status.lastErrorCode ?? "not recorded"}.`
|
|
45130
|
+
),
|
|
45131
|
+
nextStep: (
|
|
45132
|
+
// `failed_terminal` covers a refusing-but-healthy provider, a dead host
|
|
45133
|
+
// session, and a local post failure, and the run alone cannot tell them
|
|
45134
|
+
// apart — so name the check, not a diagnosis. The command needs the
|
|
45135
|
+
// credential on stdin, and the listener is still running here.
|
|
45136
|
+
// `stop` takes --principal-id and needs no credential, so it must not
|
|
45137
|
+
// read stdin: one pipe cannot feed both halves of a chained command.
|
|
45138
|
+
// `listen stop` returns while the state is still `stopping` (D-074), and
|
|
45139
|
+
// `listen start` refuses a listener that is stopping, so the two verbs
|
|
45140
|
+
// race unless the confirm step sits between them.
|
|
45141
|
+
`Read the failure codes in ${status.logPath}, then stop the listener with: cswarm listen stop --workspace-id ${status.workspaceId} --principal-id ${status.principalId}. Wait until it is no longer running -- state stopped or failed, not stopping -- confirming with: cswarm listen status --workspace-id ${status.workspaceId} --principal-id ${status.principalId}. Then restart it by piping the same agent credential into: ${listenerRestartCommand(status)}`
|
|
45142
|
+
)
|
|
44959
45143
|
});
|
|
44960
45144
|
}
|
|
44961
45145
|
return notices;
|
|
@@ -45053,6 +45237,9 @@ function listenerStatusJson(status, permissionMode, evidence = {
|
|
|
45053
45237
|
lastTerminalDeliveryFailureAt: status.lastTerminalDeliveryFailureAt ?? null,
|
|
45054
45238
|
lastClaimAt: status.lastClaimAt ?? null,
|
|
45055
45239
|
lastAckAt: status.lastAckAt ?? null,
|
|
45240
|
+
lastAckOutcome: status.lastAckOutcome ?? null,
|
|
45241
|
+
consecutiveAckFailureCount: status.consecutiveAckFailureCount ?? null,
|
|
45242
|
+
lastAckSignalId: status.lastAckSignalId ?? null,
|
|
45056
45243
|
routeMode: status.routeMode ?? "worker",
|
|
45057
45244
|
deferOverChars: status.deferOverChars ?? null,
|
|
45058
45245
|
pendingForMainCount: status.pendingForMainCount ?? 0,
|
|
@@ -45078,6 +45265,7 @@ function renderListenerStatus(status, evidence = {
|
|
|
45078
45265
|
hookSurfaceAdvanced: false
|
|
45079
45266
|
}, nowMs = Date.now(), installed = null) {
|
|
45080
45267
|
const routeMode = status.routeMode ?? "worker";
|
|
45268
|
+
const deliveryFailureRun = status.consecutiveAckFailureCount ?? 0;
|
|
45081
45269
|
const pendingForMainCount = status.pendingForMainCount ?? 0;
|
|
45082
45270
|
const droppedForMainCount = status.droppedForMainCount ?? 0;
|
|
45083
45271
|
const unattendedCount = `${pendingForMainCount} ${pendingForMainCount === 1 ? "message is" : "messages are"} unattended`;
|
|
@@ -45089,7 +45277,7 @@ function renderListenerStatus(status, evidence = {
|
|
|
45089
45277
|
lapseNotices.length > 0 ? `Listener LAPSE for agent ${status.principalId}: ${lapseNotices.map((notice) => notice.code).join(", ")}.` : pendingForMainCount > 0 ? `Listener WARNING for agent ${status.principalId}: ${unattendedCount}.` : `Listener ${status.state} for agent ${status.principalId}.`,
|
|
45090
45278
|
`CONNECTED: ${attendance.connected ? "yes" : "no"}. Transport state is ${status.state}.`,
|
|
45091
45279
|
`ATTENDED: ${attendance.attendanceState === "attended" ? "yes. The session hook has surfaced messages on this host" : attendance.attendanceState === "unattended" ? "no. The main-session queue is not draining" : attendance.attendanceState === "not_required" ? "not required for the worker route" : "not yet proven on this host"}.`,
|
|
45092
|
-
`HANDLED: ${attendance.handledState === "handled" ?
|
|
45280
|
+
`HANDLED: ${attendance.handledState === "handled" ? `yes. The newest delivery acknowledgement was ${status.lastAckOutcome}` : attendance.handledState === "not_handled" ? routeMode === "worker" ? deliveryFailureRun >= LISTENER_DELIVERY_FAILING_THRESHOLD ? `no. ${deliveryFailureRun} ${deliveryFailureRun === 1 ? "delivery has" : "deliveries have"} failed since the last reply; the newest delivery acknowledgement was ${status.lastAckOutcome ?? "not recorded"}${status.lastErrorCode ? ` (${status.lastErrorCode})` : ""}` : `no. The newest delivery acknowledgement was ${status.lastAckOutcome ?? "not recorded"}${status.lastErrorCode ? ` (${status.lastErrorCode})` : ""}` : "no. Queued messages have not reached the session hook" : "not yet measured"}.`,
|
|
45093
45281
|
`Provider: ${status.provider}; process: ${status.pid}; started: ${status.startedAt}.`,
|
|
45094
45282
|
`Provider executable: ${status.providerExecutable ?? "not measured"}.`,
|
|
45095
45283
|
`Connections opened: ${status.connectionsOpened ?? "not measured"}.`,
|
|
@@ -45097,7 +45285,7 @@ function renderListenerStatus(status, evidence = {
|
|
|
45097
45285
|
...status.activityPublishFailures !== void 0 && status.activityPublishFailures > 0 ? [`Activity publish failures: ${status.activityPublishFailures}.`] : [],
|
|
45098
45286
|
...status.activityLastErrorCode ? [`Last activity publish error code: ${status.activityLastErrorCode}.`] : [],
|
|
45099
45287
|
status.readyAt ? `Ready since: ${status.readyAt}.` : "Not ready yet.",
|
|
45100
|
-
status.lastSignalId ? pendingForMainCount > 0 ? `Last claimed and queued signal: ${status.lastSignalId}. It is not handled yet.` : routeMode === "worker" ? `Last
|
|
45288
|
+
status.lastSignalId ? pendingForMainCount > 0 ? `Last claimed and queued signal: ${status.lastSignalId}. It is not handled yet.` : routeMode === "worker" ? status.lastAckAt === null ? `Last listener signal: ${status.lastSignalId}. No delivery acknowledgement is recorded.` : status.lastAckOutcome === null ? `Last listener signal: ${status.lastSignalId}. An acknowledgement was recorded at ${status.lastAckAt}; its outcome was not recorded.` : !status.lastAckSignalId ? `Last listener signal: ${status.lastSignalId}. The newest acknowledgement was ${status.lastAckOutcome}; which signal it belonged to was not recorded.` : status.lastAckOutcome === "failed_terminal" ? `Last failed delivery signal: ${status.lastAckSignalId}.` : DELIVERY_HANDLED_OUTCOMES.has(status.lastAckOutcome) && deliveryFailureRun < LISTENER_DELIVERY_FAILING_THRESHOLD ? `Last handled signal: ${status.lastAckSignalId}.` : `Last acknowledged signal: ${status.lastAckSignalId}. Its outcome was ${status.lastAckOutcome}.` : `Last listener signal: ${status.lastSignalId}. Local status does not prove its final observed receipt.` : "No signal has been handled yet.",
|
|
45101
45289
|
status.lastErrorCode ? `Last status code: ${status.lastErrorCode}.` : "No listener process error is recorded.",
|
|
45102
45290
|
readHealth.currentEpisodeStartedAt === null ? "Current read retry episode: none." : `Current read retry episode: ${readHealth.currentEpisodeAttempts} attempt${readHealth.currentEpisodeAttempts === 1 ? "" : "s"} since ${readHealth.currentEpisodeStartedAt}; reason ${readHealth.currentReasonCode}${readHealth.currentHttpStatus === null ? "" : ` (HTTP ${readHealth.currentHttpStatus})`}${readHealth.currentErrorConstructor === null ? "" : ` (${readHealth.currentErrorConstructor})`}.`,
|
|
45103
45291
|
`Read retry episodes in the last 24h: ${readSummary.episodesLast24h}; retries in the rolling hour: ${readSummary.retriesLastHour}.`,
|
|
@@ -45203,7 +45391,7 @@ function renderListenerStatus(status, evidence = {
|
|
|
45203
45391
|
}
|
|
45204
45392
|
if (status.lastTerminalDeliveryFailureCount !== null && status.lastTerminalDeliveryFailureCount > 0) {
|
|
45205
45393
|
lines.push(
|
|
45206
|
-
`The last claim reported ${status.lastTerminalDeliveryFailureCount}
|
|
45394
|
+
`The last claim reported ${status.lastTerminalDeliveryFailureCount} ${status.lastTerminalDeliveryFailureCount === 1 ? "delivery the service gave up on because this listener never acknowledged it. It remains" : "deliveries the service gave up on because this listener never acknowledged them. They remain"} recorded, and the listener will keep receiving.`
|
|
45207
45395
|
);
|
|
45208
45396
|
}
|
|
45209
45397
|
if (status.state === "stopping" || status.state === "starting") {
|
|
@@ -46405,7 +46593,7 @@ async function runHook(args) {
|
|
|
46405
46593
|
if (command2 === "check") {
|
|
46406
46594
|
args.assertShape(["cooldown", "principal-id"], 2);
|
|
46407
46595
|
const rawPrincipalIds = args.all("principal-id");
|
|
46408
|
-
if (rawPrincipalIds.some((principalId2) => !
|
|
46596
|
+
if (rawPrincipalIds.some((principalId2) => !UUID_RE23.test(principalId2))) return;
|
|
46409
46597
|
const principalIds = rawPrincipalIds.map((principalId2) => principalId2.toLowerCase());
|
|
46410
46598
|
const rawCooldown = args.optional("cooldown");
|
|
46411
46599
|
const cooldownSeconds = rawCooldown === void 0 ? void 0 : Number(rawCooldown);
|
|
@@ -46531,7 +46719,7 @@ async function fileRows(context) {
|
|
|
46531
46719
|
);
|
|
46532
46720
|
}
|
|
46533
46721
|
async function resolveFileSelector(context, selector) {
|
|
46534
|
-
if (
|
|
46722
|
+
if (UUID_RE23.test(selector)) return selector.toLowerCase();
|
|
46535
46723
|
const rows3 = await fileRows(context);
|
|
46536
46724
|
const match = rows3.find(
|
|
46537
46725
|
(row) => row.name.toLowerCase() === selector.toLowerCase()
|