@vibedev-si/dsh-vibedev 0.10.0 → 0.11.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.
@@ -0,0 +1,86 @@
1
+ /**
2
+ * `vibedevDesktopChatConsent`: one desktop chat sign-in decision, posted with the signed-in App account's token.
3
+ *
4
+ * The VibeDev desktop asks the user natively whether Messages may sign in with the current VibeDev account, then hands
5
+ * the pending chat OIDC request (`handle`) to this service through its Host. The service checks that the plugin is
6
+ * signed in with an App account's App Token (never a development key) and that this account is the one the desktop
7
+ * named (`subject`), posts `{request, approve}` to the configured consent endpoint with that token, and answers the
8
+ * Matrix callback the gateway returned once it is exactly the callback this decision may lead to.
9
+ *
10
+ * The App Token is the one credential this service sends, and the consent endpoint the one place it goes. That is a
11
+ * controlled exception to "credentials go to the gateway origin only" (`gateway/http.ts`): the gateway consumes chat
12
+ * OIDC requests on the issuer host (`https://vibedev.studio`) alone, not on the API origin. The endpoint is validated
13
+ * configuration (https, on the issuer host), and the plugin provides the service only while its own gateway is
14
+ * first-party. Only an App Token (`vdat_…`) is ever sent: the consent route authenticates nothing else.
15
+ *
16
+ * Nothing is retried: a request handle is consumed once, so a failure is reported and the desktop offers the web
17
+ * consent page instead. A 401 that says the sign-in itself failed is reported to the credential's owner, as every other
18
+ * gateway request of the plugin does, without posting the decision again. Every outcome other than a redirect is logged
19
+ * with fixed facts only; never the token, the handle, the subject or the callback.
20
+ * @module dsh-vibedev/chat-consent/service
21
+ */
22
+ import type { AccountIdentity } from '../account/index.js';
23
+ import type { GatewayCredential } from '../gateway/http.js';
24
+ import { type VibeDevDesktopChatConsent, type VibeDevDesktopChatConsentRequest, type VibeDevDesktopChatConsentResult } from './contract.js';
25
+ /** Construction options; `fetch` and `timeoutMs` are test seams. */
26
+ export interface ChatConsentHostServiceOptions {
27
+ /** Where one decision is posted: `chatConsent.endpoint` (https on the issuer host; checked again here). */
28
+ readonly endpoint: string;
29
+ /** The Matrix callback every answer must lead to: `chatConsent.callbackUrl` (checked again here). */
30
+ readonly callbackUrl: string;
31
+ /** Who is signed in: the credential the next gateway request would carry, and its VibeDev user id. */
32
+ readonly identity: () => Promise<AccountIdentity>;
33
+ /**
34
+ * Tell the credential's owner the gateway rejected it (the plugin's `CredentialChain.reject`), as the plugin's other
35
+ * requests do after a 401 that says the sign-in failed: the plugin's own sign-in refreshes its token, and a host
36
+ * account drops a login that still holds this token. Not awaited; the decision is never posted again.
37
+ */
38
+ readonly rejectCredential?: (credential: GatewayCredential) => Promise<void>;
39
+ /** `User-Agent` of the request. */
40
+ readonly userAgent: string;
41
+ /** Where the diagnostics go: one line for every outcome other than a redirect. */
42
+ readonly log: (message: string) => void;
43
+ /** Aborted when the plugin unloads: a decision still running ends as `failed`. */
44
+ readonly signal?: AbortSignal;
45
+ /**
46
+ * The longest one `resolve()` may take in all: the account read, the request and its body (default 10 s). It is set
47
+ * below the time the desktop waits for the answer (12 s in the rc2 desktop, 15 s for the authorization control in the
48
+ * desktop that ships this service), so a decision normally ends here first. That is likely, not certain: the
49
+ * desktop's wait starts earlier and also covers the IPC hops, and ending a request that was already sent only stops
50
+ * this side from waiting — the gateway may still consume the handle. The web consent page the desktop falls back to
51
+ * can then report the request as already used.
52
+ */
53
+ readonly timeoutMs?: number;
54
+ readonly fetch?: typeof globalThis.fetch;
55
+ }
56
+ /** Why a decision did not lead to a callback, as the diagnostics name it. */
57
+ export type ChatConsentFailureReason = 'invalid-request' | 'unloaded' | 'timeout' | 'account-unavailable' | 'signed-out' | 'not-app-credential' | 'account-unknown' | 'subject-mismatch' | 'network' | 'redirect' | 'gateway-refused' | 'gateway-unavailable' | 'gateway-status' | 'response-too-large' | 'invalid-response' | 'invalid-callback' | 'internal';
58
+ /** The chat consent capability for the VibeDev desktop's Host, registered as `vibedevDesktopChatConsent`. */
59
+ export declare class ChatConsentHostService implements VibeDevDesktopChatConsent {
60
+ private readonly options;
61
+ readonly version = 1;
62
+ private readonly endpoint;
63
+ private readonly callbackUrl;
64
+ /**
65
+ * @param options - the endpoint and callback, the account, and where diagnostics go.
66
+ * @throws an Error when the endpoint is not https on the issuer host, or the callback is not an https URL without
67
+ * query or fragment: whoever constructs the service, the token cannot be pointed anywhere else.
68
+ */
69
+ constructor(options: ChatConsentHostServiceOptions);
70
+ /**
71
+ * Post one decision with the signed-in App account's token. Bound to this service, so a caller may also hold and call
72
+ * the function alone (`const { resolve } = service`).
73
+ * @param request - the decision; anything that is not a valid request is answered `failed` without a request.
74
+ * @returns the outcome; the promise never rejects.
75
+ */
76
+ readonly resolve: (request: VibeDevDesktopChatConsentRequest) => Promise<VibeDevDesktopChatConsentResult>;
77
+ private decide;
78
+ /**
79
+ * Report a rejected credential to its owner without waiting for it, so neither a slow owner nor a failing one changes
80
+ * the answer.
81
+ * @returns whether it was reported (there is an owner to tell, and the credential is not a development key).
82
+ */
83
+ private reportRejected;
84
+ /** Answer an outcome other than a redirect, with one diagnostic line of fixed facts. */
85
+ private refuse;
86
+ }
@@ -4,7 +4,10 @@
4
4
  * idempotency are handled once.
5
5
  *
6
6
  * The credential is attached only to requests on the gateway origin: upload
7
- * URLs and third-party links never see it.
7
+ * URLs and third-party links never see it. The one controlled exception lives
8
+ * outside this client: `chat-consent/service.ts` posts the App Token to the
9
+ * configured consent endpoint (`chatConsent.endpoint`), which must be on the
10
+ * chat OIDC issuer host `https://vibedev.studio`.
8
11
  * @module dsh-vibedev/gateway/http
9
12
  */
10
13
  import { MediaError } from './errors.js';
package/lib/index.d.ts CHANGED
@@ -29,6 +29,10 @@ export { ContentHostService } from './content/service.js';
29
29
  export { ContentError } from './content/errors.js';
30
30
  export type { ContentCatalogOutcome, ContentCatalogRequest, ContentFileRequest, ContentHostServiceOptions } from './content/service.js';
31
31
  export type { ContentErrorCode, ContentErrorFacts } from './content/errors.js';
32
+ export { CHAT_CONSENT_ENDPOINT_ORIGIN, CHAT_CONSENT_FIRST_PARTY_ORIGINS, CHAT_CONSENT_MAX_CALLBACK_LENGTH, CHAT_CONSENT_VERSION, DEFAULT_CHAT_CONSENT_CALLBACK_URL, DEFAULT_CHAT_CONSENT_ENDPOINT, DESKTOP_CHAT_CONSENT_SERVICE, readChatConsentCallback, readChatConsentRequest, readChatConsentResult, } from './chat-consent/contract.js';
33
+ export type { VibeDevDesktopChatConsent, VibeDevDesktopChatConsentRequest, VibeDevDesktopChatConsentResult, VibeDevDesktopChatConsentStatus, } from './chat-consent/contract.js';
34
+ export { ChatConsentHostService } from './chat-consent/service.js';
35
+ export type { ChatConsentFailureReason, ChatConsentHostServiceOptions } from './chat-consent/service.js';
32
36
  export type { HostTarget, MediaOutputView, MediaTaskView } from './service.js';
33
37
  export type { TaskPhase, TaskQueue, TaskStage, TaskTiming } from './tasks/progress.js';
34
38
  export type { AudioForm, AudioFormField, AudioMakeKind, AudioRequest } from './audio/request.js';
@@ -98,6 +102,17 @@ export interface Config {
98
102
  * it: the host keeps its own fetch unless a profile sets `web.fetchProvider: vibedev-gateway`.
99
103
  */
100
104
  gatewayFetch: boolean;
105
+ /**
106
+ * The VibeDev desktop's one-step chat sign-in (`vibedevDesktopChatConsent`). `endpoint` receives the signed-in App
107
+ * account's token with one consent decision: an https URL on the chat OIDC issuer host `https://vibedev.studio`, the
108
+ * one controlled exception to "credentials go to the gateway origin only". `callbackUrl` is the Matrix callback
109
+ * (origin and path) every answer must lead to. A blank value means the default. A value that breaks its rule only
110
+ * leaves the service out (`apply()` logs which field and which rule); the rest of the plugin runs as usual.
111
+ */
112
+ chatConsent: {
113
+ endpoint: string;
114
+ callbackUrl: string;
115
+ };
101
116
  /** Environment variable holding a development key, used only while nobody is signed in. */
102
117
  apiKeyEnv: string;
103
118
  /** Where tasks and the plugin's own sign-in are kept; empty for `<harness home>/dsh-media`. */
@@ -126,6 +141,13 @@ export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
126
141
  client: Schema<string, string, "defined">;
127
142
  primary: Schema<boolean, boolean, "defined">;
128
143
  gatewayFetch: Schema<boolean, boolean, "defined">;
144
+ chatConsent: Schema<Schemastery.ObjectS<NoInfer<{
145
+ endpoint: Schema<string, string, "defined">;
146
+ callbackUrl: Schema<string, string, "defined">;
147
+ }>>, Schemastery.ObjectT<NoInfer<{
148
+ endpoint: Schema<string, string, "defined">;
149
+ callbackUrl: Schema<string, string, "defined">;
150
+ }>>, "plain">;
129
151
  apiKeyEnv: Schema<string, string, "defined">;
130
152
  stateDir: Schema<string, string, "defined">;
131
153
  }>>, Schemastery.ObjectT<NoInfer<{
@@ -151,6 +173,13 @@ export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
151
173
  client: Schema<string, string, "defined">;
152
174
  primary: Schema<boolean, boolean, "defined">;
153
175
  gatewayFetch: Schema<boolean, boolean, "defined">;
176
+ chatConsent: Schema<Schemastery.ObjectS<NoInfer<{
177
+ endpoint: Schema<string, string, "defined">;
178
+ callbackUrl: Schema<string, string, "defined">;
179
+ }>>, Schemastery.ObjectT<NoInfer<{
180
+ endpoint: Schema<string, string, "defined">;
181
+ callbackUrl: Schema<string, string, "defined">;
182
+ }>>, "plain">;
154
183
  apiKeyEnv: Schema<string, string, "defined">;
155
184
  stateDir: Schema<string, string, "defined">;
156
185
  }>>, "plain">;