videodraft 0.14.0 → 0.15.1

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
@@ -109,7 +109,7 @@ late Byteplus output refusals are refunded but cannot be rerouted.
109
109
  | Group | Commands |
110
110
  | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
111
111
  | Auth | `login` `logout` `whoami` |
112
- | Account | `credits` `costs [model]` `models [image\|video\|audio\|voices\|styles]` `workspaces` `sessions list/create` `kling-voices list/create/delete` |
112
+ | Account | `credits` `costs [model]` `models [image\|video\|audio\|voices\|styles]` `workspaces` `sessions list/create/current/reset` `kling-voices list/create/delete` |
113
113
  | Projects | `projects list/get/delete/favorite/open` `checkpoint create/list/restore` |
114
114
  | Pipeline | `create` `shots` `produce` (`--mode full_video`) `attach` `finalize` `export` `export-status` `video-prompts` |
115
115
  | Generate | `generate image/video/audio/voiceover/music/sound-effect/dialogue/voice-changer/dub` `edit video/motion` `upscale image/video` `avatar script/create/render/get/list/fabric/lipsync` |
package/dist/client.d.ts CHANGED
@@ -1,3 +1,85 @@
1
+ /**
2
+ * Connection sessions for the CLI.
3
+ *
4
+ * The VideoDraft MCP server hands every connection an `Mcp-Session-Id` on
5
+ * `initialize` and files that connection's project-less generations into its
6
+ * own AI Studio session (named after the client and date). MCP hosts echo the
7
+ * header for free; the CLI is stateless per invocation, so it keeps the
8
+ * header in a small store and replays it on every request.
9
+ *
10
+ * Scope: one session per (profile, base URL, working directory), expiring
11
+ * after SESSION_IDLE_MS without use. A working directory is a good proxy for
12
+ * "one piece of work" — an agent's workspace, a project folder — and it is
13
+ * stable across the many short-lived shells agents spawn (parent PIDs are
14
+ * not). Override the scope with VIDEODRAFT_SESSION_SCOPE=<any label>, pin an
15
+ * explicit AI Studio session with --session / VIDEODRAFT_SESSION, or rotate
16
+ * with `videodraft sessions reset`.
17
+ *
18
+ * Runtime-agnostic: no console, no process.exit. Fails soft — a broken store
19
+ * just means the server falls back to the shared "Agent (MCP)" session.
20
+ */
21
+ declare const SESSION_IDLE_MS: number;
22
+ declare const MCP_SESSION_HEADER = "Mcp-Session-Id";
23
+ interface ConnectionSessionRecord {
24
+ token: string;
25
+ scope: string;
26
+ cwd: string;
27
+ baseUrl: string;
28
+ profile: string;
29
+ createdAt: string;
30
+ lastUsedAt: string;
31
+ }
32
+ interface ConnectionSessionStore {
33
+ /** Current token for this scope, or null when absent/expired. */
34
+ load(): string | null;
35
+ /**
36
+ * Persist a freshly minted token for this scope and return the token that
37
+ * now owns the scope. Two processes racing on an empty scope both mint;
38
+ * the first writer wins and the second gets the winner's token back, so
39
+ * one directory never ends up split across two sessions. Returns null
40
+ * when the token could NOT be persisted (read-only config dir): the
41
+ * caller must then go stateless — sending an unpersisted token would
42
+ * create a fresh AI Studio session per invocation, when the documented
43
+ * degraded mode is the shared server-side fallback.
44
+ */
45
+ save(token: string): string | null;
46
+ /** Replace the scope's token unconditionally (server re-mint). */
47
+ replace(token: string): void;
48
+ /**
49
+ * Forget the current token; the next call re-initialises. Returns whether
50
+ * the deletion actually ran — false means the scope lock could not be
51
+ * taken (or the filesystem refused) and the record may still exist.
52
+ */
53
+ reset(): boolean;
54
+ /** Where this scope's record lives (for `sessions current`). */
55
+ describe(): {
56
+ scope: string;
57
+ file: string;
58
+ record: ConnectionSessionRecord | null;
59
+ /** True when a record exists but is past the idle window. */
60
+ expired: boolean;
61
+ /** The AI Studio session id inside the token, when it parses. */
62
+ sessionId: string | null;
63
+ };
64
+ }
65
+ interface SessionScopeInput {
66
+ baseUrl: string;
67
+ profile: string;
68
+ cwd?: string;
69
+ env?: NodeJS.ProcessEnv;
70
+ now?: () => number;
71
+ }
72
+ /** Stable label for this scope; what the record is keyed by. */
73
+ declare function sessionScope(input: SessionScopeInput): string;
74
+ declare function createConnectionSessionStore(input: SessionScopeInput): ConnectionSessionStore;
75
+ /**
76
+ * Drop every stored connection session (all scopes) for this config dir.
77
+ * Each record is removed under its per-scope lock — the same protocol as
78
+ * the single-scope reset — so a concurrent touch/replace that already read
79
+ * the old record cannot recreate it right after the sweep deletes it.
80
+ */
81
+ declare function resetAllConnectionSessions(env?: NodeJS.ProcessEnv): number;
82
+
1
83
  /**
2
84
  * JSON-RPC 2.0 client for the VideoDraft MCP endpoint (POST {base}/api/mcp).
3
85
  *
@@ -5,6 +87,7 @@
5
87
  * console — this file is part of the `videodraft/client` subpath export the
6
88
  * macOS app's sidecar consumes. Errors are thrown, never printed.
7
89
  */
90
+
8
91
  interface TokenProvider {
9
92
  /** Return a bearer token (vd_mcp_...). Throw AuthError when none is available. */
10
93
  getAccessToken(): Promise<string>;
@@ -21,6 +104,20 @@ interface VideoDraftClientOptions {
21
104
  userAgent?: string;
22
105
  /** Per-request timeout in ms. Generation submits can be slow; default 300s (server maxDuration). */
23
106
  requestTimeoutMs?: number;
107
+ /**
108
+ * Optional connection-session store. When present the client performs the
109
+ * MCP `initialize` handshake once per scope, keeps the server's
110
+ * Mcp-Session-Id, and replays it on every request — which files this
111
+ * scope's project-less generations into their own AI Studio session
112
+ * instead of the shared "Agent (MCP)" one. Omit for a stateless client.
113
+ */
114
+ session?: ConnectionSessionStore;
115
+ /**
116
+ * Name reported as MCP clientInfo.name during the session handshake; it
117
+ * becomes the label of the auto-created AI Studio session ("Claude Code ·
118
+ * Aug 22, 2026"). Defaults to the user-agent's product token.
119
+ */
120
+ clientName?: string;
24
121
  }
25
122
  interface McpToolInfo {
26
123
  name: string;
@@ -33,8 +130,30 @@ declare class VideoDraftClient {
33
130
  private readonly fetchImpl;
34
131
  private readonly userAgent;
35
132
  private readonly requestTimeoutMs;
133
+ private readonly session?;
134
+ private readonly clientName;
135
+ /** In-memory copy of the Mcp-Session-Id for this process; null = none. */
136
+ private sessionId;
137
+ private handshake?;
36
138
  private nextId;
37
139
  constructor(options: VideoDraftClientOptions);
140
+ /** The Mcp-Session-Id this client sends, after the handshake (null = none). */
141
+ get connectionSessionId(): string | null;
142
+ /**
143
+ * Ensure we hold a Mcp-Session-Id when a store is configured: reuse the
144
+ * stored one, else run `initialize` once and keep what the server minted.
145
+ * Fails soft — any error here leaves sessionId null and the call proceeds
146
+ * stateless (server falls back to the shared session).
147
+ */
148
+ private ensureSession;
149
+ private sessionHeaders;
150
+ /**
151
+ * The server re-mints a Mcp-Session-Id on any response whose request
152
+ * carried one it could not verify (rotated signing secret, a token minted
153
+ * for another account on this profile). Adopt it so the store self-heals
154
+ * instead of silently falling back to the shared session until the TTL.
155
+ */
156
+ private adoptSession;
38
157
  get endpoint(): string;
39
158
  rpc<T = any>(method: string, params?: unknown): Promise<T>;
40
159
  private post;
@@ -375,4 +494,4 @@ declare function refreshAccessToken(params: {
375
494
  /** RFC 7009 revocation — best-effort, used by `videodraft logout`. */
376
495
  declare function revokeToken(baseUrl: string, token: string, fetchImpl?: typeof fetch): Promise<void>;
377
496
 
378
- export { AuthError, type CliConfig, CliError, DEFAULT_BASE_URL, type DownloadedFile, EXIT, type GenerationResult, type McpToolInfo, type PollOptions, type Profile, type ResolvedAuth, RpcError, STATIC_CLI_CLIENT_ID, TimeoutError, type TokenProvider, ToolError, type UploadResult, VideoDraftClient, type VideoDraftClientOptions, authorizeViaLoopback, buildAuthorizeUrl, configDir, configPath, createPkcePair, downloadOutputs, downloadUrl, exchangeCode, extFromUrl, extractOutputUrls, getProfile, guessContentType, nextPollDelay, pollExport, pollGeneration, pollGenerations, pollGenerationsBatch, probeClientId, profileTokenProvider, readConfig, refreshAccessToken, registerCliClient, renderTemplate, resolveAuth, revokeToken, staticTokenProvider, updateConfig, uploadFile, writeConfig };
497
+ export { AuthError, type CliConfig, CliError, type ConnectionSessionRecord, type ConnectionSessionStore, DEFAULT_BASE_URL, type DownloadedFile, EXIT, type GenerationResult, MCP_SESSION_HEADER, type McpToolInfo, type PollOptions, type Profile, type ResolvedAuth, RpcError, SESSION_IDLE_MS, STATIC_CLI_CLIENT_ID, TimeoutError, type TokenProvider, ToolError, type UploadResult, VideoDraftClient, type VideoDraftClientOptions, authorizeViaLoopback, buildAuthorizeUrl, configDir, configPath, createConnectionSessionStore, createPkcePair, downloadOutputs, downloadUrl, exchangeCode, extFromUrl, extractOutputUrls, getProfile, guessContentType, nextPollDelay, pollExport, pollGeneration, pollGenerations, pollGenerationsBatch, probeClientId, profileTokenProvider, readConfig, refreshAccessToken, registerCliClient, renderTemplate, resetAllConnectionSessions, resolveAuth, revokeToken, sessionScope, staticTokenProvider, updateConfig, uploadFile, writeConfig };