@tapflowio/agent-core 0.1.0-alpha.1
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/LICENSE +21 -0
- package/README.md +23 -0
- package/dist/AgentRegistry.d.ts +7 -0
- package/dist/AgentRegistry.d.ts.map +1 -0
- package/dist/AgentRegistry.js +23 -0
- package/dist/AgentRegistry.js.map +1 -0
- package/dist/DeviceAgent.d.ts +15 -0
- package/dist/DeviceAgent.d.ts.map +1 -0
- package/dist/DeviceAgent.js +2 -0
- package/dist/DeviceAgent.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +9 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +45 -0
- package/dist/logger.js.map +1 -0
- package/dist/types.d.ts +28 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/resources.d.ts +8 -0
- package/dist/utils/resources.d.ts.map +1 -0
- package/dist/utils/resources.js +45 -0
- package/dist/utils/resources.js.map +1 -0
- package/dist/utils/stream.d.ts +3 -0
- package/dist/utils/stream.d.ts.map +1 -0
- package/dist/utils/stream.js +19 -0
- package/dist/utils/stream.js.map +1 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 tapflow contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @tapflowio/agent-core
|
|
2
|
+
|
|
3
|
+
Shared interface and utilities for [tapflow](https://github.com/jo-duchan/tapflow) agents.
|
|
4
|
+
|
|
5
|
+
## What's inside
|
|
6
|
+
|
|
7
|
+
- `DeviceAgent` interface — implemented by `@tapflowio/ios-agent` and `@tapflowio/android-agent`
|
|
8
|
+
- `AgentRegistry` — maps platform name to agent class
|
|
9
|
+
- Shared types: `Device`, `DeviceStatus`, `AgentResources`, `AndroidButton`
|
|
10
|
+
- Internal utilities: `createResourceSampler`, `registerStreamWs` (used by agent implementations)
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
This package is consumed by agent implementations and the tapflow CLI. You don't need to install it directly.
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import type { DeviceAgent, Device } from '@tapflowio/agent-core'
|
|
18
|
+
import { AgentRegistry } from '@tapflowio/agent-core'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## License
|
|
22
|
+
|
|
23
|
+
[MIT](LICENSE) — part of the [tapflow](https://github.com/jo-duchan/tapflow) project.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DeviceAgent, DeviceAgentConstructor } from './DeviceAgent.js';
|
|
2
|
+
export declare const AgentRegistry: {
|
|
3
|
+
register(platform: string, AgentClass: DeviceAgentConstructor): void;
|
|
4
|
+
get(platform: string): DeviceAgent;
|
|
5
|
+
clear(): void;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=AgentRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentRegistry.d.ts","sourceRoot":"","sources":["../src/AgentRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AAK3E,eAAO,MAAM,aAAa;uBACL,MAAM,cAAc,sBAAsB,GAAG,IAAI;kBAKtD,MAAM,GAAG,WAAW;aAWzB,IAAI;CAId,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const constructors = new Map();
|
|
2
|
+
const instances = new Map();
|
|
3
|
+
export const AgentRegistry = {
|
|
4
|
+
register(platform, AgentClass) {
|
|
5
|
+
constructors.set(platform, AgentClass);
|
|
6
|
+
instances.delete(platform);
|
|
7
|
+
},
|
|
8
|
+
get(platform) {
|
|
9
|
+
if (!constructors.has(platform)) {
|
|
10
|
+
throw new Error(`No agent registered for platform: ${platform}`);
|
|
11
|
+
}
|
|
12
|
+
if (!instances.has(platform)) {
|
|
13
|
+
const AgentClass = constructors.get(platform);
|
|
14
|
+
instances.set(platform, new AgentClass());
|
|
15
|
+
}
|
|
16
|
+
return instances.get(platform);
|
|
17
|
+
},
|
|
18
|
+
clear() {
|
|
19
|
+
constructors.clear();
|
|
20
|
+
instances.clear();
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=AgentRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentRegistry.js","sourceRoot":"","sources":["../src/AgentRegistry.ts"],"names":[],"mappings":"AAEA,MAAM,YAAY,GAAG,IAAI,GAAG,EAAkC,CAAA;AAC9D,MAAM,SAAS,GAAG,IAAI,GAAG,EAAuB,CAAA;AAEhD,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,QAAQ,CAAC,QAAgB,EAAE,UAAkC;QAC3D,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;QACtC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IAC5B,CAAC;IAED,GAAG,CAAC,QAAgB;QAClB,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,qCAAqC,QAAQ,EAAE,CAAC,CAAA;QAClE,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC7B,MAAM,UAAU,GAAG,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAE,CAAA;YAC9C,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,UAAU,EAAE,CAAC,CAAA;QAC3C,CAAC;QACD,OAAO,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAE,CAAA;IACjC,CAAC;IAED,KAAK;QACH,YAAY,CAAC,KAAK,EAAE,CAAA;QACpB,SAAS,CAAC,KAAK,EAAE,CAAA;IACnB,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Device } from './types.js';
|
|
2
|
+
export interface DeviceAgent {
|
|
3
|
+
listDevices(): Promise<Device[]>;
|
|
4
|
+
boot(deviceId: string): Promise<void>;
|
|
5
|
+
shutdown(deviceId: string): Promise<void>;
|
|
6
|
+
installApp(path: string): Promise<void>;
|
|
7
|
+
launchApp(bundleId: string): Promise<void>;
|
|
8
|
+
screenshot(): Promise<Buffer>;
|
|
9
|
+
stream(): ReadableStream<Buffer>;
|
|
10
|
+
touchStart(x: number, y: number): void;
|
|
11
|
+
touchMove(x: number, y: number): Promise<void>;
|
|
12
|
+
touchEnd(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export type DeviceAgentConstructor = new () => DeviceAgent;
|
|
15
|
+
//# sourceMappingURL=DeviceAgent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeviceAgent.d.ts","sourceRoot":"","sources":["../src/DeviceAgent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAExC,MAAM,WAAW,WAAW;IAC1B,WAAW,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;IAChC,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACrC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACzC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACvC,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC1C,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAAA;IAC7B,MAAM,IAAI,cAAc,CAAC,MAAM,CAAC,CAAA;IAChC,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACtC,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9C,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAC1B;AAED,MAAM,MAAM,sBAAsB,GAAG,UAAU,WAAW,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeviceAgent.js","sourceRoot":"","sources":["../src/DeviceAgent.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { Platform, DeviceStatus, Device, Point, AndroidButton, AgentResources } from './types.js';
|
|
2
|
+
export type { DeviceAgent, DeviceAgentConstructor } from './DeviceAgent.js';
|
|
3
|
+
export { AgentRegistry } from './AgentRegistry.js';
|
|
4
|
+
export type { Logger, LogLevel } from './logger.js';
|
|
5
|
+
export { createLogger } from './logger.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AACtG,YAAY,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAElD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
2
|
+
export interface Logger {
|
|
3
|
+
debug(msg: string, meta?: unknown): void;
|
|
4
|
+
info(msg: string, meta?: unknown): void;
|
|
5
|
+
warn(msg: string, meta?: unknown): void;
|
|
6
|
+
error(msg: string, meta?: unknown): void;
|
|
7
|
+
}
|
|
8
|
+
export declare function createLogger(prefix: string): Logger;
|
|
9
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3D,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACzC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACxC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACxC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC1C;AA+CD,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEnD"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const LEVELS = { debug: 0, info: 1, warn: 2, error: 3 };
|
|
2
|
+
function resolveLevel() {
|
|
3
|
+
const raw = process.env.LOG_LEVEL ?? 'info';
|
|
4
|
+
return LEVELS[raw] ?? LEVELS.info;
|
|
5
|
+
}
|
|
6
|
+
function print(fn, prefix, msg, meta) {
|
|
7
|
+
if (meta !== undefined) {
|
|
8
|
+
fn(`[${prefix}] ${msg}`, meta);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
fn(`[${prefix}] ${msg}`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
class ConsoleLogger {
|
|
15
|
+
prefix;
|
|
16
|
+
minLevel;
|
|
17
|
+
constructor(prefix) {
|
|
18
|
+
this.prefix = prefix;
|
|
19
|
+
this.minLevel = resolveLevel();
|
|
20
|
+
}
|
|
21
|
+
debug(msg, meta) {
|
|
22
|
+
if (this.minLevel > LEVELS.debug)
|
|
23
|
+
return;
|
|
24
|
+
print(console.debug, this.prefix, msg, meta);
|
|
25
|
+
}
|
|
26
|
+
info(msg, meta) {
|
|
27
|
+
if (this.minLevel > LEVELS.info)
|
|
28
|
+
return;
|
|
29
|
+
print(console.log, this.prefix, msg, meta);
|
|
30
|
+
}
|
|
31
|
+
warn(msg, meta) {
|
|
32
|
+
if (this.minLevel > LEVELS.warn)
|
|
33
|
+
return;
|
|
34
|
+
print(console.warn, this.prefix, msg, meta);
|
|
35
|
+
}
|
|
36
|
+
error(msg, meta) {
|
|
37
|
+
if (this.minLevel > LEVELS.error)
|
|
38
|
+
return;
|
|
39
|
+
print(console.error, this.prefix, msg, meta);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export function createLogger(prefix) {
|
|
43
|
+
return new ConsoleLogger(prefix);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,GAA6B,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;AAElF,SAAS,YAAY;IACnB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,MAAM,CAAC;IAC5C,OAAO,MAAM,CAAC,GAAe,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC;AAChD,CAAC;AAED,SAAS,KAAK,CAAC,EAAgC,EAAE,MAAc,EAAE,GAAW,EAAE,IAAa;IACzF,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,EAAE,CAAC,I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AAO,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type Platform = 'ios' | 'android';
|
|
2
|
+
export type DeviceStatus = 'booted' | 'shutdown' | 'unknown';
|
|
3
|
+
export interface Device {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
platform: Platform;
|
|
7
|
+
status: DeviceStatus;
|
|
8
|
+
typeId?: string;
|
|
9
|
+
osVersion?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface Point {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
}
|
|
15
|
+
export interface AgentResources {
|
|
16
|
+
cpuPercent: number;
|
|
17
|
+
memUsedMB: number;
|
|
18
|
+
memTotalMB: number;
|
|
19
|
+
slotsAvailable: number;
|
|
20
|
+
slotsTotal: number;
|
|
21
|
+
reportedAt: number;
|
|
22
|
+
}
|
|
23
|
+
export interface AndroidButton {
|
|
24
|
+
name: string;
|
|
25
|
+
accessibilityTitle: string;
|
|
26
|
+
keyCode: number;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,SAAS,CAAA;AAExC,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,UAAU,GAAG,SAAS,CAAA;AAE5D,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,QAAQ,CAAA;IAClB,MAAM,EAAE,YAAY,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV;AAED,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;CACnB;AAGD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,kBAAkB,EAAE,MAAM,CAAA;IAC1B,OAAO,EAAE,MAAM,CAAA;CAChB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../src/utils/resources.ts"],"names":[],"mappings":"AAGA,wBAAgB,qBAAqB;yBAGT,MAAM;0BAmBL;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE;EAmBrE"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import os from 'os';
|
|
2
|
+
import { spawnSync } from 'child_process';
|
|
3
|
+
export function createResourceSampler() {
|
|
4
|
+
let lastCpuTimes = null;
|
|
5
|
+
function getCpuPercent() {
|
|
6
|
+
let idle = 0, total = 0;
|
|
7
|
+
for (const cpu of os.cpus()) {
|
|
8
|
+
const t = cpu.times;
|
|
9
|
+
idle += t.idle;
|
|
10
|
+
total += t.user + t.nice + t.sys + t.idle + t.irq;
|
|
11
|
+
}
|
|
12
|
+
if (!lastCpuTimes) {
|
|
13
|
+
lastCpuTimes = { idle, total };
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
const idleDiff = idle - lastCpuTimes.idle;
|
|
17
|
+
const totalDiff = total - lastCpuTimes.total;
|
|
18
|
+
lastCpuTimes = { idle, total };
|
|
19
|
+
if (totalDiff === 0)
|
|
20
|
+
return 0;
|
|
21
|
+
return Math.min(100, Math.round((1 - idleDiff / totalDiff) * 1000) / 10);
|
|
22
|
+
}
|
|
23
|
+
// macOS: active + wired + compressed pages only. Falls back to os.freemem() on other OS.
|
|
24
|
+
function getMemoryUsage() {
|
|
25
|
+
const memTotalMB = Math.round(os.totalmem() / 1024 / 1024);
|
|
26
|
+
try {
|
|
27
|
+
const { stdout, status } = spawnSync('vm_stat', [], { encoding: 'utf8' });
|
|
28
|
+
if (status !== 0 || !stdout)
|
|
29
|
+
throw new Error('vm_stat failed');
|
|
30
|
+
const lines = stdout.split('\n');
|
|
31
|
+
const pageSize = parseInt(lines[0]?.match(/page size of (\d+)/)?.[1] ?? '16384');
|
|
32
|
+
const get = (key) => {
|
|
33
|
+
const m = lines.find((l) => l.startsWith(key))?.match(/:\s*(\d+)/);
|
|
34
|
+
return parseInt(m?.[1] ?? '0');
|
|
35
|
+
};
|
|
36
|
+
const pages = get('Pages active') + get('Pages wired down') + get('Pages occupied by compressor');
|
|
37
|
+
return { memUsedMB: Math.round(pages * pageSize / 1024 / 1024), memTotalMB };
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return { memUsedMB: Math.round((os.totalmem() - os.freemem()) / 1024 / 1024), memTotalMB };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return { getCpuPercent, getMemoryUsage };
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=resources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/utils/resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAEzC,MAAM,UAAU,qBAAqB;IACnC,IAAI,YAAY,GAA2C,IAAI,CAAA;IAE/D,SAAS,aAAa;QACpB,IAAI,IAAI,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,CAAA;QACvB,KAAK,MAAM,GAAG,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC;YAC5B,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,CAAA;YACnB,IAAI,IAAI,CAAC,CAAC,IAAI,CAAA;YACd,KAAK,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,CAAA;QACnD,CAAC;QACD,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,YAAY,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;YAC9B,OAAO,CAAC,CAAA;QACV,CAAC;QACD,MAAM,QAAQ,GAAG,IAAI,GAAG,YAAY,CAAC,IAAI,CAAA;QACzC,MAAM,SAAS,GAAG,KAAK,GAAG,YAAY,CAAC,KAAK,CAAA;QAC5C,YAAY,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;QAC9B,IAAI,SAAS,KAAK,CAAC;YAAE,OAAO,CAAC,CAAA;QAC7B,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,QAAQ,GAAG,SAAS,CAAC,GAAG,IAAI,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AO,EAAE,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,EAAE,UAAU,EAAE,CAAA;QAC5F,CAAC;IACH,CAAC;IAED,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,CAAA;AAC1C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/utils/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAA;AAI9B,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBhF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Performs the stream:register handshake on an already-created WebSocket.
|
|
2
|
+
// Caller is responsible for creating the WebSocket and storing it for cleanup before calling this.
|
|
3
|
+
export function registerStreamWs(ws, sessionId) {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
ws.once('open', () => {
|
|
6
|
+
ws.send(JSON.stringify({ type: 'stream:register', sessionId }));
|
|
7
|
+
});
|
|
8
|
+
const onMsg = (data) => {
|
|
9
|
+
const msg = JSON.parse(data.toString());
|
|
10
|
+
if (msg.type === 'stream:registered') {
|
|
11
|
+
ws.off('message', onMsg);
|
|
12
|
+
resolve();
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
ws.on('message', onMsg);
|
|
16
|
+
ws.once('error', reject);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/utils/stream.ts"],"names":[],"mappings":"AAEA,0EAA0E;AAC1E,mGAAmG;AACnG,MAAM,UAAU,gBAAgB,CAAC,EAAa,EAAE,SAAiB;IAC/D,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE;YACnB,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,SAAS,EAAE,CAAC,CAAC,CAAA;QACjE,CAAC,CAAC,CAAA;QAEF,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE;YAC7B,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;YACvC,IAAI,GAAG,CAAC,IAAI,KAAK,mBAAmB,EAAE,CAAC;gBACrC,EAAE,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;gBACxB,OAAO,EAAE,CAAA;YACX,CAAC;QACH,CAAC,CAAA;QACD,EAAE,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;QACvB,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IAC1B,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tapflowio/agent-core",
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "DeviceAgent interface, AgentRegistry, and shared utilities for tapflow agents",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"tapflow",
|
|
7
|
+
"ios",
|
|
8
|
+
"android",
|
|
9
|
+
"simulator",
|
|
10
|
+
"emulator",
|
|
11
|
+
"device-agent"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/jo-duchan/tapflow",
|
|
14
|
+
"bugs": "https://github.com/jo-duchan/tapflow/issues",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/jo-duchan/tapflow.git",
|
|
18
|
+
"directory": "packages/agent-core"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": "tapflow contributors",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"main": "dist/index.js",
|
|
24
|
+
"types": "dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"source": "./src/index.ts",
|
|
28
|
+
"tsx": "./src/index.ts",
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"default": "./dist/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./utils": {
|
|
33
|
+
"source": "./src/utils/index.ts",
|
|
34
|
+
"tsx": "./src/utils/index.ts",
|
|
35
|
+
"import": "./dist/utils/index.js",
|
|
36
|
+
"default": "./dist/utils/index.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist",
|
|
41
|
+
"README.md",
|
|
42
|
+
"LICENSE"
|
|
43
|
+
],
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=20"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"ws": "^8.0.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/node": "^20.0.0",
|
|
55
|
+
"@types/ws": "^8.0.0",
|
|
56
|
+
"typescript": "^5.0.0",
|
|
57
|
+
"vitest": "^2.0.0"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsc",
|
|
61
|
+
"typecheck": "tsc --noEmit",
|
|
62
|
+
"test": "vitest run",
|
|
63
|
+
"lint": "eslint src"
|
|
64
|
+
}
|
|
65
|
+
}
|