MCPcopy Create free account
hub / github.com/diillson/chatcli / handleSaveSession

Method handleSaveSession

cli/cli_session.go:80–143  ·  view source on GitHub ↗
(ctx context.Context, name string)

Source from the content-addressed store, hash-verified

78}
79
80func (cli *ChatCLI) handleSaveSession(ctx context.Context, name string) {
81 if cli.isRemote {
82 rc := cli.getRemoteClient()
83 if rc == nil {
84 fmt.Println(i18n.T("session.error_save", fmt.Errorf("remote client unavailable")))
85 return
86 }
87
88 fmt.Println(i18n.T("session.save_where_prompt", name))
89 choice := askSessionChoice(
90 []string{"session.save_option_local", "session.save_option_remote", "session.save_option_both"},
91 map[string]string{"l": "local", "r": "remote", "b": "both"},
92 "local",
93 )
94
95 sd := cli.buildSessionData()
96
97 switch choice {
98 case "remote":
99 reqCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
100 defer cancel()
101 if err := rc.SaveSessionV2(reqCtx, name, sd); err != nil {
102 fmt.Println(i18n.T("session.error_save", err))
103 } else {
104 cli.currentSessionName = name
105 fmt.Println(i18n.T("session.save_success_remote", name))
106 }
107 case "both":
108 var localErr, remoteErr error
109 localErr = cli.sessionManager.SaveSessionV2(name, sd)
110 reqCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
111 defer cancel()
112 remoteErr = rc.SaveSessionV2(reqCtx, name, sd)
113
114 if localErr != nil {
115 fmt.Println(i18n.T("session.error_save", fmt.Errorf("local: %w", localErr)))
116 }
117 if remoteErr != nil {
118 fmt.Println(i18n.T("session.error_save", fmt.Errorf("remote: %w", remoteErr)))
119 }
120 if localErr == nil && remoteErr == nil {
121 cli.currentSessionName = name
122 fmt.Println(i18n.T("session.save_success_both", name))
123 }
124 default: // "local"
125 if err := cli.sessionManager.SaveSessionV2(name, sd); err != nil {
126 fmt.Println(i18n.T("session.error_save", err))
127 } else {
128 cli.currentSessionName = name
129 fmt.Println(i18n.T("session.save_success", name))
130 }
131 }
132 return
133 }
134
135 // Local only (not connected)
136 sd := cli.buildSessionData()
137 if err := cli.sessionManager.SaveSessionV2(name, sd); err != nil {

Callers 1

handleSessionCommandMethod · 0.80

Calls 6

getRemoteClientMethod · 0.95
buildSessionDataMethod · 0.95
TFunction · 0.92
askSessionChoiceFunction · 0.85
ErrorfMethod · 0.80
SaveSessionV2Method · 0.65

Tested by

no test coverage detected