@slates/provider-handler 1.0.0-rc.42 → 1.0.0-rc.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +44 -61
- package/dist/index.module.js +44 -61
- package/package.json +3 -3
- package/src/index.ts +63 -63
- package/src/runtimeInfo.test.ts +129 -0
package/dist/index.cjs
CHANGED
|
@@ -454,6 +454,7 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
454
454
|
let liveInvocation = new State(
|
|
455
455
|
null
|
|
456
456
|
);
|
|
457
|
+
let runtimeInfo = new State(null);
|
|
457
458
|
let getLiveInvocation = () => {
|
|
458
459
|
let directUpload = hubCapabilities.get()?.attachments?.directUpload;
|
|
459
460
|
let live = liveInvocation.get();
|
|
@@ -543,8 +544,17 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
543
544
|
};
|
|
544
545
|
};
|
|
545
546
|
let getAuthConfig = () => config.get()?.value ?? {};
|
|
546
|
-
let
|
|
547
|
-
|
|
547
|
+
let createContext = (config2, input, auth2, liveInvocationInfo = null) => new import_provider2.SlateContext(
|
|
548
|
+
config2,
|
|
549
|
+
input,
|
|
550
|
+
auth2,
|
|
551
|
+
slate.spec,
|
|
552
|
+
logger,
|
|
553
|
+
liveInvocationInfo,
|
|
554
|
+
runtimeInfo.get()
|
|
555
|
+
);
|
|
556
|
+
let getEmptyContext = () => createContext({}, {}, {});
|
|
557
|
+
let getAuthContext = () => createContext(getAuthConfig(), {}, {});
|
|
548
558
|
let withRequestTraces = (context, result) => {
|
|
549
559
|
let requestTraces = context.getHttpTraces();
|
|
550
560
|
return requestTraces.length > 0 ? { ...result, requestTraces } : result;
|
|
@@ -651,11 +661,15 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
651
661
|
baseUrl: params.baseUrl
|
|
652
662
|
});
|
|
653
663
|
});
|
|
664
|
+
manager.onNotification("slates/hub.runtime_info.set", async ({ params }) => {
|
|
665
|
+
runtimeInfo.set(params.runtimeInfo);
|
|
666
|
+
});
|
|
654
667
|
manager.onRequest("slates/provider.capabilities.get", async () => ({
|
|
655
668
|
capabilities: {
|
|
656
669
|
hub: {
|
|
657
670
|
capabilitiesNotification: true,
|
|
658
|
-
liveInvocation: true
|
|
671
|
+
liveInvocation: true,
|
|
672
|
+
runtimeInfo: true
|
|
659
673
|
},
|
|
660
674
|
provider: {
|
|
661
675
|
triggerGroups: (slate.triggerGroups?.length ?? 0) > 0 && (slate.actions ?? []).every(isMappableTrigger),
|
|
@@ -1214,19 +1228,18 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1214
1228
|
};
|
|
1215
1229
|
if (action.isPublic) {
|
|
1216
1230
|
getContextBasic();
|
|
1217
|
-
return invoke(
|
|
1231
|
+
return invoke(
|
|
1232
|
+
new import_provider2.SlatePublicContext(
|
|
1233
|
+
input,
|
|
1234
|
+
slate.spec,
|
|
1235
|
+
logger,
|
|
1236
|
+
getLiveInvocation(),
|
|
1237
|
+
runtimeInfo.get()
|
|
1238
|
+
)
|
|
1239
|
+
);
|
|
1218
1240
|
}
|
|
1219
1241
|
let ctx = getContextFull();
|
|
1220
|
-
return invoke(
|
|
1221
|
-
new import_provider2.SlateContext(
|
|
1222
|
-
ctx.config,
|
|
1223
|
-
input,
|
|
1224
|
-
ctx.auth?.output,
|
|
1225
|
-
slate.spec,
|
|
1226
|
-
logger,
|
|
1227
|
-
getLiveInvocation()
|
|
1228
|
-
)
|
|
1229
|
-
);
|
|
1242
|
+
return invoke(createContext(ctx.config, input, ctx.auth?.output, getLiveInvocation()));
|
|
1230
1243
|
});
|
|
1231
1244
|
manager.onRequest("slates/action.trigger.map_event", async ({ params }) => {
|
|
1232
1245
|
let ctx = getContextFull();
|
|
@@ -1237,7 +1250,7 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1237
1250
|
"input",
|
|
1238
1251
|
`Invalid event for trigger ID: ${params.actionId}`
|
|
1239
1252
|
);
|
|
1240
|
-
let context =
|
|
1253
|
+
let context = createContext(ctx.config, input, ctx.auth?.output);
|
|
1241
1254
|
let res = await traceProviderCall(
|
|
1242
1255
|
{
|
|
1243
1256
|
component: "action",
|
|
@@ -1309,12 +1322,10 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1309
1322
|
let ctx = getContextFull();
|
|
1310
1323
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1311
1324
|
let autoRegistration = getWebhookAutoRegistration(group);
|
|
1312
|
-
let context =
|
|
1325
|
+
let context = createContext(
|
|
1313
1326
|
ctx.config,
|
|
1314
1327
|
{ pageToken: params.pageToken ?? null },
|
|
1315
|
-
ctx.auth?.output
|
|
1316
|
-
slate.spec,
|
|
1317
|
-
logger
|
|
1328
|
+
ctx.auth?.output
|
|
1318
1329
|
);
|
|
1319
1330
|
let res = await traceProviderCall(
|
|
1320
1331
|
{
|
|
@@ -1344,16 +1355,14 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1344
1355
|
let ctx = getContextFull();
|
|
1345
1356
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1346
1357
|
let autoRegistration = getWebhookAutoRegistration(group);
|
|
1347
|
-
let context =
|
|
1358
|
+
let context = createContext(
|
|
1348
1359
|
ctx.config,
|
|
1349
1360
|
{
|
|
1350
1361
|
webhookTargetIdentifier: params.webhookTargetIdentifier,
|
|
1351
1362
|
webhookTargetPayload: params.webhookTargetPayload,
|
|
1352
1363
|
webhookUrl: params.webhookUrl
|
|
1353
1364
|
},
|
|
1354
|
-
ctx.auth?.output
|
|
1355
|
-
slate.spec,
|
|
1356
|
-
logger
|
|
1365
|
+
ctx.auth?.output
|
|
1357
1366
|
);
|
|
1358
1367
|
let res = await traceProviderCall(
|
|
1359
1368
|
{
|
|
@@ -1379,15 +1388,13 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1379
1388
|
let ctx = getContextFull();
|
|
1380
1389
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1381
1390
|
let autoRegistration = getWebhookAutoRegistration(group);
|
|
1382
|
-
let context =
|
|
1391
|
+
let context = createContext(
|
|
1383
1392
|
ctx.config,
|
|
1384
1393
|
{
|
|
1385
1394
|
webhookRegistrationIdentifier: params.webhookRegistrationIdentifier,
|
|
1386
1395
|
webhookRegistrationPayload: params.webhookRegistrationPayload
|
|
1387
1396
|
},
|
|
1388
|
-
ctx.auth?.output
|
|
1389
|
-
slate.spec,
|
|
1390
|
-
logger
|
|
1397
|
+
ctx.auth?.output
|
|
1391
1398
|
);
|
|
1392
1399
|
await traceProviderCall(
|
|
1393
1400
|
{
|
|
@@ -1410,13 +1417,7 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1410
1417
|
getContextBasic();
|
|
1411
1418
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1412
1419
|
let manualRegistration = getWebhookManualRegistration(group);
|
|
1413
|
-
let context =
|
|
1414
|
-
{},
|
|
1415
|
-
{ webhookUrl: params.webhookUrl },
|
|
1416
|
-
{},
|
|
1417
|
-
slate.spec,
|
|
1418
|
-
logger
|
|
1419
|
-
);
|
|
1420
|
+
let context = createContext({}, { webhookUrl: params.webhookUrl }, {});
|
|
1420
1421
|
let res = await traceProviderCall(
|
|
1421
1422
|
{
|
|
1422
1423
|
component: "action",
|
|
@@ -1447,16 +1448,14 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1447
1448
|
})
|
|
1448
1449
|
);
|
|
1449
1450
|
}
|
|
1450
|
-
let context =
|
|
1451
|
+
let context = createContext(
|
|
1451
1452
|
{},
|
|
1452
1453
|
{
|
|
1453
1454
|
webhookUrl: params.webhookUrl,
|
|
1454
1455
|
partialWebhookRegistrationPayload: params.partialWebhookRegistrationPayload,
|
|
1455
1456
|
userWebhookRegistrationPayload: params.userWebhookRegistrationPayload
|
|
1456
1457
|
},
|
|
1457
|
-
{}
|
|
1458
|
-
slate.spec,
|
|
1459
|
-
logger
|
|
1458
|
+
{}
|
|
1460
1459
|
);
|
|
1461
1460
|
let res = await traceProviderCall(
|
|
1462
1461
|
{
|
|
@@ -1490,15 +1489,13 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1490
1489
|
headers: params.headers,
|
|
1491
1490
|
body: params.body ? Uint8Array.from(atob(params.body.content), (c) => c.charCodeAt(0)) : null
|
|
1492
1491
|
});
|
|
1493
|
-
let context =
|
|
1492
|
+
let context = createContext(
|
|
1494
1493
|
{},
|
|
1495
1494
|
{
|
|
1496
1495
|
request: req,
|
|
1497
1496
|
webhookRegistrationPayload: params.webhookRegistrationPayload
|
|
1498
1497
|
},
|
|
1499
|
-
{}
|
|
1500
|
-
slate.spec,
|
|
1501
|
-
logger
|
|
1498
|
+
{}
|
|
1502
1499
|
);
|
|
1503
1500
|
let res = await traceProviderCall(
|
|
1504
1501
|
{
|
|
@@ -1545,7 +1542,7 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1545
1542
|
manager.onRequest("slates/trigger_group.routing_matchers.get", async ({ params }) => {
|
|
1546
1543
|
let ctx = getContextFull();
|
|
1547
1544
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1548
|
-
let context =
|
|
1545
|
+
let context = createContext(ctx.config, {}, ctx.auth?.output);
|
|
1549
1546
|
let matchers = await traceProviderCall(
|
|
1550
1547
|
{
|
|
1551
1548
|
component: "action",
|
|
@@ -1575,13 +1572,7 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1575
1572
|
})
|
|
1576
1573
|
);
|
|
1577
1574
|
}
|
|
1578
|
-
let context =
|
|
1579
|
-
ctx.config,
|
|
1580
|
-
{ state: params.state },
|
|
1581
|
-
ctx.auth?.output,
|
|
1582
|
-
slate.spec,
|
|
1583
|
-
logger
|
|
1584
|
-
);
|
|
1575
|
+
let context = createContext(ctx.config, { state: params.state }, ctx.auth?.output);
|
|
1585
1576
|
let res = await traceProviderCall(
|
|
1586
1577
|
{
|
|
1587
1578
|
component: "action",
|
|
@@ -1624,13 +1615,7 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1624
1615
|
manager.onRequest("slates/trigger_group.gateway.connect", async ({ params }) => {
|
|
1625
1616
|
let ctx = getContextFull();
|
|
1626
1617
|
let { group, gateway } = getGatewayTriggerGroup(params.triggerGroupId);
|
|
1627
|
-
let context =
|
|
1628
|
-
ctx.config,
|
|
1629
|
-
{ state: params.state },
|
|
1630
|
-
ctx.auth?.output,
|
|
1631
|
-
slate.spec,
|
|
1632
|
-
logger
|
|
1633
|
-
);
|
|
1618
|
+
let context = createContext(ctx.config, { state: params.state }, ctx.auth?.output);
|
|
1634
1619
|
let res = await traceProviderCall(
|
|
1635
1620
|
{
|
|
1636
1621
|
component: "action",
|
|
@@ -1651,12 +1636,10 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1651
1636
|
manager.onRequest("slates/trigger_group.gateway.receive", async ({ params }) => {
|
|
1652
1637
|
let ctx = getContextFull();
|
|
1653
1638
|
let { group, gateway } = getGatewayTriggerGroup(params.triggerGroupId);
|
|
1654
|
-
let context =
|
|
1639
|
+
let context = createContext(
|
|
1655
1640
|
ctx.config,
|
|
1656
1641
|
{ state: params.state, frames: params.frames, closed: params.closed ?? null },
|
|
1657
|
-
ctx.auth?.output
|
|
1658
|
-
slate.spec,
|
|
1659
|
-
logger
|
|
1642
|
+
ctx.auth?.output
|
|
1660
1643
|
);
|
|
1661
1644
|
let res = await traceProviderCall(
|
|
1662
1645
|
{
|
package/dist/index.module.js
CHANGED
|
@@ -438,6 +438,7 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
438
438
|
let liveInvocation = new State(
|
|
439
439
|
null
|
|
440
440
|
);
|
|
441
|
+
let runtimeInfo = new State(null);
|
|
441
442
|
let getLiveInvocation = () => {
|
|
442
443
|
let directUpload = hubCapabilities.get()?.attachments?.directUpload;
|
|
443
444
|
let live = liveInvocation.get();
|
|
@@ -527,8 +528,17 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
527
528
|
};
|
|
528
529
|
};
|
|
529
530
|
let getAuthConfig = () => config.get()?.value ?? {};
|
|
530
|
-
let
|
|
531
|
-
|
|
531
|
+
let createContext = (config2, input, auth2, liveInvocationInfo = null) => new SlateContext(
|
|
532
|
+
config2,
|
|
533
|
+
input,
|
|
534
|
+
auth2,
|
|
535
|
+
slate.spec,
|
|
536
|
+
logger,
|
|
537
|
+
liveInvocationInfo,
|
|
538
|
+
runtimeInfo.get()
|
|
539
|
+
);
|
|
540
|
+
let getEmptyContext = () => createContext({}, {}, {});
|
|
541
|
+
let getAuthContext = () => createContext(getAuthConfig(), {}, {});
|
|
532
542
|
let withRequestTraces = (context, result) => {
|
|
533
543
|
let requestTraces = context.getHttpTraces();
|
|
534
544
|
return requestTraces.length > 0 ? { ...result, requestTraces } : result;
|
|
@@ -635,11 +645,15 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
635
645
|
baseUrl: params.baseUrl
|
|
636
646
|
});
|
|
637
647
|
});
|
|
648
|
+
manager.onNotification("slates/hub.runtime_info.set", async ({ params }) => {
|
|
649
|
+
runtimeInfo.set(params.runtimeInfo);
|
|
650
|
+
});
|
|
638
651
|
manager.onRequest("slates/provider.capabilities.get", async () => ({
|
|
639
652
|
capabilities: {
|
|
640
653
|
hub: {
|
|
641
654
|
capabilitiesNotification: true,
|
|
642
|
-
liveInvocation: true
|
|
655
|
+
liveInvocation: true,
|
|
656
|
+
runtimeInfo: true
|
|
643
657
|
},
|
|
644
658
|
provider: {
|
|
645
659
|
triggerGroups: (slate.triggerGroups?.length ?? 0) > 0 && (slate.actions ?? []).every(isMappableTrigger),
|
|
@@ -1198,19 +1212,18 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1198
1212
|
};
|
|
1199
1213
|
if (action.isPublic) {
|
|
1200
1214
|
getContextBasic();
|
|
1201
|
-
return invoke(
|
|
1215
|
+
return invoke(
|
|
1216
|
+
new SlatePublicContext(
|
|
1217
|
+
input,
|
|
1218
|
+
slate.spec,
|
|
1219
|
+
logger,
|
|
1220
|
+
getLiveInvocation(),
|
|
1221
|
+
runtimeInfo.get()
|
|
1222
|
+
)
|
|
1223
|
+
);
|
|
1202
1224
|
}
|
|
1203
1225
|
let ctx = getContextFull();
|
|
1204
|
-
return invoke(
|
|
1205
|
-
new SlateContext(
|
|
1206
|
-
ctx.config,
|
|
1207
|
-
input,
|
|
1208
|
-
ctx.auth?.output,
|
|
1209
|
-
slate.spec,
|
|
1210
|
-
logger,
|
|
1211
|
-
getLiveInvocation()
|
|
1212
|
-
)
|
|
1213
|
-
);
|
|
1226
|
+
return invoke(createContext(ctx.config, input, ctx.auth?.output, getLiveInvocation()));
|
|
1214
1227
|
});
|
|
1215
1228
|
manager.onRequest("slates/action.trigger.map_event", async ({ params }) => {
|
|
1216
1229
|
let ctx = getContextFull();
|
|
@@ -1221,7 +1234,7 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1221
1234
|
"input",
|
|
1222
1235
|
`Invalid event for trigger ID: ${params.actionId}`
|
|
1223
1236
|
);
|
|
1224
|
-
let context =
|
|
1237
|
+
let context = createContext(ctx.config, input, ctx.auth?.output);
|
|
1225
1238
|
let res = await traceProviderCall(
|
|
1226
1239
|
{
|
|
1227
1240
|
component: "action",
|
|
@@ -1293,12 +1306,10 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1293
1306
|
let ctx = getContextFull();
|
|
1294
1307
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1295
1308
|
let autoRegistration = getWebhookAutoRegistration(group);
|
|
1296
|
-
let context =
|
|
1309
|
+
let context = createContext(
|
|
1297
1310
|
ctx.config,
|
|
1298
1311
|
{ pageToken: params.pageToken ?? null },
|
|
1299
|
-
ctx.auth?.output
|
|
1300
|
-
slate.spec,
|
|
1301
|
-
logger
|
|
1312
|
+
ctx.auth?.output
|
|
1302
1313
|
);
|
|
1303
1314
|
let res = await traceProviderCall(
|
|
1304
1315
|
{
|
|
@@ -1328,16 +1339,14 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1328
1339
|
let ctx = getContextFull();
|
|
1329
1340
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1330
1341
|
let autoRegistration = getWebhookAutoRegistration(group);
|
|
1331
|
-
let context =
|
|
1342
|
+
let context = createContext(
|
|
1332
1343
|
ctx.config,
|
|
1333
1344
|
{
|
|
1334
1345
|
webhookTargetIdentifier: params.webhookTargetIdentifier,
|
|
1335
1346
|
webhookTargetPayload: params.webhookTargetPayload,
|
|
1336
1347
|
webhookUrl: params.webhookUrl
|
|
1337
1348
|
},
|
|
1338
|
-
ctx.auth?.output
|
|
1339
|
-
slate.spec,
|
|
1340
|
-
logger
|
|
1349
|
+
ctx.auth?.output
|
|
1341
1350
|
);
|
|
1342
1351
|
let res = await traceProviderCall(
|
|
1343
1352
|
{
|
|
@@ -1363,15 +1372,13 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1363
1372
|
let ctx = getContextFull();
|
|
1364
1373
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1365
1374
|
let autoRegistration = getWebhookAutoRegistration(group);
|
|
1366
|
-
let context =
|
|
1375
|
+
let context = createContext(
|
|
1367
1376
|
ctx.config,
|
|
1368
1377
|
{
|
|
1369
1378
|
webhookRegistrationIdentifier: params.webhookRegistrationIdentifier,
|
|
1370
1379
|
webhookRegistrationPayload: params.webhookRegistrationPayload
|
|
1371
1380
|
},
|
|
1372
|
-
ctx.auth?.output
|
|
1373
|
-
slate.spec,
|
|
1374
|
-
logger
|
|
1381
|
+
ctx.auth?.output
|
|
1375
1382
|
);
|
|
1376
1383
|
await traceProviderCall(
|
|
1377
1384
|
{
|
|
@@ -1394,13 +1401,7 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1394
1401
|
getContextBasic();
|
|
1395
1402
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1396
1403
|
let manualRegistration = getWebhookManualRegistration(group);
|
|
1397
|
-
let context =
|
|
1398
|
-
{},
|
|
1399
|
-
{ webhookUrl: params.webhookUrl },
|
|
1400
|
-
{},
|
|
1401
|
-
slate.spec,
|
|
1402
|
-
logger
|
|
1403
|
-
);
|
|
1404
|
+
let context = createContext({}, { webhookUrl: params.webhookUrl }, {});
|
|
1404
1405
|
let res = await traceProviderCall(
|
|
1405
1406
|
{
|
|
1406
1407
|
component: "action",
|
|
@@ -1431,16 +1432,14 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1431
1432
|
})
|
|
1432
1433
|
);
|
|
1433
1434
|
}
|
|
1434
|
-
let context =
|
|
1435
|
+
let context = createContext(
|
|
1435
1436
|
{},
|
|
1436
1437
|
{
|
|
1437
1438
|
webhookUrl: params.webhookUrl,
|
|
1438
1439
|
partialWebhookRegistrationPayload: params.partialWebhookRegistrationPayload,
|
|
1439
1440
|
userWebhookRegistrationPayload: params.userWebhookRegistrationPayload
|
|
1440
1441
|
},
|
|
1441
|
-
{}
|
|
1442
|
-
slate.spec,
|
|
1443
|
-
logger
|
|
1442
|
+
{}
|
|
1444
1443
|
);
|
|
1445
1444
|
let res = await traceProviderCall(
|
|
1446
1445
|
{
|
|
@@ -1474,15 +1473,13 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1474
1473
|
headers: params.headers,
|
|
1475
1474
|
body: params.body ? Uint8Array.from(atob(params.body.content), (c) => c.charCodeAt(0)) : null
|
|
1476
1475
|
});
|
|
1477
|
-
let context =
|
|
1476
|
+
let context = createContext(
|
|
1478
1477
|
{},
|
|
1479
1478
|
{
|
|
1480
1479
|
request: req,
|
|
1481
1480
|
webhookRegistrationPayload: params.webhookRegistrationPayload
|
|
1482
1481
|
},
|
|
1483
|
-
{}
|
|
1484
|
-
slate.spec,
|
|
1485
|
-
logger
|
|
1482
|
+
{}
|
|
1486
1483
|
);
|
|
1487
1484
|
let res = await traceProviderCall(
|
|
1488
1485
|
{
|
|
@@ -1529,7 +1526,7 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1529
1526
|
manager.onRequest("slates/trigger_group.routing_matchers.get", async ({ params }) => {
|
|
1530
1527
|
let ctx = getContextFull();
|
|
1531
1528
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1532
|
-
let context =
|
|
1529
|
+
let context = createContext(ctx.config, {}, ctx.auth?.output);
|
|
1533
1530
|
let matchers = await traceProviderCall(
|
|
1534
1531
|
{
|
|
1535
1532
|
component: "action",
|
|
@@ -1559,13 +1556,7 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1559
1556
|
})
|
|
1560
1557
|
);
|
|
1561
1558
|
}
|
|
1562
|
-
let context =
|
|
1563
|
-
ctx.config,
|
|
1564
|
-
{ state: params.state },
|
|
1565
|
-
ctx.auth?.output,
|
|
1566
|
-
slate.spec,
|
|
1567
|
-
logger
|
|
1568
|
-
);
|
|
1559
|
+
let context = createContext(ctx.config, { state: params.state }, ctx.auth?.output);
|
|
1569
1560
|
let res = await traceProviderCall(
|
|
1570
1561
|
{
|
|
1571
1562
|
component: "action",
|
|
@@ -1608,13 +1599,7 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1608
1599
|
manager.onRequest("slates/trigger_group.gateway.connect", async ({ params }) => {
|
|
1609
1600
|
let ctx = getContextFull();
|
|
1610
1601
|
let { group, gateway } = getGatewayTriggerGroup(params.triggerGroupId);
|
|
1611
|
-
let context =
|
|
1612
|
-
ctx.config,
|
|
1613
|
-
{ state: params.state },
|
|
1614
|
-
ctx.auth?.output,
|
|
1615
|
-
slate.spec,
|
|
1616
|
-
logger
|
|
1617
|
-
);
|
|
1602
|
+
let context = createContext(ctx.config, { state: params.state }, ctx.auth?.output);
|
|
1618
1603
|
let res = await traceProviderCall(
|
|
1619
1604
|
{
|
|
1620
1605
|
component: "action",
|
|
@@ -1635,12 +1620,10 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1635
1620
|
manager.onRequest("slates/trigger_group.gateway.receive", async ({ params }) => {
|
|
1636
1621
|
let ctx = getContextFull();
|
|
1637
1622
|
let { group, gateway } = getGatewayTriggerGroup(params.triggerGroupId);
|
|
1638
|
-
let context =
|
|
1623
|
+
let context = createContext(
|
|
1639
1624
|
ctx.config,
|
|
1640
1625
|
{ state: params.state, frames: params.frames, closed: params.closed ?? null },
|
|
1641
|
-
ctx.auth?.output
|
|
1642
|
-
slate.spec,
|
|
1643
|
-
logger
|
|
1626
|
+
ctx.auth?.output
|
|
1644
1627
|
);
|
|
1645
1628
|
let res = await traceProviderCall(
|
|
1646
1629
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slates/provider-handler",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.43",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@lowerdeck/error": "^1.1.0",
|
|
35
|
-
"@slates/proto": "1.0.0-rc.
|
|
36
|
-
"@slates/provider": "1.0.0-rc.
|
|
35
|
+
"@slates/proto": "1.0.0-rc.28",
|
|
36
|
+
"@slates/provider": "1.0.0-rc.33",
|
|
37
37
|
"p-queue": "^6.6.2",
|
|
38
38
|
"zod": "^4.2.1"
|
|
39
39
|
},
|
package/src/index.ts
CHANGED
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
SLATES_PROTOCOL_VERSION,
|
|
10
10
|
type SlatesMessageAuthAdminCallbackHandleRequest,
|
|
11
11
|
type SlatesMessageAuthAuthorizationUrlGetRequest,
|
|
12
|
-
type SlatesParticipant
|
|
12
|
+
type SlatesParticipant,
|
|
13
|
+
type SlatesRuntimeInfo
|
|
13
14
|
} from '@slates/proto';
|
|
14
15
|
import {
|
|
15
16
|
AuthConfigSecretRedactor,
|
|
@@ -22,6 +23,7 @@ import {
|
|
|
22
23
|
SlateLogger,
|
|
23
24
|
type SlateLogListener,
|
|
24
25
|
SlatePublicContext,
|
|
26
|
+
type SlateRuntimeInfo,
|
|
25
27
|
uploadAttachmentDirect
|
|
26
28
|
} from '@slates/provider';
|
|
27
29
|
import { PQueue } from './pQueue';
|
|
@@ -189,6 +191,14 @@ let resolveTraceMessage = <ResultType>(
|
|
|
189
191
|
result: ResultType
|
|
190
192
|
) => (typeof message === 'function' ? message(result) : message);
|
|
191
193
|
|
|
194
|
+
// Build fails if SlateRuntimeInfo drifts from the proto schema.
|
|
195
|
+
true satisfies [SlateRuntimeInfo, SlatesRuntimeInfo] extends [
|
|
196
|
+
SlatesRuntimeInfo,
|
|
197
|
+
SlateRuntimeInfo
|
|
198
|
+
]
|
|
199
|
+
? true
|
|
200
|
+
: false;
|
|
201
|
+
|
|
192
202
|
export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
193
203
|
slate: Slate<ConfigType, AuthType>,
|
|
194
204
|
listeners: SlateLogListener[]
|
|
@@ -209,6 +219,7 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
209
219
|
let liveInvocation = new State<Pick<SlateLiveInvocationInfo, 'token' | 'baseUrl'> | null>(
|
|
210
220
|
null
|
|
211
221
|
);
|
|
222
|
+
let runtimeInfo = new State<SlateRuntimeInfo | null>(null);
|
|
212
223
|
|
|
213
224
|
let getLiveInvocation = (): SlateLiveInvocationInfo | null => {
|
|
214
225
|
let directUpload = hubCapabilities.get()?.attachments?.directUpload;
|
|
@@ -335,9 +346,24 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
335
346
|
|
|
336
347
|
let getAuthConfig = (): Record<string, any> => config.get()?.value ?? {};
|
|
337
348
|
|
|
338
|
-
let
|
|
339
|
-
|
|
340
|
-
|
|
349
|
+
let createContext = <ConfigType extends {}, InputType extends {}, AuthType extends {}>(
|
|
350
|
+
config: ConfigType,
|
|
351
|
+
input: InputType,
|
|
352
|
+
auth: AuthType,
|
|
353
|
+
liveInvocationInfo: SlateLiveInvocationInfo | null = null
|
|
354
|
+
) =>
|
|
355
|
+
new SlateContext(
|
|
356
|
+
config,
|
|
357
|
+
input,
|
|
358
|
+
auth,
|
|
359
|
+
slate.spec as any,
|
|
360
|
+
logger,
|
|
361
|
+
liveInvocationInfo,
|
|
362
|
+
runtimeInfo.get()
|
|
363
|
+
);
|
|
364
|
+
|
|
365
|
+
let getEmptyContext = () => createContext({}, {}, {});
|
|
366
|
+
let getAuthContext = () => createContext(getAuthConfig(), {}, {});
|
|
341
367
|
let withRequestTraces = <Result extends Record<string, any>>(
|
|
342
368
|
context: SlatePublicContext<any>,
|
|
343
369
|
result: Result
|
|
@@ -481,11 +507,16 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
481
507
|
});
|
|
482
508
|
});
|
|
483
509
|
|
|
510
|
+
manager.onNotification('slates/hub.runtime_info.set', async ({ params }) => {
|
|
511
|
+
runtimeInfo.set(params.runtimeInfo);
|
|
512
|
+
});
|
|
513
|
+
|
|
484
514
|
manager.onRequest('slates/provider.capabilities.get', async () => ({
|
|
485
515
|
capabilities: {
|
|
486
516
|
hub: {
|
|
487
517
|
capabilitiesNotification: true,
|
|
488
|
-
liveInvocation: true
|
|
518
|
+
liveInvocation: true,
|
|
519
|
+
runtimeInfo: true
|
|
489
520
|
},
|
|
490
521
|
provider: {
|
|
491
522
|
triggerGroups:
|
|
@@ -1131,20 +1162,19 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
1131
1162
|
|
|
1132
1163
|
if (action.isPublic) {
|
|
1133
1164
|
getContextBasic();
|
|
1134
|
-
return invoke(
|
|
1165
|
+
return invoke(
|
|
1166
|
+
new SlatePublicContext(
|
|
1167
|
+
input,
|
|
1168
|
+
slate.spec,
|
|
1169
|
+
logger,
|
|
1170
|
+
getLiveInvocation(),
|
|
1171
|
+
runtimeInfo.get()
|
|
1172
|
+
)
|
|
1173
|
+
);
|
|
1135
1174
|
}
|
|
1136
1175
|
|
|
1137
1176
|
let ctx = getContextFull();
|
|
1138
|
-
return invoke(
|
|
1139
|
-
new SlateContext(
|
|
1140
|
-
ctx.config,
|
|
1141
|
-
input,
|
|
1142
|
-
ctx.auth?.output!,
|
|
1143
|
-
slate.spec,
|
|
1144
|
-
logger,
|
|
1145
|
-
getLiveInvocation()
|
|
1146
|
-
)
|
|
1147
|
-
);
|
|
1177
|
+
return invoke(createContext(ctx.config, input, ctx.auth?.output!, getLiveInvocation()));
|
|
1148
1178
|
});
|
|
1149
1179
|
|
|
1150
1180
|
manager.onRequest('slates/action.trigger.map_event', async ({ params }) => {
|
|
@@ -1158,7 +1188,7 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
1158
1188
|
`Invalid event for trigger ID: ${params.actionId}`
|
|
1159
1189
|
);
|
|
1160
1190
|
|
|
1161
|
-
let context =
|
|
1191
|
+
let context = createContext(ctx.config, input, ctx.auth?.output!);
|
|
1162
1192
|
let res = await traceProviderCall(
|
|
1163
1193
|
{
|
|
1164
1194
|
component: 'action',
|
|
@@ -1246,12 +1276,10 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
1246
1276
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1247
1277
|
let autoRegistration = getWebhookAutoRegistration(group);
|
|
1248
1278
|
|
|
1249
|
-
let context =
|
|
1279
|
+
let context = createContext(
|
|
1250
1280
|
ctx.config,
|
|
1251
1281
|
{ pageToken: params.pageToken ?? null },
|
|
1252
|
-
ctx.auth?.output
|
|
1253
|
-
slate.spec,
|
|
1254
|
-
logger
|
|
1282
|
+
ctx.auth?.output!
|
|
1255
1283
|
);
|
|
1256
1284
|
let res = await traceProviderCall(
|
|
1257
1285
|
{
|
|
@@ -1285,16 +1313,14 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
1285
1313
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1286
1314
|
let autoRegistration = getWebhookAutoRegistration(group);
|
|
1287
1315
|
|
|
1288
|
-
let context =
|
|
1316
|
+
let context = createContext(
|
|
1289
1317
|
ctx.config,
|
|
1290
1318
|
{
|
|
1291
1319
|
webhookTargetIdentifier: params.webhookTargetIdentifier,
|
|
1292
1320
|
webhookTargetPayload: params.webhookTargetPayload,
|
|
1293
1321
|
webhookUrl: params.webhookUrl
|
|
1294
1322
|
},
|
|
1295
|
-
ctx.auth?.output
|
|
1296
|
-
slate.spec,
|
|
1297
|
-
logger
|
|
1323
|
+
ctx.auth?.output!
|
|
1298
1324
|
);
|
|
1299
1325
|
let res = await traceProviderCall(
|
|
1300
1326
|
{
|
|
@@ -1323,15 +1349,13 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
1323
1349
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1324
1350
|
let autoRegistration = getWebhookAutoRegistration(group);
|
|
1325
1351
|
|
|
1326
|
-
let context =
|
|
1352
|
+
let context = createContext(
|
|
1327
1353
|
ctx.config,
|
|
1328
1354
|
{
|
|
1329
1355
|
webhookRegistrationIdentifier: params.webhookRegistrationIdentifier,
|
|
1330
1356
|
webhookRegistrationPayload: params.webhookRegistrationPayload
|
|
1331
1357
|
},
|
|
1332
|
-
ctx.auth?.output
|
|
1333
|
-
slate.spec,
|
|
1334
|
-
logger
|
|
1358
|
+
ctx.auth?.output!
|
|
1335
1359
|
);
|
|
1336
1360
|
await traceProviderCall(
|
|
1337
1361
|
{
|
|
@@ -1357,13 +1381,7 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
1357
1381
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1358
1382
|
let manualRegistration = getWebhookManualRegistration(group);
|
|
1359
1383
|
|
|
1360
|
-
let context =
|
|
1361
|
-
{},
|
|
1362
|
-
{ webhookUrl: params.webhookUrl },
|
|
1363
|
-
{},
|
|
1364
|
-
slate.spec as any,
|
|
1365
|
-
logger
|
|
1366
|
-
);
|
|
1384
|
+
let context = createContext({}, { webhookUrl: params.webhookUrl }, {});
|
|
1367
1385
|
let res = await traceProviderCall(
|
|
1368
1386
|
{
|
|
1369
1387
|
component: 'action',
|
|
@@ -1398,16 +1416,14 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
1398
1416
|
);
|
|
1399
1417
|
}
|
|
1400
1418
|
|
|
1401
|
-
let context =
|
|
1419
|
+
let context = createContext(
|
|
1402
1420
|
{},
|
|
1403
1421
|
{
|
|
1404
1422
|
webhookUrl: params.webhookUrl,
|
|
1405
1423
|
partialWebhookRegistrationPayload: params.partialWebhookRegistrationPayload,
|
|
1406
1424
|
userWebhookRegistrationPayload: params.userWebhookRegistrationPayload
|
|
1407
1425
|
},
|
|
1408
|
-
{}
|
|
1409
|
-
slate.spec as any,
|
|
1410
|
-
logger
|
|
1426
|
+
{}
|
|
1411
1427
|
);
|
|
1412
1428
|
let res = await traceProviderCall(
|
|
1413
1429
|
{
|
|
@@ -1447,15 +1463,13 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
1447
1463
|
: null
|
|
1448
1464
|
});
|
|
1449
1465
|
|
|
1450
|
-
let context =
|
|
1466
|
+
let context = createContext(
|
|
1451
1467
|
{},
|
|
1452
1468
|
{
|
|
1453
1469
|
request: req,
|
|
1454
1470
|
webhookRegistrationPayload: params.webhookRegistrationPayload
|
|
1455
1471
|
},
|
|
1456
|
-
{}
|
|
1457
|
-
slate.spec as any,
|
|
1458
|
-
logger
|
|
1472
|
+
{}
|
|
1459
1473
|
);
|
|
1460
1474
|
let res = await traceProviderCall(
|
|
1461
1475
|
{
|
|
@@ -1511,7 +1525,7 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
1511
1525
|
let ctx = getContextFull();
|
|
1512
1526
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1513
1527
|
|
|
1514
|
-
let context =
|
|
1528
|
+
let context = createContext(ctx.config, {}, ctx.auth?.output!);
|
|
1515
1529
|
let matchers = await traceProviderCall(
|
|
1516
1530
|
{
|
|
1517
1531
|
component: 'action',
|
|
@@ -1545,13 +1559,7 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
1545
1559
|
);
|
|
1546
1560
|
}
|
|
1547
1561
|
|
|
1548
|
-
let context =
|
|
1549
|
-
ctx.config,
|
|
1550
|
-
{ state: params.state },
|
|
1551
|
-
ctx.auth?.output!,
|
|
1552
|
-
slate.spec,
|
|
1553
|
-
logger
|
|
1554
|
-
);
|
|
1562
|
+
let context = createContext(ctx.config, { state: params.state }, ctx.auth?.output!);
|
|
1555
1563
|
let res = await traceProviderCall(
|
|
1556
1564
|
{
|
|
1557
1565
|
component: 'action',
|
|
@@ -1599,13 +1607,7 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
1599
1607
|
let ctx = getContextFull();
|
|
1600
1608
|
let { group, gateway } = getGatewayTriggerGroup(params.triggerGroupId);
|
|
1601
1609
|
|
|
1602
|
-
let context =
|
|
1603
|
-
ctx.config,
|
|
1604
|
-
{ state: params.state },
|
|
1605
|
-
ctx.auth?.output!,
|
|
1606
|
-
slate.spec,
|
|
1607
|
-
logger
|
|
1608
|
-
);
|
|
1610
|
+
let context = createContext(ctx.config, { state: params.state }, ctx.auth?.output!);
|
|
1609
1611
|
let res = await traceProviderCall(
|
|
1610
1612
|
{
|
|
1611
1613
|
component: 'action',
|
|
@@ -1630,12 +1632,10 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
1630
1632
|
let ctx = getContextFull();
|
|
1631
1633
|
let { group, gateway } = getGatewayTriggerGroup(params.triggerGroupId);
|
|
1632
1634
|
|
|
1633
|
-
let context =
|
|
1635
|
+
let context = createContext(
|
|
1634
1636
|
ctx.config,
|
|
1635
1637
|
{ state: params.state, frames: params.frames, closed: params.closed ?? null },
|
|
1636
|
-
ctx.auth?.output
|
|
1637
|
-
slate.spec,
|
|
1638
|
-
logger
|
|
1638
|
+
ctx.auth?.output!
|
|
1639
1639
|
);
|
|
1640
1640
|
let res = await traceProviderCall(
|
|
1641
1641
|
{
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { SLATES_PROTOCOL_VERSION, SlatesProviderProtoHandlerManager } from '@slates/proto';
|
|
2
|
+
import {
|
|
3
|
+
getRuntimeInfo,
|
|
4
|
+
Slate,
|
|
5
|
+
SlateAuth,
|
|
6
|
+
SlateConfig,
|
|
7
|
+
SlatePublicTool,
|
|
8
|
+
SlateSpecification
|
|
9
|
+
} from '@slates/provider';
|
|
10
|
+
import { describe, expect, it } from 'vitest';
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
import { createProviderHandler } from './index';
|
|
13
|
+
|
|
14
|
+
let runtimeInfo = {
|
|
15
|
+
metorial: {
|
|
16
|
+
apiUrl: 'https://api-us1.metorial.test',
|
|
17
|
+
region: 'us1',
|
|
18
|
+
environment: 'staging'
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
let createManager = async () => {
|
|
23
|
+
let spec = SlateSpecification.create({
|
|
24
|
+
key: 'runtime-info-test',
|
|
25
|
+
name: 'Runtime Info Test',
|
|
26
|
+
config: SlateConfig.create(z.object({ apiUrl: z.string().nullable() })).getDefaultConfig(
|
|
27
|
+
() => ({ apiUrl: getRuntimeInfo()?.metorial?.apiUrl ?? null })
|
|
28
|
+
),
|
|
29
|
+
auth: SlateAuth.create().output(z.object({}))
|
|
30
|
+
});
|
|
31
|
+
let tool = SlatePublicTool.create(spec, {
|
|
32
|
+
key: 'read_runtime_info',
|
|
33
|
+
name: 'Read Runtime Info'
|
|
34
|
+
})
|
|
35
|
+
.input(z.object({}))
|
|
36
|
+
.output(z.object({ fromContext: z.any(), fromHelper: z.any() }))
|
|
37
|
+
.handleInvocation(async ctx => ({
|
|
38
|
+
output: { fromContext: ctx.runtimeInfo, fromHelper: getRuntimeInfo() },
|
|
39
|
+
message: 'ok'
|
|
40
|
+
}))
|
|
41
|
+
.build();
|
|
42
|
+
let slate = Slate.create({ spec, triggers: [], tools: [tool] });
|
|
43
|
+
let manager = await createProviderHandler(slate, []).run();
|
|
44
|
+
|
|
45
|
+
await SlatesProviderProtoHandlerManager.handleInput(manager, {
|
|
46
|
+
jsonrpc: '2.0',
|
|
47
|
+
method: 'slates/hello',
|
|
48
|
+
params: { protocol: SLATES_PROTOCOL_VERSION }
|
|
49
|
+
});
|
|
50
|
+
await SlatesProviderProtoHandlerManager.handleInput(manager, {
|
|
51
|
+
jsonrpc: '2.0',
|
|
52
|
+
method: 'slates/participant.set',
|
|
53
|
+
params: {
|
|
54
|
+
participants: [
|
|
55
|
+
{ type: 'consumer', id: 'consumer', name: 'Consumer' },
|
|
56
|
+
{ type: 'hub', id: 'hub', name: 'Hub' }
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return manager;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
let setRuntimeInfo = (manager: SlatesProviderProtoHandlerManager) =>
|
|
65
|
+
SlatesProviderProtoHandlerManager.handleInput(manager, {
|
|
66
|
+
jsonrpc: '2.0',
|
|
67
|
+
method: 'slates/hub.runtime_info.set',
|
|
68
|
+
params: { runtimeInfo }
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
let invokeTool = (manager: SlatesProviderProtoHandlerManager) =>
|
|
72
|
+
SlatesProviderProtoHandlerManager.handleInput(manager, {
|
|
73
|
+
jsonrpc: '2.0',
|
|
74
|
+
id: 'tool',
|
|
75
|
+
method: 'slates/action.tool.invoke',
|
|
76
|
+
params: { actionId: 'read_runtime_info', input: {} }
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
let getDefaultConfig = (manager: SlatesProviderProtoHandlerManager) =>
|
|
80
|
+
SlatesProviderProtoHandlerManager.handleInput(manager, {
|
|
81
|
+
jsonrpc: '2.0',
|
|
82
|
+
id: 'config',
|
|
83
|
+
method: 'slates/config.get_default',
|
|
84
|
+
params: {}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('hub runtime info', () => {
|
|
88
|
+
it('advertises the runtime info capability', async () => {
|
|
89
|
+
let response = await SlatesProviderProtoHandlerManager.handleInput(await createManager(), {
|
|
90
|
+
jsonrpc: '2.0',
|
|
91
|
+
id: 'capabilities',
|
|
92
|
+
method: 'slates/provider.capabilities.get',
|
|
93
|
+
params: {}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
expect(response).toMatchObject({
|
|
97
|
+
result: { capabilities: { hub: { runtimeInfo: true } } }
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('exposes runtime info to tools through ctx and the context helper', async () => {
|
|
102
|
+
let manager = await createManager();
|
|
103
|
+
await setRuntimeInfo(manager);
|
|
104
|
+
|
|
105
|
+
expect(await invokeTool(manager)).toMatchObject({
|
|
106
|
+
result: { output: { fromContext: runtimeInfo, fromHelper: runtimeInfo } }
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('exposes runtime info to handlers that receive no ctx argument', async () => {
|
|
111
|
+
let manager = await createManager();
|
|
112
|
+
await setRuntimeInfo(manager);
|
|
113
|
+
|
|
114
|
+
expect(await getDefaultConfig(manager)).toMatchObject({
|
|
115
|
+
result: { config: { apiUrl: runtimeInfo.metorial.apiUrl } }
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('returns null when the host sent no runtime info', async () => {
|
|
120
|
+
let manager = await createManager();
|
|
121
|
+
|
|
122
|
+
expect(await invokeTool(manager)).toMatchObject({
|
|
123
|
+
result: { output: { fromContext: null, fromHelper: null } }
|
|
124
|
+
});
|
|
125
|
+
expect(await getDefaultConfig(manager)).toMatchObject({
|
|
126
|
+
result: { config: { apiUrl: null } }
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|