@airtop/sdk 1.0.0-alpha2.13 → 1.0.0-alpha2.15
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 +222 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +157 -1
- package/dist/index.d.ts +157 -1
- package/dist/index.js +223 -11
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
@@ -9,7 +9,7 @@ var require_package = __commonJS({
|
|
9
9
|
module.exports = {
|
10
10
|
name: "@airtop/sdk",
|
11
11
|
description: "Airtop SDK for TypeScript",
|
12
|
-
version: "1.0.0-alpha2.
|
12
|
+
version: "1.0.0-alpha2.15",
|
13
13
|
type: "module",
|
14
14
|
main: "./dist/index.cjs",
|
15
15
|
module: "./dist/index.js",
|
@@ -47,7 +47,7 @@ var require_package = __commonJS({
|
|
47
47
|
},
|
48
48
|
dependencies: {
|
49
49
|
"@airtop/json-schema-adapter": "workspace:*",
|
50
|
-
"@airtop/core": "0.1.0-alpha.
|
50
|
+
"@airtop/core": "0.1.0-alpha.29",
|
51
51
|
"date-fns": "4.1.0",
|
52
52
|
loglayer: "6.3.3",
|
53
53
|
"serialize-error": "12.0.0",
|
@@ -121,6 +121,9 @@ var AirtopBase = class {
|
|
121
121
|
this.client = config.client;
|
122
122
|
this.outputJsonAdapter = config.outputSchemaAdapter;
|
123
123
|
this.jobId = config.jobId;
|
124
|
+
if (config.agentEventPublisher) {
|
125
|
+
this.agentEventPublisher = config.agentEventPublisher;
|
126
|
+
}
|
124
127
|
}
|
125
128
|
/**
|
126
129
|
* Sets the publisher for sending agent events. Internal use only.
|
@@ -193,7 +196,9 @@ var AirtopBase = class {
|
|
193
196
|
return {
|
194
197
|
client: this.client,
|
195
198
|
log: this.log,
|
196
|
-
jobId: this.jobId
|
199
|
+
jobId: this.jobId,
|
200
|
+
outputSchemaAdapter: this.outputJsonAdapter,
|
201
|
+
agentEventPublisher: this.agentEventPublisher
|
197
202
|
};
|
198
203
|
}
|
199
204
|
/**
|
@@ -513,6 +518,20 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
513
518
|
});
|
514
519
|
this.windowId = windowId;
|
515
520
|
this.sessionId = sessionId;
|
521
|
+
this.client.windows.get(
|
522
|
+
this.windowId,
|
523
|
+
{
|
524
|
+
sessionId: this.sessionId,
|
525
|
+
...config
|
526
|
+
},
|
527
|
+
this.resolveRequestOptions()
|
528
|
+
).then((results) => {
|
529
|
+
this._sendAgentPayload("LiveViewUrl", {
|
530
|
+
liveViewUrl: results.data.liveViewUrl,
|
531
|
+
windowId: this.windowId,
|
532
|
+
sessionId: this.sessionId
|
533
|
+
});
|
534
|
+
});
|
516
535
|
}
|
517
536
|
/**
|
518
537
|
* Gets the window ID.
|
@@ -541,11 +560,6 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
541
560
|
},
|
542
561
|
this.resolveRequestOptions(requestOptions)
|
543
562
|
);
|
544
|
-
this._sendAgentPayload("LiveViewUrl", {
|
545
|
-
liveViewUrl: results.data.liveViewUrl,
|
546
|
-
windowId: this.windowId,
|
547
|
-
sessionId: this.sessionId
|
548
|
-
});
|
549
563
|
return new AirtopWindow(this.getCommonConfig(), this.sessionId, results);
|
550
564
|
}
|
551
565
|
/**
|
@@ -1119,6 +1133,19 @@ var AirtopSessionClient = class extends AirtopBase {
|
|
1119
1133
|
},
|
1120
1134
|
this.resolveRequestOptions(requestOptions)
|
1121
1135
|
);
|
1136
|
+
this.client.windows.get(
|
1137
|
+
results.data.windowId,
|
1138
|
+
{
|
1139
|
+
sessionId: this.sessionId
|
1140
|
+
},
|
1141
|
+
this.resolveRequestOptions()
|
1142
|
+
).then((windowResults) => {
|
1143
|
+
this._sendAgentPayload("LiveViewUrl", {
|
1144
|
+
liveViewUrl: windowResults.data.liveViewUrl,
|
1145
|
+
windowId: results.data.windowId,
|
1146
|
+
sessionId: this.sessionId
|
1147
|
+
});
|
1148
|
+
});
|
1122
1149
|
return new AirtopWindow(this.getCommonConfig(), this.sessionId, results);
|
1123
1150
|
}
|
1124
1151
|
/**
|
@@ -1228,7 +1255,8 @@ var AirtopClient = class extends AirtopBase {
|
|
1228
1255
|
metadataFieldName: "metadata"
|
1229
1256
|
}),
|
1230
1257
|
outputSchemaAdapter: config.outputSchemaAdapter,
|
1231
|
-
jobId: config.jobId
|
1258
|
+
jobId: config.jobId,
|
1259
|
+
agentEventPublisher: config.agentEventPublisher
|
1232
1260
|
});
|
1233
1261
|
this.log.withPrefix("[Airtop SDK]");
|
1234
1262
|
this.client.logLevel = config.logLevel;
|
@@ -1448,8 +1476,191 @@ function registerAirtopPlugin(plugin) {
|
|
1448
1476
|
}
|
1449
1477
|
}
|
1450
1478
|
|
1451
|
-
// src/
|
1479
|
+
// src/agent/AirtopAgentClient.ts
|
1480
|
+
import { version as version2 } from "node:process";
|
1452
1481
|
import { Airtop as AirtopCore2 } from "@airtop/core";
|
1482
|
+
import { minutesToMilliseconds as minutesToMilliseconds2 } from "date-fns";
|
1483
|
+
import { ConsoleTransport as ConsoleTransport2 } from "loglayer";
|
1484
|
+
import { LogLayer as LogLayer2 } from "loglayer";
|
1485
|
+
import { serializeError as serializeError2 } from "serialize-error";
|
1486
|
+
var AirtopAgentClient = class extends AirtopBase {
|
1487
|
+
/**
|
1488
|
+
* Creates a new instance of the Airtop SDK.
|
1489
|
+
* @param config - Configuration options for the Airtop SDK
|
1490
|
+
*/
|
1491
|
+
constructor(config) {
|
1492
|
+
super({
|
1493
|
+
logLevel: config?.logLevel,
|
1494
|
+
client: new AirtopCore2({
|
1495
|
+
maxRetries: 0,
|
1496
|
+
timeout: minutesToMilliseconds2(1),
|
1497
|
+
apiKey: config.apiKey,
|
1498
|
+
baseURL: config?.airtopUrl,
|
1499
|
+
logLevel: config?.logLevel || "off",
|
1500
|
+
defaultHeaders: {
|
1501
|
+
"x-airtop-sdk-source": "typescript",
|
1502
|
+
"x-airtop-sdk-version": version2
|
1503
|
+
}
|
1504
|
+
}),
|
1505
|
+
log: config?.logger || new LogLayer2({
|
1506
|
+
errorSerializer: serializeError2,
|
1507
|
+
transport: new ConsoleTransport2({
|
1508
|
+
logger: console,
|
1509
|
+
messageField: "message",
|
1510
|
+
enabled: config.logLevel !== "off",
|
1511
|
+
level: config.logLevel === "off" ? "error" : config.logLevel || "error"
|
1512
|
+
}),
|
1513
|
+
contextFieldName: "context",
|
1514
|
+
metadataFieldName: "metadata"
|
1515
|
+
}),
|
1516
|
+
outputSchemaAdapter: config.outputSchemaAdapter,
|
1517
|
+
jobId: config.jobId
|
1518
|
+
});
|
1519
|
+
this.log.withPrefix("[Airtop SDK]");
|
1520
|
+
this.client.logLevel = config.logLevel;
|
1521
|
+
this.client.logger = {
|
1522
|
+
debug: (message, ...rest) => {
|
1523
|
+
processLogMessage(this.log, "debug", message, rest);
|
1524
|
+
},
|
1525
|
+
error: (message, ...rest) => {
|
1526
|
+
processLogMessage(this.log, "error", message, rest);
|
1527
|
+
},
|
1528
|
+
info: (message, ...rest) => {
|
1529
|
+
processLogMessage(this.log, "info", message, rest);
|
1530
|
+
},
|
1531
|
+
warn: (message, ...rest) => {
|
1532
|
+
processLogMessage(this.log, "warn", message, rest);
|
1533
|
+
}
|
1534
|
+
};
|
1535
|
+
}
|
1536
|
+
/**
|
1537
|
+
* Creates a new agent.
|
1538
|
+
* @param params - Parameters for creating the agent. Corresponds to `AirtopAgentCreateAgentParams`.
|
1539
|
+
* @param requestOptions - Request options.
|
1540
|
+
* @returns The created agent data, `AirtopCreateAgentResponse`.
|
1541
|
+
*/
|
1542
|
+
async createAgent(params, requestOptions = {}) {
|
1543
|
+
this.log.info("Creating agent");
|
1544
|
+
return this.client.agents.createAgent(params, this.resolveRequestOptions(requestOptions));
|
1545
|
+
}
|
1546
|
+
/**
|
1547
|
+
* Retrieves a specific agent by its ID.
|
1548
|
+
* @param agentId - The ID of the agent to retrieve.
|
1549
|
+
* @param requestOptions - Request options.
|
1550
|
+
* @returns The agent data, `AirtopGetAgentResponse`.
|
1551
|
+
*/
|
1552
|
+
async getAgent(agentId, requestOptions = {}) {
|
1553
|
+
this.log.withMetadata({ agentId }).info("Retrieving agent");
|
1554
|
+
return this.client.agents.getAgent(agentId, this.resolveRequestOptions(requestOptions));
|
1555
|
+
}
|
1556
|
+
/**
|
1557
|
+
* Lists agents.
|
1558
|
+
* @param params - Optional parameters for listing agents (e.g., pagination). Corresponds to `AirtopAgentGetAgentsParams`.
|
1559
|
+
* @param requestOptions - Request options.
|
1560
|
+
* @returns A list of agents, `AirtopGetAgentsResponse`.
|
1561
|
+
*/
|
1562
|
+
async listAgents(params, requestOptions = {}) {
|
1563
|
+
this.log.info("Listing agents");
|
1564
|
+
return this.client.agents.getAgents(params, this.resolveRequestOptions(requestOptions));
|
1565
|
+
}
|
1566
|
+
/**
|
1567
|
+
* Updates an existing agent.
|
1568
|
+
* @param agentId - The ID of the agent to update.
|
1569
|
+
* @param params - The new data for the agent. Corresponds to `AirtopAgentUpdateAgentParams`.
|
1570
|
+
* @param requestOptions - Request options.
|
1571
|
+
* @returns The updated agent data, `AirtopUpdateAgentResponse`.
|
1572
|
+
*/
|
1573
|
+
async updateAgent(agentId, params, requestOptions = {}) {
|
1574
|
+
this.log.withMetadata({ agentId }).info("Updating agent");
|
1575
|
+
return this.client.agents.updateAgent(agentId, params, this.resolveRequestOptions(requestOptions));
|
1576
|
+
}
|
1577
|
+
/**
|
1578
|
+
* Deletes one or more agents.
|
1579
|
+
* @param params - Parameters for deleting agents. Corresponds to `AirtopAgentDeleteAgentsParams`.
|
1580
|
+
* @param requestOptions - Request options.
|
1581
|
+
* @returns A response confirming the deletion, `AirtopDeleteAgentsResponse`.
|
1582
|
+
*/
|
1583
|
+
async deleteAgents(params, requestOptions = {}) {
|
1584
|
+
this.log.info("Deleting agent(s)");
|
1585
|
+
return this.client.agents.deleteAgents(params, this.resolveRequestOptions(requestOptions));
|
1586
|
+
}
|
1587
|
+
/**
|
1588
|
+
* Duplicates an agent.
|
1589
|
+
* @param agentId - The ID of the agent to duplicate.
|
1590
|
+
* @param params - Parameters for duplicating the agent (e.g., new name). Corresponds to `AirtopAgentDuplicateAgentParams`.
|
1591
|
+
* @param requestOptions - Request options.
|
1592
|
+
* @returns The duplicated agent data, `AirtopDuplicateAgentResponse`.
|
1593
|
+
*/
|
1594
|
+
async duplicateAgent(agentId, params, requestOptions = {}) {
|
1595
|
+
this.log.withMetadata({ agentId }).info("Duplicating agent");
|
1596
|
+
return this.client.agents.duplicateAgent(agentId, params, this.resolveRequestOptions(requestOptions));
|
1597
|
+
}
|
1598
|
+
/**
|
1599
|
+
* Creates a new version for an agent.
|
1600
|
+
* @param agentId - The ID of the agent for which to create a version.
|
1601
|
+
* @param params - Parameters for creating the agent version. Corresponds to `AirtopAgentCreateVersionParams`.
|
1602
|
+
* @param requestOptions - Request options.
|
1603
|
+
* @returns The created agent version data, `AirtopCreateAgentVersionResponse`.
|
1604
|
+
*/
|
1605
|
+
async createAgentVersion(agentId, params, requestOptions = {}) {
|
1606
|
+
this.log.withMetadata({ agentId }).info("Creating agent version");
|
1607
|
+
return this.client.agents.createVersion(agentId, params, this.resolveRequestOptions(requestOptions));
|
1608
|
+
}
|
1609
|
+
/**
|
1610
|
+
* Lists versions of an agent.
|
1611
|
+
* @param agentId - The ID of the agent whose versions to list.
|
1612
|
+
* @param params - Optional parameters for listing agent versions. Corresponds to `AirtopAgentGetVersionsParams`.
|
1613
|
+
* @param requestOptions - Request options.
|
1614
|
+
* @returns A list of agent versions, `AirtopGetAgentVersionsResponse`.
|
1615
|
+
*/
|
1616
|
+
async listAgentVersions(agentId, params, requestOptions = {}) {
|
1617
|
+
this.log.withMetadata({ agentId }).info("Listing agent versions");
|
1618
|
+
return this.client.agents.getVersions(agentId, params, this.resolveRequestOptions(requestOptions));
|
1619
|
+
}
|
1620
|
+
/**
|
1621
|
+
* Creates an invocation for an agent.
|
1622
|
+
* @param agentId - The ID of the agent for which to create an invocation.
|
1623
|
+
* @param params - Parameters for creating the agent invocation. Corresponds to `AirtopAgentCreateInvocationParams`.
|
1624
|
+
* @param requestOptions - Request options.
|
1625
|
+
* @returns The created agent invocation data, `AirtopCreateAgentInvocationResponse`.
|
1626
|
+
*/
|
1627
|
+
async createAgentInvocation(agentId, params, requestOptions = {}) {
|
1628
|
+
this.log.withMetadata({ agentId }).info("Creating agent invocation");
|
1629
|
+
return this.client.agents.createInvocation(agentId, params, this.resolveRequestOptions(requestOptions));
|
1630
|
+
}
|
1631
|
+
/**
|
1632
|
+
* Lists invocations of an agent.
|
1633
|
+
* @param agentIds - The ID of the agent whose invocations to list.
|
1634
|
+
* @param params - Optional parameters for listing agent invocations. Corresponds to `AirtopAgentGetInvocationsParams`.
|
1635
|
+
* @param requestOptions - Request options.
|
1636
|
+
* @returns A list of agent invocations, `AirtopGetAgentInvocationsResponse`.
|
1637
|
+
*/
|
1638
|
+
async listAgentInvocations(agentIds, params, requestOptions = {}) {
|
1639
|
+
this.log.withMetadata({ agentId: agentIds }).info("Listing agent invocations");
|
1640
|
+
return this.client.agents.getInvocations(agentIds, params, this.resolveRequestOptions(requestOptions));
|
1641
|
+
}
|
1642
|
+
/**
|
1643
|
+
* Cancels a specific invocation of an agent.
|
1644
|
+
* @param agentId - The ID of the agent.
|
1645
|
+
* @param invocationId - The ID of the invocation to cancel.
|
1646
|
+
* @param paramsBody - Optional body parameters for cancelling the invocation. Corresponds to `AirtopAgentCancelInvocationParams`.
|
1647
|
+
* @param requestOptions - Request options.
|
1648
|
+
* @returns A promise that resolves when the operation is complete.
|
1649
|
+
*/
|
1650
|
+
async cancelAgentInvocation(agentId, invocationId, paramsBody, requestOptions = {}) {
|
1651
|
+
this.log.withMetadata({ agentId, invocationId }).info("Cancelling agent invocation");
|
1652
|
+
const resolvedOptions = this.resolveRequestOptions(requestOptions);
|
1653
|
+
const finalOptions = { ...resolvedOptions };
|
1654
|
+
const params = { id: agentId, ...paramsBody };
|
1655
|
+
if (paramsBody) {
|
1656
|
+
finalOptions.body = paramsBody;
|
1657
|
+
}
|
1658
|
+
await this.client.agents.cancelInvocation(invocationId, params, finalOptions);
|
1659
|
+
}
|
1660
|
+
};
|
1661
|
+
|
1662
|
+
// src/AirtopMocks.ts
|
1663
|
+
import { Airtop as AirtopCore3 } from "@airtop/core";
|
1453
1664
|
import { MockLogLayer } from "loglayer";
|
1454
1665
|
import { v4 as uuidv4 } from "uuid";
|
1455
1666
|
function createNoOpClient(client) {
|
@@ -1472,7 +1683,7 @@ function createNoOpClient(client) {
|
|
1472
1683
|
});
|
1473
1684
|
}
|
1474
1685
|
function generateCommonAirtopConfigMock() {
|
1475
|
-
const client = new
|
1686
|
+
const client = new AirtopCore3({
|
1476
1687
|
apiKey: "test-api-key"
|
1477
1688
|
});
|
1478
1689
|
return {
|
@@ -1539,6 +1750,7 @@ var AirtopMocks = class {
|
|
1539
1750
|
}
|
1540
1751
|
};
|
1541
1752
|
export {
|
1753
|
+
AirtopAgentClient,
|
1542
1754
|
AirtopBase,
|
1543
1755
|
AirtopClient,
|
1544
1756
|
AirtopError,
|