@vibedev-si/dsh-vibedev 0.3.5 → 0.3.6

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.
@@ -25,6 +25,7 @@
25
25
  import type { ConnectionFetchRoute } from '@deepseek-ai/dsh-client-connection';
26
26
  import type { CredentialChain } from '../auth/credentials.js';
27
27
  import type { PluginLogin, SignInAttempt } from '../auth/login.js';
28
+ import type { GatewayCredential } from '../gateway/http.js';
28
29
  /** Path prefix of the plugin's Host routes. */
29
30
  export declare const ACCOUNT_ROUTE_PREFIX = "/api/dsh-vibedev/account";
30
31
  /** Where the active credential comes from. */
@@ -78,6 +79,18 @@ export interface AccountView {
78
79
  */
79
80
  readonly revision: number;
80
81
  }
82
+ /**
83
+ * Who is signed in to VibeDev right now, for work that must go out under one account (feedback): the credential the
84
+ * next request would carry, and the VibeDev user id — `/v1/account/auth/me`'s `data.id`, else (the plugin's own
85
+ * sign-in, while the gateway cannot be read) the id the sign-in answer named. Undefined when neither is known.
86
+ */
87
+ export type AccountIdentity = {
88
+ readonly signedIn: false;
89
+ } | {
90
+ readonly signedIn: true;
91
+ readonly credential: GatewayCredential;
92
+ readonly userId: string | undefined;
93
+ };
81
94
  /** What the account routes need from the plugin. */
82
95
  export interface AccountServiceOptions {
83
96
  readonly origin: string;
@@ -150,6 +163,12 @@ export declare class AccountService {
150
163
  * @returns the view.
151
164
  */
152
165
  view(fresh?: boolean): Promise<AccountView>;
166
+ /**
167
+ * Who is signed in now, with the VibeDev user id when it can be known (a recent `/auth/me` read is reused, as for
168
+ * the pages).
169
+ * @returns the identity.
170
+ */
171
+ identity(): Promise<AccountIdentity>;
153
172
  /**
154
173
  * `GET /v1/account/auth/me` for one token. A read younger than the TTL is
155
174
  * reused; an older one is answered at once while a new read runs behind it.
@@ -798,7 +798,7 @@ function redactSensitive(body) {
798
798
  */
799
799
  async function checkCredentialsFileSafety(path, onWarn = (m) => console.warn(`anthropic-sdk: ${m}`)) {
800
800
  if (typeof process === "undefined" || process.platform === "win32") return;
801
- const { fs } = await import("./node-vkDR3GtK.js").then((n) => n.i);
801
+ const { fs } = await import("./node-Br-0fshF.js").then((n) => n.i);
802
802
  let resolved = path;
803
803
  let st;
804
804
  try {
@@ -818,7 +818,7 @@ async function checkCredentialsFileSafety(path, onWarn = (m) => console.warn(`an
818
818
  * Creates the parent directory with mode 0700 and the file with mode 0600.
819
819
  */
820
820
  async function writeCredentialsFileAtomic(targetPath, data) {
821
- const { fs, path } = await import("./node-vkDR3GtK.js").then((n) => n.i);
821
+ const { fs, path } = await import("./node-Br-0fshF.js").then((n) => n.i);
822
822
  const dir = path.dirname(targetPath);
823
823
  await fs.promises.mkdir(dir, {
824
824
  recursive: true,
@@ -1128,7 +1128,7 @@ const loadConfigWithSource = async (profile) => {
1128
1128
  const profileName = profile ?? await getActiveProfileName();
1129
1129
  if (profileName === null) return null;
1130
1130
  validateProfileName(profileName);
1131
- const { fs, path } = await import("./node-vkDR3GtK.js").then((n) => n.i);
1131
+ const { fs, path } = await import("./node-Br-0fshF.js").then((n) => n.i);
1132
1132
  const configPath = path.join(rootConfigPath, "configs", `${profileName}.json`);
1133
1133
  let configRaw;
1134
1134
  try {
@@ -1205,12 +1205,12 @@ const getCredentialsPath = async (config, profile) => {
1205
1205
  const profileName = profile ?? await getActiveProfileName();
1206
1206
  if (!profileName) return null;
1207
1207
  validateProfileName(profileName);
1208
- const { path } = await import("./node-vkDR3GtK.js").then((n) => n.i);
1208
+ const { path } = await import("./node-Br-0fshF.js").then((n) => n.i);
1209
1209
  return path.join(rootConfigPath, "credentials", `${profileName}.json`);
1210
1210
  };
1211
1211
  const getRootConfigPath = async () => {
1212
1212
  if (!supportsLocalConfigFiles()) return null;
1213
- const { path } = await import("./node-vkDR3GtK.js").then((n) => n.i);
1213
+ const { path } = await import("./node-Br-0fshF.js").then((n) => n.i);
1214
1214
  const configDir = readEnv("ANTHROPIC_CONFIG_DIR");
1215
1215
  if (configDir) return configDir;
1216
1216
  if (getPlatformHeaders()["X-Stainless-OS"] === "Windows") {
@@ -1235,7 +1235,7 @@ const getActiveProfileName = async () => {
1235
1235
  if (!rootConfigPath) return null;
1236
1236
  const profileName = readEnv("ANTHROPIC_PROFILE");
1237
1237
  if (profileName) return profileName;
1238
- const { fs, path } = await import("./node-vkDR3GtK.js").then((n) => n.i);
1238
+ const { fs, path } = await import("./node-Br-0fshF.js").then((n) => n.i);
1239
1239
  const filePath = path.join(rootConfigPath, "active_config");
1240
1240
  try {
1241
1241
  return (await fs.promises.readFile(filePath, "utf-8")).trim() || "default";
@@ -1253,7 +1253,7 @@ const getActiveProfileName = async () => {
1253
1253
  function identityTokenFromFile(path) {
1254
1254
  if (!path) throw new AnthropicError("Identity token file path is empty");
1255
1255
  return async () => {
1256
- const { fs } = await import("./node-vkDR3GtK.js").then((n) => n.i);
1256
+ const { fs } = await import("./node-Br-0fshF.js").then((n) => n.i);
1257
1257
  let content;
1258
1258
  try {
1259
1259
  content = await fs.promises.readFile(path, "utf-8");
@@ -1341,7 +1341,7 @@ function oidcFederationProvider(config) {
1341
1341
  */
1342
1342
  function userOAuthProvider(config) {
1343
1343
  return async (opts) => {
1344
- const { fs } = await import("./node-vkDR3GtK.js").then((n) => n.i);
1344
+ const { fs } = await import("./node-Br-0fshF.js").then((n) => n.i);
1345
1345
  await checkCredentialsFileSafety(config.credentialsPath, config.onSafetyWarning);
1346
1346
  let raw;
1347
1347
  try {
@@ -1518,7 +1518,7 @@ function resolveIdentityTokenProvider(auth) {
1518
1518
  */
1519
1519
  function cachedExchangeProvider(exchange, credentialsPath, onCacheWriteError, onSafetyWarning) {
1520
1520
  return async (opts) => {
1521
- const { fs } = await import("./node-vkDR3GtK.js").then((n) => n.i);
1521
+ const { fs } = await import("./node-Br-0fshF.js").then((n) => n.i);
1522
1522
  await checkCredentialsFileSafety(credentialsPath, onSafetyWarning);
1523
1523
  let existing;
1524
1524
  try {
@@ -5211,7 +5211,7 @@ _EnvironmentWorker_signal = /* @__PURE__ */ new WeakMap(), _EnvironmentWorker_in
5211
5211
  const ctrl = new AbortController();
5212
5212
  const detachExternal = linkAbort(externalSignal, ctrl);
5213
5213
  const lease = new Lease(ctrl);
5214
- const agentToolset = await import("./node-Cujw_a4_.js");
5214
+ const agentToolset = await import("./node-D58f7Ea6.js");
5215
5215
  let leaseTtlMs;
5216
5216
  let runner;
5217
5217
  const heartbeatPromise = heartbeatLoop(sessionClient, work, lease, log, this.requestOptions, (ttlMs) => {
@@ -13469,4 +13469,4 @@ function mapStopReason(reason, stopDetails) {
13469
13469
  //#endregion
13470
13470
  export { checkMemorySyncInterval as a, decodeUTF8 as c, AnthropicError as d, __classPrivateFieldGet as f, MIN_MEMORY_SYNC_INTERVAL_MS as i, encodeUTF8 as l, promiseWithResolvers as n, isStatus as o, __classPrivateFieldSet as p, DEFAULT_MEMORY_SYNC_INTERVAL_MS as r, loggerFor as s, stream, streamSimple, anthropic_messages_exports as t, ToolError as u };
13471
13471
 
13472
- //# sourceMappingURL=anthropic-messages-KOS0z8Fy.js.map
13472
+ //# sourceMappingURL=anthropic-messages-BgIfgjNt.js.map
@@ -11,6 +11,11 @@
11
11
  * | podcast | model, prompt, source_url |
12
12
  * | speech | as declared; Seed: model, text_prompt, references, audio_config, watermark |
13
13
  *
14
+ * Seed (`seed-audio-1.0`) parses its body strictly: each reference is an object
15
+ * naming its input (`{"audio_url": "<url>"}`) and the watermark an object
16
+ * (`{"aigc_watermark": true}`); the model's declaration says so (the inputs of
17
+ * its reference union, `watermark_fields`), and only such a model gets them.
18
+ *
14
19
  * The main text goes in the model's `prompt_field`. A field the model does not
15
20
  * declare in `request_fields` is refused before anything is uploaded or charged;
16
21
  * music and podcasts never take speech references, output formats, sample rates
@@ -0,0 +1,51 @@
1
+ /**
2
+ * The `client` block of a feedback upload: which VibeDev app the Host serves,
3
+ * its version, the DeepSeek Harness and plugin versions, the operating system
4
+ * and the locale.
5
+ * @module dsh-vibedev/feedback/client-info
6
+ */
7
+ import { type FeedbackClient } from './wire.js';
8
+ export type HostApp = 'vibedev-desktop' | 'vibedev-web';
9
+ /** The process facts the client block is read from (a test seam). */
10
+ export interface HostFacts {
11
+ readonly versions: Readonly<Record<string, string | undefined>>;
12
+ /** The process has an IPC channel to the process that started it. */
13
+ readonly hasIpc: boolean;
14
+ readonly execPath: string;
15
+ readonly platform: string;
16
+ readonly arch: string;
17
+ readonly osRelease: string;
18
+ readonly locale: string | undefined;
19
+ }
20
+ /**
21
+ * This process's facts.
22
+ * @returns the facts.
23
+ */
24
+ export declare function hostFacts(): HostFacts;
25
+ /**
26
+ * Which app the Host serves. The VibeDev desktop app starts its Host from the window process on its own executable in
27
+ * Electron's Node mode, with an IPC channel back (apps/desktop/src/host-process.ts: `spawn(process.execPath, …,
28
+ * { stdio: [..., 'ipc'] })`); in that mode `process.versions.electron` is still set. `vibedev-app web` runs the same
29
+ * executable from a terminal, without that channel, and a DeepSeek Harness install runs on Node: both serve the
30
+ * browser. (Checked against VibeDev 0.2.1-rc.2.20261019.3: Electron 44.7.0, `process.send` present only with IPC.)
31
+ * @param facts - the process facts.
32
+ * @returns `vibedev-desktop` or `vibedev-web`.
33
+ */
34
+ export declare function hostApp(facts: HostFacts): HostApp;
35
+ /**
36
+ * The desktop app's own version, from its manifest beside the executable (`resources/app.asar/package.json`; on macOS
37
+ * `Contents/Resources`), which Electron's Node mode reads like any file.
38
+ * @param facts - the process facts.
39
+ * @param read - reads a file as text (a test seam).
40
+ * @returns the version, or undefined when there is no manifest to read.
41
+ */
42
+ export declare function desktopAppVersion(facts: HostFacts, read?: (path: string) => string): string | undefined;
43
+ /**
44
+ * The client block for this Host.
45
+ * @param facts - the process facts.
46
+ * @param pluginVersion - this plugin's version.
47
+ * @param dshVersion - DeepSeek Harness's version (the LLM runtime's own manifest, as its User-Agent reports).
48
+ * @param read - reads the desktop manifest (a test seam).
49
+ * @returns the block, every field within the contract's limits.
50
+ */
51
+ export declare function clientInfo(facts: HostFacts, pluginVersion: string, dshVersion?: string, read?: (path: string) => string): FeedbackClient;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * User feedback that reaches VibeDev. VibeDev turns off DeepSeek Harness's own
3
+ * feedback upload (session-telemetry-otel), so a rating or a `/feedback`
4
+ * stayed in the local session log; this uploads them to the gateway
5
+ * (`POST /v1/account/feedback`) with the VibeDev account they were given
6
+ * under, plus feedback given through the account menu's dialog. See observe.ts
7
+ * for what counts as new feedback, uploader.ts for the answers and the account
8
+ * rule, queue.ts for what is kept.
9
+ * @module dsh-vibedev/feedback
10
+ */
11
+ import type { Context } from '@deepseek-ai/cordis';
12
+ import type { AccountIdentity } from '../account/index.js';
13
+ import type { GatewayCredential } from '../gateway/http.js';
14
+ import { RecentErrors } from './recent-errors.js';
15
+ import { FeedbackUploader } from './uploader.js';
16
+ export { FEEDBACK_ATTACHMENT_ROUTE, FEEDBACK_ROUTE } from './routes.js';
17
+ /** What the feedback upload needs from the plugin. */
18
+ export interface FeedbackOptions {
19
+ /** The gateway and the plugin's user agent (`fetch` for tests). */
20
+ readonly gateway: {
21
+ readonly origin: string;
22
+ readonly userAgent: string;
23
+ readonly fetch?: typeof globalThis.fetch;
24
+ };
25
+ /** This gateway's state directory (the sign-in lives there too). */
26
+ readonly gatewayDir: string;
27
+ readonly pluginVersion: string;
28
+ /** Who is signed in now, with the VibeDev user id (the account service). */
29
+ readonly identity: () => Promise<AccountIdentity>;
30
+ /** Let a credential's owner renew it after the gateway refused it. */
31
+ readonly rejectCredential: (credential: GatewayCredential) => Promise<void>;
32
+ /** Subscribe to sign-in changes; returns unsubscribe. */
33
+ readonly onCredentialChange: (listener: () => void) => () => void;
34
+ readonly log: (message: string) => void;
35
+ }
36
+ /**
37
+ * Install the feedback upload: listen for new feedback and recent failures, serve the dialog's routes, and send what
38
+ * the queue holds.
39
+ * @param ctx - the plugin context.
40
+ * @param options - the gateway, the state directory, who is signed in, and the sign-in hooks.
41
+ * @returns the uploader and the recent errors (for tests and other parts of the plugin).
42
+ */
43
+ export declare function installFeedback(ctx: Context, options: FeedbackOptions): {
44
+ uploader: FeedbackUploader;
45
+ errors: RecentErrors;
46
+ };
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Which new Session events are feedback to upload, and what each says.
3
+ *
4
+ * DeepSeek Harness records feedback as Session events, the way its own
5
+ * telemetry plugin finds them (session-telemetry-otel, `isFeedback`):
6
+ *
7
+ * - `feedback/record` — `/feedback` (and the `sessionFeedback.record` Remote):
8
+ * `{ text?, category? }` (@deepseek-ai/dsh-command-feedback);
9
+ * - `feedback/message-put` — a rating of an assistant message, created or
10
+ * edited: `{ sessionId, item: { messageId, rating, note?, category?, … } }`;
11
+ * - `feedback/message-delete` — a rating removed: never uploaded
12
+ * (@deepseek-ai/dsh-message-feedback).
13
+ *
14
+ * A live Session publishes each appended event on `session/event`; feedback on
15
+ * a Session that is not open is written to its log directly and announced on
16
+ * `feedback/committed` with the event last in the inspection. Restored and
17
+ * fork-seeded history never publishes, and inherited events (a fork's copy of
18
+ * its parent, `seq < inheritedEventCount`, or a rating whose `sessionId` is the
19
+ * parent's) are skipped, so only feedback given after the plugin started is
20
+ * uploaded; no log is ever scanned.
21
+ * @module dsh-vibedev/feedback/observe
22
+ */
23
+ import type { SessionEvent } from '@deepseek-ai/dsh-session';
24
+ import type { SessionInspection } from '@deepseek-ai/dsh-session-persistence';
25
+ import { type FeedbackDraft } from './wire.js';
26
+ /** The Session an event belongs to, as far as telling new feedback from inherited feedback goes. */
27
+ export interface EventOwner {
28
+ readonly id: string;
29
+ readonly inheritedEventCount: number;
30
+ }
31
+ /**
32
+ * The feedback one newly appended event carries.
33
+ * @param owner - the Session the event was appended to.
34
+ * @param event - the event.
35
+ * @returns the draft, or undefined for anything else (another event, a deletion, inherited or empty feedback).
36
+ */
37
+ export declare function draftFromEvent(owner: EventOwner, event: SessionEvent): FeedbackDraft | undefined;
38
+ /**
39
+ * The feedback a committed write to a Session that is not open carries: the inspection's last event.
40
+ * @param inspection - the committed log, the feedback last.
41
+ * @returns the draft, or undefined.
42
+ */
43
+ export declare function draftFromCommitted(inspection: SessionInspection): FeedbackDraft | undefined;
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Feedback waiting to be uploaded, kept so a retry survives a restart: one
3
+ * JSON file next to the plugin's sign-in for this gateway
4
+ * (`<state dir>/gateways/<gateway id>/feedback-queue.json`), readable by its
5
+ * owner only, replaced atomically on every change. Each item is the exact body
6
+ * to send (its id is the idempotency key), the VibeDev account it belongs to,
7
+ * and when to try next.
8
+ *
9
+ * Caps: 200 items, 30 days, 4 MiB in all; past them the oldest give way.
10
+ * @module dsh-vibedev/feedback/queue
11
+ */
12
+ import { type FeedbackBody } from './wire.js';
13
+ export declare const QUEUE_MAX_ITEMS = 200;
14
+ export declare const QUEUE_MAX_AGE_MS: number;
15
+ export declare const QUEUE_MAX_BYTES: number;
16
+ /**
17
+ * Whose feedback it is, so it only ever goes out under that VibeDev account:
18
+ *
19
+ * - `user`: the account signed in when it was given (its VibeDev user id);
20
+ * - `signed-out`: given while nobody was signed in — it goes with the next account that signs in (once that
21
+ * account's id is known), and from its first attempt on belongs to that account;
22
+ * - `unidentified`: given while signed in to an account whose id could not be read (the gateway unreachable, the
23
+ * app's account): only the same credential, in the same run, may send it, and once that credential's account id is
24
+ * known it belongs to that account; after a restart it waits out the caps, never sent under anyone else.
25
+ */
26
+ export type FeedbackOwner = {
27
+ readonly kind: 'user';
28
+ readonly id: string;
29
+ } | {
30
+ readonly kind: 'signed-out';
31
+ } | {
32
+ readonly kind: 'unidentified';
33
+ };
34
+ /** One waiting upload. */
35
+ export interface QueueItem {
36
+ readonly body: FeedbackBody;
37
+ readonly owner: FeedbackOwner;
38
+ readonly enqueuedAt: number;
39
+ /** Attempts that ended without a final answer. */
40
+ readonly attempts: number;
41
+ /** Not before this time (epoch ms). */
42
+ readonly nextAt: number;
43
+ /** What the last attempt ended with (status or code), for diagnostics; never the body. */
44
+ readonly last?: string;
45
+ }
46
+ /** Construction options. */
47
+ export interface FeedbackQueueOptions {
48
+ readonly now?: () => number;
49
+ readonly maxItems?: number;
50
+ readonly maxAgeMs?: number;
51
+ readonly maxBytes?: number;
52
+ }
53
+ /** The persistent queue. All changes are serialized; reads see the latest state. */
54
+ export declare class FeedbackQueue {
55
+ readonly file: string;
56
+ private readonly options;
57
+ private state;
58
+ private loading;
59
+ private writing;
60
+ private readonly now;
61
+ /**
62
+ * @param file - the queue file.
63
+ * @param options - caps and the clock (test seams).
64
+ */
65
+ constructor(file: string, options?: FeedbackQueueOptions);
66
+ /** Read the file once; a missing or unreadable file is an empty queue (and is replaced on the next change). */
67
+ load(): Promise<void>;
68
+ /** The waiting items, oldest first. */
69
+ items(): readonly QueueItem[];
70
+ /**
71
+ * Queue one body at the end.
72
+ * @param body - the exact body to send.
73
+ * @param owner - the VibeDev account it belongs to.
74
+ */
75
+ add(body: FeedbackBody, owner: FeedbackOwner): Promise<void>;
76
+ /**
77
+ * Record how an attempt ended without a final answer.
78
+ * @param id - the item's body id.
79
+ * @param change - the attempt count, when to try next, and what it ended with.
80
+ */
81
+ update(id: string, change: Pick<QueueItem, 'attempts' | 'nextAt'> & {
82
+ readonly last?: string;
83
+ }): Promise<void>;
84
+ /**
85
+ * Give an item to an account (feedback given signed out, or by an account not identified then, on its first
86
+ * attempt): from now on it goes out under that account only.
87
+ * @param id - the item's body id.
88
+ * @param owner - the account.
89
+ */
90
+ bind(id: string, owner: FeedbackOwner): Promise<void>;
91
+ /**
92
+ * Put a new body in an item's place (the gateway asked for a smaller one): same position and owner, attempts start
93
+ * over.
94
+ * @param id - the item's current body id.
95
+ * @param body - the new body.
96
+ */
97
+ replace(id: string, body: FeedbackBody): Promise<void>;
98
+ /**
99
+ * Take an item out (sent, or refused for good).
100
+ * @param id - the item's body id.
101
+ */
102
+ remove(id: string): Promise<void>;
103
+ /**
104
+ * Apply the caps: too old first, then the oldest past the count, then the oldest past the size.
105
+ * @returns whether anything was dropped.
106
+ */
107
+ private prune;
108
+ /** Write the current state; owner-only from creation, replaced atomically, one write at a time. */
109
+ private save;
110
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * The last failures this Host saw, in memory only, for the feedback dialog's
3
+ * optional attachment: a tool call that failed (`tool/result` with `isError`,
4
+ * named by its `tool/call`) and a turn that ended in a model or request error
5
+ * (`turn/end` with `reason.kind: 'error'`), each with its time and Session.
6
+ * Nothing is written anywhere; the user sees the exact text before choosing to
7
+ * send it.
8
+ * @module dsh-vibedev/feedback/recent-errors
9
+ */
10
+ import type { SessionEvent } from '@deepseek-ai/dsh-session';
11
+ /** One failure. */
12
+ export interface RecentError {
13
+ readonly at: number;
14
+ readonly sessionRef: string;
15
+ readonly kind: 'tool' | 'model';
16
+ /** The failing tool's name, for a tool failure. */
17
+ readonly tool?: string;
18
+ readonly code?: string;
19
+ readonly status?: number;
20
+ /** The failure's own words, cut to 500 characters. */
21
+ readonly message: string;
22
+ }
23
+ /** The attachment as the user sees it and as it is sent. */
24
+ export interface ErrorLogAttachment {
25
+ readonly content: string;
26
+ readonly entries: number;
27
+ readonly bytes: number;
28
+ }
29
+ /** The last failures this Host saw. */
30
+ export declare class RecentErrors {
31
+ private readonly entries;
32
+ private readonly toolNames;
33
+ private readonly now;
34
+ private readonly max;
35
+ /**
36
+ * @param options - how many failures to keep, and the clock (test seams).
37
+ */
38
+ constructor(options?: {
39
+ readonly max?: number;
40
+ readonly now?: () => number;
41
+ });
42
+ /**
43
+ * Note one appended event.
44
+ * @param session - the Session it was appended to.
45
+ * @param event - the event.
46
+ */
47
+ observe(session: {
48
+ readonly id: string;
49
+ }, event: SessionEvent): void;
50
+ private push;
51
+ /** The kept failures, newest first. */
52
+ list(): readonly RecentError[];
53
+ /**
54
+ * The attachment text: a header, then one line per failure, newest first, cut to the attachment limit (so what
55
+ * gives way first is the oldest).
56
+ * @returns the text, its line count and its size; empty when nothing failed.
57
+ */
58
+ attachment(): ErrorLogAttachment;
59
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The feedback dialog's Host routes (answers are never cached):
3
+ *
4
+ * - `GET /api/dsh-vibedev/feedback/attachment` — the exact text the "attach
5
+ * recent errors" box would send, its line count and size;
6
+ * - `POST /api/dsh-vibedev/feedback` — `{ category?, text?, attachment?:
7
+ * { content }, locale? }`: queued as `source: 'menu'` (an attachment only as
8
+ * an `error-log` the user consented to by ticking the box) and sent at once
9
+ * when it can be; answers `sent`, `queued` (with why) or `rejected`. Nothing
10
+ * is queued while nobody is signed in: feedback goes with the VibeDev
11
+ * account, never anonymously.
12
+ * @module dsh-vibedev/feedback/routes
13
+ */
14
+ import type { ConnectionFetchRoute } from '@deepseek-ai/dsh-client-connection';
15
+ import type { RecentErrors } from './recent-errors.js';
16
+ import type { SubmitOutcome } from './uploader.js';
17
+ import { type FeedbackDraft } from './wire.js';
18
+ export declare const FEEDBACK_ROUTE = "/api/dsh-vibedev/feedback";
19
+ export declare const FEEDBACK_ATTACHMENT_ROUTE = "/api/dsh-vibedev/feedback/attachment";
20
+ /** What the routes need. */
21
+ export interface FeedbackRouteOptions {
22
+ readonly submit: (draft: FeedbackDraft, locale?: string) => Promise<SubmitOutcome>;
23
+ readonly errors: Pick<RecentErrors, 'attachment'>;
24
+ readonly hasCredential: () => Promise<boolean>;
25
+ }
26
+ /**
27
+ * The feedback routes.
28
+ * @param options - the uploader's submit, the recent errors and the credential check.
29
+ * @returns routes for the client connection.
30
+ */
31
+ export declare function feedbackRoutes(options: FeedbackRouteOptions): ConnectionFetchRoute[];
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Sends queued feedback to the gateway, one upload at a time, oldest first,
3
+ * each only under the VibeDev account it belongs to (queue.ts, `FeedbackOwner`):
4
+ * the account signed in when it was given; feedback given while signed out
5
+ * goes with the next account that signs in. Feedback of another account waits
6
+ * — within the queue's caps — until that account is back; it is never sent
7
+ * under a different user. The credential is pinned for each request: a renewal
8
+ * after a 401 is used only when it is still the same account.
9
+ *
10
+ * Every answer of the contract is handled:
11
+ *
12
+ * - 201 created, 200 the same id and content already received: done;
13
+ * - 400 invalid, 403 not allowed, 409 id reused with other content, 415 not
14
+ * JSON: dropped (sending it again cannot help);
15
+ * - 401: the credential's owner renews it and the same body goes once more; a
16
+ * second refusal waits for a sign-in or the next try;
17
+ * - 413 too large: the attachment is halved, as a new body with a new id;
18
+ * - 429 and 503: after `Retry-After` (else a back-off), the same body;
19
+ * - 404 (an older gateway, or the feature not on yet): kept, tried again in hours;
20
+ * - no answer, 5xx: a back-off with jitter, from 30 s up to an hour;
21
+ * - any other answer: the back-off, and dropped after the fifth.
22
+ *
23
+ * A retry always resends the stored body byte for byte. Bodies are never logged.
24
+ * @module dsh-vibedev/feedback/uploader
25
+ */
26
+ import type { AccountIdentity } from '../account/index.js';
27
+ import { type GatewayCredential } from '../gateway/http.js';
28
+ import type { FeedbackQueue } from './queue.js';
29
+ import { type FeedbackClient, type FeedbackDraft } from './wire.js';
30
+ /** What became of feedback given through the menu, as far as the dialog needs to know. */
31
+ export type SubmitOutcome = {
32
+ readonly status: 'sent';
33
+ }
34
+ /** Kept to send later: `offline` (no connection), `later` (the gateway asked to wait or does not take it yet). */
35
+ | {
36
+ readonly status: 'queued';
37
+ readonly reason: 'offline' | 'later' | 'signed-out';
38
+ } | {
39
+ readonly status: 'rejected';
40
+ readonly code: string;
41
+ };
42
+ /** Construction options; clocks, timers, randomness, ids and fetch are test seams. */
43
+ export interface FeedbackUploaderOptions {
44
+ /** The gateway, and the plugin's user agent. */
45
+ readonly gateway: {
46
+ readonly origin: string;
47
+ readonly userAgent: string;
48
+ readonly fetch?: typeof globalThis.fetch;
49
+ };
50
+ readonly queue: FeedbackQueue;
51
+ /** The client block (app, versions, os, locale). */
52
+ readonly client: () => FeedbackClient;
53
+ /** Who is signed in now, and the VibeDev user id (the account service). */
54
+ readonly identity: () => Promise<AccountIdentity>;
55
+ /** Let a credential's owner renew it after the gateway refused it. */
56
+ readonly rejectCredential: (credential: GatewayCredential) => Promise<void>;
57
+ readonly log?: (message: string) => void;
58
+ readonly now?: () => number;
59
+ /** Uniform in [0, 1), for the jitter. */
60
+ readonly random?: () => number;
61
+ readonly setTimeout?: (callback: () => void, ms: number) => unknown;
62
+ readonly clearTimeout?: (handle: unknown) => void;
63
+ readonly newId?: () => string;
64
+ }
65
+ /** The feedback uploader. */
66
+ export declare class FeedbackUploader {
67
+ private readonly options;
68
+ private flushing;
69
+ private again;
70
+ private timer;
71
+ private disposed;
72
+ private recording;
73
+ private readonly waiters;
74
+ /** Feedback of an account not identified when it was given: the credential that gave it, in this run only. */
75
+ private readonly bindings;
76
+ private readonly now;
77
+ /**
78
+ * @param options - the gateway, the queue, the client block, and who is signed in.
79
+ */
80
+ constructor(options: FeedbackUploaderOptions);
81
+ /**
82
+ * Queue one piece of feedback for the account signed in now, and try to send it.
83
+ * @param draft - what it says.
84
+ * @param locale - the locale the user chose it in, when known (the menu's dialog).
85
+ * @returns the body id, or undefined when the draft says nothing the gateway takes.
86
+ */
87
+ enqueue(draft: FeedbackDraft, locale?: string): Promise<string | undefined>;
88
+ /**
89
+ * Note who gave it and keep it. One at a time, so the queue keeps the order feedback was given in.
90
+ */
91
+ private record;
92
+ /**
93
+ * Queue feedback from the dialog (for the account signed in now) and say what became of it: sent, kept for later,
94
+ * or refused.
95
+ * @param draft - what it says.
96
+ * @param locale - the dialog's locale.
97
+ * @param waitMs - how long to wait for the first answer before calling it kept.
98
+ * @returns the outcome.
99
+ */
100
+ submit(draft: FeedbackDraft, locale?: string, waitMs?: number): Promise<SubmitOutcome>;
101
+ /** The account changed (a sign-in, a sign-out, a renewal): its feedback, and what waited on a refused renewal, goes now. */
102
+ credentialChanged(): void;
103
+ /**
104
+ * Send what is due for the account signed in now, one at a time; a call while sending makes the loop look once
105
+ * more when it ends.
106
+ * @returns once nothing more can be sent now.
107
+ */
108
+ flush(): Promise<void>;
109
+ /** Stop: no new attempt starts and the timer is cleared (the queue stays on disk). */
110
+ dispose(): void;
111
+ /** Whether an item may go out under this account. */
112
+ private sendable;
113
+ private identity;
114
+ private drain;
115
+ /**
116
+ * Feedback given signed out (or by an account not identified then) belongs, from its first attempt under a known
117
+ * account on, to that account, so a retry never changes hands.
118
+ */
119
+ private claim;
120
+ /** One POST of the stored body with the account's credential, its answer mapped onto the contract. */
121
+ private attempt;
122
+ /** 30 s doubling per attempt up to an hour, times a jitter of 0.5–1.5. */
123
+ private backoff;
124
+ private jitter;
125
+ /** What this account can send waits `ms` (its first item's turn); whoever waits on an answer hears it is kept. */
126
+ private park;
127
+ private release;
128
+ private settle;
129
+ private schedule;
130
+ private cancel;
131
+ }