(ctx context.Context, name string)
| 78 | } |
| 79 | |
| 80 | func (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 { |
no test coverage detected