repoburg 1.3.287 → 1.3.289

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.
@@ -98905,12 +98905,18 @@ Icons come from ONE library: Lucide (https://lucide.dev/icons, ISC).
98905
98905
 
98906
98906
  ## Bridge API (window.AgentPane)
98907
98907
 
98908
- - getApp() - app info (id, title)
98908
+ - getApp() - app info (id, title, workspace = the folder of this instance, '' = global)
98909
98909
  - getState() / setState(data, { ifVersion }?) - persistent JSON state, survives page reload; getState reads the stored copy on every call (see "Shared state" below)
98910
98910
  - onStateChanged(callback) - callback({ version }) when somebody else (an agent, another tab) wrote the state; not fired for this tab's own setState
98911
98911
  - createSession({ cwd, runtime_type, model, model_reasoning_effort, title }) - agent session owned by this app; model_reasoning_effort is the effort for its turns ("low" | "medium" | "high" | "xhigh" | "max" | "ultra", the levels the model supports), omitted = the runtime's default
98912
98912
  - submitTurn(sessionId, prompt, { attachments }?) - send a prompt to a session; attachments (optional) are stored files (id, url or the uploadFile result) or inline Blobs / { name, type, data } sent with that turn only; the agent sees attached images (Claude and Codex)
98913
98913
  - getSession(sessionId) - one of this app's sessions, also read headless: { id, title, status, running, backgroundTasks, lastTurn: { id, status, response, error, resumeState } | null }, null for any other id. A turn waiting to continue after an interruption has running true and resumeState 'waiting'
98914
+ - cancelTurn(sessionId) - stop the running main turn of one of this app's sessions: { cancelled }, false when none runs; a discussion thread keeps running; rejects for any other session
98915
+ - setSessionLifecycle(sessionId, 'finished' | 'working') - finish or reopen one of this app's sessions, as the sidebar does; rejects for any other session
98916
+ - callTool(tool, args) - tab only: run one of this app's manifest tools, by its bare name; it is answered like an agent's call, with caller null. The app's frame has an opaque origin and cannot fetch the pane's API, so this is how a tab gets the headless runtime to do something
98917
+ - listProviders() - tab only: the runtimes this pane offers, as /api/providers lists them (id, label, capability flags)
98918
+ - listModels(runtime, cwd?) - tab only: a runtime's models, as /api/providers/:id/models lists them; cwd for runtimes that list per workspace
98919
+ - pickDirectory() - tab only: the folder dialog of the machine the pane runs on: { path }, or { cancelled: true } when the user dismissed it; works only while the app is on screen, so call it from a click handler
98914
98920
  - onTurnCompleted(callback) - callback(event, { sessionId, turnId, response }) when a turn ends; event is 'turn:completed' or 'turn:failed' ({ sessionId, turnId, error })
98915
98921
  - onBackgroundTasks(callback) - callback({ sessionId, tasks }) when the live background-task set of one of the app's sessions changes (Monitor shells, backgrounded subagents); tasks is the CURRENT set, empty when none are left
98916
98922
  - onToolCall(callback) - callback({ callId, name, tool, args, caller }) when the AGENT calls one of the manifest tools (name and tool carry the same tool name); answer with resolveToolCall(callId, result). caller: see "Who called" below
@@ -99015,9 +99021,10 @@ Set "headlessSessions": true in manifest.json to run an app's agent work with
99015
99021
  no tab open. Without it, createSession/submitTurn reject in the headless
99016
99022
  runtime and events go to the open tab only.
99017
99023
 
99018
- - createSession and submitTurn work headless, from a tool handler or an event
99019
- callback. submitTurn reaches only sessions this app opened; attachments are
99020
- stored files or inline { name, type, data } (no Blobs in the sandbox)
99024
+ - createSession, submitTurn, cancelTurn and setSessionLifecycle work headless,
99025
+ from a tool handler or an event callback. All but createSession reach only
99026
+ sessions this app opened; attachments are stored files or inline
99027
+ { name, type, data } (no Blobs in the sandbox)
99021
99028
  - onTurnCompleted and onBackgroundTasks fire in the headless runtime, for every
99022
99029
  session of the app, also the ones its tab opened. They go to the instance
99023
99030
  that opened the session, and it loads again when it has to
@@ -99367,6 +99374,8 @@ function deleteAppFiles(appId) {
99367
99374
  function text(value) {
99368
99375
  return typeof value === "string" ? value : void 0;
99369
99376
  }
99377
+ var AppSessionError = class extends Error {
99378
+ };
99370
99379
  function openedByApp(session, appId) {
99371
99380
  if (session.origin_app_id !== appId) return false;
99372
99381
  return session.origin_app_workspace !== null || !isInAppFolder(session.cwd);
@@ -99458,6 +99467,33 @@ function appSessionInfo(appId, sessionId) {
99458
99467
  } : null
99459
99468
  };
99460
99469
  }
99470
+ function ownSession(appId, sessionId, api) {
99471
+ const session = getDb().prepare("SELECT * FROM sessions WHERE id = ?").get(String(sessionId));
99472
+ if (!session || !openedByApp(session, appId)) {
99473
+ throw new AppSessionError(`${api}: ${String(sessionId)} is not a session of this app`);
99474
+ }
99475
+ return session;
99476
+ }
99477
+ async function cancelAppTurn(appId, sessionId) {
99478
+ const session = ownSession(appId, sessionId, "cancelTurn");
99479
+ const live = getDb().prepare(`SELECT 1 FROM turns WHERE session_id = ? AND thread_id IS NULL AND status IN ('pending', 'running') LIMIT 1`).get(session.id);
99480
+ if (!live) return { cancelled: false };
99481
+ return { cancelled: await getProvider(session.runtime_type).interruptTurn(session.id) };
99482
+ }
99483
+ function setAppSessionLifecycle(appId, sessionId, lifecycle) {
99484
+ const session = ownSession(appId, sessionId, "setSessionLifecycle");
99485
+ if (lifecycle !== "working" && lifecycle !== "finished") {
99486
+ throw new Error(`setSessionLifecycle: lifecycle must be 'working' or 'finished'`);
99487
+ }
99488
+ const db2 = getDb();
99489
+ db2.prepare("UPDATE sessions SET lifecycle = ?, updated_at = ? WHERE id = ?").run(
99490
+ lifecycle,
99491
+ (/* @__PURE__ */ new Date()).toISOString(),
99492
+ session.id
99493
+ );
99494
+ broadcast("session:updated", { session: db2.prepare("SELECT * FROM sessions WHERE id = ?").get(session.id) });
99495
+ return { lifecycle };
99496
+ }
99461
99497
  function toolCaller(appId, sessionId) {
99462
99498
  if (!sessionId) return null;
99463
99499
  const session = getDb().prepare("SELECT * FROM sessions WHERE id = ?").get(sessionId);
@@ -99541,7 +99577,12 @@ function lintAppSources(files, manifestIcon) {
99541
99577
  var APP_TS = "app.ts";
99542
99578
  var BRIDGE_DTS_FILE = "agentpane.d.ts";
99543
99579
  var BRIDGE_DTS = `/** AgentPane bridge \u2014 typed contract for mini apps (ambient, no import). */
99544
- interface AgentPaneAppInfo { id: string; title?: string }
99580
+ interface AgentPaneAppInfo {
99581
+ id: string;
99582
+ title?: string;
99583
+ /** Folder of this instance ('' = global). Absent on older panes. */
99584
+ workspace?: string;
99585
+ }
99545
99586
  interface AgentPaneState {
99546
99587
  pinned: boolean;
99547
99588
  data: Record<string, unknown> | null;
@@ -99660,6 +99701,23 @@ declare const AgentPane: {
99660
99701
  submitTurn(sessionId: string, prompt: string, opts?: AgentPaneSubmitTurnOptions): Promise<unknown>;
99661
99702
  /** One of this app's sessions, null for any other id. Works headless too. */
99662
99703
  getSession(sessionId: string): Promise<AgentPaneSessionState | null>;
99704
+ /** Stop the running main turn of one of this app's sessions; cancelled is
99705
+ * false when none runs. Rejects for any other session. */
99706
+ cancelTurn(sessionId: string): Promise<{ cancelled: boolean }>;
99707
+ /** Finish or reopen one of this app's sessions, as the sidebar does. Rejects
99708
+ * for any other session. */
99709
+ setSessionLifecycle(sessionId: string, lifecycle: 'working' | 'finished'): Promise<{ lifecycle: 'working' | 'finished' }>;
99710
+ /** Tab only: run one of this app's manifest tools; it is answered like an
99711
+ * agent's call, with no caller. A sandboxed tab has no way to the API of its
99712
+ * own, and this is how it gets the headless runtime to do something. */
99713
+ callTool?(tool: string, args?: Record<string, unknown>): Promise<unknown>;
99714
+ /** Tab only: the runtimes this pane offers, as /api/providers lists them. */
99715
+ listProviders?(): Promise<unknown[]>;
99716
+ /** Tab only: a runtime's models; cwd for runtimes that list per workspace. */
99717
+ listModels?(runtime: string, cwd?: string): Promise<unknown[]>;
99718
+ /** Tab only, and only while the app is on screen, so call it from a click
99719
+ * handler: the folder dialog of the machine the pane runs on. */
99720
+ pickDirectory?(): Promise<{ path?: string; cancelled?: boolean }>;
99663
99721
  onTurnCompleted(cb: (event: 'turn:completed' | 'turn:failed', payload: AgentPaneTurnPayload | null) => void): void;
99664
99722
  onTurnDelta(cb: (payload: AgentPaneDeltaPayload) => void): void;
99665
99723
  onToolCall(cb: (payload: AgentPaneToolCallPayload) => void): void;
@@ -99964,7 +100022,7 @@ function loadRuntime(appId, workspace) {
99964
100022
  };
99965
100023
  const entry = { handler: null, turnListeners: [], taskListeners: [] };
99966
100024
  const bridge = {
99967
- getApp: () => answer(() => ({ id: appId, title: manifest?.title ?? appId })),
100025
+ getApp: () => answer(() => ({ id: appId, title: manifest?.title ?? appId, workspace })),
99968
100026
  // State is scoped to the calling session's workspace instance; '' = global
99969
100027
  // (no known workspace). The open tab keeps its own workspace-scoped view.
99970
100028
  getState: () => answer(() => getInstanceState(appId, workspace)),
@@ -100020,6 +100078,14 @@ function loadRuntime(appId, workspace) {
100020
100078
  requireHeadlessSessions("submitTurn");
100021
100079
  return submitAppTurn(appId, sessionId, prompt, opts);
100022
100080
  }),
100081
+ cancelTurn: (sessionId) => answer(() => {
100082
+ requireHeadlessSessions("cancelTurn");
100083
+ return cancelAppTurn(appId, sessionId);
100084
+ }),
100085
+ setSessionLifecycle: (sessionId, lifecycle) => answer(() => {
100086
+ requireHeadlessSessions("setSessionLifecycle");
100087
+ return setAppSessionLifecycle(appId, sessionId, lifecycle);
100088
+ }),
100023
100089
  onTurnCompleted: (cb) => {
100024
100090
  if (typeof cb === "function") entry.turnListeners.push(cb);
100025
100091
  },
@@ -100623,6 +100689,41 @@ async function registerAppRoutes(fastify, opts) {
100623
100689
  return session;
100624
100690
  }
100625
100691
  );
100692
+ fastify.post(
100693
+ "/api/apps/:id/sessions/:sessionId/cancel",
100694
+ async (request, reply) => {
100695
+ const { id, sessionId } = request.params;
100696
+ if (!APP_ID_RE.test(id)) return reply.code(400).send({ error: "Invalid app id" });
100697
+ try {
100698
+ return await cancelAppTurn(id, sessionId);
100699
+ } catch (err) {
100700
+ if (err instanceof AppSessionError) return reply.code(404).send({ error: err.message });
100701
+ throw err;
100702
+ }
100703
+ }
100704
+ );
100705
+ fastify.patch(
100706
+ "/api/apps/:id/sessions/:sessionId",
100707
+ {
100708
+ schema: {
100709
+ body: {
100710
+ type: "object",
100711
+ required: ["lifecycle"],
100712
+ properties: { lifecycle: { type: "string", enum: ["working", "finished"] } }
100713
+ }
100714
+ }
100715
+ },
100716
+ async (request, reply) => {
100717
+ const { id, sessionId } = request.params;
100718
+ if (!APP_ID_RE.test(id)) return reply.code(400).send({ error: "Invalid app id" });
100719
+ try {
100720
+ return setAppSessionLifecycle(id, sessionId, request.body.lifecycle);
100721
+ } catch (err) {
100722
+ if (err instanceof AppSessionError) return reply.code(404).send({ error: err.message });
100723
+ throw err;
100724
+ }
100725
+ }
100726
+ );
100626
100727
  fastify.post(
100627
100728
  "/api/apps/:id/edit-session",
100628
100729
  {
@@ -102874,14 +102975,23 @@ function trackResumeFrame(entry, message, db2) {
102874
102975
  clearResume(entry);
102875
102976
  return true;
102876
102977
  }
102877
- if (r.phase === "awaiting_rescue") {
102978
+ if (r.phase !== "continuing") {
102878
102979
  if (message.resume_reason) {
102879
102980
  if (r.watchdog) clearTimeout(r.watchdog);
102880
102981
  r.watchdog = null;
102881
102982
  r.phase = "continuing";
102882
102983
  } else {
102883
- if (message.type === "result") return false;
102884
- if (message.type === "system") {
102984
+ if (message.type === "result") {
102985
+ r.phase = "awaiting_rescue";
102986
+ armRescueWatchdog(entry);
102987
+ return false;
102988
+ }
102989
+ if (isModelFrame(message)) {
102990
+ if (r.watchdog) clearTimeout(r.watchdog);
102991
+ r.watchdog = null;
102992
+ r.phase = "rescuing";
102993
+ markTurnResumed(db2, r.turnId);
102994
+ } else if (message.type === "system") {
102885
102995
  const sub = message.subtype;
102886
102996
  if (sub === "api_retry" || sub === "status") armRescueWatchdog(entry);
102887
102997
  }
@@ -98888,12 +98888,18 @@ Icons come from ONE library: Lucide (https://lucide.dev/icons, ISC).
98888
98888
 
98889
98889
  ## Bridge API (window.AgentPane)
98890
98890
 
98891
- - getApp() - app info (id, title)
98891
+ - getApp() - app info (id, title, workspace = the folder of this instance, '' = global)
98892
98892
  - getState() / setState(data, { ifVersion }?) - persistent JSON state, survives page reload; getState reads the stored copy on every call (see "Shared state" below)
98893
98893
  - onStateChanged(callback) - callback({ version }) when somebody else (an agent, another tab) wrote the state; not fired for this tab's own setState
98894
98894
  - createSession({ cwd, runtime_type, model, model_reasoning_effort, title }) - agent session owned by this app; model_reasoning_effort is the effort for its turns ("low" | "medium" | "high" | "xhigh" | "max" | "ultra", the levels the model supports), omitted = the runtime's default
98895
98895
  - submitTurn(sessionId, prompt, { attachments }?) - send a prompt to a session; attachments (optional) are stored files (id, url or the uploadFile result) or inline Blobs / { name, type, data } sent with that turn only; the agent sees attached images (Claude and Codex)
98896
98896
  - getSession(sessionId) - one of this app's sessions, also read headless: { id, title, status, running, backgroundTasks, lastTurn: { id, status, response, error, resumeState } | null }, null for any other id. A turn waiting to continue after an interruption has running true and resumeState 'waiting'
98897
+ - cancelTurn(sessionId) - stop the running main turn of one of this app's sessions: { cancelled }, false when none runs; a discussion thread keeps running; rejects for any other session
98898
+ - setSessionLifecycle(sessionId, 'finished' | 'working') - finish or reopen one of this app's sessions, as the sidebar does; rejects for any other session
98899
+ - callTool(tool, args) - tab only: run one of this app's manifest tools, by its bare name; it is answered like an agent's call, with caller null. The app's frame has an opaque origin and cannot fetch the pane's API, so this is how a tab gets the headless runtime to do something
98900
+ - listProviders() - tab only: the runtimes this pane offers, as /api/providers lists them (id, label, capability flags)
98901
+ - listModels(runtime, cwd?) - tab only: a runtime's models, as /api/providers/:id/models lists them; cwd for runtimes that list per workspace
98902
+ - pickDirectory() - tab only: the folder dialog of the machine the pane runs on: { path }, or { cancelled: true } when the user dismissed it; works only while the app is on screen, so call it from a click handler
98897
98903
  - onTurnCompleted(callback) - callback(event, { sessionId, turnId, response }) when a turn ends; event is 'turn:completed' or 'turn:failed' ({ sessionId, turnId, error })
98898
98904
  - onBackgroundTasks(callback) - callback({ sessionId, tasks }) when the live background-task set of one of the app's sessions changes (Monitor shells, backgrounded subagents); tasks is the CURRENT set, empty when none are left
98899
98905
  - onToolCall(callback) - callback({ callId, name, tool, args, caller }) when the AGENT calls one of the manifest tools (name and tool carry the same tool name); answer with resolveToolCall(callId, result). caller: see "Who called" below
@@ -98998,9 +99004,10 @@ Set "headlessSessions": true in manifest.json to run an app's agent work with
98998
99004
  no tab open. Without it, createSession/submitTurn reject in the headless
98999
99005
  runtime and events go to the open tab only.
99000
99006
 
99001
- - createSession and submitTurn work headless, from a tool handler or an event
99002
- callback. submitTurn reaches only sessions this app opened; attachments are
99003
- stored files or inline { name, type, data } (no Blobs in the sandbox)
99007
+ - createSession, submitTurn, cancelTurn and setSessionLifecycle work headless,
99008
+ from a tool handler or an event callback. All but createSession reach only
99009
+ sessions this app opened; attachments are stored files or inline
99010
+ { name, type, data } (no Blobs in the sandbox)
99004
99011
  - onTurnCompleted and onBackgroundTasks fire in the headless runtime, for every
99005
99012
  session of the app, also the ones its tab opened. They go to the instance
99006
99013
  that opened the session, and it loads again when it has to
@@ -99350,6 +99357,8 @@ function deleteAppFiles(appId) {
99350
99357
  function text(value) {
99351
99358
  return typeof value === "string" ? value : void 0;
99352
99359
  }
99360
+ var AppSessionError = class extends Error {
99361
+ };
99353
99362
  function openedByApp(session, appId) {
99354
99363
  if (session.origin_app_id !== appId) return false;
99355
99364
  return session.origin_app_workspace !== null || !isInAppFolder(session.cwd);
@@ -99441,6 +99450,33 @@ function appSessionInfo(appId, sessionId) {
99441
99450
  } : null
99442
99451
  };
99443
99452
  }
99453
+ function ownSession(appId, sessionId, api) {
99454
+ const session = getDb().prepare("SELECT * FROM sessions WHERE id = ?").get(String(sessionId));
99455
+ if (!session || !openedByApp(session, appId)) {
99456
+ throw new AppSessionError(`${api}: ${String(sessionId)} is not a session of this app`);
99457
+ }
99458
+ return session;
99459
+ }
99460
+ async function cancelAppTurn(appId, sessionId) {
99461
+ const session = ownSession(appId, sessionId, "cancelTurn");
99462
+ const live = getDb().prepare(`SELECT 1 FROM turns WHERE session_id = ? AND thread_id IS NULL AND status IN ('pending', 'running') LIMIT 1`).get(session.id);
99463
+ if (!live) return { cancelled: false };
99464
+ return { cancelled: await getProvider(session.runtime_type).interruptTurn(session.id) };
99465
+ }
99466
+ function setAppSessionLifecycle(appId, sessionId, lifecycle) {
99467
+ const session = ownSession(appId, sessionId, "setSessionLifecycle");
99468
+ if (lifecycle !== "working" && lifecycle !== "finished") {
99469
+ throw new Error(`setSessionLifecycle: lifecycle must be 'working' or 'finished'`);
99470
+ }
99471
+ const db2 = getDb();
99472
+ db2.prepare("UPDATE sessions SET lifecycle = ?, updated_at = ? WHERE id = ?").run(
99473
+ lifecycle,
99474
+ (/* @__PURE__ */ new Date()).toISOString(),
99475
+ session.id
99476
+ );
99477
+ broadcast("session:updated", { session: db2.prepare("SELECT * FROM sessions WHERE id = ?").get(session.id) });
99478
+ return { lifecycle };
99479
+ }
99444
99480
  function toolCaller(appId, sessionId) {
99445
99481
  if (!sessionId) return null;
99446
99482
  const session = getDb().prepare("SELECT * FROM sessions WHERE id = ?").get(sessionId);
@@ -99524,7 +99560,12 @@ function lintAppSources(files, manifestIcon) {
99524
99560
  var APP_TS = "app.ts";
99525
99561
  var BRIDGE_DTS_FILE = "agentpane.d.ts";
99526
99562
  var BRIDGE_DTS = `/** AgentPane bridge \u2014 typed contract for mini apps (ambient, no import). */
99527
- interface AgentPaneAppInfo { id: string; title?: string }
99563
+ interface AgentPaneAppInfo {
99564
+ id: string;
99565
+ title?: string;
99566
+ /** Folder of this instance ('' = global). Absent on older panes. */
99567
+ workspace?: string;
99568
+ }
99528
99569
  interface AgentPaneState {
99529
99570
  pinned: boolean;
99530
99571
  data: Record<string, unknown> | null;
@@ -99643,6 +99684,23 @@ declare const AgentPane: {
99643
99684
  submitTurn(sessionId: string, prompt: string, opts?: AgentPaneSubmitTurnOptions): Promise<unknown>;
99644
99685
  /** One of this app's sessions, null for any other id. Works headless too. */
99645
99686
  getSession(sessionId: string): Promise<AgentPaneSessionState | null>;
99687
+ /** Stop the running main turn of one of this app's sessions; cancelled is
99688
+ * false when none runs. Rejects for any other session. */
99689
+ cancelTurn(sessionId: string): Promise<{ cancelled: boolean }>;
99690
+ /** Finish or reopen one of this app's sessions, as the sidebar does. Rejects
99691
+ * for any other session. */
99692
+ setSessionLifecycle(sessionId: string, lifecycle: 'working' | 'finished'): Promise<{ lifecycle: 'working' | 'finished' }>;
99693
+ /** Tab only: run one of this app's manifest tools; it is answered like an
99694
+ * agent's call, with no caller. A sandboxed tab has no way to the API of its
99695
+ * own, and this is how it gets the headless runtime to do something. */
99696
+ callTool?(tool: string, args?: Record<string, unknown>): Promise<unknown>;
99697
+ /** Tab only: the runtimes this pane offers, as /api/providers lists them. */
99698
+ listProviders?(): Promise<unknown[]>;
99699
+ /** Tab only: a runtime's models; cwd for runtimes that list per workspace. */
99700
+ listModels?(runtime: string, cwd?: string): Promise<unknown[]>;
99701
+ /** Tab only, and only while the app is on screen, so call it from a click
99702
+ * handler: the folder dialog of the machine the pane runs on. */
99703
+ pickDirectory?(): Promise<{ path?: string; cancelled?: boolean }>;
99646
99704
  onTurnCompleted(cb: (event: 'turn:completed' | 'turn:failed', payload: AgentPaneTurnPayload | null) => void): void;
99647
99705
  onTurnDelta(cb: (payload: AgentPaneDeltaPayload) => void): void;
99648
99706
  onToolCall(cb: (payload: AgentPaneToolCallPayload) => void): void;
@@ -99947,7 +100005,7 @@ function loadRuntime(appId, workspace) {
99947
100005
  };
99948
100006
  const entry = { handler: null, turnListeners: [], taskListeners: [] };
99949
100007
  const bridge = {
99950
- getApp: () => answer(() => ({ id: appId, title: manifest?.title ?? appId })),
100008
+ getApp: () => answer(() => ({ id: appId, title: manifest?.title ?? appId, workspace })),
99951
100009
  // State is scoped to the calling session's workspace instance; '' = global
99952
100010
  // (no known workspace). The open tab keeps its own workspace-scoped view.
99953
100011
  getState: () => answer(() => getInstanceState(appId, workspace)),
@@ -100003,6 +100061,14 @@ function loadRuntime(appId, workspace) {
100003
100061
  requireHeadlessSessions("submitTurn");
100004
100062
  return submitAppTurn(appId, sessionId, prompt, opts);
100005
100063
  }),
100064
+ cancelTurn: (sessionId) => answer(() => {
100065
+ requireHeadlessSessions("cancelTurn");
100066
+ return cancelAppTurn(appId, sessionId);
100067
+ }),
100068
+ setSessionLifecycle: (sessionId, lifecycle) => answer(() => {
100069
+ requireHeadlessSessions("setSessionLifecycle");
100070
+ return setAppSessionLifecycle(appId, sessionId, lifecycle);
100071
+ }),
100006
100072
  onTurnCompleted: (cb) => {
100007
100073
  if (typeof cb === "function") entry.turnListeners.push(cb);
100008
100074
  },
@@ -100606,6 +100672,41 @@ async function registerAppRoutes(fastify, opts) {
100606
100672
  return session;
100607
100673
  }
100608
100674
  );
100675
+ fastify.post(
100676
+ "/api/apps/:id/sessions/:sessionId/cancel",
100677
+ async (request, reply) => {
100678
+ const { id, sessionId } = request.params;
100679
+ if (!APP_ID_RE.test(id)) return reply.code(400).send({ error: "Invalid app id" });
100680
+ try {
100681
+ return await cancelAppTurn(id, sessionId);
100682
+ } catch (err) {
100683
+ if (err instanceof AppSessionError) return reply.code(404).send({ error: err.message });
100684
+ throw err;
100685
+ }
100686
+ }
100687
+ );
100688
+ fastify.patch(
100689
+ "/api/apps/:id/sessions/:sessionId",
100690
+ {
100691
+ schema: {
100692
+ body: {
100693
+ type: "object",
100694
+ required: ["lifecycle"],
100695
+ properties: { lifecycle: { type: "string", enum: ["working", "finished"] } }
100696
+ }
100697
+ }
100698
+ },
100699
+ async (request, reply) => {
100700
+ const { id, sessionId } = request.params;
100701
+ if (!APP_ID_RE.test(id)) return reply.code(400).send({ error: "Invalid app id" });
100702
+ try {
100703
+ return setAppSessionLifecycle(id, sessionId, request.body.lifecycle);
100704
+ } catch (err) {
100705
+ if (err instanceof AppSessionError) return reply.code(404).send({ error: err.message });
100706
+ throw err;
100707
+ }
100708
+ }
100709
+ );
100609
100710
  fastify.post(
100610
100711
  "/api/apps/:id/edit-session",
100611
100712
  {
@@ -102857,14 +102958,23 @@ function trackResumeFrame(entry, message, db2) {
102857
102958
  clearResume(entry);
102858
102959
  return true;
102859
102960
  }
102860
- if (r.phase === "awaiting_rescue") {
102961
+ if (r.phase !== "continuing") {
102861
102962
  if (message.resume_reason) {
102862
102963
  if (r.watchdog) clearTimeout(r.watchdog);
102863
102964
  r.watchdog = null;
102864
102965
  r.phase = "continuing";
102865
102966
  } else {
102866
- if (message.type === "result") return false;
102867
- if (message.type === "system") {
102967
+ if (message.type === "result") {
102968
+ r.phase = "awaiting_rescue";
102969
+ armRescueWatchdog(entry);
102970
+ return false;
102971
+ }
102972
+ if (isModelFrame(message)) {
102973
+ if (r.watchdog) clearTimeout(r.watchdog);
102974
+ r.watchdog = null;
102975
+ r.phase = "rescuing";
102976
+ markTurnResumed(db2, r.turnId);
102977
+ } else if (message.type === "system") {
102868
102978
  const sub = message.subtype;
102869
102979
  if (sub === "api_retry" || sub === "status") armRescueWatchdog(entry);
102870
102980
  }
@@ -1,4 +1,4 @@
1
- var en=Object.defineProperty;var tn=(e,t,i)=>t in e?en(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var Ye=(e,t,i)=>tn(e,typeof t!="symbol"?t+"":t,i);import{c as sn,b as rn,u as gi,r as lt,j as Ee,R as nn,X as on}from"./index-DUYM-Bsm.js";/**
1
+ var en=Object.defineProperty;var tn=(e,t,i)=>t in e?en(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var Ye=(e,t,i)=>tn(e,typeof t!="symbol"?t+"":t,i);import{c as sn,b as rn,u as gi,r as lt,j as Ee,R as nn,X as on}from"./index-DumuprBy.js";/**
2
2
  * @license lucide-react v0.469.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.