diff options
| author | Dax Raad <[email protected]> | 2025-05-28 12:53:22 -0400 |
|---|---|---|
| committer | Dax Raad <[email protected]> | 2025-05-28 12:53:22 -0400 |
| commit | 55a6fcdd3f5b3c55712e5cfc9dd4d994da38d4c8 (patch) | |
| tree | aef660f4e7b0fae135dc1f90cf6920b53238ed5b /js/src/session/session.ts | |
| parent | 4132fcc1b286af5e61bf5eaa89f789988362f995 (diff) | |
| download | opencode-55a6fcdd3f5b3c55712e5cfc9dd4d994da38d4c8.tar.gz opencode-55a6fcdd3f5b3c55712e5cfc9dd4d994da38d4c8.zip | |
add provider_list
Diffstat (limited to 'js/src/session/session.ts')
| -rw-r--r-- | js/src/session/session.ts | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/js/src/session/session.ts b/js/src/session/session.ts index 7447f4916..06c51625f 100644 --- a/js/src/session/session.ts +++ b/js/src/session/session.ts @@ -127,19 +127,19 @@ export namespace Session { } } - export async function chat( - sessionID: string, - ...parts: UIMessagePart<UIDataTypes>[] - ) { - const model = await LLM.findModel("claude-sonnet-4-20250514"); - const session = await get(sessionID); - const l = log.clone().tag("session", sessionID); + export async function chat(input: { + sessionID: string; + providerID: string; + modelID: string; + parts: UIMessagePart<UIDataTypes>[]; + }) { + const l = log.clone().tag("session", input.sessionID); l.info("chatting"); - - const msgs = await messages(sessionID); + const model = await LLM.findModel(input.providerID, input.modelID); + const msgs = await messages(input.sessionID); async function write(msg: Message) { return Storage.writeJSON( - "session/message/" + sessionID + "/" + msg.id, + "session/message/" + input.sessionID + "/" + msg.id, msg, ); } @@ -155,7 +155,7 @@ export namespace Session { }, ], metadata: { - sessionID, + sessionID: input.sessionID, time: { created: Date.now(), }, @@ -171,7 +171,7 @@ export namespace Session { }); } msgs.push(system); - state().messages.set(sessionID, msgs); + state().messages.set(input.sessionID, msgs); generateText({ messages: convertToModelMessages([ { @@ -185,12 +185,12 @@ export namespace Session { }, { role: "user", - parts, + parts: input.parts, }, ]), model, }).then((result) => { - return Session.update(sessionID, (draft) => { + return Session.update(input.sessionID, (draft) => { draft.title = result.text; }); }); @@ -199,21 +199,33 @@ export namespace Session { const msg: Message = { role: "user", id: Identifier.ascending("message"), - parts, + parts: input.parts, metadata: { time: { created: Date.now(), }, - sessionID, + sessionID: input.sessionID, tool: {}, }, }; msgs.push(msg); await write(msg); + const next: Message = { + id: Identifier.ascending("message"), + role: "assistant", + parts: [], + metadata: { + time: { + created: Date.now(), + }, + sessionID: input.sessionID, + tool: {}, + }, + }; const result = streamText({ onStepFinish: (step) => { - update(sessionID, (draft) => { + update(input.sessionID, (draft) => { draft.tokens.input += step.usage.inputTokens || 0; draft.tokens.output += step.usage.outputTokens || 0; draft.tokens.reasoning += step.usage.reasoningTokens || 0; @@ -225,18 +237,6 @@ export namespace Session { tools, model, }); - const next: Message = { - id: Identifier.ascending("message"), - role: "assistant", - parts: [], - metadata: { - time: { - created: Date.now(), - }, - sessionID, - tool: {}, - }, - }; msgs.push(next); let text: TextUIPart | undefined; |
