| 548 | } |
| 549 | |
| 550 | async function createFreshSession( |
| 551 | sdk: OpencodeClient, |
| 552 | input: { agent: string | undefined; model: ModelInput | undefined; variant: string | undefined }, |
| 553 | ): Promise<SessionInfo> { |
| 554 | const result = await sdk.session.create({ |
| 555 | title: args.title !== undefined && args.title !== "" ? args.title : undefined, |
| 556 | agent: input.agent, |
| 557 | model: input.model |
| 558 | ? { |
| 559 | providerID: input.model.providerID, |
| 560 | id: input.model.modelID, |
| 561 | variant: input.variant, |
| 562 | } |
| 563 | : undefined, |
| 564 | permission: [...rules], |
| 565 | }) |
| 566 | const id = result.data?.id |
| 567 | if (!id) { |
| 568 | throw new Error("Failed to create session") |
| 569 | } |
| 570 | |
| 571 | void share(sdk, id).catch(() => {}) |
| 572 | return { |
| 573 | id, |
| 574 | title: result.data?.title, |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | async function current(sdk: OpencodeClient): Promise<string> { |
| 579 | if (!args.attach) { |