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
  }
@@ -43560,7 +43560,15 @@ Each subdirectory of this folder is one mini app:
43560
43560
  manifest.json - { "title": string, "description"?: string, "icon"?: string,
43561
43561
  "tools"?: [{ "name", "description", "inputSchema" }] }
43562
43562
  index.html - markup only (full HTML document); do NOT reference app.js
43563
- app.js - app logic; injected automatically into the page
43563
+ app.ts - app logic (TypeScript, PREFERRED); injected automatically
43564
+ into the page as compiled JS
43565
+ app.js - legacy plain-JS logic; used only when app.ts is absent
43566
+
43567
+ The pane compiles app.ts on every change (strict mode, lib dom). Compile and
43568
+ type errors are shown in the app tab \u2014 check them after every edit and fix
43569
+ them before finishing. window.AgentPane is typed via ambient declarations
43570
+ (getState/setState/createSession/submitTurn/onToolCall/...); no import
43571
+ needed.
43564
43572
 
43565
43573
  App state does NOT live in this folder \u2014 it is stored in the pane database
43566
43574
  (app_instances table) and reached with getState()/setState().
@@ -43585,8 +43593,9 @@ viewer; it refreshes via AgentPane.onStateChanged(cb).
43585
43593
  Headless contract for apps that declare tools:
43586
43594
  - register AgentPane.onToolCall(handler) synchronously at startup
43587
43595
  - tool handlers must not depend on the DOM or the live UI
43588
- - headless state is the GLOBAL instance (workspace ''), shared with the
43589
- open tab via onStateChanged
43596
+ - headless state is the instance of the CALLING session's workspace
43597
+ ('' = global when the caller has no known workspace); open tabs
43598
+ sync via onStateChanged
43590
43599
  - createSession/submitTurn are not available in the headless runtime
43591
43600
 
43592
43601
  If the app cannot load headless (broken app.js, no handler), the pane
@@ -43723,7 +43732,126 @@ function deleteAppInstances(appId) {
43723
43732
  import fs3 from "node:fs";
43724
43733
 
43725
43734
  // src/apps/headless-runtime.ts
43735
+ import vm2 from "node:vm";
43736
+
43737
+ // src/apps/app-compile.ts
43726
43738
  import vm from "node:vm";
43739
+ import ts from "typescript";
43740
+ var APP_TS = "app.ts";
43741
+ var BRIDGE_DTS_FILE = "agentpane.d.ts";
43742
+ var BRIDGE_DTS = `/** AgentPane bridge \u2014 typed contract for mini apps (ambient, no import). */
43743
+ interface AgentPaneAppInfo { id: string; title?: string }
43744
+ interface AgentPaneState { pinned: boolean; data: Record<string, unknown> | null }
43745
+ interface AgentPaneSessionInfo { id: string; title?: string | null }
43746
+ interface AgentPaneCreateSessionOptions { title?: string; runtime_type?: string; model?: string; cwd?: string }
43747
+ interface AgentPaneTurnPayload { turnId?: string; response?: string | null; error?: string }
43748
+ interface AgentPaneDeltaPayload { sessionId?: string; turnId?: string; itemId?: string; delta?: string }
43749
+ interface AgentPaneToolCallPayload { callId: string; tool: string; name: string; args: Record<string, unknown> }
43750
+
43751
+ declare const AgentPane: {
43752
+ getApp(): Promise<AgentPaneAppInfo>;
43753
+ getState(): Promise<AgentPaneState>;
43754
+ setState(data: Record<string, unknown> | null): Promise<AgentPaneState>;
43755
+ createSession(opts?: AgentPaneCreateSessionOptions): Promise<AgentPaneSessionInfo>;
43756
+ submitTurn(sessionId: string, prompt: string): Promise<unknown>;
43757
+ onTurnCompleted(cb: (event: 'turn:completed' | 'turn:failed', payload: AgentPaneTurnPayload | null) => void): void;
43758
+ onTurnDelta(cb: (payload: AgentPaneDeltaPayload) => void): void;
43759
+ onToolCall(cb: (payload: AgentPaneToolCallPayload) => void): void;
43760
+ onStateChanged(cb: (payload: unknown) => void): void;
43761
+ resolveToolCall(callId: string, result?: unknown): Promise<{ ok: boolean }>;
43762
+ };
43763
+ `;
43764
+ var cache = /* @__PURE__ */ new Map();
43765
+ function invalidateCompiledApp(appId) {
43766
+ if (!appId) cache.clear();
43767
+ else cache.delete(appId);
43768
+ }
43769
+ function tsDiagnosticToFile(file, d) {
43770
+ if (!d.file) return null;
43771
+ const pos = d.file.getLineAndCharacterOfPosition(d.start ?? 0);
43772
+ return {
43773
+ severity: d.category === ts.DiagnosticCategory.Error ? "error" : "warning",
43774
+ file,
43775
+ line: pos.line + 1,
43776
+ column: pos.character + 1,
43777
+ message: ts.flattenDiagnosticMessageText(d.messageText, "\n")
43778
+ };
43779
+ }
43780
+ function typeCheckAppTs(source) {
43781
+ const options = {
43782
+ noEmit: true,
43783
+ target: ts.ScriptTarget.ES2020,
43784
+ module: ts.ModuleKind.None,
43785
+ lib: ["lib.es2020.d.ts", "lib.dom.d.ts"],
43786
+ strict: true,
43787
+ skipLibCheck: true
43788
+ };
43789
+ const host = ts.createCompilerHost(options);
43790
+ const origReadFile = host.readFile.bind(host);
43791
+ const origFileExists = host.fileExists.bind(host);
43792
+ host.readFile = (fname) => {
43793
+ if (fname === APP_TS) return source;
43794
+ if (fname === BRIDGE_DTS_FILE) return BRIDGE_DTS;
43795
+ return origReadFile(fname);
43796
+ };
43797
+ host.fileExists = (fname) => fname === APP_TS || fname === BRIDGE_DTS_FILE ? true : origFileExists(fname);
43798
+ host.writeFile = () => {
43799
+ };
43800
+ const program = ts.createProgram([APP_TS, BRIDGE_DTS_FILE], options, host);
43801
+ const appFile = program.getSourceFile(APP_TS);
43802
+ if (!appFile) return [];
43803
+ return [...program.getSyntacticDiagnostics(appFile), ...program.getSemanticDiagnostics(appFile)].map((d) => tsDiagnosticToFile(APP_TS, d)).filter((d) => d !== null);
43804
+ }
43805
+ function checkJsSyntax(js) {
43806
+ try {
43807
+ new vm.Script(js, { filename: "app.js" });
43808
+ return [];
43809
+ } catch (err) {
43810
+ const stack = err.stack ?? "";
43811
+ const m = stack.match(/app\.js:(\d+)/);
43812
+ return [
43813
+ {
43814
+ severity: "error",
43815
+ file: "app.js",
43816
+ line: m ? Number(m[1]) : 0,
43817
+ column: 0,
43818
+ message: err.message
43819
+ }
43820
+ ];
43821
+ }
43822
+ }
43823
+ function compileAppJs(appId) {
43824
+ const cached = cache.get(appId);
43825
+ if (cached) return cached;
43826
+ const tsSource = readAppFile(appId, APP_TS);
43827
+ let result;
43828
+ if (tsSource.trim()) {
43829
+ const transpiled = ts.transpileModule(tsSource, {
43830
+ compilerOptions: { target: ts.ScriptTarget.ES2020, module: ts.ModuleKind.None },
43831
+ reportDiagnostics: true,
43832
+ fileName: APP_TS
43833
+ });
43834
+ const syntaxDiags = (transpiled.diagnostics ?? []).map((d) => tsDiagnosticToFile(APP_TS, d)).filter((d) => d !== null);
43835
+ const blocked = syntaxDiags.some((d) => d.severity === "error");
43836
+ result = {
43837
+ js: blocked ? "" : transpiled.outputText,
43838
+ sourceFile: "app.ts",
43839
+ diagnostics: blocked ? syntaxDiags : [...syntaxDiags, ...typeCheckAppTs(tsSource)]
43840
+ };
43841
+ } else {
43842
+ const js = readAppFile(appId, "app.js");
43843
+ if (!js.trim()) {
43844
+ result = { js: "", sourceFile: null, diagnostics: [] };
43845
+ } else {
43846
+ const syntaxDiags = checkJsSyntax(js);
43847
+ result = { js: syntaxDiags.length ? "" : js, sourceFile: "app.js", diagnostics: syntaxDiags };
43848
+ }
43849
+ }
43850
+ cache.set(appId, result);
43851
+ return result;
43852
+ }
43853
+
43854
+ // src/apps/headless-runtime.ts
43727
43855
  var HEADLESS_TOOL_TIMEOUT_MS = Number(process.env.AGENT_PANE_TOOL_TIMEOUT_MS ?? 3e4);
43728
43856
  function stub() {
43729
43857
  const fn = function stub2() {
@@ -43742,22 +43870,26 @@ function stub() {
43742
43870
  has: () => true
43743
43871
  });
43744
43872
  }
43873
+ function runtimeKey(appId, workspace) {
43874
+ return `${appId}\0${workspace}`;
43875
+ }
43745
43876
  var runtimes = /* @__PURE__ */ new Map();
43746
43877
  var pendingCalls = /* @__PURE__ */ new Map();
43747
- function getHeadlessToolHandler(appId) {
43748
- const cached = runtimes.get(appId);
43878
+ function getHeadlessToolHandler(appId, workspace = "") {
43879
+ const key = runtimeKey(appId, workspace);
43880
+ const cached = runtimes.get(key);
43749
43881
  if (cached) return cached.handler;
43750
- const js = readAppFile(appId, "app.js");
43882
+ const js = compileAppJs(appId).js;
43751
43883
  if (!js.trim()) return null;
43752
43884
  const manifest = readManifest(appId);
43753
43885
  let handler = null;
43754
43886
  const bridge = {
43755
43887
  getApp: () => Promise.resolve({ id: appId, title: manifest?.title ?? appId }),
43756
- // Headless state = the GLOBAL instance (workspace ''). Tool calls carry
43757
- // no workspace context; the open tab keeps its own workspace-scoped view.
43758
- getState: () => Promise.resolve(getInstanceState(appId, "")),
43888
+ // State is scoped to the calling session's workspace instance; '' = global
43889
+ // (no known workspace). The open tab keeps its own workspace-scoped view.
43890
+ getState: () => Promise.resolve(getInstanceState(appId, workspace)),
43759
43891
  setState: (data) => {
43760
- const next = updateInstanceState(appId, "", { data });
43892
+ const next = updateInstanceState(appId, workspace, { data });
43761
43893
  broadcast("app:state_changed", { appId });
43762
43894
  return Promise.resolve(next);
43763
43895
  },
@@ -43802,14 +43934,14 @@ function getHeadlessToolHandler(appId) {
43802
43934
  sandbox.window = windowObj;
43803
43935
  sandbox.self = windowObj;
43804
43936
  try {
43805
- const context = vm.createContext(sandbox);
43806
- vm.runInContext(js, context, { filename: `${appId}/app.js` });
43937
+ const context = vm2.createContext(sandbox);
43938
+ vm2.runInContext(js, context, { filename: `${appId}/app.js` });
43807
43939
  } catch (err) {
43808
43940
  console.warn(`[headless:${appId}] app.js load failed: ${err.message}`);
43809
43941
  return null;
43810
43942
  }
43811
43943
  if (!handler) return null;
43812
- runtimes.set(appId, { handler });
43944
+ runtimes.set(key, { handler });
43813
43945
  return handler;
43814
43946
  }
43815
43947
  function dispatchHeadlessToolCall(handler, tool, args) {
@@ -43846,8 +43978,14 @@ function resolveHeadlessToolCall(callId, result) {
43846
43978
  return true;
43847
43979
  }
43848
43980
  function invalidateHeadlessRuntime(appId) {
43849
- if (appId) runtimes.delete(appId);
43850
- else runtimes.clear();
43981
+ invalidateCompiledApp(appId);
43982
+ if (!appId) {
43983
+ runtimes.clear();
43984
+ return;
43985
+ }
43986
+ for (const key of runtimes.keys()) {
43987
+ if (key.startsWith(`${appId}\0`)) runtimes.delete(key);
43988
+ }
43851
43989
  }
43852
43990
 
43853
43991
  // src/apps/mcp-tools.ts
@@ -43878,7 +44016,7 @@ function splitToolName(name) {
43878
44016
  return { appId: name.slice(0, idx), localName: name.slice(idx + TOOL_NS.length) };
43879
44017
  }
43880
44018
  var pendingCalls2 = /* @__PURE__ */ new Map();
43881
- function dispatchAppTool(toolName, args) {
44019
+ function dispatchAppTool(toolName, args, workspace = "") {
43882
44020
  const split = splitToolName(toolName);
43883
44021
  if (!split) {
43884
44022
  throw new Error(`Invalid tool name: ${toolName}`);
@@ -43889,7 +44027,7 @@ function dispatchAppTool(toolName, args) {
43889
44027
  if (!manifest || !tool) {
43890
44028
  throw new Error(`Unknown mini-app tool: ${toolName}`);
43891
44029
  }
43892
- const headlessHandler = getHeadlessToolHandler(appId);
44030
+ const headlessHandler = getHeadlessToolHandler(appId, workspace);
43893
44031
  if (headlessHandler) {
43894
44032
  return dispatchHeadlessToolCall(headlessHandler, localName, args);
43895
44033
  }
@@ -43908,8 +44046,8 @@ function dispatchAppTool(toolName, args) {
43908
44046
  });
43909
44047
  return { callId, result };
43910
44048
  }
43911
- async function callAppTool(toolName, args) {
43912
- return dispatchAppTool(toolName, args).result;
44049
+ async function callAppTool(toolName, args, workspace = "") {
44050
+ return dispatchAppTool(toolName, args, workspace).result;
43913
44051
  }
43914
44052
  function resolveAppToolCall(callId, result, error) {
43915
44053
  const pending = pendingCalls2.get(callId);
@@ -43926,6 +44064,11 @@ function anyAppHasTools() {
43926
44064
 
43927
44065
  // src/routes/apps.ts
43928
44066
  var IMPORT_FILE_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
44067
+ function resolveToolWorkspace(workspace) {
44068
+ if (!workspace) return "";
44069
+ const row = getDb().prepare("SELECT 1 FROM workspaces WHERE path = ? AND deleted = 0").get(workspace);
44070
+ return row ? workspace : "";
44071
+ }
43929
44072
  var IMPORT_MAX_FILES = 50;
43930
44073
  var IMPORT_MAX_FILE_BYTES = 512 * 1024;
43931
44074
  var SKELETON_HTML = `<!DOCTYPE html>
@@ -43940,19 +44083,24 @@ var SKELETON_HTML = `<!DOCTYPE html>
43940
44083
  </body>
43941
44084
  </html>
43942
44085
  `;
43943
- var SKELETON_JS = `// Skeleton mini app. window.AgentPane is the pane bridge:
44086
+ var SKELETON_TS = `// Skeleton mini app (TypeScript). window.AgentPane is the typed pane bridge:
43944
44087
  // getState() / setState(data) persistent state (survives reloads)
43945
44088
  // createSession / submitTurn talk to an agent session
43946
44089
  // onTurnCompleted / onToolCall react to agent events
43947
- var ui = { ready: false };
44090
+ interface Ui {
44091
+ ready: boolean;
44092
+ data: Record<string, unknown>;
44093
+ }
44094
+
44095
+ const ui: Ui = { ready: false, data: {} };
43948
44096
 
43949
- function render() {
43950
- document.getElementById('out').textContent =
43951
- ui.ready ? 'State: ' + JSON.stringify(ui.data) : 'Loading\u2026';
44097
+ function render(): void {
44098
+ const out = document.getElementById('out');
44099
+ if (out) out.textContent = ui.ready ? 'State: ' + JSON.stringify(ui.data) : 'Loading\u2026';
43952
44100
  }
43953
44101
 
43954
- (async function init() {
43955
- var state = await AgentPane.getState();
44102
+ (async function init(): Promise<void> {
44103
+ const state = await AgentPane.getState();
43956
44104
  ui.data = (state && state.data) || {};
43957
44105
  ui.ready = true;
43958
44106
  render();
@@ -43989,6 +44137,7 @@ async function registerAppRoutes(fastify, opts) {
43989
44137
  return [];
43990
44138
  }
43991
44139
  });
44140
+ fastify.get("/api/apps/root", async () => ({ root: appsRoot() }));
43992
44141
  fastify.get("/api/apps/mcp/tools", async () => listAppTools());
43993
44142
  fastify.get("/api/apps/examples", async () => {
43994
44143
  const exRoot = examplesRoot();
@@ -44063,7 +44212,7 @@ async function registerAppRoutes(fastify, opts) {
44063
44212
  )
44064
44213
  );
44065
44214
  fs4.writeFileSync(path5.join(dir, "index.html"), SKELETON_HTML.replaceAll("__TITLE__", cleanTitle2));
44066
- fs4.writeFileSync(path5.join(dir, "app.js"), SKELETON_JS);
44215
+ fs4.writeFileSync(path5.join(dir, "app.ts"), SKELETON_TS);
44067
44216
  return { ok: true, id };
44068
44217
  }
44069
44218
  );
@@ -44115,15 +44264,16 @@ async function registerAppRoutes(fastify, opts) {
44115
44264
  required: ["tool"],
44116
44265
  properties: {
44117
44266
  tool: { type: "string" },
44118
- args: { type: ["object", "null"] }
44267
+ args: { type: ["object", "null"] },
44268
+ workspace: { type: ["string", "null"] }
44119
44269
  }
44120
44270
  }
44121
44271
  }
44122
44272
  },
44123
44273
  async (request, reply) => {
44124
- const { tool, args } = request.body || {};
44274
+ const { tool, args, workspace } = request.body || {};
44125
44275
  try {
44126
- const result = await callAppTool(tool, args ?? {});
44276
+ const result = await callAppTool(tool, args ?? {}, resolveToolWorkspace(workspace));
44127
44277
  return { ok: true, result };
44128
44278
  } catch (err) {
44129
44279
  return reply.code(200).send({ ok: false, error: err.message });
@@ -44158,10 +44308,13 @@ async function registerAppRoutes(fastify, opts) {
44158
44308
  if (!APP_ID_RE.test(id)) return reply.code(400).send({ error: "Invalid app id" });
44159
44309
  const manifest = readManifest(id);
44160
44310
  if (!manifest) return reply.code(404).send({ error: "App not found" });
44311
+ const compiled = compileAppJs(id);
44161
44312
  return {
44162
44313
  manifest,
44163
44314
  html: readAppFile(id, "index.html"),
44164
- js: readAppFile(id, "app.js")
44315
+ js: compiled.js,
44316
+ sourceFile: compiled.sourceFile,
44317
+ diagnostics: compiled.diagnostics
44165
44318
  };
44166
44319
  });
44167
44320
  fastify.get(
@@ -44232,8 +44385,6 @@ async function registerAppRoutes(fastify, opts) {
44232
44385
  if (!manifest) return reply.code(404).send({ error: "App not found" });
44233
44386
  const dir = appDir(id);
44234
44387
  const db2 = getDb();
44235
- const existing = db2.prepare("SELECT * FROM sessions WHERE origin_app_id = ? AND cwd = ? ORDER BY created_at DESC LIMIT 1").get(id, dir);
44236
- if (existing) return existing;
44237
44388
  const { runtime_type = "claude", model = null, model_reasoning_effort = null } = request.body || {};
44238
44389
  const sessionId = v4_default();
44239
44390
  const now = (/* @__PURE__ */ new Date()).toISOString();
@@ -44348,8 +44499,9 @@ function stdioScriptPath() {
44348
44499
  return null;
44349
44500
  }
44350
44501
  var registered = /* @__PURE__ */ new Set();
44351
- async function registerMiniAppMcp(baseUrl) {
44352
- if (registered.has(baseUrl)) return true;
44502
+ async function registerMiniAppMcp(baseUrl, workspace = "") {
44503
+ const key = `${baseUrl}|${workspace}`;
44504
+ if (registered.has(key)) return true;
44353
44505
  const script = stdioScriptPath();
44354
44506
  if (!script) {
44355
44507
  console.warn("[miniapp-mcp] stdio proxy script not found \u2014 registration skipped");
@@ -44366,8 +44518,11 @@ async function registerMiniAppMcp(baseUrl) {
44366
44518
  const servers = await res2.json();
44367
44519
  const names = servers.map((s) => s.server_name ?? s.name);
44368
44520
  if (names.includes(MCP_SERVER_NAME)) {
44369
- registered.add(baseUrl);
44370
- return true;
44521
+ await fetch(`${base}/mcp/configs/${MCP_SERVER_NAME}`, {
44522
+ method: "DELETE",
44523
+ signal: AbortSignal.timeout(5e3)
44524
+ }).catch(() => {
44525
+ });
44371
44526
  }
44372
44527
  }
44373
44528
  } catch {
@@ -44376,7 +44531,7 @@ async function registerMiniAppMcp(baseUrl) {
44376
44531
  configJson: JSON.stringify({
44377
44532
  [MCP_SERVER_NAME]: {
44378
44533
  command: process.execPath,
44379
- args: [script, panePublicUrl()],
44534
+ args: [script, panePublicUrl(), workspace],
44380
44535
  env: {}
44381
44536
  }
44382
44537
  })
@@ -44388,13 +44543,13 @@ async function registerMiniAppMcp(baseUrl) {
44388
44543
  signal: AbortSignal.timeout(1e4)
44389
44544
  });
44390
44545
  if (res.status === 201) {
44391
- console.log(`[miniapp-mcp] gateway registered in workspace backend ${base}`);
44392
- registered.add(baseUrl);
44546
+ console.log(`[miniapp-mcp] gateway registered in workspace backend ${base} (workspace: ${workspace || "global"})`);
44547
+ registered.add(key);
44393
44548
  return true;
44394
44549
  }
44395
44550
  const text = await res.text();
44396
44551
  if (res.status === 400 && /already exists/i.test(text)) {
44397
- registered.add(baseUrl);
44552
+ registered.add(key);
44398
44553
  return true;
44399
44554
  }
44400
44555
  console.warn(`[miniapp-mcp] registration failed (${res.status}): ${text.slice(0, 200)}`);
@@ -44404,7 +44559,7 @@ async function registerMiniAppMcp(baseUrl) {
44404
44559
  return false;
44405
44560
  }
44406
44561
  }
44407
- function codexMiniAppLaunchArgs() {
44562
+ function codexMiniAppLaunchArgs(workspace = "") {
44408
44563
  const script = stdioScriptPath();
44409
44564
  if (!script || !anyAppHasTools()) return null;
44410
44565
  return [
@@ -44415,7 +44570,7 @@ function codexMiniAppLaunchArgs() {
44415
44570
  "-c",
44416
44571
  `mcp_servers.${MCP_SERVER_NAME}.command=${JSON.stringify(process.execPath)}`,
44417
44572
  "-c",
44418
- `mcp_servers.${MCP_SERVER_NAME}.args=${JSON.stringify([script, panePublicUrl()])}`
44573
+ `mcp_servers.${MCP_SERVER_NAME}.args=${JSON.stringify([script, panePublicUrl(), workspace])}`
44419
44574
  ];
44420
44575
  }
44421
44576
 
@@ -44480,7 +44635,7 @@ function isEmptyReasoning(item) {
44480
44635
  return summary.length === 0 && content.length === 0 && text.length === 0;
44481
44636
  }
44482
44637
  function appServerClientOptions(_session, cwd) {
44483
- const launchArgs = codexMiniAppLaunchArgs();
44638
+ const launchArgs = codexMiniAppLaunchArgs(cwd);
44484
44639
  return launchArgs ? { cwd, launchArgs } : { cwd, launchArgs: [] };
44485
44640
  }
44486
44641
  function autoApproveToolUserInput(client) {
@@ -46264,7 +46419,7 @@ async function startService(daemon, projectPath) {
46264
46419
  throw new Error(`Daemon failed to start backend for ${projectPath}: ${daemonErrorMessage(err)}`);
46265
46420
  }
46266
46421
  }
46267
- function cache(absPath, service) {
46422
+ function cache2(absPath, service) {
46268
46423
  const resolved = {
46269
46424
  baseUrl: serviceBaseUrl(service),
46270
46425
  port: service.port,
@@ -46297,22 +46452,22 @@ async function resolveBackendUrl(projectPath, opts = {}) {
46297
46452
  const match = coveringService(services, absPath);
46298
46453
  if (match && match.status === "running") {
46299
46454
  if (await backendHealthy(serviceBaseUrl(match), match.path)) {
46300
- return cache(absPath, match);
46455
+ return cache2(absPath, match);
46301
46456
  }
46302
46457
  if (!autoStart) return null;
46303
46458
  await restartService(daemon, match.name);
46304
46459
  await waitForHealthy(serviceBaseUrl(match), match.name, match.path);
46305
- return cache(absPath, match);
46460
+ return cache2(absPath, match);
46306
46461
  }
46307
46462
  if (!autoStart) return null;
46308
46463
  if (match) {
46309
46464
  await restartService(daemon, match.name);
46310
46465
  await waitForHealthy(serviceBaseUrl(match), match.name, match.path);
46311
- return cache(absPath, match);
46466
+ return cache2(absPath, match);
46312
46467
  }
46313
46468
  const service = await startService(daemon, absPath);
46314
46469
  await waitForHealthy(serviceBaseUrl(service), service.name, absPath);
46315
- return cache(absPath, service);
46470
+ return cache2(absPath, service);
46316
46471
  }
46317
46472
 
46318
46473
  // src/repoburg/action-mapping.ts
@@ -47455,7 +47610,7 @@ async function startTurn3(session, turn) {
47455
47610
  `[repoburg] resolved backend ${baseUrl} differs from pinned ${pinned.baseUrl} for session ${session.id} \u2014 keeping the pinned entry.`
47456
47611
  );
47457
47612
  }
47458
- void registerMiniAppMcp(baseUrl);
47613
+ void registerMiniAppMcp(baseUrl, session.cwd ?? "");
47459
47614
  let entry;
47460
47615
  try {
47461
47616
  entry = turn.thread_id ? await ensureThreadSession(session, turn, client, baseUrl) : await ensureSession(session, client, baseUrl);