use full filepath
Some checks are pending
deploy / deploy (push) Waiting to run
publish / publish (push) Waiting to run

This commit is contained in:
Dax Raad 2025-07-04 17:57:48 -04:00
parent 107363b1d9
commit ea6bfef21a
3 changed files with 28 additions and 23 deletions

View file

@ -1,6 +1,8 @@
import { App } from "../app/app" import { App } from "../app/app"
import { Log } from "../util/log"
export namespace FileTime { export namespace FileTime {
const log = Log.create({ service: "file.time" })
export const state = App.state("tool.filetimes", () => { export const state = App.state("tool.filetimes", () => {
const read: { const read: {
[sessionID: string]: { [sessionID: string]: {
@ -13,6 +15,7 @@ export namespace FileTime {
}) })
export function read(sessionID: string, file: string) { export function read(sessionID: string, file: string) {
log.info("read", { sessionID, file })
const { read } = state() const { read } = state()
read[sessionID] = read[sessionID] || {} read[sessionID] = read[sessionID] || {}
read[sessionID][file] = new Date() read[sessionID][file] = new Date()

View file

@ -1,41 +1,42 @@
import path from "node:path" import path from "node:path"
import { App } from "../app/app" import { Decimal } from "decimal.js"
import { Identifier } from "../id/id" import { z, ZodSchema } from "zod"
import { Storage } from "../storage/storage"
import { Log } from "../util/log"
import { import {
generateText, generateText,
LoadAPIKeyError, LoadAPIKeyError,
convertToCoreMessages, convertToCoreMessages,
streamText, streamText,
tool, tool,
wrapLanguageModel,
type Tool as AITool, type Tool as AITool,
type LanguageModelUsage, type LanguageModelUsage,
type CoreMessage, type CoreMessage,
type UIMessage, type UIMessage,
type ProviderMetadata, type ProviderMetadata,
wrapLanguageModel,
type Attachment, type Attachment,
} from "ai" } from "ai"
import { z, ZodSchema } from "zod"
import { Decimal } from "decimal.js"
import PROMPT_INITIALIZE from "../session/prompt/initialize.txt" import PROMPT_INITIALIZE from "../session/prompt/initialize.txt"
import { Share } from "../share/share" import { App } from "../app/app"
import { Message } from "./message"
import { Bus } from "../bus" import { Bus } from "../bus"
import { Provider } from "../provider/provider"
import { MCP } from "../mcp"
import { NamedError } from "../util/error"
import type { Tool } from "../tool/tool"
import { SystemPrompt } from "./system"
import { Flag } from "../flag/flag"
import type { ModelsDev } from "../provider/models"
import { Installation } from "../installation"
import { Config } from "../config/config" import { Config } from "../config/config"
import { Flag } from "../flag/flag"
import { Identifier } from "../id/id"
import { Installation } from "../installation"
import { MCP } from "../mcp"
import { Provider } from "../provider/provider"
import { ProviderTransform } from "../provider/transform" import { ProviderTransform } from "../provider/transform"
import type { ModelsDev } from "../provider/models"
import { Share } from "../share/share"
import { Snapshot } from "../snapshot" import { Snapshot } from "../snapshot"
import { Storage } from "../storage/storage"
import type { Tool } from "../tool/tool"
import { Log } from "../util/log"
import { NamedError } from "../util/error"
import { Message } from "./message"
import { SystemPrompt } from "./system"
import { FileTime } from "../file/time"
export namespace Session { export namespace Session {
const log = Log.create({ service: "session" }) const log = Log.create({ service: "session" })
@ -367,10 +368,11 @@ export namespace Session {
const url = new URL(part.url) const url = new URL(part.url)
switch (url.protocol) { switch (url.protocol) {
case "file:": case "file:":
let content = Bun.file(path.join(app.path.cwd, url.pathname)) const filepath = path.join(app.path.cwd, url.pathname)
let file = Bun.file(filepath)
if (part.mediaType === "text/plain") { if (part.mediaType === "text/plain") {
let text = await content.text() let text = await file.text()
const range = { const range = {
start: url.searchParams.get("start"), start: url.searchParams.get("start"),
end: url.searchParams.get("end"), end: url.searchParams.get("end"),
@ -381,6 +383,7 @@ export namespace Session {
const end = range.end ? parseInt(range.end) : lines.length const end = range.end ? parseInt(range.end) : lines.length
text = lines.slice(start, end).join("\n") text = lines.slice(start, end).join("\n")
} }
FileTime.read(input.sessionID, filepath)
return [ return [
{ {
type: "text", type: "text",
@ -403,9 +406,9 @@ export namespace Session {
type: "file", type: "file",
url: url:
`data:${part.mediaType};base64,` + `data:${part.mediaType};base64,` +
Buffer.from(await content.bytes()).toString("base64url"), Buffer.from(await file.bytes()).toString("base64url"),
mediaType: part.mediaType, mediaType: part.mediaType,
filename: path.basename(part.filename!), filename: part.filename!,
}, },
] ]
} }

View file

@ -92,7 +92,6 @@ func (m *editorComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Now, insert the attachment at the position where the '@' was. // Now, insert the attachment at the position where the '@' was.
// The cursor is now at `atIndex` after the replacement. // The cursor is now at `atIndex` after the replacement.
filePath := msg.CompletionValue filePath := msg.CompletionValue
fileName := filepath.Base(filePath)
extension := filepath.Ext(filePath) extension := filepath.Ext(filePath)
mediaType := "" mediaType := ""
switch extension { switch extension {
@ -107,7 +106,7 @@ func (m *editorComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
} }
attachment := &textarea.Attachment{ attachment := &textarea.Attachment{
ID: uuid.NewString(), ID: uuid.NewString(),
Display: "@" + fileName, Display: "@" + filePath,
URL: fmt.Sprintf("file://./%s", filePath), URL: fmt.Sprintf("file://./%s", filePath),
Filename: filePath, Filename: filePath,
MediaType: mediaType, MediaType: mediaType,