@hosty-sdk/app 0.41.1 → 0.43.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/dist/decisions-server.d.ts +6 -0
- package/dist/decisions-server.js +21 -0
- package/dist/decisions.d.ts +140 -0
- package/dist/decisions.js +53 -0
- package/dist/install-react.js +3 -1
- package/dist/install.d.ts +3 -0
- package/dist/install.js +4 -0
- package/dist/tasks.d.ts +4 -0
- package/dist/tasks.js +2 -0
- package/package.json +9 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ProviderServerOptions } from "@hosty-sdk/app/providers/server";
|
|
2
|
+
import { DecisionClient } from "@hosty-sdk/app/decisions";
|
|
3
|
+
/** App-server transport. Resolve a fresh user identity for each request; never persist it with a wait. */
|
|
4
|
+
export declare class DecisionServerClient extends DecisionClient {
|
|
5
|
+
constructor(userToken: () => string | Promise<string>, options?: ProviderServerOptions);
|
|
6
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DecisionClient, DecisionError } from "@hosty-sdk/app/decisions";
|
|
2
|
+
/** App-server transport. Resolve a fresh user identity for each request; never persist it with a wait. */
|
|
3
|
+
export class DecisionServerClient extends DecisionClient {
|
|
4
|
+
constructor(userToken, options = {}) {
|
|
5
|
+
const appId = options.appId ?? process.env.HOSTY_APP_ID ?? "";
|
|
6
|
+
const origin = new URL(options.coreOrigin ?? process.env.HOSTY_CORE_ORIGIN ?? "http://127.0.0.1:7070");
|
|
7
|
+
const service = options.serviceToken ?? process.env.HOSTY_APP_SERVICE_TOKEN ?? "";
|
|
8
|
+
if (!appId || !service)
|
|
9
|
+
throw new DecisionError("hosty_misconfigured", "Hosty application credentials are unavailable.", 503);
|
|
10
|
+
super(async (route, method, body, signal) => {
|
|
11
|
+
const token = await userToken();
|
|
12
|
+
if (!token)
|
|
13
|
+
throw new DecisionError("identity_required", "Sign in to use Decisions.", 401);
|
|
14
|
+
return fetch(new URL("/api/internal/apps/" + encodeURIComponent(appId) + "/decisions/v1" + route, origin), {
|
|
15
|
+
method, redirect: "error", cache: "no-store", signal: route === "/events" ? signal : signal ? AbortSignal.any([signal, AbortSignal.timeout(30_000)]) : AbortSignal.timeout(30_000),
|
|
16
|
+
headers: { authorization: "Bearer " + service, "X-Hosty-User-Token": token, "content-type": "application/json" },
|
|
17
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/** Addressed input. A decision answer never grants tool, installation, or task-review permission. */
|
|
2
|
+
export interface DecisionOption {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
description?: string | null;
|
|
6
|
+
}
|
|
7
|
+
export interface DecisionQuestion {
|
|
8
|
+
id: string;
|
|
9
|
+
question: string;
|
|
10
|
+
options?: DecisionOption[] | null;
|
|
11
|
+
allowText?: boolean;
|
|
12
|
+
multiple?: boolean;
|
|
13
|
+
header?: string | null;
|
|
14
|
+
}
|
|
15
|
+
export interface DecisionReference {
|
|
16
|
+
kind: string;
|
|
17
|
+
id: string;
|
|
18
|
+
revision?: string | null;
|
|
19
|
+
}
|
|
20
|
+
export interface DecisionInput {
|
|
21
|
+
correlationKey: string;
|
|
22
|
+
title: string;
|
|
23
|
+
questions: DecisionQuestion[];
|
|
24
|
+
reason?: string | null;
|
|
25
|
+
subject?: DecisionReference | null;
|
|
26
|
+
task?: DecisionReference | null;
|
|
27
|
+
materials?: DecisionReference[] | null;
|
|
28
|
+
originPath?: string | null;
|
|
29
|
+
waitReference?: string | null;
|
|
30
|
+
expiresAt?: string | null;
|
|
31
|
+
predecessorId?: string | null;
|
|
32
|
+
}
|
|
33
|
+
export interface DecisionCreate {
|
|
34
|
+
requestId: string;
|
|
35
|
+
input: DecisionInput;
|
|
36
|
+
}
|
|
37
|
+
export interface DecisionAnswer {
|
|
38
|
+
optionIds?: string[] | null;
|
|
39
|
+
text?: string | null;
|
|
40
|
+
}
|
|
41
|
+
export type DecisionAnswers = Record<string, DecisionAnswer>;
|
|
42
|
+
export interface DecisionResolve {
|
|
43
|
+
requestId: string;
|
|
44
|
+
expectedRevision: number;
|
|
45
|
+
answers: DecisionAnswers;
|
|
46
|
+
}
|
|
47
|
+
export interface DecisionWithdraw {
|
|
48
|
+
requestId: string;
|
|
49
|
+
expectedRevision: number;
|
|
50
|
+
reason: string;
|
|
51
|
+
currentSubjectRevision?: string | null;
|
|
52
|
+
removeContent?: boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface DecisionAck {
|
|
55
|
+
requestId: string;
|
|
56
|
+
resolutionRevision: number;
|
|
57
|
+
}
|
|
58
|
+
export type DecisionContinuationState = "pending" | "received" | "blocked" | "admitted" | "running" | "completed" | "failed" | "cancelled";
|
|
59
|
+
export type DecisionContinuationReason = "missing_authority" | "missing_provider" | "unknown_stop" | "unknown_admission" | "stale_input" | "unsupported_resume" | "paused" | "cancelled" | "provider_failed";
|
|
60
|
+
export interface DecisionContinue {
|
|
61
|
+
requestId: string;
|
|
62
|
+
commandId: string;
|
|
63
|
+
expectedRevision: number;
|
|
64
|
+
state: DecisionContinuationState;
|
|
65
|
+
reason?: DecisionContinuationReason | null;
|
|
66
|
+
outcome?: string | null;
|
|
67
|
+
}
|
|
68
|
+
export type DecisionState = "pending" | "answered" | "withdrawn" | "expired" | "stale";
|
|
69
|
+
export interface DecisionQuery {
|
|
70
|
+
cursor?: string;
|
|
71
|
+
limit?: number;
|
|
72
|
+
state?: DecisionState | "history";
|
|
73
|
+
subject?: string;
|
|
74
|
+
task?: string;
|
|
75
|
+
}
|
|
76
|
+
export interface DecisionResolution {
|
|
77
|
+
revision: number;
|
|
78
|
+
userId: string;
|
|
79
|
+
principalId: string;
|
|
80
|
+
answers: DecisionAnswers;
|
|
81
|
+
answeredAt: string;
|
|
82
|
+
}
|
|
83
|
+
export interface DecisionContinuation {
|
|
84
|
+
revision: number;
|
|
85
|
+
commandId: string | null;
|
|
86
|
+
state: DecisionContinuationState;
|
|
87
|
+
updatedAt: string;
|
|
88
|
+
reason?: DecisionContinuationReason | null;
|
|
89
|
+
outcome?: string | null;
|
|
90
|
+
}
|
|
91
|
+
export interface DecisionRecord {
|
|
92
|
+
id: string;
|
|
93
|
+
sequence: number;
|
|
94
|
+
revision: number;
|
|
95
|
+
userId: string;
|
|
96
|
+
correlationHash: string;
|
|
97
|
+
sourceAppId: string | null;
|
|
98
|
+
sourceInstallation: string | null;
|
|
99
|
+
sourcePrincipal: string;
|
|
100
|
+
input: DecisionInput | null;
|
|
101
|
+
state: DecisionState;
|
|
102
|
+
createdAt: string;
|
|
103
|
+
updatedAt: string;
|
|
104
|
+
resolution: DecisionResolution | null;
|
|
105
|
+
delivery: {
|
|
106
|
+
resolutionRevision: number;
|
|
107
|
+
receivedAt: string | null;
|
|
108
|
+
} | null;
|
|
109
|
+
continuation: DecisionContinuation | null;
|
|
110
|
+
reason?: string | null;
|
|
111
|
+
contentRemovedAt?: string | null;
|
|
112
|
+
}
|
|
113
|
+
export interface DecisionPage {
|
|
114
|
+
items: DecisionRecord[];
|
|
115
|
+
pendingCount: number;
|
|
116
|
+
cursor: string | null;
|
|
117
|
+
}
|
|
118
|
+
export declare class DecisionError extends Error {
|
|
119
|
+
readonly code: string;
|
|
120
|
+
readonly status: number;
|
|
121
|
+
constructor(code: string, message: string, status: number);
|
|
122
|
+
}
|
|
123
|
+
/** The transport supplies current authority on each call. Mutations are never implicitly retried. */
|
|
124
|
+
export type DecisionTransport = (route: string, method: "GET" | "POST", body?: unknown, signal?: AbortSignal) => Promise<Response>;
|
|
125
|
+
export declare class DecisionClient {
|
|
126
|
+
private readonly transport;
|
|
127
|
+
constructor(transport: DecisionTransport);
|
|
128
|
+
private send;
|
|
129
|
+
/** Private change hints. Reload authorized state on stream.ready and decisions.changed. */
|
|
130
|
+
events(signal: AbortSignal): Promise<Response>;
|
|
131
|
+
create(input: DecisionCreate, signal?: AbortSignal): Promise<DecisionRecord>;
|
|
132
|
+
get(id: string, signal?: AbortSignal): Promise<DecisionRecord>;
|
|
133
|
+
list(query?: DecisionQuery, signal?: AbortSignal): Promise<DecisionPage>;
|
|
134
|
+
resolve(id: string, input: DecisionResolve, signal?: AbortSignal): Promise<DecisionRecord>;
|
|
135
|
+
withdraw(id: string, input: DecisionWithdraw, signal?: AbortSignal): Promise<DecisionRecord>;
|
|
136
|
+
invalidate(id: string, input: DecisionWithdraw, signal?: AbortSignal): Promise<DecisionRecord>;
|
|
137
|
+
responses(query?: DecisionQuery, signal?: AbortSignal): Promise<DecisionPage>;
|
|
138
|
+
acknowledge(id: string, input: DecisionAck, signal?: AbortSignal): Promise<DecisionRecord>;
|
|
139
|
+
continuation(id: string, input: DecisionContinue, signal?: AbortSignal): Promise<DecisionRecord>;
|
|
140
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export class DecisionError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
status;
|
|
4
|
+
constructor(code, message, status) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.status = status;
|
|
8
|
+
this.name = "DecisionError";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export class DecisionClient {
|
|
12
|
+
transport;
|
|
13
|
+
constructor(transport) {
|
|
14
|
+
this.transport = transport;
|
|
15
|
+
}
|
|
16
|
+
async send(route, body, signal) {
|
|
17
|
+
const response = await this.transport(route, body === undefined ? "GET" : "POST", body, signal);
|
|
18
|
+
const value = await response.json().catch(() => null);
|
|
19
|
+
if (!response.ok) {
|
|
20
|
+
const envelope = value;
|
|
21
|
+
const error = envelope?.error ?? envelope;
|
|
22
|
+
throw new DecisionError(error?.code ?? "decision_unavailable", error?.message ?? "Decisions are unavailable. Your answer has not been discarded.", response.status);
|
|
23
|
+
}
|
|
24
|
+
if (value === null)
|
|
25
|
+
throw new DecisionError("decision_response_invalid", "Core returned no decision result.", 502);
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
/** Private change hints. Reload authorized state on stream.ready and decisions.changed. */
|
|
29
|
+
async events(signal) {
|
|
30
|
+
const response = await this.transport("/events", "GET", undefined, signal);
|
|
31
|
+
if (!response.ok || !response.body || !response.headers.get("content-type")?.startsWith("text/event-stream")) {
|
|
32
|
+
await response.body?.cancel();
|
|
33
|
+
throw new DecisionError("decision_stream_unavailable", "Decision updates are unavailable.", response.ok ? 502 : response.status);
|
|
34
|
+
}
|
|
35
|
+
return response;
|
|
36
|
+
}
|
|
37
|
+
create(input, signal) { return this.send("/requests", input, signal); }
|
|
38
|
+
get(id, signal) { return this.send("/requests/" + encodeURIComponent(id), undefined, signal); }
|
|
39
|
+
list(query = {}, signal) { return this.send("/requests" + queryString(query), undefined, signal); }
|
|
40
|
+
resolve(id, input, signal) { return this.send("/requests/" + encodeURIComponent(id) + "/resolve", input, signal); }
|
|
41
|
+
withdraw(id, input, signal) { return this.send("/requests/" + encodeURIComponent(id) + "/withdraw", input, signal); }
|
|
42
|
+
invalidate(id, input, signal) { return this.send("/requests/" + encodeURIComponent(id) + "/invalidate", input, signal); }
|
|
43
|
+
responses(query = {}, signal) { return this.send("/responses" + queryString(query), undefined, signal); }
|
|
44
|
+
acknowledge(id, input, signal) { return this.send("/responses/" + encodeURIComponent(id) + "/ack", input, signal); }
|
|
45
|
+
continuation(id, input, signal) { return this.send("/requests/" + encodeURIComponent(id) + "/continuation", input, signal); }
|
|
46
|
+
}
|
|
47
|
+
function queryString(query) {
|
|
48
|
+
const params = new URLSearchParams();
|
|
49
|
+
for (const key of ["cursor", "limit", "state", "subject", "task"])
|
|
50
|
+
if (query[key] !== undefined)
|
|
51
|
+
params.set(key, String(query[key]));
|
|
52
|
+
return params.size ? "?" + params.toString() : "";
|
|
53
|
+
}
|
package/dist/install-react.js
CHANGED
|
@@ -127,7 +127,9 @@ function InstallationSession({ client, source, confirmationWindow, onClose, onCh
|
|
|
127
127
|
const popup = openInstallationConfirmation();
|
|
128
128
|
claimPopup(popup);
|
|
129
129
|
// A known draft submit failure retries its existing identity, without resolving the feed again.
|
|
130
|
-
if (
|
|
130
|
+
if (request?.updatePlan?.error)
|
|
131
|
+
flow.clearReview();
|
|
132
|
+
if (!flow.snapshot().request)
|
|
131
133
|
await flow.review(initialSource ?? { manifestPath: manifestPath.trim() });
|
|
132
134
|
if (flow.snapshot().request?.status !== "draft") {
|
|
133
135
|
closeUnusedPopup(popup);
|
package/dist/install.d.ts
CHANGED
|
@@ -114,6 +114,9 @@ export interface InstallationRequest {
|
|
|
114
114
|
status: "draft" | "pending" | "executing" | "succeeded" | "denied" | "failed";
|
|
115
115
|
plan: InstallPlan | null;
|
|
116
116
|
updatePlan?: {
|
|
117
|
+
error?: string | null;
|
|
118
|
+
errorCode?: string | null;
|
|
119
|
+
readiness?: string | null;
|
|
117
120
|
appId: string;
|
|
118
121
|
displayName?: string | null;
|
|
119
122
|
targetVersion: string;
|
package/dist/install.js
CHANGED
|
@@ -78,6 +78,10 @@ export class InstallationFlow {
|
|
|
78
78
|
async submit(settings, autostart) {
|
|
79
79
|
if (this.state.busy || this.state.uncertainSubmit || this.state.request?.status !== "draft")
|
|
80
80
|
return null;
|
|
81
|
+
if (this.state.request.updatePlan?.error) {
|
|
82
|
+
this.set({ ...this.state, error: this.state.request.updatePlan.error });
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
81
85
|
const id = this.state.request.id;
|
|
82
86
|
const generation = this.generation;
|
|
83
87
|
this.submitting = true;
|
package/dist/tasks.d.ts
CHANGED
|
@@ -59,6 +59,8 @@ export type TaskExecutionReceipt = {
|
|
|
59
59
|
revision: number;
|
|
60
60
|
state: TaskExecutionState;
|
|
61
61
|
stopConfirmed: boolean;
|
|
62
|
+
/** Native segment exit while the same attempt remains awaiting_input; does not release the attempt. */
|
|
63
|
+
nativeStopConfirmed?: boolean;
|
|
62
64
|
createdAt: string;
|
|
63
65
|
updatedAt: string;
|
|
64
66
|
result?: TaskResult;
|
|
@@ -146,3 +148,5 @@ export type TaskExecutorOptions = {
|
|
|
146
148
|
};
|
|
147
149
|
export declare const taskStatuses: TaskStatus[];
|
|
148
150
|
export declare const taskExecutionTerminal: (state: TaskExecutionState) => boolean;
|
|
151
|
+
/** Collision-free opaque reference for cross-provider links and filters; grants no task access. */
|
|
152
|
+
export declare const taskReferenceKey: (ref: TaskRef) => string;
|
package/dist/tasks.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export const taskStatuses = ["Draft", "Ready", "InProgress", "Blocked", "Done", "Cancelled"];
|
|
2
2
|
export const taskExecutionTerminal = (state) => ["completed", "failed", "cancelled", "interrupted"].includes(state);
|
|
3
|
+
/** Collision-free opaque reference for cross-provider links and filters; grants no task access. */
|
|
4
|
+
export const taskReferenceKey = (ref) => JSON.stringify([ref.appId, ref.installationId, ref.key, ref.id]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hosty-sdk/app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.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",
|
|
@@ -160,6 +160,14 @@
|
|
|
160
160
|
"./feedback/client": {
|
|
161
161
|
"types": "./dist/feedback-client.d.ts",
|
|
162
162
|
"default": "./dist/feedback-client.js"
|
|
163
|
+
},
|
|
164
|
+
"./decisions": {
|
|
165
|
+
"types": "./dist/decisions.d.ts",
|
|
166
|
+
"default": "./dist/decisions.js"
|
|
167
|
+
},
|
|
168
|
+
"./decisions/server": {
|
|
169
|
+
"types": "./dist/decisions-server.d.ts",
|
|
170
|
+
"default": "./dist/decisions-server.js"
|
|
163
171
|
}
|
|
164
172
|
},
|
|
165
173
|
"scripts": {
|