@302ai/media-studio-cli 0.1.1-beta.1 → 0.1.1-beta.2

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.
Files changed (2) hide show
  1. package/dist/index.js +52 -11
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4284,7 +4284,7 @@ var consola = createConsola2();
4284
4284
  // package.json
4285
4285
  var package_default = {
4286
4286
  name: "@302ai/media-studio-cli",
4287
- version: "0.1.1-beta.1",
4287
+ version: "0.1.1-beta.2",
4288
4288
  description: "CLI for AI Media Studio — let external agents drive the core media-studio features",
4289
4289
  author: "302.AI",
4290
4290
  license: "Apache-2.0",
@@ -9784,6 +9784,7 @@ var ErrCode = {
9784
9784
  FORBIDDEN: 20301,
9785
9785
  ADMIN_REQUIRED: 20302,
9786
9786
  ACCOUNT_DEACTIVATED: 20303,
9787
+ CAPTCHA_VERIFY_FAILED: 20401,
9787
9788
  INSUFFICIENT_BALANCE: 30001,
9788
9789
  CREDIT_FREEZE_FAILED: 30002,
9789
9790
  FREEZE_RECORD_NOT_FOUND: 30003,
@@ -9929,6 +9930,7 @@ var ERR_NEXT_STEP = {
9929
9930
  20301: "none",
9930
9931
  20302: "none",
9931
9932
  20303: "relogin",
9933
+ 20401: "fix_input",
9932
9934
  30001: "top_up_balance",
9933
9935
  30002: "retry",
9934
9936
  30003: "none",
@@ -16906,6 +16908,7 @@ var AuthDataSchema = object2({
16906
16908
  });
16907
16909
  var ConfigFileSchema = object2({
16908
16910
  lastSessionId: string4().optional(),
16911
+ lastSessionPendingNote: boolean4().optional(),
16909
16912
  updateCheck: object2({
16910
16913
  checkedAt: number4(),
16911
16914
  beta: string4().optional(),
@@ -16984,8 +16987,17 @@ function writeConfigFile(patch) {
16984
16987
  function readLastSessionId() {
16985
16988
  return readConfigFile()?.lastSessionId ?? null;
16986
16989
  }
16987
- function saveLastSessionId(sessionId) {
16988
- writeConfigFile({ lastSessionId: sessionId });
16990
+ function saveLastSessionId(sessionId, options) {
16991
+ writeConfigFile({
16992
+ lastSessionId: sessionId,
16993
+ lastSessionPendingNote: options?.pendingNote ?? false
16994
+ });
16995
+ }
16996
+ function readLastSessionPendingNote() {
16997
+ return readConfigFile()?.lastSessionPendingNote ?? false;
16998
+ }
16999
+ function clearLastSessionPendingNote() {
17000
+ writeConfigFile({ lastSessionPendingNote: false });
16989
17001
  }
16990
17002
  function readUpdateCheck() {
16991
17003
  return readConfigFile()?.updateCheck;
@@ -17102,6 +17114,14 @@ var ListArtifactsQuerySchema = object2({
17102
17114
  var ListArtifactsResponseSchema = ApiResponseBaseSchema.extend({
17103
17115
  data: ArtifactItemsSchema
17104
17116
  });
17117
+ var SessionDetailSummarySchema = ApiResponseBaseSchema.extend({
17118
+ titleCustomized: boolean4().optional(),
17119
+ title_customized: boolean4().optional(),
17120
+ snapshots: array2(unknown2()).optional()
17121
+ }).transform((data) => ({
17122
+ titleCustomized: data.titleCustomized ?? data.title_customized ?? false,
17123
+ isEmpty: (data.snapshots?.length ?? 0) === 0
17124
+ }));
17105
17125
  var PrewarmSessionReadySchema = object2({
17106
17126
  session_id: string4(),
17107
17127
  note: string4().nullable(),
@@ -17170,15 +17190,22 @@ class ClientSessions {
17170
17190
  const url = `${this.baseUrl}/api/sessions${search ? `?${search}` : ""}`;
17171
17191
  return requestJson(this.customFetch, url, { method: "GET", headers: this.authHeaders() }, ListSessionsResponseSchema, (status) => `Failed to fetch sessions with status ${status}`);
17172
17192
  }
17173
- async exists(sessionId) {
17193
+ async getDetailSummary(sessionId) {
17174
17194
  const params = new URLSearchParams({ sessionId, limit: "1" });
17175
- const [err] = await attemptAsync(() => requestJson(this.customFetch, `${this.baseUrl}/api/sessions/detail?${params.toString()}`, { method: "GET", headers: this.authHeaders() }, unknown2(), (status) => `Failed to verify session ${sessionId} with status ${status}`));
17176
- if (!err)
17177
- return true;
17195
+ const [err, res] = await attemptAsync(() => requestJson(this.customFetch, `${this.baseUrl}/api/sessions/detail?${params.toString()}`, { method: "GET", headers: this.authHeaders() }, SessionDetailSummarySchema, (status) => `Failed to fetch session detail for ${sessionId} with status ${status}`));
17196
+ if (!err && res)
17197
+ return res;
17178
17198
  if (err instanceof ChatUpstreamError && err.status === 404)
17179
- return false;
17199
+ return null;
17180
17200
  throw err;
17181
17201
  }
17202
+ async updateNote(sessionId, note) {
17203
+ await requestJson(this.customFetch, `${this.baseUrl}/api/sessions/note`, {
17204
+ method: "POST",
17205
+ headers: { ...this.authHeaders(), "Content-Type": "application/json" },
17206
+ body: JSON.stringify({ sessionId, note })
17207
+ }, unknown2(), (status) => `Failed to update session note for ${sessionId} with status ${status}`);
17208
+ }
17182
17209
  async artifacts(query) {
17183
17210
  const params = new URLSearchParams({ sessionId: query.sessionId });
17184
17211
  if (query.taskId !== undefined)
@@ -18106,8 +18133,9 @@ async function ensureSessionExists(options) {
18106
18133
  baseUrl: options.apiBaseUrl,
18107
18134
  apiKey: options.apiKey
18108
18135
  });
18109
- if (await client.sessions.exists(options.sessionId))
18110
- return;
18136
+ const detail = await client.sessions.getDetailSummary(options.sessionId);
18137
+ if (detail)
18138
+ return detail;
18111
18139
  throw new SessionNotFoundError(options.sessionId);
18112
18140
  }
18113
18141
  function finalizeProvision(result, spinner) {
@@ -18541,8 +18569,9 @@ var chatCommand = defineCommand({
18541
18569
  if (args.new && args.session) {
18542
18570
  throw new Error("--new and --session cannot be combined: --session selects an existing session, --new creates one.");
18543
18571
  }
18572
+ let explicitSessionDetail;
18544
18573
  if (args.session) {
18545
- await ensureSessionExists({
18574
+ explicitSessionDetail = await ensureSessionExists({
18546
18575
  apiBaseUrl,
18547
18576
  apiKey: resolveApiKey(),
18548
18577
  sessionId: args.session
@@ -18573,6 +18602,17 @@ var chatCommand = defineCommand({
18573
18602
  spinner,
18574
18603
  quiet: args.json === true
18575
18604
  });
18605
+ if (args.session || args.new) {
18606
+ clearLastSessionPendingNote();
18607
+ }
18608
+ const shouldPatchNote = Boolean(explicitSessionDetail && !explicitSessionDetail.titleCustomized && explicitSessionDetail.isEmpty || !args.session && !args.new && readLastSessionPendingNote());
18609
+ if (shouldPatchNote) {
18610
+ const derivedNote = deriveFirstTurnNote(buildNotePrompt(promptWithAttachments, attachments), { fallbackTitle: CLI_DEFAULT_SESSION_NOTE });
18611
+ new MediaStudioClient({
18612
+ baseUrl: apiBaseUrl,
18613
+ apiKey: resolveApiKey()
18614
+ }).sessions.updateNote(resolved.sessionId, derivedNote).then(() => clearLastSessionPendingNote()).catch(() => {});
18615
+ }
18576
18616
  await runTurn({
18577
18617
  args,
18578
18618
  prompt: promptWithAttachments,
@@ -20887,6 +20927,7 @@ var useSessionCommand = defineCommand({
20887
20927
  note: CLI_DEFAULT_SESSION_NOTE
20888
20928
  });
20889
20929
  const created = finalizeProvision(result);
20930
+ saveLastSessionId(created, { pendingNote: true });
20890
20931
  if (args.json) {
20891
20932
  process.stdout.write(`${JSON.stringify({ sessionId: created })}
20892
20933
  `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@302ai/media-studio-cli",
3
- "version": "0.1.1-beta.1",
3
+ "version": "0.1.1-beta.2",
4
4
  "description": "CLI for AI Media Studio — let external agents drive the core media-studio features",
5
5
  "author": "302.AI",
6
6
  "license": "Apache-2.0",