@sixb/app 0.1.1 → 0.1.2

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/README.md CHANGED
@@ -48,6 +48,24 @@ These routes are generated only when the project has at least one `app/` page, s
48
48
 
49
49
  The default agent UI is imported through `@sixb/app/agents`, so app projects do not need to import `@sixb/agent-ui` directly. A framework-owned `agent-ui.css` bundle is generated before the app stylesheet and imports normal `@sixb/ui` styles, which means app-level token overrides in `app/globals.css` still apply in the usual way.
50
50
 
51
+ Wrap the app layout with `AgentWorkspaceProvider` to make the built-in agent navigation match the
52
+ custom app shell without replacing any routes:
53
+
54
+ ```tsx
55
+ import { AgentWorkspaceProvider } from "@sixb/app/agents"
56
+
57
+ <AgentWorkspaceProvider
58
+ sidebarHeader={<AppSidebarHeader />}
59
+ sidebarFooter={<AppSidebarFooter />}
60
+ sidebarWidth="12.5rem"
61
+ >
62
+ <AppShell>{children}</AppShell>
63
+ </AgentWorkspaceProvider>
64
+ ```
65
+
66
+ Explicit props passed to a project-owned `AgentsPage` override provider defaults. The custom width
67
+ applies to the persistent desktop rail; the mobile sheet keeps its responsive width.
68
+
51
69
  ### Embedded Agent Panel
52
70
 
53
71
  Embed the same conversation runtime without changing the page route:
package/dist/agents.d.ts CHANGED
@@ -1,6 +1,11 @@
1
1
  import { type AgentChatPageProps } from "@sixb/agent-ui/react-router";
2
+ import { type PropsWithChildren } from "react";
2
3
  export { AgentContextProvider, AgentPanel, type AgentPanelProps, useAgentContext, } from "@sixb/agent-ui";
3
4
  export { agentContext } from "@sixb/core/agents/context";
4
5
  export type AgentsPageProps = Omit<AgentChatPageProps, "routeBase">;
5
- export default function AgentsPage({ className, ...props }: AgentsPageProps): import("react").FunctionComponentElement<AgentChatPageProps>;
6
+ type AgentWorkspaceChrome = Pick<AgentsPageProps, "sidebarHeader" | "sidebarFooter" | "sidebarWidth">;
7
+ export type AgentWorkspaceProviderProps = PropsWithChildren<AgentWorkspaceChrome>;
8
+ /** Configure the framework-owned Agents routes from a custom app's root layout. */
9
+ export declare function AgentWorkspaceProvider({ sidebarHeader, sidebarFooter, sidebarWidth, children, }: AgentWorkspaceProviderProps): import("react").FunctionComponentElement<import("react").ProviderProps<AgentWorkspaceChrome>>;
10
+ export default function AgentsPage(props: AgentsPageProps): import("react").FunctionComponentElement<AgentChatPageProps>;
6
11
  //# sourceMappingURL=agents.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../src/agents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAGpF,OAAO,EACL,oBAAoB,EACpB,UAAU,EACV,KAAK,eAAe,EACpB,eAAe,GAChB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAExD,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,kBAAkB,EAAE,WAAW,CAAC,CAAA;AAEnE,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,eAAe,gEAQ1E"}
1
+ {"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../src/agents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AACpF,OAAO,EAAgC,KAAK,iBAAiB,EAAc,MAAM,OAAO,CAAA;AAExF,OAAO,EACL,oBAAoB,EACpB,UAAU,EACV,KAAK,eAAe,EACpB,eAAe,GAChB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAExD,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,kBAAkB,EAAE,WAAW,CAAC,CAAA;AAEnE,KAAK,oBAAoB,GAAG,IAAI,CAC9B,eAAe,EACf,eAAe,GAAG,eAAe,GAAG,cAAc,CACnD,CAAA;AAED,MAAM,MAAM,2BAA2B,GAAG,iBAAiB,CAAC,oBAAoB,CAAC,CAAA;AAIjF,mFAAmF;AACnF,wBAAgB,sBAAsB,CAAC,EACrC,aAAa,EACb,aAAa,EACb,YAAY,EACZ,QAAQ,GACT,EAAE,2BAA2B,iGAM7B;AAED,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,KAAK,EAAE,eAAe,gEAQxD"}
package/dist/agents.js CHANGED
@@ -1,26 +1,37 @@
1
1
  // @bun
2
2
  // src/agents.ts
3
3
  import { AgentChatPage } from "@sixb/agent-ui/react-router";
4
- import { createElement } from "react";
4
+ import { createContext, createElement, useContext } from "react";
5
5
  import {
6
6
  AgentContextProvider,
7
7
  AgentPanel,
8
8
  useAgentContext
9
9
  } from "@sixb/agent-ui";
10
10
  import { agentContext } from "@sixb/core/agents/context";
11
- function AgentsPage({ className, ...props }) {
11
+ var AgentWorkspaceContext = createContext({});
12
+ function AgentWorkspaceProvider({
13
+ sidebarHeader,
14
+ sidebarFooter,
15
+ sidebarWidth,
16
+ children
17
+ }) {
18
+ return createElement(AgentWorkspaceContext.Provider, { value: { sidebarHeader, sidebarFooter, sidebarWidth } }, children);
19
+ }
20
+ function AgentsPage(props) {
21
+ const workspaceChrome = useContext(AgentWorkspaceContext);
12
22
  return createElement(AgentChatPage, {
23
+ ...workspaceChrome,
13
24
  ...props,
14
- routeBase: "/agents",
15
- className: className ? `h-dvh min-h-dvh max-h-dvh overflow-hidden ${className}` : "h-dvh min-h-dvh max-h-dvh overflow-hidden"
25
+ routeBase: "/agents"
16
26
  });
17
27
  }
18
28
  export {
19
29
  useAgentContext,
20
30
  AgentsPage as default,
21
31
  agentContext,
32
+ AgentWorkspaceProvider,
22
33
  AgentPanel,
23
34
  AgentContextProvider
24
35
  };
25
36
 
26
- //# debugId=AE7E5198DF11A9EE64756E2164756E21
37
+ //# debugId=FD2DDDBFD9CFF84864756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/agents.ts"],
4
4
  "sourcesContent": [
5
- "import { AgentChatPage, type AgentChatPageProps } from \"@sixb/agent-ui/react-router\"\nimport { createElement } from \"react\"\n\nexport {\n AgentContextProvider,\n AgentPanel,\n type AgentPanelProps,\n useAgentContext,\n} from \"@sixb/agent-ui\"\n\nexport { agentContext } from \"@sixb/core/agents/context\"\n\nexport type AgentsPageProps = Omit<AgentChatPageProps, \"routeBase\">\n\nexport default function AgentsPage({ className, ...props }: AgentsPageProps) {\n return createElement(AgentChatPage, {\n ...props,\n routeBase: \"/agents\",\n className: className\n ? `h-dvh min-h-dvh max-h-dvh overflow-hidden ${className}`\n : \"h-dvh min-h-dvh max-h-dvh overflow-hidden\",\n })\n}\n"
5
+ "import { AgentChatPage, type AgentChatPageProps } from \"@sixb/agent-ui/react-router\"\nimport { createContext, createElement, type PropsWithChildren, useContext } from \"react\"\n\nexport {\n AgentContextProvider,\n AgentPanel,\n type AgentPanelProps,\n useAgentContext,\n} from \"@sixb/agent-ui\"\n\nexport { agentContext } from \"@sixb/core/agents/context\"\n\nexport type AgentsPageProps = Omit<AgentChatPageProps, \"routeBase\">\n\ntype AgentWorkspaceChrome = Pick<\n AgentsPageProps,\n \"sidebarHeader\" | \"sidebarFooter\" | \"sidebarWidth\"\n>\n\nexport type AgentWorkspaceProviderProps = PropsWithChildren<AgentWorkspaceChrome>\n\nconst AgentWorkspaceContext = createContext<AgentWorkspaceChrome>({})\n\n/** Configure the framework-owned Agents routes from a custom app's root layout. */\nexport function AgentWorkspaceProvider({\n sidebarHeader,\n sidebarFooter,\n sidebarWidth,\n children,\n}: AgentWorkspaceProviderProps) {\n return createElement(\n AgentWorkspaceContext.Provider,\n { value: { sidebarHeader, sidebarFooter, sidebarWidth } },\n children\n )\n}\n\nexport default function AgentsPage(props: AgentsPageProps) {\n const workspaceChrome = useContext(AgentWorkspaceContext)\n\n return createElement(AgentChatPage, {\n ...workspaceChrome,\n ...props,\n routeBase: \"/agents\",\n })\n}\n"
6
6
  ],
7
- "mappings": ";;AAAA;AACA;AAEA;AAAA;AAAA;AAAA;AAAA;AAOA;AAIA,SAAwB,UAAU,GAAG,cAAc,SAA0B;AAAA,EAC3E,OAAO,cAAc,eAAe;AAAA,OAC/B;AAAA,IACH,WAAW;AAAA,IACX,WAAW,YACP,6CAA6C,cAC7C;AAAA,EACN,CAAC;AAAA;",
8
- "debugId": "AE7E5198DF11A9EE64756E2164756E21",
7
+ "mappings": ";;AAAA;AACA;AAEA;AAAA;AAAA;AAAA;AAAA;AAOA;AAWA,IAAM,wBAAwB,cAAoC,CAAC,CAAC;AAG7D,SAAS,sBAAsB;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAC8B;AAAA,EAC9B,OAAO,cACL,sBAAsB,UACtB,EAAE,OAAO,EAAE,eAAe,eAAe,aAAa,EAAE,GACxD,QACF;AAAA;AAGF,SAAwB,UAAU,CAAC,OAAwB;AAAA,EACzD,MAAM,kBAAkB,WAAW,qBAAqB;AAAA,EAExD,OAAO,cAAc,eAAe;AAAA,OAC/B;AAAA,OACA;AAAA,IACH,WAAW;AAAA,EACb,CAAC;AAAA;",
8
+ "debugId": "FD2DDDBFD9CFF84864756E2164756E21",
9
9
  "names": []
10
10
  }
package/dist/build.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export interface BuildAppOptions {
2
2
  /** Path to the generated index.html entry point */
3
3
  entryPath: string;
4
+ /** Browser TypeScript entry generated alongside `entryPath`. */
5
+ scriptEntryPath: string;
4
6
  /** Generated manifest copied to the stable `/app.webmanifest` output path. */
5
7
  manifestPath?: string;
6
8
  /** Output directory, defaults to `.sixb/dist/app` */
@@ -12,8 +14,7 @@ export interface BuildAppResult {
12
14
  logs?: string[];
13
15
  }
14
16
  /**
15
- * Builds the app using `Bun.build()` on the generated HTML entry point.
16
- * Outputs a production-ready static bundle.
17
+ * Builds the generated browser entry and writes a production-ready static shell and bundle.
17
18
  */
18
19
  export declare function buildApp(options: BuildAppOptions): Promise<BuildAppResult>;
19
20
  export declare function prepareAppHtmlBundleEntry(entryPath: string): Promise<string>;
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,eAAe;IAC9B,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAA;IACjB,8EAA8E;IAC9E,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;CAChB;AAED;;;GAGG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CA4ChF;AAKD,wBAAsB,yBAAyB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CASlF;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzD"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,eAAe;IAC9B,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAA;IACjB,gEAAgE;IAChE,eAAe,EAAE,MAAM,CAAA;IACvB,8EAA8E;IAC9E,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;CAChB;AAED;;GAEG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CA2EhF;AAKD,wBAAsB,yBAAyB,CAAC,SAAS,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AAM,CAAA;CAChB;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,mBAAmB,CAAA;IAC9B,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC,CAAA;IAClC,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;IAC7B,GAAG,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;IAC/D,KAAK,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;IAC/D,KAAK,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;CACpE;AAWD,wBAAsB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CA2WjG"}
package/dist/index.js CHANGED
@@ -2,33 +2,44 @@
2
2
  // src/createCustomApp.ts
3
3
  import { watch } from "fs";
4
4
  import { access as access2, cp, mkdir as mkdir4, readFile as readFile5, writeFile as writeFile3 } from "fs/promises";
5
- import { dirname as dirname3, isAbsolute, join as join7, normalize, relative as relative3, resolve as resolve2 } from "path";
5
+ import { dirname as dirname3, isAbsolute, join as join7, normalize, relative as relative3, resolve as resolve3 } from "path";
6
6
  import { pathToFileURL as pathToFileURL2 } from "url";
7
7
 
8
8
  // src/build.ts
9
- import { copyFile, mkdir, readFile, rename, rm, writeFile } from "fs/promises";
10
- import { basename, dirname, join } from "path";
9
+ import { existsSync } from "fs";
10
+ import { copyFile, mkdir, readFile, rm, writeFile } from "fs/promises";
11
+ import { basename, dirname, extname, join, resolve } from "path";
12
+ import { promisify } from "util";
13
+ import {
14
+ brotliCompress as brotliCompressCallback,
15
+ gzip as gzipCallback,
16
+ constants as zlibConstants
17
+ } from "zlib";
11
18
  var STATIC_ASSET_ORIGIN = "https://sixb-static.invalid";
19
+ var brotliCompress = promisify(brotliCompressCallback);
20
+ var gzip = promisify(gzipCallback);
21
+ var PRECOMPRESSION_CONCURRENCY = 4;
12
22
  async function buildApp(options) {
13
23
  const outdir = options.outdir ?? join(process.cwd(), ".sixb", "dist", "app");
14
24
  await rm(outdir, { recursive: true, force: true });
15
25
  await mkdir(outdir, { recursive: true });
16
- const bundleEntryPath = await prepareAppHtmlBundleEntry(options.entryPath);
17
- let result;
18
- try {
19
- result = await Bun.build({
20
- entrypoints: [bundleEntryPath],
21
- outdir,
22
- target: "browser",
23
- conditions: ["bun"],
24
- publicPath: "/",
25
- minify: true,
26
- define: { "process.env.NODE_ENV": '"production"' },
27
- sourcemap: "external"
28
- });
29
- } finally {
30
- await rm(bundleEntryPath, { force: true });
31
- }
26
+ const result = await Bun.build({
27
+ entrypoints: [options.scriptEntryPath],
28
+ outdir,
29
+ target: "browser",
30
+ conditions: ["bun"],
31
+ publicPath: "/",
32
+ minify: true,
33
+ splitting: true,
34
+ naming: {
35
+ entry: "app-[hash].[ext]",
36
+ chunk: "chunk-[name]-[hash].[ext]",
37
+ asset: "asset-[name]-[hash].[ext]"
38
+ },
39
+ plugins: [extensionlessSourceImportPlugin],
40
+ define: { "process.env.NODE_ENV": '"production"' },
41
+ sourcemap: "external"
42
+ });
32
43
  if (!result.success) {
33
44
  return {
34
45
  success: false,
@@ -36,12 +47,26 @@ async function buildApp(options) {
36
47
  logs: result.logs.map(String)
37
48
  };
38
49
  }
39
- const bundleHtmlPath = join(outdir, basename(bundleEntryPath));
40
- await rename(bundleHtmlPath, join(outdir, "index.html"));
41
- await rewriteIndexAssetPaths(outdir);
50
+ const script = result.outputs.find((output) => output.kind === "entry-point" && output.type.startsWith("text/javascript"));
51
+ const stylesheets = result.outputs.filter((output) => output.type.startsWith("text/css"));
52
+ if (!script || stylesheets.length > 1) {
53
+ throw new Error(`[SixbCustomApp] Expected one browser entry and at most one stylesheet, found ${script ? 1 : 0} entries and ${stylesheets.length} stylesheets.`);
54
+ }
55
+ const sourceHtml = restoreAppStaticUrls(await readFile(options.entryPath, "utf-8"));
56
+ const sourceEntryPattern = /\s*<script\s+type=["']module["']\s+src=["']\.\/main\.tsx["']><\/script>/;
57
+ if (!sourceEntryPattern.test(sourceHtml)) {
58
+ throw new Error("[SixbCustomApp] Generated app shell is missing its ./main.tsx entry.");
59
+ }
60
+ const assetTags = [
61
+ ...stylesheets.map((stylesheet) => `<link rel="stylesheet" crossorigin href="/${basename(stylesheet.path)}">`),
62
+ `<script type="module" crossorigin src="/${basename(script.path)}"></script>`
63
+ ].join("");
64
+ const html = withLoadingShell(sourceHtml).replace(sourceEntryPattern, "").replace("</head>", ` ${assetTags}</head>`);
65
+ await writeFile(join(outdir, "index.html"), html, "utf-8");
42
66
  if (options.manifestPath) {
43
67
  await copyFile(options.manifestPath, join(outdir, "app.webmanifest"));
44
68
  }
69
+ await precompressBuildAssets(result.outputs);
45
70
  return { success: true, outdir };
46
71
  }
47
72
  async function prepareAppHtmlBundleEntry(entryPath) {
@@ -54,22 +79,69 @@ async function prepareAppHtmlBundleEntry(entryPath) {
54
79
  function restoreAppStaticUrls(html) {
55
80
  return html.replaceAll(STATIC_ASSET_ORIGIN, "");
56
81
  }
57
- async function rewriteIndexAssetPaths(outdir) {
58
- const indexPath = join(outdir, "index.html");
59
- const originalHtml = await readFile(indexPath, "utf-8");
60
- const html = restoreAppStaticUrls(originalHtml);
61
- const rewritten = html.replace(/(href|src)=(["'])((?!\/|#|[a-zA-Z][a-zA-Z\d+.-]*:)(?:\.\/)?[^"'?#]+(?:[?#][^"']*)?)\2/g, (_match, attr, quote, url) => {
62
- const normalized = url.startsWith("./") ? url.slice(2) : url;
63
- return `${attr}=${quote}/${normalized}${quote}`;
64
- });
65
- if (rewritten !== originalHtml) {
66
- await writeFile(indexPath, rewritten, "utf-8");
82
+ function withLoadingShell(html) {
83
+ const styles = `<style data-sixb-loading-shell>
84
+ .sixb-loading-shell{position:fixed;inset:0;display:grid;place-items:center;background:#fff;color:#71717a}
85
+ .sixb-loading-spinner{width:1.25rem;height:1.25rem;border:2px solid currentColor;border-right-color:transparent;border-radius:9999px;animation:sixb-loading-spin .7s linear infinite}
86
+ @media(prefers-color-scheme:dark){.sixb-loading-shell{background:#09090b;color:#a1a1aa}}
87
+ @media(prefers-reduced-motion:reduce){.sixb-loading-spinner{animation-duration:1.5s}}
88
+ @keyframes sixb-loading-spin{to{transform:rotate(360deg)}}
89
+ </style>`;
90
+ const root = '<div id="root"><div class="sixb-loading-shell" role="status" aria-label="Loading application"><span class="sixb-loading-spinner" aria-hidden="true"></span></div></div>';
91
+ if (!html.includes('<div id="root"></div>') || !html.includes("</head>")) {
92
+ throw new Error("[SixbCustomApp] Generated app shell is missing its root or head element.");
93
+ }
94
+ return html.replace("</head>", `${styles}
95
+ </head>`).replace('<div id="root"></div>', root);
96
+ }
97
+ var extensionlessSourceImportPlugin = {
98
+ name: "sixb-extensionless-source-imports",
99
+ setup(build) {
100
+ build.onResolve({ filter: /^\.\.?\// }, (args) => {
101
+ if (extname(args.path))
102
+ return;
103
+ const base = resolve(dirname(args.importer), args.path);
104
+ for (const candidate of [
105
+ `${base}.ts`,
106
+ `${base}.tsx`,
107
+ `${base}.js`,
108
+ `${base}.jsx`,
109
+ join(base, "index.ts"),
110
+ join(base, "index.tsx"),
111
+ join(base, "index.js"),
112
+ join(base, "index.jsx")
113
+ ]) {
114
+ if (existsSync(candidate))
115
+ return { path: candidate };
116
+ }
117
+ return;
118
+ });
67
119
  }
120
+ };
121
+ async function precompressBuildAssets(outputs) {
122
+ const paths = outputs.filter((output) => output.type.startsWith("text/javascript") || output.type.startsWith("text/css")).map((output) => output.path);
123
+ let cursor = 0;
124
+ const worker = async () => {
125
+ while (cursor < paths.length) {
126
+ const path = paths[cursor++];
127
+ const bytes = await Bun.file(path).arrayBuffer();
128
+ const [brotli, gzipped] = await Promise.all([
129
+ brotliCompress(bytes, {
130
+ params: {
131
+ [zlibConstants.BROTLI_PARAM_QUALITY]: 5
132
+ }
133
+ }),
134
+ gzip(bytes, { level: 9 })
135
+ ]);
136
+ await Promise.all([writeFile(`${path}.br`, brotli), writeFile(`${path}.gz`, gzipped)]);
137
+ }
138
+ };
139
+ await Promise.all(Array.from({ length: Math.min(PRECOMPRESSION_CONCURRENCY, paths.length) }, worker));
68
140
  }
69
141
 
70
142
  // src/codegen.ts
71
143
  import { access, mkdir as mkdir2, readFile as readFile3, writeFile as writeFile2 } from "fs/promises";
72
- import { join as join3, relative, resolve } from "path";
144
+ import { join as join3, relative, resolve as resolve2 } from "path";
73
145
 
74
146
  // src/manifest.ts
75
147
  function renderAppManifest(metadata) {
@@ -92,7 +164,7 @@ function renderAppManifest(metadata) {
92
164
  import { createHash } from "crypto";
93
165
  import { readFile as readFile2, stat } from "fs/promises";
94
166
  import { createRequire } from "module";
95
- import { extname, join as join2 } from "path";
167
+ import { extname as extname2, join as join2 } from "path";
96
168
  import { pathToFileURL } from "url";
97
169
  var metadataRequire = createRequire(import.meta.url);
98
170
  var metadataFields = [
@@ -201,7 +273,7 @@ function inferImageMimeType(url) {
201
273
  try {
202
274
  pathname = new URL(url, "https://sixb.invalid").pathname;
203
275
  } catch {}
204
- switch (extname(pathname).toLowerCase()) {
276
+ switch (extname2(pathname).toLowerCase()) {
205
277
  case ".svg":
206
278
  return "image/svg+xml";
207
279
  case ".png":
@@ -269,8 +341,8 @@ ${routeEntries}
269
341
  }
270
342
  async function generateAppEntry(projectRoot, generatedDir, options = {}) {
271
343
  await mkdir2(generatedDir, { recursive: true });
272
- const appDir = options.appDir ? resolve(projectRoot, options.appDir) : join3(projectRoot, "app");
273
- const publicDir = options.publicDir ? resolve(projectRoot, options.publicDir) : join3(appDir, "public");
344
+ const appDir = options.appDir ? resolve2(projectRoot, options.appDir) : join3(projectRoot, "app");
345
+ const publicDir = options.publicDir ? resolve2(projectRoot, options.publicDir) : join3(appDir, "public");
274
346
  const globalsCssPath = join3(appDir, "globals.css");
275
347
  const layoutPath = join3(appDir, "layout.tsx");
276
348
  const metadata = await resolveAppMetadata({ layoutPath, publicDir });
@@ -824,8 +896,8 @@ function createTailwindCssCompiler(options) {
824
896
  activeProcess = proc;
825
897
  const stderr = new Response(proc.stderr).text().catch(() => "");
826
898
  let timeout;
827
- const timedOut = new Promise((resolve2) => {
828
- timeout = setTimeout(() => resolve2("timeout"), timeoutMs);
899
+ const timedOut = new Promise((resolve3) => {
900
+ timeout = setTimeout(() => resolve3("timeout"), timeoutMs);
829
901
  });
830
902
  try {
831
903
  const outcome = await Promise.race([proc.exited, timedOut]);
@@ -914,17 +986,17 @@ function usesTailwind(css) {
914
986
  }
915
987
 
916
988
  // src/createCustomApp.ts
917
- var packageRoot = resolve2(import.meta.dir, "..");
989
+ var packageRoot = resolve3(import.meta.dir, "..");
918
990
  var builtInAgentRouteModule = "@sixb/app/agents";
919
991
  var builtInAgentRoutePaths = ["/agents", "/agents/new/:agentId", "/agents/:threadId"];
920
992
  var builtInAgentRouteSourcePath = join7(packageRoot, "src", "agents.ts");
921
993
  var customAppManifestRoute = "/app.webmanifest";
922
994
  var internalAppShellRoute = "/__sixb/generated/app-shell";
923
995
  async function createCustomApp(options) {
924
- const rootDir = resolve2(options.rootDir);
925
- const appDir = options.appDir ? resolve2(rootDir, options.appDir) : resolve2(rootDir, "app");
926
- const generatedDir = resolve2(rootDir, options.generatedDir ?? join7(".sixb", "generated"));
927
- const publicDir = options.publicDir ? resolve2(rootDir, options.publicDir) : resolve2(appDir, "public");
996
+ const rootDir = resolve3(options.rootDir);
997
+ const appDir = options.appDir ? resolve3(rootDir, options.appDir) : resolve3(rootDir, "app");
998
+ const generatedDir = resolve3(rootDir, options.generatedDir ?? join7(".sixb", "generated"));
999
+ const publicDir = options.publicDir ? resolve3(rootDir, options.publicDir) : resolve3(appDir, "public");
928
1000
  const apiBaseUrl = options.apiBaseUrl;
929
1001
  const audience = options.audience ?? "app";
930
1002
  const authEnabled = options.authEnabled ?? true;
@@ -1028,7 +1100,7 @@ async function createCustomApp(options) {
1028
1100
  const builtInRoutes = agentRoutesEnabled ? builtInAgentRoutesFor(routes) : [];
1029
1101
  const stylesheets = await prepareStylesheets(builtInRoutes);
1030
1102
  await generateRouteManifest(routes, generatedDir, { builtInRoutes });
1031
- const { htmlPath, manifestPath } = await generateAppEntry(rootDir, generatedDir, {
1103
+ const { htmlPath, mainPath, manifestPath } = await generateAppEntry(rootDir, generatedDir, {
1032
1104
  apiBaseUrl,
1033
1105
  audience,
1034
1106
  authEnabled,
@@ -1037,7 +1109,7 @@ async function createCustomApp(options) {
1037
1109
  frameworkStylesheetPaths: stylesheets.frameworkStylesheetPaths,
1038
1110
  stylesheetPath: stylesheets.stylesheetPath
1039
1111
  });
1040
- return { htmlPath, manifestPath, routes };
1112
+ return { htmlPath, mainPath, manifestPath, routes };
1041
1113
  }
1042
1114
  return {
1043
1115
  async scanRoutes() {
@@ -1119,10 +1191,11 @@ async function createCustomApp(options) {
1119
1191
  };
1120
1192
  },
1121
1193
  async build(buildOptions = {}) {
1122
- const outdir = resolve2(rootDir, buildOptions.outdir ?? join7(".sixb", "dist", "app"));
1123
- const { htmlPath, manifestPath } = await prepareGeneratedApp();
1194
+ const outdir = resolve3(rootDir, buildOptions.outdir ?? join7(".sixb", "dist", "app"));
1195
+ const { htmlPath, mainPath, manifestPath } = await prepareGeneratedApp();
1124
1196
  const result = await buildApp({
1125
1197
  entryPath: htmlPath,
1198
+ scriptEntryPath: mainPath,
1126
1199
  manifestPath,
1127
1200
  outdir
1128
1201
  });
@@ -1130,7 +1203,7 @@ async function createCustomApp(options) {
1130
1203
  await cp(publicDir, outdir, {
1131
1204
  recursive: true,
1132
1205
  force: true,
1133
- filter: (source) => resolve2(source) !== join7(publicDir, "app.webmanifest")
1206
+ filter: (source) => resolve3(source) !== join7(publicDir, "app.webmanifest")
1134
1207
  });
1135
1208
  }
1136
1209
  return result;
@@ -1138,7 +1211,7 @@ async function createCustomApp(options) {
1138
1211
  async start(startOptions = {}) {
1139
1212
  const host = startOptions.host ?? "0.0.0.0";
1140
1213
  const port = startOptions.port ?? 3001;
1141
- const outdir = resolve2(rootDir, startOptions.outdir ?? join7(".sixb", "dist", "app"));
1214
+ const outdir = resolve3(rootDir, startOptions.outdir ?? join7(".sixb", "dist", "app"));
1142
1215
  const indexPath = join7(outdir, "index.html");
1143
1216
  if (!await pathExists(indexPath)) {
1144
1217
  throw new Error(`[SixbCustomApp] No built app found in ${outdir}`);
@@ -1169,7 +1242,7 @@ async function createCustomApp(options) {
1169
1242
  }
1170
1243
  const directFile = Bun.file(resolvedPath);
1171
1244
  if (await directFile.exists()) {
1172
- return fileResponse(req, directFile, staticAssetHeaders(url.pathname));
1245
+ return staticFileResponse(req, resolvedPath, staticAssetHeaders(url.pathname));
1173
1246
  }
1174
1247
  if (isAssetRequest(url.pathname)) {
1175
1248
  return notFoundResponse();
@@ -1316,7 +1389,7 @@ function resolveStaticPath(appRoot, pathname) {
1316
1389
  if (segments.includes(".."))
1317
1390
  return null;
1318
1391
  const normalizedPath = normalize(decodedPath).replace(/^[\\/]+/, "");
1319
- const resolvedPath = resolve2(appRoot, normalizedPath);
1392
+ const resolvedPath = resolve3(appRoot, normalizedPath);
1320
1393
  const rel = relative3(appRoot, resolvedPath);
1321
1394
  if (rel.startsWith("..") || isAbsolute(rel))
1322
1395
  return null;
@@ -1349,7 +1422,7 @@ function htmlResponse(request, html) {
1349
1422
  }
1350
1423
  });
1351
1424
  }
1352
- var IMMUTABLE_ASSET_PATTERN = /^chunk-[a-z0-9]+\.(js|css|js\.map|css\.map)$/;
1425
+ var IMMUTABLE_ASSET_PATTERN = /^(?:(?:app|chunk)-[a-z0-9]+|(?:chunk|asset)-.+-[a-z0-9]+)\.[a-z0-9]+(?:\.map)?$/;
1353
1426
  function staticAssetHeaders(pathname) {
1354
1427
  if (pathname === customAppManifestRoute) {
1355
1428
  return {
@@ -1363,6 +1436,54 @@ function staticAssetHeaders(pathname) {
1363
1436
  }
1364
1437
  return { "cache-control": "public, max-age=31536000, immutable" };
1365
1438
  }
1439
+ async function staticFileResponse(request, path, headers) {
1440
+ const responseHeaders = new Headers(headers);
1441
+ const originalFile = Bun.file(path);
1442
+ let responseFile = originalFile;
1443
+ if (isPrecompressedAsset(path)) {
1444
+ responseHeaders.append("vary", "Accept-Encoding");
1445
+ if (!request.headers.has("range")) {
1446
+ for (const encoding of acceptedPrecompressedEncodings(request)) {
1447
+ const candidate = Bun.file(`${path}.${encoding === "br" ? "br" : "gz"}`);
1448
+ if (!await candidate.exists())
1449
+ continue;
1450
+ responseFile = candidate;
1451
+ responseHeaders.set("content-encoding", encoding);
1452
+ responseHeaders.set("content-type", originalFile.type);
1453
+ break;
1454
+ }
1455
+ }
1456
+ }
1457
+ return new Response(request.method === "HEAD" ? null : responseFile, {
1458
+ headers: responseHeaders
1459
+ });
1460
+ }
1461
+ function isPrecompressedAsset(path) {
1462
+ return path.endsWith(".js") || path.endsWith(".css");
1463
+ }
1464
+ function acceptedPrecompressedEncodings(request) {
1465
+ const header = request.headers.get("accept-encoding");
1466
+ if (!header)
1467
+ return [];
1468
+ const qualities = new Map;
1469
+ for (const item of header.split(",")) {
1470
+ const [rawName, ...parameters] = item.trim().split(";");
1471
+ const name = rawName.toLowerCase();
1472
+ let quality = 1;
1473
+ for (const parameter of parameters) {
1474
+ const match = parameter.trim().match(/^q=(0(?:\.\d+)?|1(?:\.0+)?)$/);
1475
+ if (match)
1476
+ quality = Number(match[1]);
1477
+ }
1478
+ qualities.set(name, quality);
1479
+ }
1480
+ const wildcard = qualities.get("*") ?? 0;
1481
+ return ["br", "gzip"].map((encoding, preference) => ({
1482
+ encoding,
1483
+ preference,
1484
+ quality: qualities.get(encoding) ?? wildcard
1485
+ })).filter((candidate) => candidate.quality > 0).sort((left, right) => right.quality - left.quality || left.preference - right.preference).map((candidate) => candidate.encoding);
1486
+ }
1366
1487
  function fileResponse(request, file, headers = {}) {
1367
1488
  return new Response(request.method === "HEAD" ? null : file, { headers });
1368
1489
  }
@@ -1461,4 +1582,4 @@ export {
1461
1582
  createCustomApp
1462
1583
  };
1463
1584
 
1464
- //# debugId=EF77EB82048A32D864756E2164756E21
1585
+ //# debugId=E6B6484555ADAD4D64756E2164756E21