Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: split packages #7

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { h } from 'vue'

import type { Theme } from 'vitepress'

import DefaultTheme from 'vitepress/theme'
import { h } from 'vue'

import 'virtual:uno.css'

Expand Down
2 changes: 1 addition & 1 deletion docs/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from 'vite'
import UnoCSS from 'unocss/vite'
import { defineConfig } from 'vite'
import Inspect from 'vite-plugin-inspect'

export default defineConfig({
Expand Down
4 changes: 2 additions & 2 deletions examples/neuri/documentations-from-unit-tests/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { env } from 'node:process'
import OpenAI from 'openai'

import {
composeAgent,
} from 'neuri/openai'

import OpenAI from 'openai'

async function main() {
const o = new OpenAI({
baseURL: env.OPENAI_API_BASEURL,
Expand Down
6 changes: 3 additions & 3 deletions examples/neuri/weather-query/src/valibot.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { env } from 'node:process'
import OpenAI from 'openai'
import * as v from 'valibot'

import {
composeAgent,
defineToolFunction,
Expand All @@ -11,6 +8,9 @@ import {
toolFunction,
user,
} from 'neuri/openai'
import OpenAI from 'openai'

import * as v from 'valibot'

async function main() {
const o = new OpenAI({
Expand Down
6 changes: 3 additions & 3 deletions examples/neuri/weather-query/src/zod.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { env } from 'node:process'
import OpenAI from 'openai'
import * as z from 'zod'

import {
composeAgent,
defineToolFunction,
Expand All @@ -11,6 +8,9 @@ import {
toolFunction,
user,
} from 'neuri/openai'
import OpenAI from 'openai'

import * as z from 'zod'

async function main() {
const o = new OpenAI({
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"scripts": {
"stub": "pnpm -r --filter=./packages/* --parallel run stub",
"lint": "eslint --cache .",
"lint:fix": "eslint --cache --fix .",
"docs:dev": "pnpm -r --filter=./docs run dev",
"docs:build": "pnpm -r --filter=./docs run build",
"docs:preview": "pnpm -r --filter=./docs run preview",
Expand Down
59 changes: 59 additions & 0 deletions packages/format-code/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "@neuri/format-code",
"type": "module",
"version": "0.0.5",
"description": "Code related output parsers for neuri",
"author": {
"name": "Lingtic.io Neuri Team",
"email": "[email protected]",
"url": "https://github.com/lingticio"
},
"license": "MIT",
"homepage": "https://docs.lingtic.io/pages/en/neuri",
"repository": {
"type": "git",
"url": "https://github.com/lingticio/neuri-js.git",
"directory": "packages/format-code"
},
"keywords": [
"guiiai",
"llm",
"openai",
"lingtic",
"neuri"
],
"exports": {
".": {
"types": "./dist/textmate/index.d.ts",
"import": "./dist/textmate/index.mjs"
},
"./textmate": {
"types": "./dist/textmate/index.d.ts",
"import": "./dist/textmate/index.mjs"
}
},
"module": "./dist/textmate/index.mjs",
"types": "./dist/textmate/index.d.ts",
"files": [
"LICENSE",
"README.md",
"dist",
"package.json"
],
"scripts": {
"dev": "unbuild --stub",
"stub": "unbuild --stub",
"build": "unbuild",
"package:publish": "pnpm build && pnpm publish --access public --no-git-checks"
},
"dependencies": {
"@guiiai/logg": "^1.0.3",
"@shikijs/core": "^1.14.1",
"@shikijs/vscode-textmate": "^9.2.2",
"shiki": "^1.14.1",
"tm-grammars": "^1.17.18"
},
"devDependencies": {
"@types/node": "^20.11.17"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'

import { tokenizeByTextMateGrammar } from './textmate'
import { tokenizeByTextMateGrammar } from '.'

describe('tokenizeByTextMateGrammar', () => {
it('should tokenize vue code', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { LanguageRegistration, ShikiInternal } from '@shikijs/core'
import { createShikiInternal, loadWasm } from '@shikijs/core'
import type { BundledLanguage } from 'shiki'

import { createShikiInternal, loadWasm } from '@shikijs/core'
import { bundledLanguages } from 'shiki'

let wasmLoaded = false
Expand Down
14 changes: 0 additions & 14 deletions packages/neuri/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,10 @@
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs"
},
"./agents/fs": {
"types": "./dist/agents/fs/index.d.ts",
"import": "./dist/agents/fs/index.mjs"
},
"./formats/json": {
"types": "./dist/formats/json/index.d.ts",
"import": "./dist/formats/json/index.mjs"
},
"./formats/code/textmate": {
"types": "./dist/formats/code/textmate.d.ts",
"import": "./dist/formats/code/textmate.mjs"
},
"./formats/markdown": {
"types": "./dist/formats/markdown/index.d.ts",
"import": "./dist/formats/markdown/index.mjs"
Expand All @@ -64,19 +56,13 @@
},
"dependencies": {
"@guiiai/logg": "^1.0.3",
"@shikijs/core": "^1.14.1",
"@shikijs/vscode-textmate": "^9.2.2",
"@valibot/to-json-schema": "^0.2.1",
"ajv": "^8.17.1",
"defu": "^6.1.4",
"execa": "^9.3.1",
"ignore": "^5.3.2",
"json-schema": "^0.4.0",
"nanoid": "^5.0.7",
"openai": "^4.54.0",
"remark-parse": "^11.0.0",
"shiki": "^1.14.1",
"tm-grammars": "^1.17.18",
"unified": "^11.0.5",
"unist-util-filter": "^5.0.1",
"unist-util-is": "^6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/neuri/src/formats/json/jsonParser.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import type { Token } from './jsonParser'
import { describe, expect, it } from 'vitest'
import { createJSONParser, stringifyTokens } from './jsonParser'

describe('jsonParser', () => {
Expand Down
7 changes: 4 additions & 3 deletions packages/neuri/src/formats/json/jsonParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function createJSONParser() {
}

function handleStateJSONNumber(char: string) {
if (/[\d.eE+-]/.test(char)) {
if (/[\d.e+-]/i.test(char)) {
buffer += char
}
else {
Expand Down Expand Up @@ -101,15 +101,16 @@ export function createJSONParser() {
}

function trimTrailingNonNumber(s: string): string {
return s.replace(/[^0-9.eE+-]+$/, '')
return s.replace(/[^0-9.e+-]+$/i, '')
}

function determineValueType(value: string): TokenType {
if (value === 'true' || value === 'false')
return 'JSONBoolean'
if (value === 'null')
return 'JSONNull'
if (/^-?\d+(\.\d+)?([eE][+-]?\d+)?$/.test(value))
// eslint-disable-next-line regexp/no-unused-capturing-group
if (/^-?\d+(\.\d+)?(e[+-]?\d+)?$/i.test(value))
return 'JSONNumber'
return 'JSONString'
}
Expand Down
2 changes: 1 addition & 1 deletion packages/neuri/src/formats/json/jsonschema.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import type { JSONSchemaDraft202012 } from './jsonschema'
import { describe, expect, it } from 'vitest'
import { buildRegexFromSchema, buildRegexFromSchemaString, extractBySchema, extractObjectBySchema } from './jsonschema'

describe('buildRegexFromSchemaString', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/neuri/src/formats/json/streamJsonParser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { JSONSchema7 } from 'json-schema'
import Ajv from 'ajv'
import type { Token } from './jsonParser'
import Ajv from 'ajv'
import { createJSONParser } from './jsonParser'

type JSONValue = string | number | boolean | null | { [key: string]: JSONValue } | JSONValue[]
Expand Down
6 changes: 3 additions & 3 deletions packages/neuri/src/formats/markdown/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { unified } from 'unified'
import RemarkParse from 'remark-parse'
import type { Code, Node } from 'mdast'
import RemarkParse from 'remark-parse'
import { unified } from 'unified'
import { visit } from 'unist-util-visit'

function isCodeNode(node: Node): node is Code {
Expand Down Expand Up @@ -46,7 +46,7 @@ interface StreamableParser {
}

function trimCodeBlockBoundary(content: string): string {
return content.replace(/\n(`){1,}$/, '')
return content.replace(/\n(`)+$/, '')
}

/**
Expand Down
55 changes: 55 additions & 0 deletions packages/use-fs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "@neuri/use-fs",
"type": "module",
"version": "0.0.5",
"description": "FileSystem related agent implementation for neuri",
"author": {
"name": "Lingtic.io Neuri Team",
"email": "[email protected]",
"url": "https://github.com/lingticio"
},
"license": "MIT",
"homepage": "https://docs.lingtic.io/pages/en/neuri",
"repository": {
"type": "git",
"url": "https://github.com/lingticio/neuri-js.git",
"directory": "packages/use-fs"
},
"keywords": [
"guiiai",
"llm",
"openai",
"lingtic",
"neuri"
],
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs"
}
},
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"LICENSE",
"README.md",
"dist",
"package.json"
],
"scripts": {
"dev": "unbuild --stub",
"stub": "unbuild --stub",
"build": "unbuild",
"package:publish": "pnpm build && pnpm publish --access public --no-git-checks"
},
"dependencies": {
"@guiiai/logg": "^1.0.3",
"defu": "^6.1.4",
"execa": "^9.3.1",
"ignore": "^5.3.2",
"neuri": "workspace:^"
},
"devDependencies": {
"@types/node": "^20.11.17"
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { fileURLToPath } from 'node:url'
import { dirname, join } from 'node:path'
import { readFile as fsReadFile, writeFile as fsWriteFile, mkdir, rmdir } from 'node:fs/promises'
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { Format, LogLevel, setGlobalFormat, setGlobalLogLevel } from '@guiiai/logg'
import { afterAll, beforeAll, describe, expect, it } from 'vitest'

import { exists } from './utils'
import { FileSystem } from '.'
import { exists } from './utils'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import type { CallableComponent } from 'neuri'
import {
readFile as fsReadFile,
writeFile as fsWriteFile,
readdir,
} from 'node:fs/promises'
import { cwd } from 'node:process'
import { join, relative } from 'node:path'
import { defu } from 'defu'
import { cwd } from 'node:process'
import { useLogg } from '@guiiai/logg'
import ignore from 'ignore'
import { defu } from 'defu'
import { execa } from 'execa'

import type { CallableComponent } from '../../callable'
import { defineCallable, defineCallableComponent } from '../../callable'
import ignore from 'ignore'
import { defineCallable, defineCallableComponent } from 'neuri'
import { exists } from './utils'

export function FileSystem(options?: { basePath?: string }): CallableComponent {
Expand Down
File renamed without changes.
Loading
Loading