| 1 | package control |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "errors" |
| 6 | "reasonix/internal/agent" |
| 7 | "reasonix/internal/session" |
| 8 | ) |
| 9 | |
| 10 | // InitializeReservedSession initializes only an explicitly reserved, still empty |
| 11 | // identity. It shares the ordinary creation seed, including the system prompt. |
| 12 | // The Desktop creation owner holds the per-operation lease across this call. |
| 13 | func (c *Controller) InitializeReservedSession(ctx context.Context, ref session.SessionRef) (result error) { |
| 14 | service, _, _ := c.v3Binding() |
| 15 | if service == nil { |
| 16 | return errors.New("session service is unavailable") |
| 17 | } |
| 18 | binding, err := service.Open(ctx, ref) |
| 19 | if err != nil { |
| 20 | return err |
| 21 | } |
| 22 | defer func() { result = errors.Join(result, binding.Release(context.Background())) }() |
| 23 | runtime := binding.Runtime() |
| 24 | if len(runtime.Session().ExecutionSnapshot().Projection.ModelMessages) == 0 { |
| 25 | fresh := agent.NewSession(c.basePrompt()) |
| 26 | if err := seedRuntimeSession(ctx, runtime, "session-create", fresh.Snapshot(), c.ModelRef(), c.ModelSelectionIdentity()); err != nil { |
| 27 | return err |
| 28 | } |
| 29 | } |
| 30 | _, err = runtime.Session().Flush(ctx) |
| 31 | return err |
| 32 | } |
| 33 |