mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-24 19:24:22 +01:00
type error fix
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { z, type ZodType } from "zod";
|
||||
import { App } from "../app";
|
||||
import { App } from "../app/app";
|
||||
import { Log } from "../util/log";
|
||||
|
||||
export namespace Bus {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import path from "path";
|
||||
import { Log } from "../util/log";
|
||||
import { z } from "zod";
|
||||
import { App } from ".";
|
||||
import { App } from "../app/app";
|
||||
import { Provider } from "../provider/provider";
|
||||
|
||||
export namespace Config {
|
||||
const log = Log.create({ service: "config" });
|
||||
@@ -11,38 +12,9 @@ export namespace Config {
|
||||
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
|
||||
.object({
|
||||
providers: z.record(z.string(), Provider).optional(),
|
||||
providers: z.record(z.string(), Provider.Info).optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import "zod-openapi/extend";
|
||||
import { App } from "./app";
|
||||
import { App } from "./app/app";
|
||||
import { Server } from "./server/server";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { App } from "../app";
|
||||
import { App } from "../app/app";
|
||||
import { Log } from "../util/log";
|
||||
import { mergeDeep } from "remeda";
|
||||
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 { Config } from "../app/config";
|
||||
import { Config } from "../config/config";
|
||||
import { BunProc } from "../bun";
|
||||
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: {
|
||||
models: {
|
||||
"claude-sonnet-4-20250514": {
|
||||
@@ -76,18 +77,18 @@ export namespace LLM {
|
||||
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 providers: Record<
|
||||
string,
|
||||
{
|
||||
info: Config.Provider;
|
||||
instance: Provider;
|
||||
info: Provider.Info;
|
||||
instance: ProviderInstance;
|
||||
}
|
||||
> = {};
|
||||
const models = new Map<
|
||||
string,
|
||||
{ info: Config.Model; instance: LanguageModel }
|
||||
{ info: Provider.Model; instance: LanguageModel }
|
||||
>();
|
||||
|
||||
const list = mergeDeep(NATIVE_PROVIDERS, config.providers ?? {});
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export * as anthropic from "./anthropic";
|
||||
@@ -1,11 +0,0 @@
|
||||
export interface ModelInfo {
|
||||
cost: {
|
||||
input: number;
|
||||
inputCached: number;
|
||||
output: number;
|
||||
outputCached: number;
|
||||
};
|
||||
contextWindow: number;
|
||||
maxTokens: number;
|
||||
attachment: boolean;
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
StreamMessageWriter,
|
||||
} from "vscode-jsonrpc/node";
|
||||
import type { Diagnostic as VSCodeDiagnostic } from "vscode-languageserver-types";
|
||||
import { App } from "../app";
|
||||
import { App } from "../app/app";
|
||||
import { Log } from "../util/log";
|
||||
import { LANGUAGE_EXTENSIONS } from "./language";
|
||||
import { Bus } from "../bus";
|
||||
@@ -31,7 +31,6 @@ export namespace LSPClient {
|
||||
|
||||
export async function create(input: { cmd: string[]; serverID: string }) {
|
||||
log.info("starting client", input);
|
||||
let version = 0;
|
||||
|
||||
const app = await App.use();
|
||||
const [command, ...args] = input.cmd;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { App } from "../app";
|
||||
import { App } from "../app/app";
|
||||
import { Log } from "../util/log";
|
||||
import { LSPClient } from "./client";
|
||||
import path from "path";
|
||||
@@ -9,6 +9,7 @@ export namespace LSP {
|
||||
const state = App.state(
|
||||
"lsp",
|
||||
async () => {
|
||||
log.info("initializing");
|
||||
const clients = new Map<string, LSPClient.Info>();
|
||||
|
||||
return {
|
||||
|
||||
32
js/src/provider/provider.ts
Normal file
32
js/src/provider/provider.ts
Normal file
@@ -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>;
|
||||
}
|
||||
@@ -6,9 +6,9 @@ import { streamSSE } from "hono/streaming";
|
||||
import { Session } from "../session/session";
|
||||
import { resolver, validator as zValidator } from "hono-openapi/zod";
|
||||
import { z } from "zod";
|
||||
import { Config } from "../app/config";
|
||||
import { LLM } from "../llm/llm";
|
||||
import { Message } from "../session/message";
|
||||
import { Provider } from "../provider/provider";
|
||||
|
||||
export namespace Server {
|
||||
const log = Log.create({ service: "server" });
|
||||
@@ -234,7 +234,7 @@ export namespace Server {
|
||||
description: "List of providers",
|
||||
content: {
|
||||
"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) => {
|
||||
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)) {
|
||||
result[providerID] = provider.info;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import path from "path";
|
||||
import { App } from "../app/";
|
||||
import { App } from "../app/app";
|
||||
import { Identifier } from "../id/id";
|
||||
import { LLM } from "../llm/llm";
|
||||
import { Storage } from "../storage/storage";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { App } from "../app";
|
||||
import { App } from "../app/app";
|
||||
import { Bus } from "../bus";
|
||||
import { Session } from "../session/session";
|
||||
import { Storage } from "../storage/storage";
|
||||
|
||||
@@ -2,7 +2,7 @@ import { FileStorage } from "@flystorage/file-storage";
|
||||
import { LocalStorageAdapter } from "@flystorage/local-fs";
|
||||
import fs from "fs/promises";
|
||||
import { Log } from "../util/log";
|
||||
import { App } from "../app";
|
||||
import { App } from "../app/app";
|
||||
import { AppPath } from "../app/path";
|
||||
import { Bus } from "../bus";
|
||||
import z from "zod";
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import { z } from "zod";
|
||||
import * as path from "path";
|
||||
import { Log } from "../util/log";
|
||||
import { Tool } from "./tool";
|
||||
import { FileTimes } from "./util/file-times";
|
||||
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.
|
||||
|
||||
Before using this tool:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { z } from "zod";
|
||||
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).
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { z } from "zod";
|
||||
import { Tool } from "./tool";
|
||||
import { App } from "../app";
|
||||
import { App } from "../app/app";
|
||||
import { spawn } from "child_process";
|
||||
import { promises as fs } from "fs";
|
||||
import path from "path";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { z } from "zod";
|
||||
import { Tool } from "./tool";
|
||||
import { App } from "../app";
|
||||
import { App } from "../app/app";
|
||||
import * as path from "path";
|
||||
import * as fs from "fs";
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { z } from "zod";
|
||||
import { Tool } from "./tool";
|
||||
import path from "path";
|
||||
import { LSP } from "../lsp";
|
||||
import { App } from "../app";
|
||||
import { App } from "../app/app";
|
||||
|
||||
export const LspDiagnosticTool = Tool.define({
|
||||
name: "diagnostics",
|
||||
|
||||
@@ -2,7 +2,7 @@ import { z } from "zod";
|
||||
import { Tool } from "./tool";
|
||||
import path from "path";
|
||||
import { LSP } from "../lsp";
|
||||
import { App } from "../app";
|
||||
import { App } from "../app/app";
|
||||
|
||||
export const LspHoverTool = Tool.define({
|
||||
name: "lsp.hover",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { App } from "../../app";
|
||||
import { App } from "../../app/app";
|
||||
|
||||
export namespace FileTimes {
|
||||
export const state = App.state("tool.filetimes", () => ({
|
||||
|
||||
Reference in New Issue
Block a user