@hosty-sdk/app 0.57.0 → 0.58.0

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
@@ -643,6 +643,13 @@ reporters get immediate submission confirmation but no processing inbox or notif
643
643
  See [App Feedback Inbox](../../docs/features/app-feedback-inbox/feature.md) for limits, access,
644
644
  manual chat dispatch, exact-prompt outcomes and workspace deletion retention.
645
645
 
646
+ ## Workspace review links
647
+
648
+ Mark one manifest `ui.navigation` entry with `workspaceReview: true` to let Shell open a workspace
649
+ from Storage. Read the opaque workspace ID from the page's `workspace` query parameter. The
650
+ installed app needs the reviewed `apps.workspaces.read` permission and the user needs app access.
651
+ Use the normal authenticated workspace API when loading the review.
652
+
646
653
  ## Child Core sandbox controls
647
654
 
648
655
  `@hosty-sdk/app/sandbox/react` exports `CoreEnvironmentPanel` for operator-facing child Core
@@ -50,7 +50,9 @@ export declare class AgentClient {
50
50
  startRun(sessionId: string, runId: string, input: AgentRunInput, options?: AgentRequestOptions): Promise<AgentRunSnapshot>;
51
51
  run(runId: string, options?: AgentRequestOptions): Promise<AgentRunSnapshot>;
52
52
  closure(runId: string, options?: AgentRequestOptions): Promise<import("./agent.js").AgentRunClosure>;
53
- discardDelivery(runId: string, requestId: string, options?: AgentRequestOptions): Promise<import("./agent.js").AgentDiscardReceipt>;
53
+ discardDelivery(runId: string, requestId: string, options?: AgentRequestOptions & {
54
+ deleteNativeContext?: true;
55
+ }): Promise<import("./agent.js").AgentDiscardReceipt>;
54
56
  respond(runId: string, input: AgentResponseInput, options?: AgentRequestOptions): Promise<AgentControlReceipt>;
55
57
  stop(runId: string, requestId?: string, options?: AgentRequestOptions): Promise<AgentControlReceipt>;
56
58
  cancel(runId: string, input: AgentCancelInput, options?: AgentRequestOptions): Promise<AgentControlReceipt>;
@@ -117,9 +117,9 @@ export class AgentClient {
117
117
  return value;
118
118
  }
119
119
  async discardDelivery(runId, requestId, options) {
120
- const command = prepareAgentRequest("runs.discard", "PUT", `/runs/${segment(runId)}/discard`, { requestId }, { runId });
120
+ const command = prepareAgentRequest("runs.discard", "PUT", `/runs/${segment(runId)}/discard`, { requestId, ...(options?.deleteNativeContext ? { deleteNativeContext: true } : {}) }, { runId });
121
121
  const value = await this.execute(command, options);
122
- if (value?.requestId !== requestId || value.runId !== runId || value.state !== "discarded")
122
+ if (value?.requestId !== requestId || value.runId !== runId || value.state !== "discarded" || options?.deleteNativeContext && value.nativeContextDeleted !== true)
123
123
  throw new AgentApiError("response_invalid", "The provider returned a different discard receipt.", 502);
124
124
  return value;
125
125
  }
@@ -47,8 +47,8 @@ export const AGENT_SCHEMAS = {
47
47
  DecisionResponse: { oneOf: [object({ kind: { const: "approval" }, decision: { enum: ["allow", "deny"] }, message: { type: "string", maxLength: 65536 } }, ["kind", "decision"]),
48
48
  object({ kind: { const: "question" }, answers: { type: "object", maxProperties: 128, propertyNames: id, additionalProperties: { oneOf: [{ type: "string", maxLength: 65536 }, list({ type: "string", maxLength: 65536 }, 128)] } } })] },
49
49
  ResponseInput: object({ ...baseControl, decisionId: id, decisionRevision: revision, response: ref("DecisionResponse") }),
50
- DiscardInput: object({ requestId: uuid }),
51
- DiscardReceipt: object({ requestId: uuid, runId: uuid, state: { const: "discarded" } }),
50
+ DiscardInput: object({ requestId: uuid, deleteNativeContext: { const: true } }, ["requestId"]),
51
+ DiscardReceipt: object({ requestId: uuid, runId: uuid, state: { const: "discarded" }, nativeContextDeleted: { const: true } }, ["requestId", "runId", "state"]),
52
52
  CancelInput: { oneOf: [object({ requestId: uuid }), object(baseControl), object({ requestId: uuid, fenceIfNotAdmitted: object({ sessionId: id, startDigest: digest }) })] },
53
53
  ControlInput: { oneOf: [
54
54
  object({ ...baseControl, command: { const: "park" }, decisionId: id, decisionRevision: revision, reason: text(8192) }, [...Object.keys(baseControl), "command", "decisionId", "decisionRevision"]),
@@ -31,6 +31,7 @@ export type AgentParsedRequest = AgentParsedBase & ({
31
31
  operation: "runs.discard";
32
32
  input: {
33
33
  requestId: string;
34
+ deleteNativeContext?: true;
34
35
  };
35
36
  } | {
36
37
  operation: "runs.cancel";
@@ -392,7 +392,9 @@ export function validateAgentRequest(method, path, body, expectedOperation) {
392
392
  else if (operation === "runs.respond")
393
393
  validateAgentResponseInput(input);
394
394
  else if (operation === "runs.discard") {
395
- shape(input, ["requestId"], "delivery discard");
395
+ shape(input, ["requestId", "deleteNativeContext"], "delivery discard");
396
+ if (input.deleteNativeContext !== undefined && input.deleteNativeContext !== true)
397
+ fail("Native context removal requires explicit confirmation.");
396
398
  if (!uuid(input.requestId))
397
399
  fail("A discard request UUID is required.");
398
400
  }
package/dist/agent.d.ts CHANGED
@@ -375,6 +375,7 @@ export type AgentDiscardReceipt = {
375
375
  requestId: string;
376
376
  runId: string;
377
377
  state: "discarded";
378
+ nativeContextDeleted?: true;
378
379
  };
379
380
  export type AgentRunClosure = Pick<AgentRunSnapshot, "ref" | "sessionId" | "generation" | "revision" | "state" | "phase" | "stopConfirmed" | "writerScopeClosed" | "pendingContinuations">;
380
381
  export type AgentApprovalResponse = {
@@ -1,5 +1,5 @@
1
1
  /** Provider categories supported by Core. Task execution does not expose model/profile configuration. */
2
- export type ProviderKind = "agent" | "speech-to-text" | "text-to-speech" | "assistant" | "translation" | "tasks" | "task-executor" | "conversation-history" | "agent-sessions";
2
+ export type ProviderKind = "agent" | "speech-to-text" | "text-to-speech" | "assistant" | "translation" | "tasks" | "task-executor" | "conversation-history" | "agent-sessions" | "storage-maintenance";
3
3
  export type ProviderDescriptor = {
4
4
  appId: string;
5
5
  displayName: string;
@@ -218,3 +218,81 @@ export type TaskWorkflowRequest = Omit<TaskWorkflowBinding, "rootTaskRef"> & {
218
218
  operation: "create_child" | "edit" | "read" | "action" | "observe" | "bind_session" | "prepare_source" | "bind_source" | "observe_source";
219
219
  payload: Record<string, unknown>;
220
220
  };
221
+ /** Core-mediated storage-maintenance v1 request and result shapes for an owning app. */
222
+ export type StorageCleanupMode = "cache" | "recoverable" | "optional";
223
+ export type StorageCleanupPreviewRequest = {
224
+ installationId: string;
225
+ groupId: string;
226
+ mode: StorageCleanupMode;
227
+ };
228
+ export type StorageCleanupApplyRequest = StorageCleanupPreviewRequest & {
229
+ planDigest: string;
230
+ requestId: string;
231
+ };
232
+ export type StorageCleanupPreview = {
233
+ groupId: string;
234
+ planDigest: string;
235
+ eligibleBytes: number;
236
+ eligibleFiles: number;
237
+ };
238
+ export type StorageCleanupResult = {
239
+ groupId: string;
240
+ requestId: string;
241
+ removedBytes: number;
242
+ removedFiles: number;
243
+ skippedFiles: number;
244
+ };
245
+ export type StorageMaintenanceTrigger = "age" | "size" | "pressure" | "generations";
246
+ export type StorageMaintenancePolicy = {
247
+ intervalMinutes: number;
248
+ maxFiles: number;
249
+ maxBytes: number;
250
+ minAgeHours?: number | null;
251
+ highBytes?: number | null;
252
+ lowBytes?: number | null;
253
+ pressureLowBytes?: number | null;
254
+ pressureHighBytes?: number | null;
255
+ keepGenerations?: number | null;
256
+ };
257
+ export type StoragePolicyObservation = {
258
+ policy: StorageMaintenancePolicy;
259
+ observedAt: string;
260
+ availableBytes: number | null;
261
+ };
262
+ export type StoragePolicyPreviewRequest = Omit<StorageCleanupPreviewRequest, "mode"> & {
263
+ mode: "cache";
264
+ } & StoragePolicyObservation;
265
+ export type StoragePolicyApplyRequest = Omit<StorageCleanupApplyRequest, "mode"> & {
266
+ mode: "cache";
267
+ } & StoragePolicyObservation;
268
+ export type StoragePolicyPreview = {
269
+ groupId: string;
270
+ state: "eligible" | "no_candidates" | "blocked" | "protected";
271
+ planDigest?: string;
272
+ eligibleFiles: number | null;
273
+ eligibleBytes: number | null;
274
+ reason?: string;
275
+ protectedFiles?: number;
276
+ busyFiles?: number;
277
+ wantedFiles?: number;
278
+ };
279
+ /** The owner supplies candidates from its complete bounded inventory, using a monotonic
280
+ * generation number if offered. Account for pinned, wanted and open entries in total size. */
281
+ export type StoragePolicyCandidate = {
282
+ id: string;
283
+ bytes: number;
284
+ lastUsedAt: number;
285
+ generation?: number;
286
+ availability?: "available" | "protected" | "busy" | "wanted";
287
+ };
288
+ export declare function isStorageMaintenancePolicy(value: unknown, triggers: readonly StorageMaintenanceTrigger[]): value is StorageMaintenancePolicy;
289
+ /** Compute an owner-side review from exact observations before deciding whether to mutate.
290
+ * Re-run under the reader/writer lease and preserve the candidate identities in the receipt. */
291
+ export declare function selectStoragePolicyCandidates<T extends StoragePolicyCandidate>(candidates: readonly T[], observation: StoragePolicyObservation): {
292
+ eligible: T[];
293
+ eligibleBytes: number;
294
+ protectedFiles: number;
295
+ busyFiles: number;
296
+ wantedFiles: number;
297
+ pressureUnavailable: boolean;
298
+ };
package/dist/providers.js CHANGED
@@ -51,3 +51,71 @@ export function resolveSpeechTargetLanguage(requested, preferences, capabilities
51
51
  throw new ProviderError("speech_target_language_unsupported", "The selected speech provider does not support this target language.", 400);
52
52
  return undefined;
53
53
  }
54
+ const between = (value, min, max) => typeof value === "number" && Number.isSafeInteger(value) && value >= min && value <= max;
55
+ const threshold = 1_125_899_906_842_624;
56
+ const watermarks = (low, high) => (low == null && high == null) || between(low, 0, threshold) && between(high, 1, threshold) && low < high;
57
+ export function isStorageMaintenancePolicy(value, triggers) {
58
+ if (!value || typeof value !== "object")
59
+ return false;
60
+ const policy = value;
61
+ if (!between(policy.intervalMinutes, 60, 10080) || !between(policy.maxFiles, 1, 4096) || !between(policy.maxBytes, 1, 8_589_934_592)
62
+ || !watermarks(policy.lowBytes, policy.highBytes) || !watermarks(policy.pressureLowBytes, policy.pressureHighBytes))
63
+ return false;
64
+ if (policy.minAgeHours != null && (!between(policy.minAgeHours, 1, 8760) || !triggers.includes("age")))
65
+ return false;
66
+ if (policy.keepGenerations != null && (!between(policy.keepGenerations, 1, 512) || !triggers.includes("generations")))
67
+ return false;
68
+ if (policy.highBytes != null && !triggers.includes("size") || policy.pressureLowBytes != null && !triggers.includes("pressure"))
69
+ return false;
70
+ return policy.minAgeHours != null || policy.highBytes != null || policy.pressureLowBytes != null || policy.keepGenerations != null;
71
+ }
72
+ /** Compute an owner-side review from exact observations before deciding whether to mutate.
73
+ * Re-run under the reader/writer lease and preserve the candidate identities in the receipt. */
74
+ export function selectStoragePolicyCandidates(candidates, observation) {
75
+ const policy = observation.policy;
76
+ const now = Date.parse(observation.observedAt);
77
+ let pressure = observation.availableBytes;
78
+ let total = candidates.reduce((bytes, entry) => bytes + entry.bytes, 0);
79
+ if (!Number.isFinite(now) || !Number.isSafeInteger(total)
80
+ || candidates.some(entry => !between(entry.bytes, 0, Number.MAX_SAFE_INTEGER) || !Number.isFinite(entry.lastUsedAt)))
81
+ throw new RangeError("Invalid storage inventory.");
82
+ if (pressure != null && !between(pressure, 0, Number.MAX_SAFE_INTEGER))
83
+ pressure = null;
84
+ const belowPressure = pressure != null && policy.pressureLowBytes != null && pressure < policy.pressureLowBytes;
85
+ const aboveSize = policy.highBytes != null && total > policy.highBytes;
86
+ const expireBefore = policy.minAgeHours == null ? null : now - policy.minAgeHours * 3_600_000;
87
+ const generations = new Set(candidates.map(entry => entry.generation).filter((value) => between(value, 0, Number.MAX_SAFE_INTEGER)));
88
+ const keep = new Set([...generations].sort((a, b) => b - a).slice(0, policy.keepGenerations ?? 0));
89
+ const summary = { eligible: [], eligibleBytes: 0, protectedFiles: 0, busyFiles: 0, wantedFiles: 0,
90
+ pressureUnavailable: policy.pressureLowBytes != null && pressure === null };
91
+ const ordered = [...candidates].sort((a, b) => a.lastUsedAt - b.lastUsedAt || (a.id < b.id ? -1 : Number(a.id > b.id)));
92
+ for (const entry of ordered) {
93
+ if (entry.availability === "busy") {
94
+ summary.busyFiles++;
95
+ continue;
96
+ }
97
+ if (entry.availability === "wanted") {
98
+ summary.wantedFiles++;
99
+ continue;
100
+ }
101
+ const hasGeneration = entry.generation != null && generations.has(entry.generation);
102
+ if (entry.availability === "protected" || policy.keepGenerations != null && (!hasGeneration || keep.has(entry.generation))) {
103
+ summary.protectedFiles++;
104
+ continue;
105
+ }
106
+ if (summary.eligible.length >= policy.maxFiles || entry.bytes > policy.maxBytes - summary.eligibleBytes)
107
+ continue;
108
+ const age = expireBefore !== null && entry.lastUsedAt <= expireBefore;
109
+ const generation = policy.keepGenerations != null && hasGeneration;
110
+ const size = aboveSize && total > policy.lowBytes;
111
+ const disk = belowPressure && pressure < policy.pressureHighBytes;
112
+ if (!age && !generation && !(entry.bytes > 0 && (size || disk)))
113
+ continue;
114
+ summary.eligible.push(entry);
115
+ summary.eligibleBytes += entry.bytes;
116
+ total -= entry.bytes;
117
+ if (pressure !== null)
118
+ pressure += entry.bytes;
119
+ }
120
+ return summary;
121
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hosty-sdk/app",
3
- "version": "0.57.0",
3
+ "version": "0.58.0",
4
4
  "description": "Hosty app auth: session state machine, recovery bridge, Core revalidation, and the embedder responder.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "type": "module",
@@ -830,6 +830,9 @@
830
830
  "requestId": {
831
831
  "type": "string",
832
832
  "format": "uuid"
833
+ },
834
+ "deleteNativeContext": {
835
+ "const": true
833
836
  }
834
837
  },
835
838
  "required": [
@@ -850,6 +853,9 @@
850
853
  },
851
854
  "state": {
852
855
  "const": "discarded"
856
+ },
857
+ "nativeContextDeleted": {
858
+ "const": true
853
859
  }
854
860
  },
855
861
  "required": [
@@ -4393,6 +4393,9 @@
4393
4393
  "requestId": {
4394
4394
  "type": "string",
4395
4395
  "format": "uuid"
4396
+ },
4397
+ "deleteNativeContext": {
4398
+ "const": true
4396
4399
  }
4397
4400
  },
4398
4401
  "required": [
@@ -4413,6 +4416,9 @@
4413
4416
  },
4414
4417
  "state": {
4415
4418
  "const": "discarded"
4419
+ },
4420
+ "nativeContextDeleted": {
4421
+ "const": true
4416
4422
  }
4417
4423
  },
4418
4424
  "required": [