Improve workflow UI, retain stage diffs, and add portable pipeline transfers
Make OpenCode authoring responsive and expand the managed skill references. Add conflict-aware import/export, real-provider reference workflows, and tracked V2 generation for reliable budget accounting.
This commit is contained in:
@@ -157,7 +157,7 @@ func safeCommandDiagnostic(err error, data []byte) string {
|
||||
return detail
|
||||
}
|
||||
|
||||
func (c OpenCodeClient) Generate(ctx context.Context, config ModelConfig, prompt string) (text string, err error) {
|
||||
func (c *OpenCodeClient) Generate(ctx context.Context, config ModelConfig, prompt string) (text string, err error) {
|
||||
if c.Operations != nil {
|
||||
c.Operations.Provider, c.Operations.Model = config.Provider, config.Model
|
||||
}
|
||||
@@ -240,6 +240,50 @@ func (c OpenCodeClient) Generate(ctx context.Context, config ModelConfig, prompt
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
// V2 /generate returns text only and does not persist messages or update
|
||||
// session usage. Budgeted calls must use tracked, deny-all prompting instead.
|
||||
if c.Backend == "v2" && config.Budget.Enabled() {
|
||||
if _, err = c.call(ctx, "post", "/api/session/"+session.Data.ID+"/prompt", generationBody("text", prompt, config, c.Backend)); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if _, err = c.call(ctx, "post", "/api/experimental/session/"+session.Data.ID+"/wait", nil); err != nil {
|
||||
return "", err
|
||||
}
|
||||
var data []byte
|
||||
data, err = c.call(ctx, "get", "/api/session/"+session.Data.ID+"/message?order=desc&limit=100&type=assistant", nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
c.FormatAudit = string(data)
|
||||
text, err = completedAgentResult(data)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
// A completed tracked response must have accounted tokens; session-zero
|
||||
// placeholders are not proof of a free, zero-token provider request.
|
||||
usageCtx, usageCancel := context.WithTimeout(context.WithoutCancel(ctx), 2*time.Second)
|
||||
usage, usageErr := c.call(usageCtx, "get", "/api/session/"+session.Data.ID, nil)
|
||||
usageCancel()
|
||||
if usageErr != nil {
|
||||
return "", fmt.Errorf("%w: %v", ErrBudgetAccounting, usageErr)
|
||||
}
|
||||
if usageErr = config.Budget.readUsage(session.Data.ID, usage, false, true); usageErr != nil {
|
||||
return "", usageErr
|
||||
}
|
||||
if config.Budget.Snapshot().LimitTokens > 0 {
|
||||
var response struct {
|
||||
Data struct{ reportedUsage } `json:"data"`
|
||||
}
|
||||
if json.Unmarshal(usage, &response) != nil {
|
||||
return "", ErrBudgetAccounting
|
||||
}
|
||||
u := response.Data.Tokens
|
||||
if u == nil || u.Input == nil || u.Output == nil || u.Reasoning == nil || u.Cache == nil || u.Cache.Read == nil || u.Cache.Write == nil || *u.Input+*u.Output+*u.Reasoning+*u.Cache.Read+*u.Cache.Write == 0 {
|
||||
return "", fmt.Errorf("%w: completed V2 response reported zero tokens", ErrBudgetAccounting)
|
||||
}
|
||||
}
|
||||
return text, nil
|
||||
}
|
||||
response, err := c.call(ctx, "post", "/api/session/"+session.Data.ID+"/generate", body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
Reference in New Issue
Block a user