Browse Source

type error fix

Dax Raad 9 months ago
parent
commit
80597cd3fd

+ 0 - 1
js/example/broken.ts

@@ -1 +0,0 @@
-export const x: number = "asd";

+ 0 - 21
js/example/cli.ts

@@ -1,21 +0,0 @@
-import { App } from "../src/app";
-import path from "path";
-import { edit } from "../src/tool";
-import { FileTimes } from "../src/tool/util/file-times";
-
-await App.provide({ directory: process.cwd() }, async () => {
-  const file = path.join(process.cwd(), "example/broken.ts");
-  FileTimes.read(file);
-  const tool = await edit.execute(
-    {
-      file_path: file,
-      old_string: "x:",
-      new_string: "x:",
-    },
-    {
-      toolCallId: "test",
-      messages: [],
-    },
-  );
-  console.log(tool.output);
-});

+ 0 - 122
js/example/ink.tsx

@@ -1,122 +0,0 @@
-import React, { useEffect, useState } from "react";
-import type { Server } from "../src/server/server";
-import type { Session } from "../src/session/session";
-import { hc } from "hono/client";
-import { createInterface, Interface } from "readline";
-
-const client = hc<Server.App>(`http://localhost:16713`);
-
-
-const session = await client.session_create.$post().then((res) => res.json());
-
-const initial: {
-  session: {
-    info: {
-      [sessionID: string]: Session.Info;
-    };
-    message: {
-      [sessionID: string]: {
-        [messageID: string]: Session.Message;
-      };
-    };
-  };
-} = {
-  session: {
-    info: {
-      [session.id]: session
-    },
-    message: {
-      [session.id]: {}
-    },
-  },
-};
-
-import { render, Text, Newline, useStdout, Box } from "ink";
-import TextInput from "ink-text-input"
-
-function App() {
-  const [state, setState] = useState(initial)
-  const [input, setInput] = useState("")
-
-  useEffect(() => {
-    fetch("http://localhost:16713/event")
-      .then(stream => {
-        const decoder = new TextDecoder();
-        stream.body!.pipeTo(
-          new WritableStream({
-            write(chunk) {
-              const data = decoder.decode(chunk);
-              if (data.startsWith("data: ")) {
-                try {
-                  const event = JSON.parse(data.substring(6));
-                  switch (event.type) {
-                    case "storage.write":
-                      const splits: string[] = event.properties.key.split("/");
-                      let item = state as any;
-                      for (let i = 0; i < splits.length; i++) {
-                        const part = splits[i];
-                        if (i === splits.length - 1) {
-                          item[part] = event.properties.body;
-                          continue;
-                        }
-                        if (!item[part]) item[part] = {};
-                        item = item[part];
-                      }
-                  }
-                  setState({ ...state })
-                } catch {
-                }
-              }
-            },
-          }),
-        )
-      });
-  }, [])
-
-
-  return (
-    <>
-      <Text>{session.title}</Text>
-      {
-        Object.values(state.session.message[session.id])
-          .filter(message => message.role !== "system")
-          .map(message => {
-            return Object.values(message.parts)
-              .map((part, index) => {
-                if (part.type === "text") {
-                  return <Text key={`${message.id}-${index}`}>{message.role}: {part.text}</Text>
-                }
-                if (part.type === "tool-invocation") {
-                  return <Text key={`${message.id}-${index}`}>{message.role}: {part.toolInvocation.toolName} {JSON.stringify(part.toolInvocation.args)}</Text>
-                }
-              })
-          })
-      }
-      <Box gap={1} >
-        <Text>Input:</Text>
-        <TextInput
-          value={input}
-          onChange={setInput}
-          onSubmit={() => {
-            setInput("")
-            client.session_chat.$post({
-              json: {
-                sessionID: session.id,
-                parts: [
-                  {
-                    type: "text",
-                    text: input,
-                  },
-                ],
-              }
-            })
-          }}
-        />
-      </Box>
-    </>
-  );
-};
-
-console.clear();
-render(<App />);
-

+ 0 - 0
js/src/app/index.ts → js/src/app/app.ts


+ 1 - 1
js/src/bus/index.ts

@@ -1,5 +1,5 @@
 import { z, type ZodType } from "zod";
 import { z, type ZodType } from "zod";
-import { App } from "../app";
+import { App } from "../app/app";
 import { Log } from "../util/log";
 import { Log } from "../util/log";
 
 
 export namespace Bus {
 export namespace Bus {

+ 3 - 31
js/src/app/config.ts → js/src/config/config.ts

@@ -1,7 +1,8 @@
 import path from "path";
 import path from "path";
 import { Log } from "../util/log";
 import { Log } from "../util/log";
 import { z } from "zod";
 import { z } from "zod";
-import { App } from ".";
+import { App } from "../app/app";
+import { Provider } from "../provider/provider";
 
 
 export namespace Config {
 export namespace Config {
   const log = Log.create({ service: "config" });
   const log = Log.create({ service: "config" });
@@ -11,38 +12,9 @@ export namespace Config {
     return result;
     return result;
   });
   });
 
 
-  export const Model = z
-    .object({
-      name: z.string().optional(),
-      cost: z.object({
-        input: z.number(),
-        inputCached: z.number(),
-        output: z.number(),
-        outputCached: z.number(),
-      }),
-      contextWindow: z.number(),
-      maxTokens: z.number().optional(),
-      attachment: z.boolean(),
-      reasoning: z.boolean().optional(),
-    })
-    .openapi({
-      ref: "model",
-    });
-  export type Model = z.output<typeof Model>;
-
-  export const Provider = z
-    .object({
-      options: z.record(z.string(), z.any()).optional(),
-      models: z.record(z.string(), Model),
-    })
-    .openapi({
-      ref: "provider",
-    });
-  export type Provider = z.output<typeof Provider>;
-
   export const Info = z
   export const Info = z
     .object({
     .object({
-      providers: z.record(z.string(), Provider).optional(),
+      providers: z.record(z.string(), Provider.Info).optional(),
     })
     })
     .strict();
     .strict();
 
 

+ 1 - 1
js/src/index.ts

@@ -1,5 +1,5 @@
 import "zod-openapi/extend";
 import "zod-openapi/extend";
-import { App } from "./app";
+import { App } from "./app/app";
 import { Server } from "./server/server";
 import { Server } from "./server/server";
 import fs from "fs/promises";
 import fs from "fs/promises";
 import path from "path";
 import path from "path";

+ 9 - 8
js/src/llm/llm.ts

@@ -1,11 +1,12 @@
-import { App } from "../app";
+import { App } from "../app/app";
 import { Log } from "../util/log";
 import { Log } from "../util/log";
 import { mergeDeep } from "remeda";
 import { mergeDeep } from "remeda";
 import path from "path";
 import path from "path";
+import { Provider } from "../provider/provider";
 
 
-import type { LanguageModel, Provider } from "ai";
+import type { LanguageModel, Provider as ProviderInstance } from "ai";
 import { NoSuchModelError } from "ai";
 import { NoSuchModelError } from "ai";
-import { Config } from "../app/config";
+import { Config } from "../config/config";
 import { BunProc } from "../bun";
 import { BunProc } from "../bun";
 import { Global } from "../global";
 import { Global } from "../global";
 
 
@@ -18,7 +19,7 @@ export namespace LLM {
     }
     }
   }
   }
 
 
-  const NATIVE_PROVIDERS: Record<string, Config.Provider> = {
+  const NATIVE_PROVIDERS: Record<string, Provider.Info> = {
     anthropic: {
     anthropic: {
       models: {
       models: {
         "claude-sonnet-4-20250514": {
         "claude-sonnet-4-20250514": {
@@ -76,18 +77,18 @@ export namespace LLM {
     google: ["GOOGLE_GENERATIVE_AI_API_KEY"],
     google: ["GOOGLE_GENERATIVE_AI_API_KEY"],
   };
   };
 
 
-  const state = App.state("llm", async (app) => {
+  const state = App.state("llm", async () => {
     const config = await Config.get();
     const config = await Config.get();
     const providers: Record<
     const providers: Record<
       string,
       string,
       {
       {
-        info: Config.Provider;
-        instance: Provider;
+        info: Provider.Info;
+        instance: ProviderInstance;
       }
       }
     > = {};
     > = {};
     const models = new Map<
     const models = new Map<
       string,
       string,
-      { info: Config.Model; instance: LanguageModel }
+      { info: Provider.Model; instance: LanguageModel }
     >();
     >();
 
 
     const list = mergeDeep(NATIVE_PROVIDERS, config.providers ?? {});
     const list = mergeDeep(NATIVE_PROVIDERS, config.providers ?? {});

+ 0 - 0
js/src/llm/models/anthropic.ts


+ 0 - 1
js/src/llm/models/index.ts

@@ -1 +0,0 @@
-export * as anthropic from "./anthropic";

+ 0 - 11
js/src/llm/models/model.ts

@@ -1,11 +0,0 @@
-export interface ModelInfo {
-  cost: {
-    input: number;
-    inputCached: number;
-    output: number;
-    outputCached: number;
-  };
-  contextWindow: number;
-  maxTokens: number;
-  attachment: boolean;
-}

+ 1 - 2
js/src/lsp/client.ts

@@ -6,7 +6,7 @@ import {
   StreamMessageWriter,
   StreamMessageWriter,
 } from "vscode-jsonrpc/node";
 } from "vscode-jsonrpc/node";
 import type { Diagnostic as VSCodeDiagnostic } from "vscode-languageserver-types";
 import type { Diagnostic as VSCodeDiagnostic } from "vscode-languageserver-types";
-import { App } from "../app";
+import { App } from "../app/app";
 import { Log } from "../util/log";
 import { Log } from "../util/log";
 import { LANGUAGE_EXTENSIONS } from "./language";
 import { LANGUAGE_EXTENSIONS } from "./language";
 import { Bus } from "../bus";
 import { Bus } from "../bus";
@@ -31,7 +31,6 @@ export namespace LSPClient {
 
 
   export async function create(input: { cmd: string[]; serverID: string }) {
   export async function create(input: { cmd: string[]; serverID: string }) {
     log.info("starting client", input);
     log.info("starting client", input);
-    let version = 0;
 
 
     const app = await App.use();
     const app = await App.use();
     const [command, ...args] = input.cmd;
     const [command, ...args] = input.cmd;

+ 2 - 1
js/src/lsp/index.ts

@@ -1,4 +1,4 @@
-import { App } from "../app";
+import { App } from "../app/app";
 import { Log } from "../util/log";
 import { Log } from "../util/log";
 import { LSPClient } from "./client";
 import { LSPClient } from "./client";
 import path from "path";
 import path from "path";
@@ -9,6 +9,7 @@ export namespace LSP {
   const state = App.state(
   const state = App.state(
     "lsp",
     "lsp",
     async () => {
     async () => {
+      log.info("initializing");
       const clients = new Map<string, LSPClient.Info>();
       const clients = new Map<string, LSPClient.Info>();
 
 
       return {
       return {

+ 32 - 0
js/src/provider/provider.ts

@@ -0,0 +1,32 @@
+import z from "zod";
+
+export namespace Provider {
+  export const Model = z
+    .object({
+      name: z.string().optional(),
+      cost: z.object({
+        input: z.number(),
+        inputCached: z.number(),
+        output: z.number(),
+        outputCached: z.number(),
+      }),
+      contextWindow: z.number(),
+      maxTokens: z.number().optional(),
+      attachment: z.boolean(),
+      reasoning: z.boolean().optional(),
+    })
+    .openapi({
+      ref: "Provider.Model",
+    });
+  export type Model = z.output<typeof Model>;
+
+  export const Info = z
+    .object({
+      options: z.record(z.string(), z.any()).optional(),
+      models: z.record(z.string(), Model),
+    })
+    .openapi({
+      ref: "Provider.Info",
+    });
+  export type Info = z.output<typeof Info>;
+}

+ 3 - 3
js/src/server/server.ts

@@ -6,9 +6,9 @@ import { streamSSE } from "hono/streaming";
 import { Session } from "../session/session";
 import { Session } from "../session/session";
 import { resolver, validator as zValidator } from "hono-openapi/zod";
 import { resolver, validator as zValidator } from "hono-openapi/zod";
 import { z } from "zod";
 import { z } from "zod";
-import { Config } from "../app/config";
 import { LLM } from "../llm/llm";
 import { LLM } from "../llm/llm";
 import { Message } from "../session/message";
 import { Message } from "../session/message";
+import { Provider } from "../provider/provider";
 
 
 export namespace Server {
 export namespace Server {
   const log = Log.create({ service: "server" });
   const log = Log.create({ service: "server" });
@@ -234,7 +234,7 @@ export namespace Server {
               description: "List of providers",
               description: "List of providers",
               content: {
               content: {
                 "application/json": {
                 "application/json": {
-                  schema: resolver(z.record(z.string(), Config.Provider)),
+                  schema: resolver(z.record(z.string(), Provider.Info)),
                 },
                 },
               },
               },
             },
             },
@@ -242,7 +242,7 @@ export namespace Server {
         }),
         }),
         async (c) => {
         async (c) => {
           const providers = await LLM.providers();
           const providers = await LLM.providers();
-          const result: Record<string, Config.Provider> = {};
+          const result: Record<string, Provider.Info> = {};
           for (const [providerID, provider] of Object.entries(providers)) {
           for (const [providerID, provider] of Object.entries(providers)) {
             result[providerID] = provider.info;
             result[providerID] = provider.info;
           }
           }

+ 1 - 1
js/src/session/session.ts

@@ -1,5 +1,5 @@
 import path from "path";
 import path from "path";
-import { App } from "../app/";
+import { App } from "../app/app";
 import { Identifier } from "../id/id";
 import { Identifier } from "../id/id";
 import { LLM } from "../llm/llm";
 import { LLM } from "../llm/llm";
 import { Storage } from "../storage/storage";
 import { Storage } from "../storage/storage";

+ 1 - 1
js/src/share/share.ts

@@ -1,4 +1,4 @@
-import { App } from "../app";
+import { App } from "../app/app";
 import { Bus } from "../bus";
 import { Bus } from "../bus";
 import { Session } from "../session/session";
 import { Session } from "../session/session";
 import { Storage } from "../storage/storage";
 import { Storage } from "../storage/storage";

+ 1 - 1
js/src/storage/storage.ts

@@ -2,7 +2,7 @@ import { FileStorage } from "@flystorage/file-storage";
 import { LocalStorageAdapter } from "@flystorage/local-fs";
 import { LocalStorageAdapter } from "@flystorage/local-fs";
 import fs from "fs/promises";
 import fs from "fs/promises";
 import { Log } from "../util/log";
 import { Log } from "../util/log";
-import { App } from "../app";
+import { App } from "../app/app";
 import { AppPath } from "../app/path";
 import { AppPath } from "../app/path";
 import { Bus } from "../bus";
 import { Bus } from "../bus";
 import z from "zod";
 import z from "zod";

+ 0 - 3
js/src/tool/edit.ts

@@ -1,12 +1,9 @@
 import { z } from "zod";
 import { z } from "zod";
 import * as path from "path";
 import * as path from "path";
-import { Log } from "../util/log";
 import { Tool } from "./tool";
 import { Tool } from "./tool";
 import { FileTimes } from "./util/file-times";
 import { FileTimes } from "./util/file-times";
 import { LSP } from "../lsp";
 import { LSP } from "../lsp";
 
 
-const log = Log.create({ service: "tool.edit" });
-
 const DESCRIPTION = `Edits files by replacing text, creating new files, or deleting content. For moving or renaming files, use the Bash tool with the 'mv' command instead. For larger file edits, use the FileWrite tool to overwrite files.
 const DESCRIPTION = `Edits files by replacing text, creating new files, or deleting content. For moving or renaming files, use the Bash tool with the 'mv' command instead. For larger file edits, use the FileWrite tool to overwrite files.
 
 
 Before using this tool:
 Before using this tool:

+ 1 - 1
js/src/tool/glob.ts

@@ -1,6 +1,6 @@
 import { z } from "zod";
 import { z } from "zod";
 import { Tool } from "./tool";
 import { Tool } from "./tool";
-import { App } from "../app";
+import { App } from "../app/app";
 
 
 const DESCRIPTION = `Fast file pattern matching tool that finds files by name and pattern, returning matching paths sorted by modification time (newest first).
 const DESCRIPTION = `Fast file pattern matching tool that finds files by name and pattern, returning matching paths sorted by modification time (newest first).
 
 

+ 1 - 1
js/src/tool/grep.ts

@@ -1,6 +1,6 @@
 import { z } from "zod";
 import { z } from "zod";
 import { Tool } from "./tool";
 import { Tool } from "./tool";
-import { App } from "../app";
+import { App } from "../app/app";
 import { spawn } from "child_process";
 import { spawn } from "child_process";
 import { promises as fs } from "fs";
 import { promises as fs } from "fs";
 import path from "path";
 import path from "path";

+ 1 - 1
js/src/tool/ls.ts

@@ -1,6 +1,6 @@
 import { z } from "zod";
 import { z } from "zod";
 import { Tool } from "./tool";
 import { Tool } from "./tool";
-import { App } from "../app";
+import { App } from "../app/app";
 import * as path from "path";
 import * as path from "path";
 import * as fs from "fs";
 import * as fs from "fs";
 
 

+ 1 - 1
js/src/tool/lsp-diagnostics.ts

@@ -2,7 +2,7 @@ import { z } from "zod";
 import { Tool } from "./tool";
 import { Tool } from "./tool";
 import path from "path";
 import path from "path";
 import { LSP } from "../lsp";
 import { LSP } from "../lsp";
-import { App } from "../app";
+import { App } from "../app/app";
 
 
 export const LspDiagnosticTool = Tool.define({
 export const LspDiagnosticTool = Tool.define({
   name: "diagnostics",
   name: "diagnostics",

+ 1 - 1
js/src/tool/lsp-hover.ts

@@ -2,7 +2,7 @@ import { z } from "zod";
 import { Tool } from "./tool";
 import { Tool } from "./tool";
 import path from "path";
 import path from "path";
 import { LSP } from "../lsp";
 import { LSP } from "../lsp";
-import { App } from "../app";
+import { App } from "../app/app";
 
 
 export const LspHoverTool = Tool.define({
 export const LspHoverTool = Tool.define({
   name: "lsp.hover",
   name: "lsp.hover",

+ 1 - 1
js/src/tool/util/file-times.ts

@@ -1,4 +1,4 @@
-import { App } from "../../app";
+import { App } from "../../app/app";
 
 
 export namespace FileTimes {
 export namespace FileTimes {
   export const state = App.state("tool.filetimes", () => ({
   export const state = App.state("tool.filetimes", () => ({

+ 1 - 1
js/test/tool/tool.test.ts

@@ -1,5 +1,5 @@
 import { describe, expect, test } from "bun:test";
 import { describe, expect, test } from "bun:test";
-import { App } from "../../src/app";
+import { App } from "../../src/app/app";
 import { glob } from "../../src/tool/glob";
 import { glob } from "../../src/tool/glob";
 import { ls } from "../../src/tool/ls";
 import { ls } from "../../src/tool/ls";
 
 

+ 4 - 4
pkg/client/gen/openapi.json

@@ -238,7 +238,7 @@
                 "schema": {
                 "schema": {
                   "type": "object",
                   "type": "object",
                   "additionalProperties": {
                   "additionalProperties": {
-                    "$ref": "#/components/schemas/provider"
+                    "$ref": "#/components/schemas/Provider.Info"
                   }
                   }
                 }
                 }
               }
               }
@@ -740,7 +740,7 @@
           "title"
           "title"
         ]
         ]
       },
       },
-      "provider": {
+      "Provider.Info": {
         "type": "object",
         "type": "object",
         "properties": {
         "properties": {
           "options": {
           "options": {
@@ -750,7 +750,7 @@
           "models": {
           "models": {
             "type": "object",
             "type": "object",
             "additionalProperties": {
             "additionalProperties": {
-              "$ref": "#/components/schemas/model"
+              "$ref": "#/components/schemas/Provider.Model"
             }
             }
           }
           }
         },
         },
@@ -758,7 +758,7 @@
           "models"
           "models"
         ]
         ]
       },
       },
-      "model": {
+      "Provider.Model": {
         "type": "object",
         "type": "object",
         "properties": {
         "properties": {
           "name": {
           "name": {

+ 10 - 10
pkg/client/generated-client.go

@@ -170,8 +170,14 @@ type MessageToolInvocationToolResult struct {
 	ToolName   string       `json:"toolName"`
 	ToolName   string       `json:"toolName"`
 }
 }
 
 
-// Model defines model for model.
-type Model struct {
+// ProviderInfo defines model for Provider.Info.
+type ProviderInfo struct {
+	Models  map[string]ProviderModel `json:"models"`
+	Options *map[string]interface{}  `json:"options,omitempty"`
+}
+
+// ProviderModel defines model for Provider.Model.
+type ProviderModel struct {
 	Attachment    bool    `json:"attachment"`
 	Attachment    bool    `json:"attachment"`
 	ContextWindow float32 `json:"contextWindow"`
 	ContextWindow float32 `json:"contextWindow"`
 	Cost          struct {
 	Cost          struct {
@@ -185,12 +191,6 @@ type Model struct {
 	Reasoning *bool    `json:"reasoning,omitempty"`
 	Reasoning *bool    `json:"reasoning,omitempty"`
 }
 }
 
 
-// Provider defines model for provider.
-type Provider struct {
-	Models  map[string]Model        `json:"models"`
-	Options *map[string]interface{} `json:"options,omitempty"`
-}
-
 // SessionInfo defines model for session.info.
 // SessionInfo defines model for session.info.
 type SessionInfo struct {
 type SessionInfo struct {
 	Id      string  `json:"id"`
 	Id      string  `json:"id"`
@@ -1329,7 +1329,7 @@ func (r GetEventResponse) StatusCode() int {
 type PostProviderListResponse struct {
 type PostProviderListResponse struct {
 	Body         []byte
 	Body         []byte
 	HTTPResponse *http.Response
 	HTTPResponse *http.Response
-	JSON200      *map[string]Provider
+	JSON200      *map[string]ProviderInfo
 }
 }
 
 
 // Status returns HTTPResponse.Status
 // Status returns HTTPResponse.Status
@@ -1625,7 +1625,7 @@ func ParsePostProviderListResponse(rsp *http.Response) (*PostProviderListRespons
 
 
 	switch {
 	switch {
 	case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
 	case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
-		var dest map[string]Provider
+		var dest map[string]ProviderInfo
 		if err := json.Unmarshal(bodyBytes, &dest); err != nil {
 		if err := json.Unmarshal(bodyBytes, &dest); err != nil {
 			return nil, err
 			return nil, err
 		}
 		}