dsh-lark-bot 0.15.6 → 0.15.8

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/cli.js CHANGED
@@ -3950,7 +3950,19 @@ function renderApprovalCard(input) {
3950
3950
  body: {
3951
3951
  elements: [
3952
3952
  { tag: "markdown", content: markdown2 },
3953
- { tag: "action", actions }
3953
+ ...actions.length > 0 ? [
3954
+ {
3955
+ tag: "column_set",
3956
+ flex_mode: "none",
3957
+ horizontal_spacing: "default",
3958
+ columns: actions.map((button2) => ({
3959
+ tag: "column",
3960
+ width: "auto",
3961
+ vertical_align: "center",
3962
+ elements: [button2]
3963
+ }))
3964
+ }
3965
+ ] : []
3954
3966
  ]
3955
3967
  }
3956
3968
  };
@@ -3993,15 +4005,18 @@ function renderQuestionCard(input) {
3993
4005
  body: {
3994
4006
  elements: [
3995
4007
  { tag: "markdown", content: `\u2753 ${input.question}` },
3996
- formElement(input),
3997
4008
  {
3998
- tag: "action",
3999
- actions: [
4009
+ tag: "form",
4010
+ name: `form-${input.id}`,
4011
+ elements: [
4012
+ formElement(input),
4000
4013
  {
4001
4014
  tag: "button",
4002
4015
  text: { tag: "plain_text", content: "\u63D0\u4EA4" },
4003
4016
  type: "primary",
4004
- value: { cmd: "question-submit", id: input.id }
4017
+ value: { cmd: "question-submit", id: input.id },
4018
+ form_action_type: "submit",
4019
+ name: `btn-submit-${input.id}`
4005
4020
  }
4006
4021
  ]
4007
4022
  }
@@ -4499,14 +4514,42 @@ function normalizeBaseUrl(url) {
4499
4514
  throw new Error(`baseURL \u4EC5\u652F\u6301 http/https\uFF1A${url}`);
4500
4515
  }
4501
4516
  validateBaseUrl(url);
4502
- const pathname = parsed.pathname.replace(/\/+$/, "");
4503
- if (pathname === "" || pathname === "/") {
4517
+ const pathname = stripApiOperationSuffix(parsed.pathname);
4518
+ if (pathname === "") {
4504
4519
  parsed.pathname = "/v1";
4505
4520
  } else {
4506
4521
  parsed.pathname = pathname;
4507
4522
  }
4508
4523
  return parsed.toString();
4509
4524
  }
4525
+ function normalizeDeepseekBaseUrl(url) {
4526
+ let parsed;
4527
+ try {
4528
+ parsed = new URL(url);
4529
+ } catch {
4530
+ throw new Error(`baseURL \u4E0D\u662F\u5408\u6CD5 URL\uFF1A${url}`);
4531
+ }
4532
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
4533
+ throw new Error(`baseURL \u4EC5\u652F\u6301 http/https\uFF1A${url}`);
4534
+ }
4535
+ validateBaseUrl(url);
4536
+ const pathname = stripApiOperationSuffix(parsed.pathname);
4537
+ if (pathname === "" || pathname === "/") {
4538
+ return parsed.origin;
4539
+ }
4540
+ parsed.pathname = pathname;
4541
+ return parsed.toString();
4542
+ }
4543
+ var API_OPERATION_SUFFIXES = ["/chat/completions", "/responses", "/messages"];
4544
+ function stripApiOperationSuffix(pathname) {
4545
+ const trimmed = pathname.replace(/\/+$/, "");
4546
+ for (const suffix of API_OPERATION_SUFFIXES) {
4547
+ if (trimmed.endsWith(suffix)) {
4548
+ return trimmed.slice(0, trimmed.length - suffix.length).replace(/\/+$/, "");
4549
+ }
4550
+ }
4551
+ return trimmed;
4552
+ }
4510
4553
  function validateBaseUrl(url) {
4511
4554
  let parsed;
4512
4555
  try {
@@ -4705,8 +4748,7 @@ var DshProviderManager = class {
4705
4748
  const current = isMapLike(settings[DEEPSEEK_NAMESPACE]) ? settings[DEEPSEEK_NAMESPACE] : {};
4706
4749
  const section = { ...current };
4707
4750
  if (input.baseURL !== void 0) {
4708
- validateBaseUrl(input.baseURL);
4709
- section.baseURL = input.baseURL;
4751
+ section.baseURL = normalizeDeepseekBaseUrl(input.baseURL);
4710
4752
  }
4711
4753
  if (input.apiKeyEnv !== void 0) section.apiKeyEnv = input.apiKeyEnv;
4712
4754
  if (input.apiKey !== void 0) {
@@ -5042,7 +5084,11 @@ async function handleModel(args, ctx) {
5042
5084
  }
5043
5085
  if (!requireAdmin(ctx)) return;
5044
5086
  await ctx.dshConfig.setDefaultModel(id);
5045
- await reply(ctx, `\u5DF2\u5199\u5165 dsh \u9ED8\u8BA4\u6A21\u578B\uFF08agent-default-model\uFF09\uFF1A\`${id}\`\uFF0C\u65B0\u4F1A\u8BDD\u751F\u6548\u3002`);
5087
+ await ctx.setDefaultModelPreference?.(id);
5088
+ await reply(
5089
+ ctx,
5090
+ `\u5DF2\u5199\u5165 dsh \u9ED8\u8BA4\u6A21\u578B\uFF08agent-default-model\uFF09\uFF1A\`${id}\`\uFF08\u540C\u65F6\u66F4\u65B0 profile \u9ED8\u8BA4\u6A21\u578B\uFF09\uFF0C\u65B0\u4F1A\u8BDD\u751F\u6548\u3002`
5091
+ );
5046
5092
  return;
5047
5093
  }
5048
5094
  if (sub === "add" || sub === "remove") {
@@ -5249,8 +5295,18 @@ function button(text, value, type = "default") {
5249
5295
  value
5250
5296
  };
5251
5297
  }
5252
- function actionRow(actions) {
5253
- return { tag: "action", actions };
5298
+ function buttonRow(buttons) {
5299
+ return {
5300
+ tag: "column_set",
5301
+ flex_mode: "none",
5302
+ horizontal_spacing: "default",
5303
+ columns: buttons.map((button2) => ({
5304
+ tag: "column",
5305
+ width: "auto",
5306
+ vertical_align: "center",
5307
+ elements: [button2]
5308
+ }))
5309
+ };
5254
5310
  }
5255
5311
  function wizardValue(flow, step, extra) {
5256
5312
  return { cmd: "wizard", flow, step, ...extra };
@@ -5281,22 +5337,22 @@ function renderConfigHubCard(input) {
5281
5337
  `dsh \u9ED8\u8BA4\u6A21\u578B\uFF1A${defaultLine}`
5282
5338
  ].join("\n")
5283
5339
  },
5284
- actionRow([
5340
+ buttonRow([
5285
5341
  button("\u2795 \u6DFB\u52A0 Provider", { cmd: "cfg", action: "provider-add" }, "primary"),
5286
5342
  button("\u270F\uFE0F \u4FEE\u6539 Provider", { cmd: "cfg", action: "provider-update" }),
5287
5343
  button("\u{1F5D1} \u5220\u9664 Provider", { cmd: "cfg", action: "provider-remove" }, "danger")
5288
5344
  ]),
5289
- actionRow([
5345
+ buttonRow([
5290
5346
  button("\u{1F9E0} \u6DFB\u52A0\u6A21\u578B", { cmd: "cfg", action: "model-add" }),
5291
5347
  button("\u274C \u5220\u9664\u6A21\u578B", { cmd: "cfg", action: "model-remove" }, "danger"),
5292
5348
  button("\u{1F3AF} \u5207\u6362\u6A21\u578B", { cmd: "cfg", action: "model-use" })
5293
5349
  ]),
5294
- actionRow([
5350
+ buttonRow([
5295
5351
  button("\u{1F3E0} \u8BBE\u7F6E\u9ED8\u8BA4\u6A21\u578B", { cmd: "cfg", action: "model-default" }),
5296
5352
  button("\u{1F511} \u8BBE\u7F6E\u51ED\u636E", { cmd: "cfg", action: "key-set" }),
5297
5353
  button("\u{1F513} \u5220\u9664\u51ED\u636E", { cmd: "cfg", action: "key-remove" }, "danger")
5298
5354
  ]),
5299
- actionRow([
5355
+ buttonRow([
5300
5356
  button("\u{1F504} \u5237\u65B0", { cmd: "cfg", action: "refresh" }),
5301
5357
  button("\u2716\uFE0F \u5173\u95ED", { cmd: "cfg", action: "dismiss" })
5302
5358
  ])
@@ -5309,13 +5365,14 @@ function renderWizardOptionsCard(input) {
5309
5365
  const rows = [];
5310
5366
  for (let index = 0; index < input.options.length; index += 3) {
5311
5367
  rows.push(
5312
- actionRow(
5368
+ buttonRow(
5313
5369
  input.options.slice(index, index + 3).map(
5314
5370
  (option, offset) => button(option.label, wizardValue(input.flow, input.step, { choose: index + offset }))
5315
5371
  )
5316
5372
  )
5317
5373
  );
5318
5374
  }
5375
+ rows.push(buttonRow([cancel]));
5319
5376
  return {
5320
5377
  schema: "2.0",
5321
5378
  config: {
@@ -5328,8 +5385,7 @@ function renderWizardOptionsCard(input) {
5328
5385
  content: [input.question, input.hint ? `
5329
5386
  ${input.hint}` : ""].join("")
5330
5387
  },
5331
- ...rows,
5332
- actionRow([cancel])
5388
+ ...rows
5333
5389
  ]
5334
5390
  }
5335
5391
  };
@@ -5348,14 +5404,23 @@ function renderWizardTextStepCard(input) {
5348
5404
  ${input.hint}` : ""].join("")
5349
5405
  },
5350
5406
  {
5351
- tag: "input",
5352
- name: "answer",
5353
- placeholder: { tag: "plain_text", content: input.placeholder ?? "\u8BF7\u8F93\u5165\u2026" }
5407
+ tag: "form",
5408
+ name: `form-${input.flow}-${input.step}`,
5409
+ elements: [
5410
+ {
5411
+ tag: "input",
5412
+ name: "answer",
5413
+ ...input.required === true ? { required: true } : {},
5414
+ placeholder: { tag: "plain_text", content: input.placeholder ?? "\u8BF7\u8F93\u5165\u2026" }
5415
+ },
5416
+ {
5417
+ ...button("\u63D0\u4EA4", wizardValue(input.flow, input.step, { submit: true }), "primary"),
5418
+ form_action_type: "submit",
5419
+ name: `btn-submit-${input.flow}-${input.step}`
5420
+ }
5421
+ ]
5354
5422
  },
5355
- actionRow([
5356
- button("\u63D0\u4EA4", wizardValue(input.flow, input.step, { submit: true }), "primary"),
5357
- button("\u53D6\u6D88", wizardValue(input.flow, input.step, { cancel: true }))
5358
- ])
5423
+ button("\u53D6\u6D88", wizardValue(input.flow, input.step, { cancel: true }))
5359
5424
  ]
5360
5425
  }
5361
5426
  };
@@ -5374,7 +5439,7 @@ function renderWizardConfirmStepCard(input) {
5374
5439
 
5375
5440
  ${input.summary}`
5376
5441
  },
5377
- actionRow([
5442
+ buttonRow([
5378
5443
  button(input.confirmLabel ?? "\u2705 \u786E\u8BA4", wizardValue(input.flow, input.step, { confirm: true }), "primary"),
5379
5444
  button("\u53D6\u6D88", wizardValue(input.flow, input.step, { cancel: true }))
5380
5445
  ])
@@ -5472,7 +5537,7 @@ var FLOWS = {
5472
5537
  kind: "text",
5473
5538
  question: "Base URL",
5474
5539
  placeholder: "https://www.kingapi.xyz",
5475
- hint: "\u5F62\u5982 https://gateway.example/v1\uFF1B\u6839\u57DF\u540D\u4F1A\u81EA\u52A8\u8865\u5168 /v1",
5540
+ hint: "\u5F62\u5982 https://gateway.example/v1\uFF1B\u6839\u57DF\u540D\u4F1A\u81EA\u52A8\u8865\u5168 /v1\uFF0C\u8BEF\u586B /chat/completions \u7B49\u5B8C\u6574\u63A5\u53E3\u5730\u5740\u4F1A\u81EA\u52A8\u53BB\u6389\u672B\u5C3E\u8DEF\u5F84",
5476
5541
  parse: (raw) => normalizeBaseUrl(asString(raw)?.trim() ?? "")
5477
5542
  },
5478
5543
  {
@@ -5626,8 +5691,7 @@ var FLOWS = {
5626
5691
  const url = asString(raw)?.trim() ?? "";
5627
5692
  if (!url) throw new Error("Base URL \u4E0D\u80FD\u4E3A\u7A7A");
5628
5693
  if (asString(data.provider) === DEEPSEEK_PROVIDER) {
5629
- normalizeBaseUrl(url);
5630
- return url;
5694
+ return normalizeDeepseekBaseUrl(url);
5631
5695
  }
5632
5696
  return normalizeBaseUrl(url);
5633
5697
  }
@@ -5840,7 +5904,8 @@ var FLOWS = {
5840
5904
  summary: (_ctx, data) => Promise.resolve(`\u5C06\u5199\u5165 dsh \u9ED8\u8BA4\u6A21\u578B\uFF1A\`${asString(data.model)}\``),
5841
5905
  execute: async (ctx, data) => {
5842
5906
  await ctx.dshConfig.setDefaultModel(asString(data.model));
5843
- return `\u5DF2\u5199\u5165 dsh \u9ED8\u8BA4\u6A21\u578B\uFF08agent-default-model\uFF09\uFF1A\`${asString(data.model)}\`\uFF0C\u65B0\u4F1A\u8BDD\u751F\u6548\u3002`;
5907
+ await ctx.setDefaultModelPreference?.(asString(data.model));
5908
+ return `\u5DF2\u5199\u5165 dsh \u9ED8\u8BA4\u6A21\u578B\uFF08agent-default-model\uFF09\uFF1A\`${asString(data.model)}\`\uFF08\u540C\u65F6\u66F4\u65B0 profile \u9ED8\u8BA4\u6A21\u578B\uFF09\uFF0C\u65B0\u4F1A\u8BDD\u751F\u6548\u3002`;
5844
5909
  }
5845
5910
  },
5846
5911
  "key-set": {
@@ -5991,6 +6056,7 @@ ${labels}
5991
6056
  flow: flow.id,
5992
6057
  step: state.step,
5993
6058
  question: step.question,
6059
+ ...step.optional === true ? {} : { required: true },
5994
6060
  ...step.placeholder === void 0 ? {} : { placeholder: step.placeholder },
5995
6061
  ...step.hint === void 0 ? {} : { hint: step.hint }
5996
6062
  })
@@ -7083,6 +7149,7 @@ async function startChannel(deps) {
7083
7149
  channel: commandChannel,
7084
7150
  defaultWorkspace: deps.defaultWorkspace,
7085
7151
  defaultModel: deps.defaultModel,
7152
+ ...deps.setDefaultModelPreference ? { setDefaultModelPreference: deps.setDefaultModelPreference } : {},
7086
7153
  senderId: msg.senderId
7087
7154
  };
7088
7155
  const handled = await tryHandleCommand(msg.content, context).catch(async (error) => {
@@ -7200,7 +7267,8 @@ function wizardContextFor(event, deps, channel, scope) {
7200
7267
  accessManager: deps.accessManager,
7201
7268
  models: deps.models,
7202
7269
  wizards: deps.wizardStore,
7203
- defaultModel: deps.defaultModel
7270
+ defaultModel: deps.defaultModel,
7271
+ ...deps.setDefaultModelPreference ? { setDefaultModelPreference: deps.setDefaultModelPreference } : {}
7204
7272
  };
7205
7273
  }
7206
7274
 
@@ -8614,6 +8682,14 @@ async function startBridgeEngine(options) {
8614
8682
  dshConfig,
8615
8683
  defaultRunTimeoutMs: activeProfile.preferences.runTimeoutMs ?? env.runTimeoutMs,
8616
8684
  defaultModel: activeProfile.preferences.model ?? env.model,
8685
+ setDefaultModelPreference: async (model) => {
8686
+ await configStore.saveProfile(profileName, {
8687
+ tenant: activeProfile.tenant,
8688
+ appId: activeProfile.accounts.appId,
8689
+ appSecret: activeProfile.accounts.appSecret,
8690
+ model
8691
+ });
8692
+ },
8617
8693
  accessManager: new AccessManager(configStore, profileName),
8618
8694
  pending,
8619
8695
  defaultWorkspace,