@alexkroman1/aai 0.8.0 → 0.8.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/dist/cli.js
CHANGED
|
@@ -557,204 +557,6 @@ var init_ink = __esm({
|
|
|
557
557
|
}
|
|
558
558
|
});
|
|
559
559
|
|
|
560
|
-
// ui/_dom_shim.ts
|
|
561
|
-
import { DOMParser } from "linkedom";
|
|
562
|
-
function installDomShim() {
|
|
563
|
-
if (installed) return;
|
|
564
|
-
installed = true;
|
|
565
|
-
const doc = new DOMParser().parseFromString(
|
|
566
|
-
"<!DOCTYPE html><html><head></head><body></body></html>",
|
|
567
|
-
"text/html"
|
|
568
|
-
);
|
|
569
|
-
const g2 = globalThis;
|
|
570
|
-
g2.document = doc;
|
|
571
|
-
g2.HTMLElement = doc.documentElement.constructor;
|
|
572
|
-
if (!Object.getOwnPropertyDescriptor(
|
|
573
|
-
g2.HTMLElement.prototype,
|
|
574
|
-
"scrollIntoView"
|
|
575
|
-
)) {
|
|
576
|
-
g2.HTMLElement.prototype.scrollIntoView = () => {
|
|
577
|
-
};
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
var installed;
|
|
581
|
-
var init_dom_shim = __esm({
|
|
582
|
-
"ui/_dom_shim.ts"() {
|
|
583
|
-
"use strict";
|
|
584
|
-
installed = false;
|
|
585
|
-
}
|
|
586
|
-
});
|
|
587
|
-
|
|
588
|
-
// sdk/_mock_ws.ts
|
|
589
|
-
function installMockWebSocket() {
|
|
590
|
-
const saved = globalThis.WebSocket;
|
|
591
|
-
const created = [];
|
|
592
|
-
g.WebSocket = class extends MockWebSocket {
|
|
593
|
-
constructor(url, protocols) {
|
|
594
|
-
super(url, protocols);
|
|
595
|
-
created.push(this);
|
|
596
|
-
}
|
|
597
|
-
};
|
|
598
|
-
return {
|
|
599
|
-
created,
|
|
600
|
-
get lastWs() {
|
|
601
|
-
return created.at(-1) ?? null;
|
|
602
|
-
},
|
|
603
|
-
restore() {
|
|
604
|
-
globalThis.WebSocket = saved;
|
|
605
|
-
},
|
|
606
|
-
[Symbol.dispose]() {
|
|
607
|
-
globalThis.WebSocket = saved;
|
|
608
|
-
}
|
|
609
|
-
};
|
|
610
|
-
}
|
|
611
|
-
var MockWebSocket, g;
|
|
612
|
-
var init_mock_ws = __esm({
|
|
613
|
-
"sdk/_mock_ws.ts"() {
|
|
614
|
-
"use strict";
|
|
615
|
-
MockWebSocket = class _MockWebSocket extends EventTarget {
|
|
616
|
-
// mirrors the WebSocket API
|
|
617
|
-
static CONNECTING = 0;
|
|
618
|
-
// mirrors the WebSocket API
|
|
619
|
-
static OPEN = 1;
|
|
620
|
-
// mirrors the WebSocket API
|
|
621
|
-
static CLOSING = 2;
|
|
622
|
-
// mirrors the WebSocket API
|
|
623
|
-
static CLOSED = 3;
|
|
624
|
-
readyState = _MockWebSocket.CONNECTING;
|
|
625
|
-
binaryType = "arraybuffer";
|
|
626
|
-
/** All messages passed to {@linkcode send}, in order. */
|
|
627
|
-
sent = [];
|
|
628
|
-
url;
|
|
629
|
-
/**
|
|
630
|
-
* Create a new MockWebSocket.
|
|
631
|
-
*
|
|
632
|
-
* Automatically transitions to `OPEN` state on the next microtask,
|
|
633
|
-
* dispatching an `"open"` event.
|
|
634
|
-
*
|
|
635
|
-
* @param url - The WebSocket URL.
|
|
636
|
-
* @param _protocols - Ignored; accepted for API compatibility.
|
|
637
|
-
*/
|
|
638
|
-
constructor(url, _protocols) {
|
|
639
|
-
super();
|
|
640
|
-
this.url = typeof url === "string" ? url : url.toString();
|
|
641
|
-
queueMicrotask(() => {
|
|
642
|
-
if (this.readyState === _MockWebSocket.CONNECTING) {
|
|
643
|
-
this.readyState = _MockWebSocket.OPEN;
|
|
644
|
-
this.dispatchEvent(new Event("open"));
|
|
645
|
-
}
|
|
646
|
-
});
|
|
647
|
-
}
|
|
648
|
-
/**
|
|
649
|
-
* Record a sent message without transmitting it.
|
|
650
|
-
*
|
|
651
|
-
* @param data - The message data to record.
|
|
652
|
-
*/
|
|
653
|
-
send(data) {
|
|
654
|
-
this.sent.push(data);
|
|
655
|
-
}
|
|
656
|
-
/**
|
|
657
|
-
* Transition to `CLOSED` state and dispatch a `"close"` event.
|
|
658
|
-
*
|
|
659
|
-
* @param code - The close code (defaults to 1000).
|
|
660
|
-
* @param _reason - Ignored; accepted for API compatibility.
|
|
661
|
-
*/
|
|
662
|
-
close(code, _reason) {
|
|
663
|
-
this.readyState = _MockWebSocket.CLOSED;
|
|
664
|
-
this.dispatchEvent(new CloseEvent("close", { code: code ?? 1e3 }));
|
|
665
|
-
}
|
|
666
|
-
/**
|
|
667
|
-
* Simulate receiving a message from the server.
|
|
668
|
-
*
|
|
669
|
-
* @param data - The message data (string or binary).
|
|
670
|
-
*/
|
|
671
|
-
simulateMessage(data) {
|
|
672
|
-
this.dispatchEvent(new MessageEvent("message", { data }));
|
|
673
|
-
}
|
|
674
|
-
/** Transition to `OPEN` state and dispatch an `"open"` event. */
|
|
675
|
-
open() {
|
|
676
|
-
this.readyState = _MockWebSocket.OPEN;
|
|
677
|
-
this.dispatchEvent(new Event("open"));
|
|
678
|
-
}
|
|
679
|
-
/**
|
|
680
|
-
* Shorthand for {@linkcode simulateMessage}.
|
|
681
|
-
*
|
|
682
|
-
* @param data - The message data to dispatch.
|
|
683
|
-
*/
|
|
684
|
-
msg(data) {
|
|
685
|
-
this.dispatchEvent(new MessageEvent("message", { data }));
|
|
686
|
-
}
|
|
687
|
-
/**
|
|
688
|
-
* Simulate a connection close from the server.
|
|
689
|
-
*
|
|
690
|
-
* @param code - The close code (defaults to 1000).
|
|
691
|
-
*/
|
|
692
|
-
disconnect(code = 1e3) {
|
|
693
|
-
this.dispatchEvent(new CloseEvent("close", { code }));
|
|
694
|
-
}
|
|
695
|
-
/** Dispatch an `"error"` event on this socket. */
|
|
696
|
-
error() {
|
|
697
|
-
this.dispatchEvent(new Event("error"));
|
|
698
|
-
}
|
|
699
|
-
/**
|
|
700
|
-
* Return all sent string messages parsed as JSON objects.
|
|
701
|
-
*
|
|
702
|
-
* Binary messages are filtered out.
|
|
703
|
-
*
|
|
704
|
-
* @returns An array of parsed JSON objects from sent string messages.
|
|
705
|
-
*/
|
|
706
|
-
sentJson() {
|
|
707
|
-
return this.sent.filter((d) => typeof d === "string").map((s) => JSON.parse(s));
|
|
708
|
-
}
|
|
709
|
-
};
|
|
710
|
-
g = globalThis;
|
|
711
|
-
}
|
|
712
|
-
});
|
|
713
|
-
|
|
714
|
-
// sdk/_render_check.ts
|
|
715
|
-
var render_check_exports = {};
|
|
716
|
-
__export(render_check_exports, {
|
|
717
|
-
renderCheck: () => renderCheck
|
|
718
|
-
});
|
|
719
|
-
import { createServer as createViteServer } from "vite";
|
|
720
|
-
async function renderCheck(clientEntry, cwd) {
|
|
721
|
-
installDomShim();
|
|
722
|
-
const g2 = globalThis;
|
|
723
|
-
const doc = new DOMParser().parseFromString(
|
|
724
|
-
'<!DOCTYPE html><html><head></head><body><main id="app"></main></body></html>',
|
|
725
|
-
"text/html"
|
|
726
|
-
);
|
|
727
|
-
const prevDoc = g2.document;
|
|
728
|
-
const prevLocation = g2.location;
|
|
729
|
-
g2.document = doc;
|
|
730
|
-
g2.location = { origin: "http://localhost:3000", pathname: "/", href: "http://localhost:3000/" };
|
|
731
|
-
const mock = installMockWebSocket();
|
|
732
|
-
const vite = await createViteServer({
|
|
733
|
-
root: cwd,
|
|
734
|
-
logLevel: "silent",
|
|
735
|
-
server: { middlewareMode: true }
|
|
736
|
-
});
|
|
737
|
-
try {
|
|
738
|
-
await vite.ssrLoadModule(clientEntry);
|
|
739
|
-
const app = doc.querySelector("#app");
|
|
740
|
-
if (!app?.innerHTML) {
|
|
741
|
-
throw new Error("client.tsx render check failed: #app is empty after mount()");
|
|
742
|
-
}
|
|
743
|
-
} finally {
|
|
744
|
-
await vite.close();
|
|
745
|
-
mock.restore();
|
|
746
|
-
g2.document = prevDoc;
|
|
747
|
-
g2.location = prevLocation;
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
var init_render_check = __esm({
|
|
751
|
-
"sdk/_render_check.ts"() {
|
|
752
|
-
"use strict";
|
|
753
|
-
init_dom_shim();
|
|
754
|
-
init_mock_ws();
|
|
755
|
-
}
|
|
756
|
-
});
|
|
757
|
-
|
|
758
560
|
// cli/_build.ts
|
|
759
561
|
import React2 from "react";
|
|
760
562
|
async function buildAgentBundle(cwd, log) {
|
|
@@ -776,12 +578,18 @@ async function buildAgentBundle(cwd, log) {
|
|
|
776
578
|
const clientCount = Object.keys(bundle.clientFiles).length;
|
|
777
579
|
log(React2.createElement(Info, { msg: `worker: ${kb} KB, client: ${clientCount} file(s)` }));
|
|
778
580
|
if (agent.clientEntry) {
|
|
779
|
-
log(React2.createElement(Step, { action: "Render", msg: "check" }));
|
|
780
581
|
try {
|
|
781
|
-
const
|
|
782
|
-
await
|
|
582
|
+
const renderCheckPath = "../sdk/_render_check.ts";
|
|
583
|
+
const { renderCheck } = await import(
|
|
584
|
+
/* @vite-ignore */
|
|
585
|
+
renderCheckPath
|
|
586
|
+
);
|
|
587
|
+
log(React2.createElement(Step, { action: "Render", msg: "check" }));
|
|
588
|
+
await renderCheck(agent.clientEntry, cwd);
|
|
783
589
|
} catch (err) {
|
|
784
|
-
|
|
590
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
591
|
+
if (msg.includes("linkedom") || msg.includes("_render_check")) return bundle;
|
|
592
|
+
throw new Error(`Render check failed: ${msg}`);
|
|
785
593
|
}
|
|
786
594
|
}
|
|
787
595
|
return bundle;
|
|
@@ -2966,10 +2774,10 @@ import React3 from "react";
|
|
|
2966
2774
|
init_discover();
|
|
2967
2775
|
import fs5 from "node:fs/promises";
|
|
2968
2776
|
import path7 from "node:path";
|
|
2969
|
-
import { createServer as
|
|
2777
|
+
import { createServer as createViteServer } from "vite";
|
|
2970
2778
|
async function loadAgentDef(cwd) {
|
|
2971
2779
|
const agentPath = path7.resolve(cwd, "agent.ts");
|
|
2972
|
-
const vite = await
|
|
2780
|
+
const vite = await createViteServer({
|
|
2973
2781
|
root: cwd,
|
|
2974
2782
|
logLevel: "silent",
|
|
2975
2783
|
server: { middlewareMode: true }
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
* Smoke-test a client.tsx by loading it via Vite SSR in a DOM-shimmed
|
|
3
3
|
* environment. The module's top-level `mount()` call executes as a side
|
|
4
4
|
* effect; if it throws, the client code has a render-time bug.
|
|
5
|
+
*
|
|
6
|
+
* Imports linkedom dynamically so this module can be loaded even when
|
|
7
|
+
* linkedom is not installed (the caller catches and skips).
|
|
5
8
|
*/
|
|
6
9
|
export declare function renderCheck(clientEntry: string, cwd: string): Promise<void>;
|
|
7
10
|
//# sourceMappingURL=_render_check.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_render_check.d.ts","sourceRoot":"","sources":["../../sdk/_render_check.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"_render_check.d.ts","sourceRoot":"","sources":["../../sdk/_render_check.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAoCjF"}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
// Copyright 2025 the AAI authors. MIT license.
|
|
2
2
|
import { createServer as createViteServer } from "vite";
|
|
3
|
-
import { DOMParser, installDomShim } from "../ui/_dom_shim.js";
|
|
4
|
-
import { installMockWebSocket } from "./_mock_ws.js";
|
|
5
3
|
/**
|
|
6
4
|
* Smoke-test a client.tsx by loading it via Vite SSR in a DOM-shimmed
|
|
7
5
|
* environment. The module's top-level `mount()` call executes as a side
|
|
8
6
|
* effect; if it throws, the client code has a render-time bug.
|
|
7
|
+
*
|
|
8
|
+
* Imports linkedom dynamically so this module can be loaded even when
|
|
9
|
+
* linkedom is not installed (the caller catches and skips).
|
|
9
10
|
*/
|
|
10
11
|
export async function renderCheck(clientEntry, cwd) {
|
|
12
|
+
// Dynamic imports so esbuild doesn't bundle linkedom into the CLI dist.
|
|
13
|
+
const { DOMParser, installDomShim } = await import("../ui/_dom_shim.js");
|
|
14
|
+
const { installMockWebSocket } = await import("./_mock_ws.js");
|
|
11
15
|
installDomShim();
|
|
12
16
|
const g = globalThis;
|
|
13
17
|
const doc = new DOMParser().parseFromString('<!DOCTYPE html><html><head></head><body><main id="app"></main></body></html>', "text/html");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_render_check.js","sourceRoot":"","sources":["../../sdk/_render_check.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAE/C,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"_render_check.js","sourceRoot":"","sources":["../../sdk/_render_check.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAE/C,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,MAAM,CAAC;AAExD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,WAAmB,EAAE,GAAW;IAChE,wEAAwE;IACxE,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC,CAAC;IACzE,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,CAAC;IAE/D,cAAc,EAAE,CAAC;IAEjB,MAAM,CAAC,GAAG,UAAgD,CAAC;IAC3D,MAAM,GAAG,GAAG,IAAI,SAAS,EAAE,CAAC,eAAe,CACzC,8EAA8E,EAC9E,WAAW,CACZ,CAAC;IACF,MAAM,OAAO,GAAG,CAAC,CAAC,QAAQ,CAAC;IAC3B,MAAM,YAAY,GAAG,CAAC,CAAC,QAAQ,CAAC;IAChC,CAAC,CAAC,QAAQ,GAAG,GAAG,CAAC;IACjB,CAAC,CAAC,QAAQ,GAAG,EAAE,MAAM,EAAE,uBAAuB,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,wBAAwB,EAAE,CAAC;IAEhG,MAAM,IAAI,GAAG,oBAAoB,EAAE,CAAC;IACpC,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC;QAClC,IAAI,EAAE,GAAG;QACT,QAAQ,EAAE,QAAQ;QAClB,MAAM,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE;KACjC,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,MAAM,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;QACtC,MAAM,GAAG,GAAI,GAA2B,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC/D,IAAI,CAAC,GAAG,EAAE,SAAS,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;QACjF,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QACnB,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,CAAC,CAAC,QAAQ,GAAG,OAAO,CAAC;QACrB,CAAC,CAAC,QAAQ,GAAG,YAAY,CAAC;IAC5B,CAAC;AACH,CAAC"}
|