mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-21 17:54:23 +01:00
fix: invisible html tags and compact long delay (#304)
This commit is contained in:
@@ -248,7 +248,7 @@ export namespace Session {
|
|||||||
if (
|
if (
|
||||||
model.info.limit.context &&
|
model.info.limit.context &&
|
||||||
tokens >
|
tokens >
|
||||||
(model.info.limit.context - (model.info.limit.output ?? 0)) * 0.9
|
(model.info.limit.context - (model.info.limit.output ?? 0)) * 0.9
|
||||||
) {
|
) {
|
||||||
await summarize({
|
await summarize({
|
||||||
sessionID: input.sessionID,
|
sessionID: input.sessionID,
|
||||||
@@ -295,7 +295,7 @@ export namespace Session {
|
|||||||
draft.title = result.text
|
draft.title = result.text
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.catch(() => {})
|
.catch(() => { })
|
||||||
}
|
}
|
||||||
const msg: Message.Info = {
|
const msg: Message.Info = {
|
||||||
role: "user",
|
role: "user",
|
||||||
@@ -572,7 +572,7 @@ export namespace Session {
|
|||||||
case "tool-call": {
|
case "tool-call": {
|
||||||
const [match] = next.parts.flatMap((p) =>
|
const [match] = next.parts.flatMap((p) =>
|
||||||
p.type === "tool-invocation" &&
|
p.type === "tool-invocation" &&
|
||||||
p.toolInvocation.toolCallId === value.toolCallId
|
p.toolInvocation.toolCallId === value.toolCallId
|
||||||
? [p]
|
? [p]
|
||||||
: [],
|
: [],
|
||||||
)
|
)
|
||||||
@@ -736,7 +736,9 @@ export namespace Session {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
await updateMessage(next)
|
await updateMessage(next)
|
||||||
const result = await generateText({
|
|
||||||
|
let text: Message.TextPart | undefined
|
||||||
|
const result = streamText({
|
||||||
abortSignal: abort.signal,
|
abortSignal: abort.signal,
|
||||||
model: model.language,
|
model: model.language,
|
||||||
messages: [
|
messages: [
|
||||||
@@ -757,16 +759,46 @@ export namespace Session {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
onStepFinish: async (step) => {
|
||||||
|
const assistant = next.metadata!.assistant!
|
||||||
|
const usage = getUsage(model.info, step.usage, step.providerMetadata)
|
||||||
|
assistant.cost += usage.cost
|
||||||
|
assistant.tokens = usage.tokens
|
||||||
|
await updateMessage(next)
|
||||||
|
if (text) {
|
||||||
|
Bus.publish(Message.Event.PartUpdated, {
|
||||||
|
part: text,
|
||||||
|
messageID: next.id,
|
||||||
|
sessionID: next.metadata.sessionID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
text = undefined
|
||||||
|
},
|
||||||
|
async onFinish(input) {
|
||||||
|
const assistant = next.metadata!.assistant!
|
||||||
|
const usage = getUsage(model.info, input.usage, input.providerMetadata)
|
||||||
|
assistant.cost = usage.cost
|
||||||
|
assistant.tokens = usage.tokens
|
||||||
|
next.metadata!.time.completed = Date.now()
|
||||||
|
await updateMessage(next)
|
||||||
|
},
|
||||||
})
|
})
|
||||||
next.parts.push({
|
|
||||||
type: "text",
|
for await (const value of result.fullStream) {
|
||||||
text: result.text,
|
switch (value.type) {
|
||||||
})
|
case "text-delta":
|
||||||
const assistant = next.metadata!.assistant!
|
if (!text) {
|
||||||
const usage = getUsage(model.info, result.usage, result.providerMetadata)
|
text = {
|
||||||
assistant.cost = usage.cost
|
type: "text",
|
||||||
assistant.tokens = usage.tokens
|
text: value.textDelta,
|
||||||
await updateMessage(next)
|
}
|
||||||
|
next.parts.push(text)
|
||||||
|
} else text.text += value.textDelta
|
||||||
|
|
||||||
|
await updateMessage(next)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function lock(sessionID: string) {
|
function lock(sessionID: string) {
|
||||||
|
|||||||
@@ -252,17 +252,19 @@ func (a *App) InitializeProject(ctx context.Context) tea.Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) CompactSession(ctx context.Context) tea.Cmd {
|
func (a *App) CompactSession(ctx context.Context) tea.Cmd {
|
||||||
response, err := a.Client.PostSessionSummarizeWithResponse(ctx, client.PostSessionSummarizeJSONRequestBody{
|
go func() {
|
||||||
SessionID: a.Session.Id,
|
response, err := a.Client.PostSessionSummarizeWithResponse(ctx, client.PostSessionSummarizeJSONRequestBody{
|
||||||
ProviderID: a.Provider.Id,
|
SessionID: a.Session.Id,
|
||||||
ModelID: a.Model.Id,
|
ProviderID: a.Provider.Id,
|
||||||
})
|
ModelID: a.Model.Id,
|
||||||
if err != nil {
|
})
|
||||||
slog.Error("Failed to compact session", "error", err)
|
if err != nil {
|
||||||
}
|
slog.Error("Failed to compact session", "error", err)
|
||||||
if response != nil && response.StatusCode() != 200 {
|
}
|
||||||
slog.Error("Failed to compact session", "error", response.StatusCode)
|
if response != nil && response.StatusCode() != 200 {
|
||||||
}
|
slog.Error("Failed to compact session", "error", response.StatusCode)
|
||||||
|
}
|
||||||
|
}()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import (
|
|||||||
func toMarkdown(content string, width int, backgroundColor compat.AdaptiveColor) string {
|
func toMarkdown(content string, width int, backgroundColor compat.AdaptiveColor) string {
|
||||||
r := styles.GetMarkdownRenderer(width, backgroundColor)
|
r := styles.GetMarkdownRenderer(width, backgroundColor)
|
||||||
content = strings.ReplaceAll(content, app.RootPath+"/", "")
|
content = strings.ReplaceAll(content, app.RootPath+"/", "")
|
||||||
|
content = strings.ReplaceAll(content, "<", "\\<")
|
||||||
|
content = strings.ReplaceAll(content, ">", "\\>")
|
||||||
rendered, _ := r.Render(content)
|
rendered, _ := r.Render(content)
|
||||||
lines := strings.Split(rendered, "\n")
|
lines := strings.Split(rendered, "\n")
|
||||||
|
|
||||||
@@ -44,7 +46,6 @@ func toMarkdown(content string, width int, backgroundColor compat.AdaptiveColor)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
content = strings.Join(lines, "\n")
|
content = strings.Join(lines, "\n")
|
||||||
return strings.TrimSuffix(content, "\n")
|
return strings.TrimSuffix(content, "\n")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user