@meshad/sdk 0.0.0-stage → 0.2.0

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.
@@ -0,0 +1,61 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Terminal presentation for the SDK — a thin shell around the CLI's renderer.
5
+ *
6
+ * Drawing is the CLI's LineRenderer + Animator verbatim (vendored render.js):
7
+ * the ad lives on the bottom rows, fenced off from the host's output by a
8
+ * scroll region, and clear() erases exactly those rows in one synchronous
9
+ * write. The host's own output scrolls above it untouched.
10
+ *
11
+ * Added here: NO_COLOR (https://no-color.org). When set, every SGR sequence is
12
+ * stripped on the way out — the ad still renders, cursor-movement escapes
13
+ * still work, only colour and weight are gone.
14
+ */
15
+
16
+ const { LineRenderer, Animator, buildTimeline } = require('./render');
17
+
18
+ const SGR_RE = /\x1b\[[0-9;]*m/g;
19
+
20
+ /** A stream facade that drops SGR (colour) escapes but keeps everything else. */
21
+ function noColorStream(stream) {
22
+ return {
23
+ get isTTY() {
24
+ return stream.isTTY;
25
+ },
26
+ get columns() {
27
+ return stream.columns;
28
+ },
29
+ get rows() {
30
+ return stream.rows;
31
+ },
32
+ write(s) {
33
+ return stream.write(String(s).replace(SGR_RE, ''));
34
+ },
35
+ };
36
+ }
37
+
38
+ class TerminalAdRenderer {
39
+ constructor({ stream = process.stdout, env = process.env } = {}) {
40
+ this.stream = stream;
41
+ this.noColor = env.NO_COLOR !== undefined && env.NO_COLOR !== '';
42
+ this.renderer = new LineRenderer(this.noColor ? noColorStream(stream) : stream);
43
+ this.animator = new Animator(this.renderer);
44
+ this.visible = false;
45
+ }
46
+
47
+ /** Draw `ad`. Returns true only if something was actually drawn. */
48
+ show(ad) {
49
+ const timeline = buildTimeline(ad, this.stream.columns || 80, this.stream.rows || 24);
50
+ this.visible = this.animator.play(timeline);
51
+ return this.visible;
52
+ }
53
+
54
+ /** Stop any animation and erase the ad rows. Synchronous, idempotent. */
55
+ hide() {
56
+ this.animator.stop();
57
+ this.visible = false;
58
+ }
59
+ }
60
+
61
+ module.exports = { TerminalAdRenderer, noColorStream };
package/package.json CHANGED
@@ -1,6 +1,30 @@
1
1
  {
2
2
  "name": "@meshad/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Embeddable MeshAd SDK for AI agents and CLIs — show a signed ad only while the user is actually waiting, with the same privacy guarantees as the official client.",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "type": "commonjs",
8
+ "license": "Apache-2.0",
9
+ "files": [
10
+ "index.js",
11
+ "index.d.ts",
12
+ "lib",
13
+ "examples",
14
+ "README.md"
15
+ ],
16
+ "engines": {
17
+ "node": ">=22"
18
+ },
19
+ "scripts": {
20
+ "test": "node --test-force-exit --test test/*.test.js",
21
+ "typecheck": "tsc -p tsconfig.json"
22
+ },
23
+ "dependencies": {
24
+ "@meshad/creative": "file:../creative",
25
+ "@meshad/schema": "file:../schema"
26
+ },
27
+ "devDependencies": {
28
+ "typescript": "^5.6.3"
29
+ }
30
+ }