MCPcopy Index your code
hub / github.com/the-open-agent/openagent / createSession

Method createSession

model/opencode.go:147–178  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

145}
146
147func (p *OpenCodeProvider) createSession() (string, error) {
148 ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
149 defer cancel()
150
151 req, err := http.NewRequestWithContext(ctx, "POST", p.serverUrl+"/session", bytes.NewReader([]byte("{}")))
152 if err != nil {
153 return "", err
154 }
155
156 p.setAuth(req)
157 req.Header.Set("Content-Type", "application/json")
158
159 resp, err := p.client.Do(req)
160 if err != nil {
161 return "", err
162 }
163 defer resp.Body.Close()
164
165 if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
166 body, _ := io.ReadAll(resp.Body)
167 return "", fmt.Errorf("HTTP %d: %s", resp.StatusCode, string(body))
168 }
169
170 var result struct {
171 ID string `json:"id"`
172 }
173 if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
174 return "", err
175 }
176
177 return result.ID, nil
178}
179
180func (p *OpenCodeProvider) deleteSession(sessionID string) {
181 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)

Callers 1

QueryTextMethod · 0.95

Calls 2

setAuthMethod · 0.95
CloseMethod · 0.45

Tested by

no test coverage detected