initialized

This commit is contained in:
Dax Raad
2025-06-03 14:24:45 -04:00
parent be4155a838
commit caf9fdc893
5 changed files with 382 additions and 18 deletions

View File

@@ -10,15 +10,15 @@ export namespace App {
export const Info = z
.object({
time: z.object({
initialized: z.number().optional(),
}),
git: z.boolean(),
path: z.object({
data: z.string(),
root: z.string(),
cwd: z.string(),
}),
time: z.object({
initialized: z.number().optional(),
}),
})
.openapi({
ref: "App.Info",
@@ -33,16 +33,12 @@ export namespace App {
)
const data = path.join(Global.data(), git ?? "global")
await Bun.write(path.join(data, "version"), input.version)
const stateFile = Bun.file(path.join(data, "state"))
const state = (
(await stateFile.exists()) ? await stateFile.json() : {}
) as {
const state = (await stateFile.json().catch(() => ({}))) as {
initialized: number
version: string
}
state.version = input.version
if (!git) state.initialized = Date.now()
await stateFile.write(JSON.stringify(state))
const services = new Map<
@@ -67,6 +63,7 @@ export namespace App {
},
}
const result = {
version: input.version,
services,
info,
}
@@ -102,7 +99,6 @@ export namespace App {
cb: T,
) {
const app = await create(input)
return ctx.provide(app, async () => {
const result = await cb(app.info)
for (const [key, entry] of app.services.entries()) {
@@ -112,4 +108,16 @@ export namespace App {
return result
})
}
export async function initialize() {
const { info, version } = ctx.use()
info.time.initialized = Date.now()
await Bun.write(
path.join(info.path.data, "state"),
JSON.stringify({
version,
initialized: Date.now(),
}),
)
}
}

View File

@@ -100,6 +100,26 @@ export namespace Server {
return c.json(App.info())
},
)
.post(
"/app_initialize",
describeRoute({
description: "Initialize the app",
responses: {
200: {
description: "Initialize the app",
content: {
"application/json": {
schema: resolver(z.boolean()),
},
},
},
},
}),
async (c) => {
await App.initialize()
return c.json(true)
},
)
.post(
"/session_initialize",
describeRoute({

View File

@@ -350,6 +350,7 @@ ${app.git ? await ListTool.execute({ path: app.path.cwd }, { sessionID: input.se
assistant.tokens = usage.tokens
await updateMessage(next)
},
toolCallStreaming: false,
abortSignal: abort.signal,
maxRetries: 6,
stopWhen: stepCountIs(1000),
@@ -403,6 +404,21 @@ ${app.git ? await ListTool.execute({ path: app.path.cwd }, { sessionID: input.se
})
break
case "tool-call-streaming-start":
next.parts.push({
type: "tool-invocation",
toolInvocation: {
state: "call",
toolName: value.toolName,
toolCallId: value.toolCallId,
args: {},
},
})
break
case "tool-call-delta":
break
case "tool-result":
const match = next.parts.find(
(p) =>
@@ -566,5 +582,6 @@ ${app.git ? await ListTool.execute({ path: app.path.cwd }, { sessionID: input.se
},
],
})
await App.initialize()
}
}