stub := exec.Command("npx", "dari-gateway-stub", "--plans", "openai_codex")
out, _ := stub.StdoutPipe()
if err := stub.Start(); err != nil {
t.Fatal(err)
}
defer stub.Process.Signal(os.Interrupt)
var dari struct {
ControlURL string `json:"controlUrl"`
App struct{ GatewayURL, ClientID, ClientSecret, RedirectURI string }
}
json.NewDecoder(out).Decode(&dari)
// Point your app at it.
configure(dari.App.GatewayURL, dari.App.ClientID, dari.App.ClientSecret, dari.App.RedirectURI)
// The user clicks Connect with Dari and approves. This is what your page gets:
var approved struct {
Code string `json:"code"`
CodeVerifier string `json:"code_verifier"`
}
res, err := http.Post(dari.ControlURL+"/connect", "application/json", nil)
if err != nil {
t.Fatal(err)
}
json.NewDecoder(res.Body).Decode(&approved)
myApp.Connect(approved.Code, approved.CodeVerifier)
// Run what your app does, then check what reached the provider.
var served struct {
Calls []struct{ Kind, Model string }
}
res, _ = http.Get(dari.ControlURL + "/served")
json.NewDecoder(res.Body).Decode(&served)