seed-e2e.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { AppRuntime } from "@/effect/app-runtime"
  2. const dir = process.env.KILO_E2E_PROJECT_DIR ?? process.cwd()
  3. const title = process.env.KILO_E2E_SESSION_TITLE ?? "E2E Session"
  4. const text = process.env.KILO_E2E_MESSAGE ?? "Seeded for UI e2e"
  5. const model = process.env.KILO_E2E_MODEL ?? "kilo/kilo-auto/frontier"
  6. const parts = model.split("/")
  7. const providerID = parts[0] ?? "kilo" // kilocode_change
  8. const modelID = parts.slice(1).join("/") || "kilo-auto/frontier" // kilocode_change
  9. const now = Date.now()
  10. const seed = async () => {
  11. const { Instance } = await import("../src/project/instance")
  12. const { InstanceBootstrap } = await import("../src/project/bootstrap")
  13. const { Config } = await import("../src/config/config")
  14. const { Session } = await import("../src/session")
  15. const { MessageID, PartID } = await import("../src/session/schema")
  16. const { Project } = await import("../src/project/project")
  17. const { ModelID, ProviderID } = await import("../src/provider/schema")
  18. const { ToolRegistry } = await import("../src/tool/registry")
  19. const { Effect } = await import("effect")
  20. try {
  21. await Instance.provide({
  22. directory: dir,
  23. init: () => AppRuntime.runPromise(InstanceBootstrap),
  24. fn: async () => {
  25. await AppRuntime.runPromise(Config.Service.use((cfg) => cfg.waitForDependencies()))
  26. await AppRuntime.runPromise(
  27. Effect.gen(function* () {
  28. const registry = yield* ToolRegistry.Service
  29. yield* registry.ids()
  30. }),
  31. )
  32. await AppRuntime.runPromise(
  33. Effect.gen(function* () {
  34. const session = yield* Session.Service
  35. const result = yield* session.create({ title })
  36. const messageID = MessageID.ascending()
  37. const partID = PartID.ascending()
  38. const message = {
  39. id: messageID,
  40. sessionID: result.id,
  41. role: "user" as const,
  42. time: { created: now },
  43. agent: "code", // kilocode_change - renamed from "build" to "code"
  44. model: {
  45. providerID: ProviderID.make(providerID),
  46. modelID: ModelID.make(modelID),
  47. },
  48. }
  49. const part = {
  50. id: partID,
  51. sessionID: result.id,
  52. messageID,
  53. type: "text" as const,
  54. text,
  55. time: { start: now },
  56. }
  57. yield* session.updateMessage(message)
  58. yield* session.updatePart(part)
  59. }),
  60. )
  61. await AppRuntime.runPromise(
  62. Project.Service.use((svc) => svc.update({ projectID: Instance.project.id, name: "E2E Project" })),
  63. )
  64. },
  65. })
  66. } finally {
  67. await Instance.disposeAll().catch(() => {})
  68. await AppRuntime.dispose().catch(() => {})
  69. }
  70. }
  71. await seed()