Skip to content

Commit 363a7e1

Browse files
author
Joshua Chittick
committed
fix: switch Lark channel/github fields to text inputs
Use input components for working directory, base branch, system message, git name, git email, and GitHub token while preserving callback updates from card form values.
1 parent 465e881 commit 363a7e1

File tree

2 files changed

+104
-148
lines changed

2 files changed

+104
-148
lines changed

packages/ims/lark/client.ts

Lines changed: 76 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,22 @@ function extractFormValues(payload: unknown): Record<string, string> {
731731
return normalized;
732732
}
733733

734+
function pickFormValue(
735+
formValues: Record<string, string>,
736+
key: string
737+
): { exists: boolean; value: string } {
738+
if (Object.prototype.hasOwnProperty.call(formValues, key)) {
739+
return {
740+
exists: true,
741+
value: formValues[key] ?? "",
742+
};
743+
}
744+
return {
745+
exists: false,
746+
value: "",
747+
};
748+
}
749+
734750
async function processLarkCardAction(payload: unknown): Promise<void> {
735751
if (!payload || typeof payload !== "object") return;
736752
const envelope = payload as LarkCardActionEnvelope;
@@ -809,10 +825,15 @@ async function processLarkCardAction(payload: unknown): Promise<void> {
809825
}
810826

811827
if (action === "set_channel_settings") {
828+
const formValues = extractFormValues(payload);
812829
const selected = pickActionSelectedOption(payload);
813830
const field = firstNonEmptyString(
814831
pickValueField(value, "field")
815832
);
833+
const formModel = pickFormValue(formValues, "model");
834+
const formWorkingDirectory = pickFormValue(formValues, "workingDirectory");
835+
const formBaseBranch = pickFormValue(formValues, "baseBranch");
836+
const formSystemMessage = pickFormValue(formValues, "channelSystemMessage");
816837
const provider = firstNonEmptyString(
817838
pickValueField(value, "provider"),
818839
field === "provider" ? selected : ""
@@ -831,60 +852,74 @@ async function processLarkCardAction(payload: unknown): Promise<void> {
831852
setChannelAgentProvider(channelId, provider);
832853
}
833854

834-
const model = firstNonEmptyString(
835-
pickValueField(value, "model"),
836-
field === "model" ? selected : ""
837-
);
855+
const model = formModel.exists
856+
? formModel.value
857+
: firstNonEmptyString(
858+
pickValueField(value, "model"),
859+
field === "model" ? selected : ""
860+
);
838861
setChannelModel(channelId, model);
839862

840-
const workingDirectory = firstNonEmptyString(
841-
pickValueField(value, "working_directory"),
842-
pickValueField(value, "workingDirectory"),
843-
field === "workingDirectory" ? selected : ""
844-
);
863+
const workingDirectory = formWorkingDirectory.exists
864+
? formWorkingDirectory.value
865+
: firstNonEmptyString(
866+
pickValueField(value, "working_directory"),
867+
pickValueField(value, "workingDirectory"),
868+
field === "workingDirectory" ? selected : ""
869+
);
845870
setChannelWorkingDirectory(channelId, workingDirectory || null);
846871

847-
const baseBranch = firstNonEmptyString(
848-
pickValueField(value, "base_branch"),
849-
pickValueField(value, "baseBranch"),
850-
field === "baseBranch" ? selected : ""
851-
);
872+
const baseBranch = formBaseBranch.exists
873+
? formBaseBranch.value
874+
: firstNonEmptyString(
875+
pickValueField(value, "base_branch"),
876+
pickValueField(value, "baseBranch"),
877+
field === "baseBranch" ? selected : ""
878+
);
852879
setChannelBaseBranch(channelId, baseBranch || null);
853880

854-
const channelSystemMessage = firstNonEmptyString(
855-
pickValueField(value, "channel_system_message"),
856-
pickValueField(value, "channelSystemMessage"),
857-
field === "channelSystemMessage" ? selected : ""
858-
);
881+
const channelSystemMessage = formSystemMessage.exists
882+
? formSystemMessage.value
883+
: firstNonEmptyString(
884+
pickValueField(value, "channel_system_message"),
885+
pickValueField(value, "channelSystemMessage"),
886+
field === "channelSystemMessage" ? selected : ""
887+
);
859888
setChannelSystemMessage(channelId, channelSystemMessage || null);
860889
}
861890

862891
if (action === "set_github_info") {
863892
const formValues = extractFormValues(payload);
864893
const selected = pickActionSelectedOption(payload);
865894
const field = firstNonEmptyString(pickValueField(value, "field"));
866-
const token = firstNonEmptyString(
867-
pickValueField(value, "github_token"),
868-
pickValueField(value, "githubToken"),
869-
formValues.githubToken,
870-
field === "githubToken" ? selected : ""
871-
);
872-
const gitName = firstNonEmptyString(
873-
pickValueField(value, "git_name"),
874-
pickValueField(value, "github_name"),
875-
pickValueField(value, "gitName"),
876-
pickValueField(value, "githubName"),
877-
formValues.githubName,
878-
field === "githubName" ? selected : ""
879-
);
880-
const gitEmail = firstNonEmptyString(
881-
pickValueField(value, "git_email"),
882-
pickValueField(value, "github_email"),
883-
pickValueField(value, "gitEmail"),
884-
pickValueField(value, "githubEmail"),
885-
formValues.githubEmail,
886-
field === "githubEmail" ? selected : ""
887-
);
895+
const formGithubToken = pickFormValue(formValues, "githubToken");
896+
const formGithubName = pickFormValue(formValues, "githubName");
897+
const formGithubEmail = pickFormValue(formValues, "githubEmail");
898+
const token = formGithubToken.exists
899+
? formGithubToken.value
900+
: firstNonEmptyString(
901+
pickValueField(value, "github_token"),
902+
pickValueField(value, "githubToken"),
903+
field === "githubToken" ? selected : ""
904+
);
905+
const gitName = formGithubName.exists
906+
? formGithubName.value
907+
: firstNonEmptyString(
908+
pickValueField(value, "git_name"),
909+
pickValueField(value, "github_name"),
910+
pickValueField(value, "gitName"),
911+
pickValueField(value, "githubName"),
912+
field === "githubName" ? selected : ""
913+
);
914+
const gitEmail = formGithubEmail.exists
915+
? formGithubEmail.value
916+
: firstNonEmptyString(
917+
pickValueField(value, "git_email"),
918+
pickValueField(value, "github_email"),
919+
pickValueField(value, "gitEmail"),
920+
pickValueField(value, "githubEmail"),
921+
field === "githubEmail" ? selected : ""
922+
);
888923
setGitHubInfoForUser(userId || "", {
889924
token,
890925
gitName,

packages/ims/lark/settings.ts

Lines changed: 28 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -330,26 +330,6 @@ export function buildLarkSettingsDetailCard(params: {
330330
text: { tag: "plain_text", content: item },
331331
value: item,
332332
}));
333-
const workingDirectoryOptions = Array.from(new Set([
334-
cwd === "(not set)" ? "" : cwd,
335-
"/root/ode-new",
336-
"/root",
337-
])).map((item) => ({
338-
text: { tag: "plain_text", content: item || "(empty)" },
339-
value: item,
340-
}));
341-
const baseBranchOptions = ["main", "master", "develop", "dev"].map((item) => ({
342-
text: { tag: "plain_text", content: item },
343-
value: item,
344-
}));
345-
const channelSystemMessageOptions = [
346-
{ label: "(empty)", value: "" },
347-
{ label: "concise", value: "Please keep responses concise and actionable." },
348-
{ label: "detailed", value: "Please provide detailed reasoning and include implementation notes." },
349-
].map((item) => ({
350-
text: { tag: "plain_text", content: item.label },
351-
value: item.value,
352-
}));
353333
const settingsBaseValue = {
354334
action: "set_channel_settings",
355335
channelId,
@@ -430,65 +410,41 @@ export function buildLarkSettingsDetailCard(params: {
430410
content: "Working directory",
431411
},
432412
{
433-
tag: "action",
434-
actions: [
435-
{
436-
tag: "select_static",
437-
placeholder: { tag: "plain_text", content: "Select working directory" },
438-
options: workingDirectoryOptions,
439-
value: {
440-
...settingsBaseValue,
441-
field: "workingDirectory",
442-
},
443-
},
444-
],
413+
tag: "input",
414+
name: "workingDirectory",
415+
placeholder: { tag: "plain_text", content: "Enter working directory" },
416+
value: cwd === "(not set)" ? "" : cwd,
445417
},
446418
{
447419
tag: "markdown",
448420
content: "Base branch",
449421
},
450422
{
451-
tag: "action",
452-
actions: [
453-
{
454-
tag: "select_static",
455-
placeholder: { tag: "plain_text", content: "Select base branch" },
456-
options: baseBranchOptions,
457-
value: {
458-
...settingsBaseValue,
459-
field: "baseBranch",
460-
},
461-
},
462-
],
423+
tag: "input",
424+
name: "baseBranch",
425+
placeholder: { tag: "plain_text", content: "Enter base branch" },
426+
value: baseBranch,
463427
},
464428
{
465429
tag: "markdown",
466430
content: "Channel system message",
467431
},
468432
{
469-
tag: "action",
470-
actions: [
471-
{
472-
tag: "select_static",
473-
placeholder: { tag: "plain_text", content: "Select system message preset" },
474-
options: channelSystemMessageOptions,
475-
value: {
476-
...settingsBaseValue,
477-
field: "channelSystemMessage",
478-
},
479-
},
480-
],
433+
tag: "input",
434+
name: "channelSystemMessage",
435+
placeholder: { tag: "plain_text", content: "Enter channel system message" },
436+
value: systemMessage === "(none)" ? "" : systemMessage,
481437
},
482438
{
483439
tag: "action",
484440
actions: [
485441
{
486442
tag: "button",
487443
type: "primary",
488-
text: { tag: "plain_text", content: "Refresh" },
444+
text: { tag: "plain_text", content: "Save channel setting" },
489445
value: {
490446
...settingsBaseValue,
491-
field: "refresh",
447+
field: "save",
492448
},
493449
},
494450
{
@@ -550,76 +506,41 @@ export function buildLarkSettingsDetailCard(params: {
550506
content: "GitHub token",
551507
},
552508
{
553-
tag: "action",
554-
actions: [
555-
{
556-
tag: "select_static",
557-
placeholder: { tag: "plain_text", content: "Token action" },
558-
options: [
559-
{ text: { tag: "plain_text", content: "Keep current" }, value: githubToken },
560-
{ text: { tag: "plain_text", content: "Clear token" }, value: "" },
561-
],
562-
value: {
563-
...githubBaseValue,
564-
field: "githubToken",
565-
},
566-
},
567-
],
509+
tag: "input",
510+
name: "githubToken",
511+
placeholder: { tag: "plain_text", content: "Enter GitHub token" },
512+
value: githubToken,
568513
},
569514
{
570515
tag: "markdown",
571516
content: "Git name",
572517
},
573518
{
574-
tag: "action",
575-
actions: [
576-
{
577-
tag: "select_static",
578-
placeholder: { tag: "plain_text", content: "Select git name" },
579-
options: [
580-
{ text: { tag: "plain_text", content: githubName || "(not set)" }, value: githubName },
581-
{ text: { tag: "plain_text", content: "LIU9293" }, value: "LIU9293" },
582-
{ text: { tag: "plain_text", content: "(empty)" }, value: "" },
583-
],
584-
value: {
585-
...githubBaseValue,
586-
field: "githubName",
587-
},
588-
},
589-
],
519+
tag: "input",
520+
name: "githubName",
521+
placeholder: { tag: "plain_text", content: "Enter git name" },
522+
value: githubName,
590523
},
591524
{
592525
tag: "markdown",
593526
content: "Git email",
594527
},
595528
{
596-
tag: "action",
597-
actions: [
598-
{
599-
tag: "select_static",
600-
placeholder: { tag: "plain_text", content: "Select git email" },
601-
options: [
602-
{ text: { tag: "plain_text", content: githubEmail || "(not set)" }, value: githubEmail },
603-
{ text: { tag: "plain_text", content: "mylock.kai@gmail.com" }, value: "mylock.kai@gmail.com" },
604-
{ text: { tag: "plain_text", content: "(empty)" }, value: "" },
605-
],
606-
value: {
607-
...githubBaseValue,
608-
field: "githubEmail",
609-
},
610-
},
611-
],
529+
tag: "input",
530+
name: "githubEmail",
531+
placeholder: { tag: "plain_text", content: "Enter git email" },
532+
value: githubEmail,
612533
},
613534
{
614535
tag: "action",
615536
actions: [
616537
{
617538
tag: "button",
618539
type: "primary",
619-
text: { tag: "plain_text", content: "Refresh" },
540+
text: { tag: "plain_text", content: "Save GitHub setting" },
620541
value: {
621542
...githubBaseValue,
622-
field: "refresh",
543+
field: "save",
623544
},
624545
},
625546
{

0 commit comments

Comments
 (0)