@hosty-sdk/app 0.56.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 +15 -0
- package/dist/agent-client.d.ts +3 -1
- package/dist/agent-client.js +2 -2
- package/dist/agent-schemas.js +2 -2
- package/dist/agent-server.d.ts +1 -0
- package/dist/agent-server.js +3 -1
- package/dist/agent.d.ts +1 -0
- package/dist/providers-server.d.ts +1 -1
- package/dist/providers-server.js +6 -3
- package/dist/providers.d.ts +94 -1
- package/dist/providers.js +111 -0
- package/package.json +1 -1
- package/schemas/agent-event-v1.schema.json +6 -0
- package/schemas/agent-v2.openapi.json +6 -0
package/README.md
CHANGED
|
@@ -310,6 +310,14 @@ static and named entries. Keep the installation, key and implementation ID with
|
|
|
310
310
|
`displayName` is the current human-readable label. Pass the selection to `speechCapabilities`
|
|
311
311
|
and `transcribe`, or to `textToSpeechCapabilities` and `synthesize(selected, { text }, signal)`.
|
|
312
312
|
Synthesis returns a streaming fetch Response. Abort or cancel its body to stop the request.
|
|
313
|
+
|
|
314
|
+
For translated read-aloud, call `resolveSpeechTargetLanguage(requested, preferences, capabilities)`
|
|
315
|
+
from `@hosty-sdk/app/providers` before playback and pass the returned tag as `targetLanguage`
|
|
316
|
+
to `synthesize`. The resolver checks an explicit target first, then the acting user's
|
|
317
|
+
`{ preferredLanguage, autoTranslateReadAloud }` preferences. An unsupported explicit target raises
|
|
318
|
+
`speech_target_language_unsupported`. An unavailable automatic target resolves to `undefined`,
|
|
319
|
+
which retains the original-language request. Reuse the resolved target for all chunks of one
|
|
320
|
+
playback.
|
|
313
321
|
The provider backend publishes with `publishImplementations` and resolves the exact implementation
|
|
314
322
|
from `validate` on each request. See the [app manifest guide](../../skills/hosty-app-skill/references/app-manifest.md#named-provider-implementations).
|
|
315
323
|
|
|
@@ -635,6 +643,13 @@ reporters get immediate submission confirmation but no processing inbox or notif
|
|
|
635
643
|
See [App Feedback Inbox](../../docs/features/app-feedback-inbox/feature.md) for limits, access,
|
|
636
644
|
manual chat dispatch, exact-prompt outcomes and workspace deletion retention.
|
|
637
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
|
+
|
|
638
653
|
## Child Core sandbox controls
|
|
639
654
|
|
|
640
655
|
`@hosty-sdk/app/sandbox/react` exports `CoreEnvironmentPanel` for operator-facing child Core
|
package/dist/agent-client.d.ts
CHANGED
|
@@ -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
|
|
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>;
|
package/dist/agent-client.js
CHANGED
|
@@ -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
|
}
|
package/dist/agent-schemas.js
CHANGED
|
@@ -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"]),
|
package/dist/agent-server.d.ts
CHANGED
package/dist/agent-server.js
CHANGED
|
@@ -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 = {
|
|
@@ -46,7 +46,7 @@ export declare class ProviderClient {
|
|
|
46
46
|
timeoutMs?: number;
|
|
47
47
|
}): Promise<SpeechResult>;
|
|
48
48
|
textToSpeechCapabilities(provider: ProviderSelection, signal?: AbortSignal): Promise<TextToSpeechCapabilities>;
|
|
49
|
-
/** Stream 24 kHz mono
|
|
49
|
+
/** Stream 24 kHz mono PCM using a target resolved against the selected implementation, when provided. Cancel the signal or response body to stop. */
|
|
50
50
|
synthesize(provider: ProviderSelection, input: SpeechSynthesisRequest, signal?: AbortSignal): Promise<Response>;
|
|
51
51
|
translationCapabilities(provider: ProviderSelection, signal?: AbortSignal, options?: {
|
|
52
52
|
connection: {
|
package/dist/providers-server.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { Agent, fetch as speechFetch } from "undici";
|
|
3
3
|
import { AssistantClient } from "@hosty-sdk/app/assistant";
|
|
4
|
-
import { ProviderError } from "@hosty-sdk/app/providers";
|
|
4
|
+
import { normalizeLanguageTag, ProviderError } from "@hosty-sdk/app/providers";
|
|
5
5
|
/** Server-only provider client. Its app service token must never be sent to a browser or provider. */
|
|
6
6
|
export class ProviderClient {
|
|
7
7
|
appId;
|
|
@@ -111,16 +111,19 @@ export class ProviderClient {
|
|
|
111
111
|
return read(await fetch(`${binding.url}/capabilities`, { redirect: "error", signal: signal ? AbortSignal.any([signal, deadline]) : deadline,
|
|
112
112
|
headers: { authorization: `Bearer ${binding.token}` } }));
|
|
113
113
|
}
|
|
114
|
-
/** Stream 24 kHz mono
|
|
114
|
+
/** Stream 24 kHz mono PCM using a target resolved against the selected implementation, when provided. Cancel the signal or response body to stop. */
|
|
115
115
|
async synthesize(provider, input, signal) {
|
|
116
116
|
if (typeof input.text !== "string" || !input.text.trim() || input.text.length > 4000)
|
|
117
117
|
throw new ProviderError("speech_text_invalid", "Provide between 1 and 4000 UTF-16 code units of text.", 400);
|
|
118
|
+
const targetLanguage = normalizeLanguageTag(input.targetLanguage)?.tag;
|
|
119
|
+
if (input.targetLanguage !== undefined && targetLanguage === undefined)
|
|
120
|
+
throw new ProviderError("speech_target_language_invalid", "Provide a valid target language tag.", 400);
|
|
118
121
|
const timeout = AbortSignal.timeout(300_000);
|
|
119
122
|
const deadline = signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
120
123
|
const binding = await this.connect({ ...provider, kind: "text-to-speech" }, deadline);
|
|
121
124
|
const response = await fetch(`${binding.url}/speech`, { method: "POST", redirect: "error", signal: deadline,
|
|
122
125
|
headers: { authorization: `Bearer ${binding.token}`, "content-type": "application/json", accept: "audio/pcm" },
|
|
123
|
-
body: JSON.stringify({ text: input.text }) });
|
|
126
|
+
body: JSON.stringify({ text: input.text, targetLanguage }) });
|
|
124
127
|
if (!response.ok)
|
|
125
128
|
await read(response);
|
|
126
129
|
if (!response.body || !/^audio\/pcm\s*;\s*rate=24000\s*$/i.test(response.headers.get("content-type") ?? "")) {
|
package/dist/providers.d.ts
CHANGED
|
@@ -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;
|
|
@@ -105,9 +105,17 @@ export type TextToSpeechCapabilities = {
|
|
|
105
105
|
maxCharacters: number;
|
|
106
106
|
backend: string;
|
|
107
107
|
ready: boolean;
|
|
108
|
+
supportsTranslation?: boolean;
|
|
109
|
+
/** When omitted by a translation-capable provider, there is no advertised language restriction. */
|
|
110
|
+
targetLanguages?: string[];
|
|
108
111
|
};
|
|
109
112
|
export type SpeechSynthesisRequest = {
|
|
110
113
|
text: string;
|
|
114
|
+
targetLanguage?: string;
|
|
115
|
+
};
|
|
116
|
+
export type SpeechLanguagePreferences = {
|
|
117
|
+
preferredLanguage?: string | null;
|
|
118
|
+
autoTranslateReadAloud?: boolean;
|
|
111
119
|
};
|
|
112
120
|
export type TranslationRequest = {
|
|
113
121
|
text: string;
|
|
@@ -138,6 +146,13 @@ export declare class ProviderError extends Error {
|
|
|
138
146
|
readonly status: number;
|
|
139
147
|
constructor(code: string, message: string, status: number);
|
|
140
148
|
}
|
|
149
|
+
/** @internal Shared language-tag validation for provider client and transport. */
|
|
150
|
+
export declare function normalizeLanguageTag(value: unknown): {
|
|
151
|
+
tag: string;
|
|
152
|
+
withoutRegion: string;
|
|
153
|
+
} | undefined;
|
|
154
|
+
/** Resolve the language once for playback using the selected implementation's capabilities. */
|
|
155
|
+
export declare function resolveSpeechTargetLanguage(requested: string | undefined, preferences: SpeechLanguagePreferences | undefined, capabilities: Pick<TextToSpeechCapabilities, "supportsTranslation" | "targetLanguages">): string | undefined;
|
|
141
156
|
/** Non-secret receipt reference. Only its reviewed source and executor installations can use it. */
|
|
142
157
|
export type TaskDispatchRef = {
|
|
143
158
|
userId: string;
|
|
@@ -203,3 +218,81 @@ export type TaskWorkflowRequest = Omit<TaskWorkflowBinding, "rootTaskRef"> & {
|
|
|
203
218
|
operation: "create_child" | "edit" | "read" | "action" | "observe" | "bind_session" | "prepare_source" | "bind_source" | "observe_source";
|
|
204
219
|
payload: Record<string, unknown>;
|
|
205
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
|
@@ -8,3 +8,114 @@ export class ProviderError extends Error {
|
|
|
8
8
|
this.status = status;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
+
// Keep the language-tag grammar and casing aligned with the .NET SDK's LanguageTag.cs.
|
|
12
|
+
const languageTag = /^([a-z]{2,3}(?:-[a-z]{3}){0,3}|[a-z]{4,8})(-[a-z]{4})?(-(?:[a-z]{2}|[0-9]{3}))?((?:-(?:[a-z0-9]{5,8}|[0-9][a-z0-9]{3}))*)((?:-[0-9a-wy-z](?:-[a-z0-9]{2,8})+)*)(-x(?:-[a-z0-9]{1,8})+)?$/;
|
|
13
|
+
/** @internal Shared language-tag validation for provider client and transport. */
|
|
14
|
+
export function normalizeLanguageTag(value) {
|
|
15
|
+
if (typeof value !== "string")
|
|
16
|
+
return undefined;
|
|
17
|
+
// Match .NET's Unicode whitespace trimming, which retains a BOM for validation to reject.
|
|
18
|
+
const tag = value.replace(/^\p{White_Space}+|\p{White_Space}+$/gu, "");
|
|
19
|
+
if (tag.length > 63 || !/^[A-Za-z0-9-]+$/.test(tag))
|
|
20
|
+
return undefined;
|
|
21
|
+
const match = languageTag.exec(tag.toLowerCase());
|
|
22
|
+
if (!match)
|
|
23
|
+
return undefined;
|
|
24
|
+
const [, language = "", script = "", region = "", variants = "", extensions = "", privateUse = ""] = match;
|
|
25
|
+
const variantTags = variants.split("-").slice(1);
|
|
26
|
+
const extensionKeys = extensions.split("-").filter(part => part.length === 1);
|
|
27
|
+
if (new Set(variantTags).size !== variantTags.length || new Set(extensionKeys).size !== extensionKeys.length)
|
|
28
|
+
return undefined;
|
|
29
|
+
const prefix = script ? language + "-" + script[1].toUpperCase() + script.slice(2) : language;
|
|
30
|
+
const suffix = variants + extensions + privateUse;
|
|
31
|
+
return { tag: prefix + region.toUpperCase() + suffix, withoutRegion: prefix + suffix };
|
|
32
|
+
}
|
|
33
|
+
/** Resolve the language once for playback using the selected implementation's capabilities. */
|
|
34
|
+
export function resolveSpeechTargetLanguage(requested, preferences, capabilities) {
|
|
35
|
+
const explicit = requested !== undefined;
|
|
36
|
+
const preferred = preferences?.autoTranslateReadAloud === true ? preferences.preferredLanguage : undefined;
|
|
37
|
+
const language = normalizeLanguageTag(explicit ? requested : preferred);
|
|
38
|
+
if (!language) {
|
|
39
|
+
if (explicit)
|
|
40
|
+
throw new ProviderError("speech_target_language_invalid", "Provide a valid target language tag.", 400);
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
const targets = capabilities.targetLanguages;
|
|
44
|
+
if (capabilities.supportsTranslation === true && (targets == null ||
|
|
45
|
+
Array.isArray(targets) && targets.some(target => {
|
|
46
|
+
const advertised = normalizeLanguageTag(target)?.tag;
|
|
47
|
+
return advertised === language.tag || advertised === language.withoutRegion;
|
|
48
|
+
})))
|
|
49
|
+
return language.tag;
|
|
50
|
+
if (explicit)
|
|
51
|
+
throw new ProviderError("speech_target_language_unsupported", "The selected speech provider does not support this target language.", 400);
|
|
52
|
+
return undefined;
|
|
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
|
@@ -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": [
|