repoburg 1.3.237 → 1.3.239

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.
@@ -76,7 +76,7 @@ var require_queue = __commonJS({
76
76
  if (!(_concurrency >= 1)) {
77
77
  throw new Error("fastqueue concurrency must be equal to or greater than 1");
78
78
  }
79
- var cache2 = reusify(Task);
79
+ var cache3 = reusify(Task);
80
80
  var queueHead = null;
81
81
  var queueTail = null;
82
82
  var _running = 0;
@@ -155,7 +155,7 @@ var require_queue = __commonJS({
155
155
  return _running === 0 && self.length() === 0;
156
156
  }
157
157
  function push(value, done) {
158
- var current = cache2.get();
158
+ var current = cache3.get();
159
159
  current.context = context;
160
160
  current.release = release;
161
161
  current.value = value;
@@ -176,7 +176,7 @@ var require_queue = __commonJS({
176
176
  }
177
177
  }
178
178
  function unshift(value, done) {
179
- var current = cache2.get();
179
+ var current = cache3.get();
180
180
  current.context = context;
181
181
  current.release = release;
182
182
  current.value = value;
@@ -198,7 +198,7 @@ var require_queue = __commonJS({
198
198
  }
199
199
  function release(holder) {
200
200
  if (holder) {
201
- cache2.release(holder);
201
+ cache3.release(holder);
202
202
  }
203
203
  var next = queueHead;
204
204
  if (next && _running <= _concurrency) {
@@ -3985,7 +3985,7 @@ var require_content_type = __commonJS({
3985
3985
  var quotedPairReg = /\\([\t\u0020-\u00ff])/gu;
3986
3986
  var typeNameReg = /^[\w!#$%&'*+.^`|~-]+$/;
3987
3987
  var subtypeNameReg = /^[\w!#$%&'*+.^`|~-]+\s*$/;
3988
- var cache2 = new Lru(100);
3988
+ var cache3 = new Lru(100);
3989
3989
  var ContentType = class _ContentType {
3990
3990
  #valid = false;
3991
3991
  #empty = true;
@@ -3999,7 +3999,7 @@ var require_content_type = __commonJS({
3999
3999
  * @type {Lru<ContentType>}
4000
4000
  */
4001
4001
  static get cache() {
4002
- return cache2;
4002
+ return cache3;
4003
4003
  }
4004
4004
  /**
4005
4005
  * Create a ContentType instance from a header value. If the value has been
@@ -4008,10 +4008,10 @@ var require_content_type = __commonJS({
4008
4008
  * @returns {ContentType | undefined}
4009
4009
  */
4010
4010
  static from(headerValue) {
4011
- let contentType = cache2.get(headerValue);
4011
+ let contentType = cache3.get(headerValue);
4012
4012
  if (contentType !== void 0) return contentType;
4013
4013
  contentType = new _ContentType(headerValue);
4014
- cache2.set(headerValue, contentType);
4014
+ cache3.set(headerValue, contentType);
4015
4015
  return contentType;
4016
4016
  }
4017
4017
  constructor(headerValue) {
@@ -8982,12 +8982,12 @@ var require_levels = __commonJS({
8982
8982
  function genLsCache(instance2) {
8983
8983
  const formatter = instance2[formattersSym].level;
8984
8984
  const { labels } = instance2.levels;
8985
- const cache2 = {};
8985
+ const cache3 = {};
8986
8986
  for (const label in labels) {
8987
8987
  const level = formatter(labels[label], Number(label));
8988
- cache2[label] = JSON.stringify(level).slice(0, -1);
8988
+ cache3[label] = JSON.stringify(level).slice(0, -1);
8989
8989
  }
8990
- instance2[lsCacheSym] = cache2;
8990
+ instance2[lsCacheSym] = cache3;
8991
8991
  return instance2;
8992
8992
  }
8993
8993
  function isStandardLevel(level, useOnlyCustomLevels) {
@@ -15405,8 +15405,8 @@ var require_dataType = __commonJS({
15405
15405
  return types;
15406
15406
  }
15407
15407
  exports.getSchemaTypes = getSchemaTypes;
15408
- function getJSONTypes(ts) {
15409
- const types = Array.isArray(ts) ? ts : ts ? [ts] : [];
15408
+ function getJSONTypes(ts2) {
15409
+ const types = Array.isArray(ts2) ? ts2 : ts2 ? [ts2] : [];
15410
15410
  if (types.every(rules_1.isJSONType))
15411
15411
  return types;
15412
15412
  throw new Error("type must be JSONType or JSONType[]: " + types.join(","));
@@ -16448,18 +16448,18 @@ var require_validate = __commonJS({
16448
16448
  });
16449
16449
  narrowSchemaTypes(it, types);
16450
16450
  }
16451
- function checkMultipleTypes(it, ts) {
16452
- if (ts.length > 1 && !(ts.length === 2 && ts.includes("null"))) {
16451
+ function checkMultipleTypes(it, ts2) {
16452
+ if (ts2.length > 1 && !(ts2.length === 2 && ts2.includes("null"))) {
16453
16453
  strictTypesError(it, "use allowUnionTypes to allow union type keyword");
16454
16454
  }
16455
16455
  }
16456
- function checkKeywordTypes(it, ts) {
16456
+ function checkKeywordTypes(it, ts2) {
16457
16457
  const rules = it.self.RULES.all;
16458
16458
  for (const keyword in rules) {
16459
16459
  const rule = rules[keyword];
16460
16460
  if (typeof rule == "object" && (0, applicability_1.shouldUseRule)(it.schema, rule)) {
16461
16461
  const { type } = rule.definition;
16462
- if (type.length && !type.some((t) => hasApplicableType(ts, t))) {
16462
+ if (type.length && !type.some((t) => hasApplicableType(ts2, t))) {
16463
16463
  strictTypesError(it, `missing type "${type.join(",")}" for keyword "${keyword}"`);
16464
16464
  }
16465
16465
  }
@@ -16468,18 +16468,18 @@ var require_validate = __commonJS({
16468
16468
  function hasApplicableType(schTs, kwdT) {
16469
16469
  return schTs.includes(kwdT) || kwdT === "number" && schTs.includes("integer");
16470
16470
  }
16471
- function includesType(ts, t) {
16472
- return ts.includes(t) || t === "integer" && ts.includes("number");
16471
+ function includesType(ts2, t) {
16472
+ return ts2.includes(t) || t === "integer" && ts2.includes("number");
16473
16473
  }
16474
16474
  function narrowSchemaTypes(it, withTypes) {
16475
- const ts = [];
16475
+ const ts2 = [];
16476
16476
  for (const t of it.dataTypes) {
16477
16477
  if (includesType(withTypes, t))
16478
- ts.push(t);
16478
+ ts2.push(t);
16479
16479
  else if (withTypes.includes("integer") && t === "number")
16480
- ts.push("integer");
16480
+ ts2.push("integer");
16481
16481
  }
16482
- it.dataTypes = ts;
16482
+ it.dataTypes = ts2;
16483
16483
  }
16484
16484
  function strictTypesError(it, msg) {
16485
16485
  const schemaPath = it.schemaEnv.baseId + it.errSchemaPath;
@@ -28885,7 +28885,7 @@ var require_range = __commonJS({
28885
28885
  range = range.replace(BUILDSTRIPRE, "");
28886
28886
  const memoOpts = (this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) | (this.options.loose && FLAG_LOOSE);
28887
28887
  const memoKey = memoOpts + ":" + range;
28888
- const cached = cache2.get(memoKey);
28888
+ const cached = cache3.get(memoKey);
28889
28889
  if (cached) {
28890
28890
  return cached;
28891
28891
  }
@@ -28919,7 +28919,7 @@ var require_range = __commonJS({
28919
28919
  rangeMap.delete("");
28920
28920
  }
28921
28921
  const result = [...rangeMap.values()];
28922
- cache2.set(memoKey, result);
28922
+ cache3.set(memoKey, result);
28923
28923
  return result;
28924
28924
  }
28925
28925
  intersects(range, options) {
@@ -28958,7 +28958,7 @@ var require_range = __commonJS({
28958
28958
  };
28959
28959
  module.exports = Range;
28960
28960
  var LRU = require_lrucache();
28961
- var cache2 = new LRU();
28961
+ var cache3 = new LRU();
28962
28962
  var parseOptions = require_parse_options();
28963
28963
  var Comparator = require_comparator();
28964
28964
  var debug = require_debug2();
@@ -29908,12 +29908,12 @@ var require_plugin_utils = __commonJS({
29908
29908
  if (display) {
29909
29909
  return display;
29910
29910
  }
29911
- const cache2 = __require.cache;
29912
- if (cache2) {
29913
- const keys = Object.keys(cache2);
29911
+ const cache3 = __require.cache;
29912
+ if (cache3) {
29913
+ const keys = Object.keys(cache3);
29914
29914
  for (let i = 0; i < keys.length; i++) {
29915
29915
  const key = keys[i];
29916
- if (cache2[key].exports === func) {
29916
+ if (cache3[key].exports === func) {
29917
29917
  return key;
29918
29918
  }
29919
29919
  }
@@ -43573,7 +43573,15 @@ Each subdirectory of this folder is one mini app:
43573
43573
  manifest.json - { "title": string, "description"?: string, "icon"?: string,
43574
43574
  "tools"?: [{ "name", "description", "inputSchema" }] }
43575
43575
  index.html - markup only (full HTML document); do NOT reference app.js
43576
- app.js - app logic; injected automatically into the page
43576
+ app.ts - app logic (TypeScript, PREFERRED); injected automatically
43577
+ into the page as compiled JS
43578
+ app.js - legacy plain-JS logic; used only when app.ts is absent
43579
+
43580
+ The pane compiles app.ts on every change (strict mode, lib dom). Compile and
43581
+ type errors are shown in the app tab \u2014 check them after every edit and fix
43582
+ them before finishing. window.AgentPane is typed via ambient declarations
43583
+ (getState/setState/createSession/submitTurn/onToolCall/...); no import
43584
+ needed.
43577
43585
 
43578
43586
  App state does NOT live in this folder \u2014 it is stored in the pane database
43579
43587
  (app_instances table) and reached with getState()/setState().
@@ -43598,8 +43606,9 @@ viewer; it refreshes via AgentPane.onStateChanged(cb).
43598
43606
  Headless contract for apps that declare tools:
43599
43607
  - register AgentPane.onToolCall(handler) synchronously at startup
43600
43608
  - tool handlers must not depend on the DOM or the live UI
43601
- - headless state is the GLOBAL instance (workspace ''), shared with the
43602
- open tab via onStateChanged
43609
+ - headless state is the instance of the CALLING session's workspace
43610
+ ('' = global when the caller has no known workspace); open tabs
43611
+ sync via onStateChanged
43603
43612
  - createSession/submitTurn are not available in the headless runtime
43604
43613
 
43605
43614
  If the app cannot load headless (broken app.js, no handler), the pane
@@ -43736,7 +43745,126 @@ function deleteAppInstances(appId) {
43736
43745
  import fs3 from "node:fs";
43737
43746
 
43738
43747
  // src/apps/headless-runtime.ts
43748
+ import vm2 from "node:vm";
43749
+
43750
+ // src/apps/app-compile.ts
43739
43751
  import vm from "node:vm";
43752
+ import ts from "typescript";
43753
+ var APP_TS = "app.ts";
43754
+ var BRIDGE_DTS_FILE = "agentpane.d.ts";
43755
+ var BRIDGE_DTS = `/** AgentPane bridge \u2014 typed contract for mini apps (ambient, no import). */
43756
+ interface AgentPaneAppInfo { id: string; title?: string }
43757
+ interface AgentPaneState { pinned: boolean; data: Record<string, unknown> | null }
43758
+ interface AgentPaneSessionInfo { id: string; title?: string | null }
43759
+ interface AgentPaneCreateSessionOptions { title?: string; runtime_type?: string; model?: string; cwd?: string }
43760
+ interface AgentPaneTurnPayload { turnId?: string; response?: string | null; error?: string }
43761
+ interface AgentPaneDeltaPayload { sessionId?: string; turnId?: string; itemId?: string; delta?: string }
43762
+ interface AgentPaneToolCallPayload { callId: string; tool: string; name: string; args: Record<string, unknown> }
43763
+
43764
+ declare const AgentPane: {
43765
+ getApp(): Promise<AgentPaneAppInfo>;
43766
+ getState(): Promise<AgentPaneState>;
43767
+ setState(data: Record<string, unknown> | null): Promise<AgentPaneState>;
43768
+ createSession(opts?: AgentPaneCreateSessionOptions): Promise<AgentPaneSessionInfo>;
43769
+ submitTurn(sessionId: string, prompt: string): Promise<unknown>;
43770
+ onTurnCompleted(cb: (event: 'turn:completed' | 'turn:failed', payload: AgentPaneTurnPayload | null) => void): void;
43771
+ onTurnDelta(cb: (payload: AgentPaneDeltaPayload) => void): void;
43772
+ onToolCall(cb: (payload: AgentPaneToolCallPayload) => void): void;
43773
+ onStateChanged(cb: (payload: unknown) => void): void;
43774
+ resolveToolCall(callId: string, result?: unknown): Promise<{ ok: boolean }>;
43775
+ };
43776
+ `;
43777
+ var cache = /* @__PURE__ */ new Map();
43778
+ function invalidateCompiledApp(appId) {
43779
+ if (!appId) cache.clear();
43780
+ else cache.delete(appId);
43781
+ }
43782
+ function tsDiagnosticToFile(file, d) {
43783
+ if (!d.file) return null;
43784
+ const pos = d.file.getLineAndCharacterOfPosition(d.start ?? 0);
43785
+ return {
43786
+ severity: d.category === ts.DiagnosticCategory.Error ? "error" : "warning",
43787
+ file,
43788
+ line: pos.line + 1,
43789
+ column: pos.character + 1,
43790
+ message: ts.flattenDiagnosticMessageText(d.messageText, "\n")
43791
+ };
43792
+ }
43793
+ function typeCheckAppTs(source) {
43794
+ const options = {
43795
+ noEmit: true,
43796
+ target: ts.ScriptTarget.ES2020,
43797
+ module: ts.ModuleKind.None,
43798
+ lib: ["lib.es2020.d.ts", "lib.dom.d.ts"],
43799
+ strict: true,
43800
+ skipLibCheck: true
43801
+ };
43802
+ const host = ts.createCompilerHost(options);
43803
+ const origReadFile = host.readFile.bind(host);
43804
+ const origFileExists = host.fileExists.bind(host);
43805
+ host.readFile = (fname) => {
43806
+ if (fname === APP_TS) return source;
43807
+ if (fname === BRIDGE_DTS_FILE) return BRIDGE_DTS;
43808
+ return origReadFile(fname);
43809
+ };
43810
+ host.fileExists = (fname) => fname === APP_TS || fname === BRIDGE_DTS_FILE ? true : origFileExists(fname);
43811
+ host.writeFile = () => {
43812
+ };
43813
+ const program = ts.createProgram([APP_TS, BRIDGE_DTS_FILE], options, host);
43814
+ const appFile = program.getSourceFile(APP_TS);
43815
+ if (!appFile) return [];
43816
+ return [...program.getSyntacticDiagnostics(appFile), ...program.getSemanticDiagnostics(appFile)].map((d) => tsDiagnosticToFile(APP_TS, d)).filter((d) => d !== null);
43817
+ }
43818
+ function checkJsSyntax(js) {
43819
+ try {
43820
+ new vm.Script(js, { filename: "app.js" });
43821
+ return [];
43822
+ } catch (err) {
43823
+ const stack = err.stack ?? "";
43824
+ const m = stack.match(/app\.js:(\d+)/);
43825
+ return [
43826
+ {
43827
+ severity: "error",
43828
+ file: "app.js",
43829
+ line: m ? Number(m[1]) : 0,
43830
+ column: 0,
43831
+ message: err.message
43832
+ }
43833
+ ];
43834
+ }
43835
+ }
43836
+ function compileAppJs(appId) {
43837
+ const cached = cache.get(appId);
43838
+ if (cached) return cached;
43839
+ const tsSource = readAppFile(appId, APP_TS);
43840
+ let result;
43841
+ if (tsSource.trim()) {
43842
+ const transpiled = ts.transpileModule(tsSource, {
43843
+ compilerOptions: { target: ts.ScriptTarget.ES2020, module: ts.ModuleKind.None },
43844
+ reportDiagnostics: true,
43845
+ fileName: APP_TS
43846
+ });
43847
+ const syntaxDiags = (transpiled.diagnostics ?? []).map((d) => tsDiagnosticToFile(APP_TS, d)).filter((d) => d !== null);
43848
+ const blocked = syntaxDiags.some((d) => d.severity === "error");
43849
+ result = {
43850
+ js: blocked ? "" : transpiled.outputText,
43851
+ sourceFile: "app.ts",
43852
+ diagnostics: blocked ? syntaxDiags : [...syntaxDiags, ...typeCheckAppTs(tsSource)]
43853
+ };
43854
+ } else {
43855
+ const js = readAppFile(appId, "app.js");
43856
+ if (!js.trim()) {
43857
+ result = { js: "", sourceFile: null, diagnostics: [] };
43858
+ } else {
43859
+ const syntaxDiags = checkJsSyntax(js);
43860
+ result = { js: syntaxDiags.length ? "" : js, sourceFile: "app.js", diagnostics: syntaxDiags };
43861
+ }
43862
+ }
43863
+ cache.set(appId, result);
43864
+ return result;
43865
+ }
43866
+
43867
+ // src/apps/headless-runtime.ts
43740
43868
  var HEADLESS_TOOL_TIMEOUT_MS = Number(process.env.AGENT_PANE_TOOL_TIMEOUT_MS ?? 3e4);
43741
43869
  function stub() {
43742
43870
  const fn = function stub2() {
@@ -43755,22 +43883,26 @@ function stub() {
43755
43883
  has: () => true
43756
43884
  });
43757
43885
  }
43886
+ function runtimeKey(appId, workspace) {
43887
+ return `${appId}\0${workspace}`;
43888
+ }
43758
43889
  var runtimes = /* @__PURE__ */ new Map();
43759
43890
  var pendingCalls = /* @__PURE__ */ new Map();
43760
- function getHeadlessToolHandler(appId) {
43761
- const cached = runtimes.get(appId);
43891
+ function getHeadlessToolHandler(appId, workspace = "") {
43892
+ const key = runtimeKey(appId, workspace);
43893
+ const cached = runtimes.get(key);
43762
43894
  if (cached) return cached.handler;
43763
- const js = readAppFile(appId, "app.js");
43895
+ const js = compileAppJs(appId).js;
43764
43896
  if (!js.trim()) return null;
43765
43897
  const manifest = readManifest(appId);
43766
43898
  let handler = null;
43767
43899
  const bridge = {
43768
43900
  getApp: () => Promise.resolve({ id: appId, title: manifest?.title ?? appId }),
43769
- // Headless state = the GLOBAL instance (workspace ''). Tool calls carry
43770
- // no workspace context; the open tab keeps its own workspace-scoped view.
43771
- getState: () => Promise.resolve(getInstanceState(appId, "")),
43901
+ // State is scoped to the calling session's workspace instance; '' = global
43902
+ // (no known workspace). The open tab keeps its own workspace-scoped view.
43903
+ getState: () => Promise.resolve(getInstanceState(appId, workspace)),
43772
43904
  setState: (data) => {
43773
- const next = updateInstanceState(appId, "", { data });
43905
+ const next = updateInstanceState(appId, workspace, { data });
43774
43906
  broadcast("app:state_changed", { appId });
43775
43907
  return Promise.resolve(next);
43776
43908
  },
@@ -43815,14 +43947,14 @@ function getHeadlessToolHandler(appId) {
43815
43947
  sandbox.window = windowObj;
43816
43948
  sandbox.self = windowObj;
43817
43949
  try {
43818
- const context = vm.createContext(sandbox);
43819
- vm.runInContext(js, context, { filename: `${appId}/app.js` });
43950
+ const context = vm2.createContext(sandbox);
43951
+ vm2.runInContext(js, context, { filename: `${appId}/app.js` });
43820
43952
  } catch (err) {
43821
43953
  console.warn(`[headless:${appId}] app.js load failed: ${err.message}`);
43822
43954
  return null;
43823
43955
  }
43824
43956
  if (!handler) return null;
43825
- runtimes.set(appId, { handler });
43957
+ runtimes.set(key, { handler });
43826
43958
  return handler;
43827
43959
  }
43828
43960
  function dispatchHeadlessToolCall(handler, tool, args) {
@@ -43859,8 +43991,14 @@ function resolveHeadlessToolCall(callId, result) {
43859
43991
  return true;
43860
43992
  }
43861
43993
  function invalidateHeadlessRuntime(appId) {
43862
- if (appId) runtimes.delete(appId);
43863
- else runtimes.clear();
43994
+ invalidateCompiledApp(appId);
43995
+ if (!appId) {
43996
+ runtimes.clear();
43997
+ return;
43998
+ }
43999
+ for (const key of runtimes.keys()) {
44000
+ if (key.startsWith(`${appId}\0`)) runtimes.delete(key);
44001
+ }
43864
44002
  }
43865
44003
 
43866
44004
  // src/apps/mcp-tools.ts
@@ -43891,7 +44029,7 @@ function splitToolName(name) {
43891
44029
  return { appId: name.slice(0, idx), localName: name.slice(idx + TOOL_NS.length) };
43892
44030
  }
43893
44031
  var pendingCalls2 = /* @__PURE__ */ new Map();
43894
- function dispatchAppTool(toolName, args) {
44032
+ function dispatchAppTool(toolName, args, workspace = "") {
43895
44033
  const split = splitToolName(toolName);
43896
44034
  if (!split) {
43897
44035
  throw new Error(`Invalid tool name: ${toolName}`);
@@ -43902,7 +44040,7 @@ function dispatchAppTool(toolName, args) {
43902
44040
  if (!manifest || !tool) {
43903
44041
  throw new Error(`Unknown mini-app tool: ${toolName}`);
43904
44042
  }
43905
- const headlessHandler = getHeadlessToolHandler(appId);
44043
+ const headlessHandler = getHeadlessToolHandler(appId, workspace);
43906
44044
  if (headlessHandler) {
43907
44045
  return dispatchHeadlessToolCall(headlessHandler, localName, args);
43908
44046
  }
@@ -43921,8 +44059,8 @@ function dispatchAppTool(toolName, args) {
43921
44059
  });
43922
44060
  return { callId, result };
43923
44061
  }
43924
- async function callAppTool(toolName, args) {
43925
- return dispatchAppTool(toolName, args).result;
44062
+ async function callAppTool(toolName, args, workspace = "") {
44063
+ return dispatchAppTool(toolName, args, workspace).result;
43926
44064
  }
43927
44065
  function resolveAppToolCall(callId, result, error) {
43928
44066
  const pending = pendingCalls2.get(callId);
@@ -43939,6 +44077,11 @@ function anyAppHasTools() {
43939
44077
 
43940
44078
  // src/routes/apps.ts
43941
44079
  var IMPORT_FILE_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
44080
+ function resolveToolWorkspace(workspace) {
44081
+ if (!workspace) return "";
44082
+ const row = getDb().prepare("SELECT 1 FROM workspaces WHERE path = ? AND deleted = 0").get(workspace);
44083
+ return row ? workspace : "";
44084
+ }
43942
44085
  var IMPORT_MAX_FILES = 50;
43943
44086
  var IMPORT_MAX_FILE_BYTES = 512 * 1024;
43944
44087
  var SKELETON_HTML = `<!DOCTYPE html>
@@ -43953,19 +44096,24 @@ var SKELETON_HTML = `<!DOCTYPE html>
43953
44096
  </body>
43954
44097
  </html>
43955
44098
  `;
43956
- var SKELETON_JS = `// Skeleton mini app. window.AgentPane is the pane bridge:
44099
+ var SKELETON_TS = `// Skeleton mini app (TypeScript). window.AgentPane is the typed pane bridge:
43957
44100
  // getState() / setState(data) persistent state (survives reloads)
43958
44101
  // createSession / submitTurn talk to an agent session
43959
44102
  // onTurnCompleted / onToolCall react to agent events
43960
- var ui = { ready: false };
44103
+ interface Ui {
44104
+ ready: boolean;
44105
+ data: Record<string, unknown>;
44106
+ }
44107
+
44108
+ const ui: Ui = { ready: false, data: {} };
43961
44109
 
43962
- function render() {
43963
- document.getElementById('out').textContent =
43964
- ui.ready ? 'State: ' + JSON.stringify(ui.data) : 'Loading\u2026';
44110
+ function render(): void {
44111
+ const out = document.getElementById('out');
44112
+ if (out) out.textContent = ui.ready ? 'State: ' + JSON.stringify(ui.data) : 'Loading\u2026';
43965
44113
  }
43966
44114
 
43967
- (async function init() {
43968
- var state = await AgentPane.getState();
44115
+ (async function init(): Promise<void> {
44116
+ const state = await AgentPane.getState();
43969
44117
  ui.data = (state && state.data) || {};
43970
44118
  ui.ready = true;
43971
44119
  render();
@@ -44002,6 +44150,7 @@ async function registerAppRoutes(fastify, opts) {
44002
44150
  return [];
44003
44151
  }
44004
44152
  });
44153
+ fastify.get("/api/apps/root", async () => ({ root: appsRoot() }));
44005
44154
  fastify.get("/api/apps/mcp/tools", async () => listAppTools());
44006
44155
  fastify.get("/api/apps/examples", async () => {
44007
44156
  const exRoot = examplesRoot();
@@ -44076,7 +44225,7 @@ async function registerAppRoutes(fastify, opts) {
44076
44225
  )
44077
44226
  );
44078
44227
  fs4.writeFileSync(path5.join(dir, "index.html"), SKELETON_HTML.replaceAll("__TITLE__", cleanTitle2));
44079
- fs4.writeFileSync(path5.join(dir, "app.js"), SKELETON_JS);
44228
+ fs4.writeFileSync(path5.join(dir, "app.ts"), SKELETON_TS);
44080
44229
  return { ok: true, id };
44081
44230
  }
44082
44231
  );
@@ -44128,15 +44277,16 @@ async function registerAppRoutes(fastify, opts) {
44128
44277
  required: ["tool"],
44129
44278
  properties: {
44130
44279
  tool: { type: "string" },
44131
- args: { type: ["object", "null"] }
44280
+ args: { type: ["object", "null"] },
44281
+ workspace: { type: ["string", "null"] }
44132
44282
  }
44133
44283
  }
44134
44284
  }
44135
44285
  },
44136
44286
  async (request, reply) => {
44137
- const { tool, args } = request.body || {};
44287
+ const { tool, args, workspace } = request.body || {};
44138
44288
  try {
44139
- const result = await callAppTool(tool, args ?? {});
44289
+ const result = await callAppTool(tool, args ?? {}, resolveToolWorkspace(workspace));
44140
44290
  return { ok: true, result };
44141
44291
  } catch (err) {
44142
44292
  return reply.code(200).send({ ok: false, error: err.message });
@@ -44171,10 +44321,13 @@ async function registerAppRoutes(fastify, opts) {
44171
44321
  if (!APP_ID_RE.test(id)) return reply.code(400).send({ error: "Invalid app id" });
44172
44322
  const manifest = readManifest(id);
44173
44323
  if (!manifest) return reply.code(404).send({ error: "App not found" });
44324
+ const compiled = compileAppJs(id);
44174
44325
  return {
44175
44326
  manifest,
44176
44327
  html: readAppFile(id, "index.html"),
44177
- js: readAppFile(id, "app.js")
44328
+ js: compiled.js,
44329
+ sourceFile: compiled.sourceFile,
44330
+ diagnostics: compiled.diagnostics
44178
44331
  };
44179
44332
  });
44180
44333
  fastify.get(
@@ -44245,8 +44398,6 @@ async function registerAppRoutes(fastify, opts) {
44245
44398
  if (!manifest) return reply.code(404).send({ error: "App not found" });
44246
44399
  const dir = appDir(id);
44247
44400
  const db2 = getDb();
44248
- const existing = db2.prepare("SELECT * FROM sessions WHERE origin_app_id = ? AND cwd = ? ORDER BY created_at DESC LIMIT 1").get(id, dir);
44249
- if (existing) return existing;
44250
44401
  const { runtime_type = "claude", model = null, model_reasoning_effort = null } = request.body || {};
44251
44402
  const sessionId = v4_default();
44252
44403
  const now = (/* @__PURE__ */ new Date()).toISOString();
@@ -44361,8 +44512,9 @@ function stdioScriptPath() {
44361
44512
  return null;
44362
44513
  }
44363
44514
  var registered = /* @__PURE__ */ new Set();
44364
- async function registerMiniAppMcp(baseUrl) {
44365
- if (registered.has(baseUrl)) return true;
44515
+ async function registerMiniAppMcp(baseUrl, workspace = "") {
44516
+ const key = `${baseUrl}|${workspace}`;
44517
+ if (registered.has(key)) return true;
44366
44518
  const script = stdioScriptPath();
44367
44519
  if (!script) {
44368
44520
  console.warn("[miniapp-mcp] stdio proxy script not found \u2014 registration skipped");
@@ -44379,8 +44531,11 @@ async function registerMiniAppMcp(baseUrl) {
44379
44531
  const servers = await res2.json();
44380
44532
  const names = servers.map((s) => s.server_name ?? s.name);
44381
44533
  if (names.includes(MCP_SERVER_NAME)) {
44382
- registered.add(baseUrl);
44383
- return true;
44534
+ await fetch(`${base}/mcp/configs/${MCP_SERVER_NAME}`, {
44535
+ method: "DELETE",
44536
+ signal: AbortSignal.timeout(5e3)
44537
+ }).catch(() => {
44538
+ });
44384
44539
  }
44385
44540
  }
44386
44541
  } catch {
@@ -44389,7 +44544,7 @@ async function registerMiniAppMcp(baseUrl) {
44389
44544
  configJson: JSON.stringify({
44390
44545
  [MCP_SERVER_NAME]: {
44391
44546
  command: process.execPath,
44392
- args: [script, panePublicUrl()],
44547
+ args: [script, panePublicUrl(), workspace],
44393
44548
  env: {}
44394
44549
  }
44395
44550
  })
@@ -44401,13 +44556,13 @@ async function registerMiniAppMcp(baseUrl) {
44401
44556
  signal: AbortSignal.timeout(1e4)
44402
44557
  });
44403
44558
  if (res.status === 201) {
44404
- console.log(`[miniapp-mcp] gateway registered in workspace backend ${base}`);
44405
- registered.add(baseUrl);
44559
+ console.log(`[miniapp-mcp] gateway registered in workspace backend ${base} (workspace: ${workspace || "global"})`);
44560
+ registered.add(key);
44406
44561
  return true;
44407
44562
  }
44408
44563
  const text = await res.text();
44409
44564
  if (res.status === 400 && /already exists/i.test(text)) {
44410
- registered.add(baseUrl);
44565
+ registered.add(key);
44411
44566
  return true;
44412
44567
  }
44413
44568
  console.warn(`[miniapp-mcp] registration failed (${res.status}): ${text.slice(0, 200)}`);
@@ -44417,7 +44572,7 @@ async function registerMiniAppMcp(baseUrl) {
44417
44572
  return false;
44418
44573
  }
44419
44574
  }
44420
- function codexMiniAppLaunchArgs() {
44575
+ function codexMiniAppLaunchArgs(workspace = "") {
44421
44576
  const script = stdioScriptPath();
44422
44577
  if (!script || !anyAppHasTools()) return null;
44423
44578
  return [
@@ -44428,7 +44583,7 @@ function codexMiniAppLaunchArgs() {
44428
44583
  "-c",
44429
44584
  `mcp_servers.${MCP_SERVER_NAME}.command=${JSON.stringify(process.execPath)}`,
44430
44585
  "-c",
44431
- `mcp_servers.${MCP_SERVER_NAME}.args=${JSON.stringify([script, panePublicUrl()])}`
44586
+ `mcp_servers.${MCP_SERVER_NAME}.args=${JSON.stringify([script, panePublicUrl(), workspace])}`
44432
44587
  ];
44433
44588
  }
44434
44589
 
@@ -44493,7 +44648,7 @@ function isEmptyReasoning(item) {
44493
44648
  return summary.length === 0 && content.length === 0 && text.length === 0;
44494
44649
  }
44495
44650
  function appServerClientOptions(_session, cwd) {
44496
- const launchArgs = codexMiniAppLaunchArgs();
44651
+ const launchArgs = codexMiniAppLaunchArgs(cwd);
44497
44652
  return launchArgs ? { cwd, launchArgs } : { cwd, launchArgs: [] };
44498
44653
  }
44499
44654
  function autoApproveToolUserInput(client) {
@@ -46277,7 +46432,7 @@ async function startService(daemon, projectPath) {
46277
46432
  throw new Error(`Daemon failed to start backend for ${projectPath}: ${daemonErrorMessage(err)}`);
46278
46433
  }
46279
46434
  }
46280
- function cache(absPath, service) {
46435
+ function cache2(absPath, service) {
46281
46436
  const resolved = {
46282
46437
  baseUrl: serviceBaseUrl(service),
46283
46438
  port: service.port,
@@ -46310,22 +46465,22 @@ async function resolveBackendUrl(projectPath, opts = {}) {
46310
46465
  const match = coveringService(services, absPath);
46311
46466
  if (match && match.status === "running") {
46312
46467
  if (await backendHealthy(serviceBaseUrl(match), match.path)) {
46313
- return cache(absPath, match);
46468
+ return cache2(absPath, match);
46314
46469
  }
46315
46470
  if (!autoStart) return null;
46316
46471
  await restartService(daemon, match.name);
46317
46472
  await waitForHealthy(serviceBaseUrl(match), match.name, match.path);
46318
- return cache(absPath, match);
46473
+ return cache2(absPath, match);
46319
46474
  }
46320
46475
  if (!autoStart) return null;
46321
46476
  if (match) {
46322
46477
  await restartService(daemon, match.name);
46323
46478
  await waitForHealthy(serviceBaseUrl(match), match.name, match.path);
46324
- return cache(absPath, match);
46479
+ return cache2(absPath, match);
46325
46480
  }
46326
46481
  const service = await startService(daemon, absPath);
46327
46482
  await waitForHealthy(serviceBaseUrl(service), service.name, absPath);
46328
- return cache(absPath, service);
46483
+ return cache2(absPath, service);
46329
46484
  }
46330
46485
 
46331
46486
  // src/repoburg/action-mapping.ts
@@ -47468,7 +47623,7 @@ async function startTurn3(session, turn) {
47468
47623
  `[repoburg] resolved backend ${baseUrl} differs from pinned ${pinned.baseUrl} for session ${session.id} \u2014 keeping the pinned entry.`
47469
47624
  );
47470
47625
  }
47471
- void registerMiniAppMcp(baseUrl);
47626
+ void registerMiniAppMcp(baseUrl, session.cwd ?? "");
47472
47627
  let entry;
47473
47628
  try {
47474
47629
  entry = turn.thread_id ? await ensureThreadSession(session, turn, client, baseUrl) : await ensureSession(session, client, baseUrl);