From 854da65a79b05b19f4a5c945f72bc7d6b604d765 Mon Sep 17 00:00:00 2001 From: synw Date: Tue, 12 Mar 2024 15:30:26 +0100 Subject: [PATCH] Update packages --- packages/body/package.json | 3 +- packages/body/src/bodyinterfaces.ts | 3 +- packages/body/src/core.ts | 5 +- packages/body/src/main.ts | 6 +- packages/brain/package.json | 4 +- packages/brain/src/lm.ts | 21 ++- packages/jobs/package.json | 7 +- packages/jobs/src/job.ts | 12 +- packages/jobs/src/task.ts | 7 +- packages/smem/package.json | 46 ++++++ packages/smem/rollup.config.js | 28 ++++ packages/smem/src/main.ts | 17 +++ packages/smem/src/smeminterfaces.ts | 40 ++++++ packages/smem/src/useSmem.ts | 142 +++++++++++++++++++ packages/smem/src/useSnode.ts | 95 +++++++++++++ packages/smem/tsconfig.json | 56 ++++++++ packages/smem/types/transformers.d.ts | 1 + packages/tmem-jobs/package.json | 5 +- packages/tmem-jobs/src/main.ts | 2 +- packages/tmem-jobs/src/tmem_jobs.ts | 4 +- packages/tmem-jobs/src/tmemjobsinterfaces.ts | 4 +- packages/tmem/package.json | 2 +- packages/tmem/src/tmem.ts | 4 +- 23 files changed, 479 insertions(+), 35 deletions(-) create mode 100644 packages/smem/package.json create mode 100644 packages/smem/rollup.config.js create mode 100644 packages/smem/src/main.ts create mode 100644 packages/smem/src/smeminterfaces.ts create mode 100644 packages/smem/src/useSmem.ts create mode 100644 packages/smem/src/useSnode.ts create mode 100644 packages/smem/tsconfig.json create mode 100644 packages/smem/types/transformers.d.ts diff --git a/packages/body/package.json b/packages/body/package.json index e25c2bb..ed8d4c2 100644 --- a/packages/body/package.json +++ b/packages/body/package.json @@ -1,6 +1,6 @@ { "name": "@agent-smith/body", - "version": "0.0.4", + "version": "0.0.5", "description": "An api to create human friendly agents", "repository": "https://github.com/synw/agent-smith", "scripts": { @@ -13,6 +13,7 @@ }, "devDependencies": { "@agent-smith/brain": "^0.0.3", + "@agent-smith/jobs": "^0.0.1", "@rollup/plugin-node-resolve": "^15.2.3", "@rollup/plugin-terser": "^0.4.4", "@rollup/plugin-typescript": "^11.1.5", diff --git a/packages/body/src/bodyinterfaces.ts b/packages/body/src/bodyinterfaces.ts index 976165f..653a40b 100644 --- a/packages/body/src/bodyinterfaces.ts +++ b/packages/body/src/bodyinterfaces.ts @@ -1,6 +1,7 @@ import { MapStore } from "nanostores"; import { AgentBrain } from "@agent-smith/brain" -import { AgentJob } from "../../jobs/src/jobsinterfaces.js"; +//import { AgentJob } from "../../jobs/src/jobsinterfaces.js"; +import { AgentJob } from "@agent-smith/jobs"; /** * Interface for the specification of an agent. diff --git a/packages/body/src/core.ts b/packages/body/src/core.ts index e12a500..d6c2ceb 100644 --- a/packages/body/src/core.ts +++ b/packages/body/src/core.ts @@ -1,7 +1,8 @@ import { map } from 'nanostores' -import { AgentSmith, AgentState, type AgentSpec, type ConfirmFunction, type ConfirmOptions } from "./bodyinterfaces.js"; import { AgentBrain } from '@agent-smith/brain'; -import { AgentJob } from "../../jobs/src/jobsinterfaces.js"; +//import { AgentJob } from "../../jobs/src/jobsinterfaces.js"; +import { AgentJob } from "@agent-smith/jobs"; +import { AgentSmith, AgentState, type AgentSpec, type ConfirmFunction, type ConfirmOptions } from "./bodyinterfaces.js"; const useAgentSmith = (initParams: AgentSpec): AgentSmith => { const name = initParams.name; diff --git a/packages/body/src/main.ts b/packages/body/src/main.ts index 0c4b4a5..50aeee1 100644 --- a/packages/body/src/main.ts +++ b/packages/body/src/main.ts @@ -1,11 +1,13 @@ import { useAgentSmith } from "./core.js"; import { - AgentSpec, AgentSmith, + AgentSpec, JsonData, ConfirmFunction, ConfirmOptions, TalkFunction, + AgentState, + AgentInteractions, } from "./bodyinterfaces.js"; export { @@ -16,4 +18,6 @@ export { ConfirmFunction, ConfirmOptions, TalkFunction, + AgentState, + AgentInteractions, } \ No newline at end of file diff --git a/packages/brain/package.json b/packages/brain/package.json index 8a465a0..1395ef2 100644 --- a/packages/brain/package.json +++ b/packages/brain/package.json @@ -1,7 +1,7 @@ { "name": "@agent-smith/brain", - "version": "0.0.3", - "description": "An api to ceate human friendly agents: the AI brain module", + "version": "0.0.5", + "description": "An api to create human friendly agents: the AI brain module", "repository": "https://github.com/synw/agent-smith", "scripts": { "buildrl": "rm -rf dist/* && rollup -c", diff --git a/packages/brain/src/lm.ts b/packages/brain/src/lm.ts index d60b5fc..ce3dcf2 100644 --- a/packages/brain/src/lm.ts +++ b/packages/brain/src/lm.ts @@ -74,8 +74,6 @@ const useLmExpert = (spec: LmExpertSpec): LmExpert => { delete completionParams.stop; } } - console.log("Params", inferenceParams); - console.log("Options", options); if (options?.tsGrammar) { completionParams.grammar = serializeGrammar(await compile(options.tsGrammar, "Grammar")); } @@ -103,7 +101,9 @@ const useLmExpert = (spec: LmExpertSpec): LmExpert => { throw new Error(msg) }; if (options?.verbose) { - console.log("Inference params", JSON.stringify(completionParams, null, " ")); + console.log("Params", completionParams); + console.log("Options", options); + //console.log("Inference params", JSON.stringify(completionParams, null, " ")); } const p = template.prompt(prompt); state.setKey("isThinking", true); @@ -112,9 +112,18 @@ const useLmExpert = (spec: LmExpertSpec): LmExpert => { _parseJson = options.parseJson } let parseJsonFunc = (t: string) => JSON.parse(t); - // dirty patch - if (template.name == "chatml") { - parseJsonFunc = (t: string) => JSON.parse(t.replace("<|im_end|>", "")); + if (_parseJson) { + if (_lm.providerType == "koboldcpp") { + parseJsonFunc = (t: string) => { + //console.log("Start T", t); + let s = t.replace(/\\_/g, '_'); + if (template.stop) { + s = s.replace(template.stop[0], ""); + } + //console.log("End T", s, [t].includes('\\_')); + return JSON.parse(s) + }; + } } const respData = await _lm.infer(p, completionParams, _parseJson, parseJsonFunc); state.setKey("isStreaming", false); diff --git a/packages/jobs/package.json b/packages/jobs/package.json index a5cffd7..d22ed73 100644 --- a/packages/jobs/package.json +++ b/packages/jobs/package.json @@ -1,7 +1,7 @@ { "name": "@agent-smith/jobs", - "version": "0.0.1", - "description": "An api to ceate human friendly agents: the jobs management module", + "version": "0.0.2", + "description": "An api to create human friendly agents: the jobs management module", "repository": "https://github.com/synw/agent-smith", "scripts": { "buildrl": "rm -rf dist/* && rollup -c", @@ -9,6 +9,9 @@ "test": "jest --coverage", "docs": "typedoc --entryPointStrategy expand" }, + "dependencies": { + "nanostores": "^0.10.0" + }, "devDependencies": { "@agent-smith/tmem-jobs": "^0.0.2", "@rollup/plugin-node-resolve": "^15.2.3", diff --git a/packages/jobs/src/job.ts b/packages/jobs/src/job.ts index 1fd5e95..7beaafe 100644 --- a/packages/jobs/src/job.ts +++ b/packages/jobs/src/job.ts @@ -22,7 +22,7 @@ const useAgentJob = (initParams: AgentJobSpec): AgentJob => { }); const _runTask = async (t: AgentTask, params: any, autoComplete: boolean): Promise> => { - console.log("JOB RUN TASK", t.id, autoComplete, params); + //console.log("JOB RUN TASK", t.id, autoComplete, params); //console.log("JOB running task:", t.name); try { let res: Record = {}; @@ -61,7 +61,7 @@ const useAgentJob = (initParams: AgentJobSpec): AgentJob => { } const continueTask = async (params: any = {}): Promise> => { - console.log("JOB TASK CONTINUE -------- TASK PARAMS", params); + //console.log("JOB TASK CONTINUE -------- TASK PARAMS", params); if (!state.get().isRunningTask) { throw new Error('No task is running, can not continue'); } @@ -70,7 +70,7 @@ const useAgentJob = (initParams: AgentJobSpec): AgentJob => { } const runTask = async (name: string, params: any = {}): Promise> => { - console.log("JOB TASK RUN -------- TASK PARAMS", params); + //console.log("JOB TASK RUN -------- TASK PARAMS", params); if (state.get().isRunningTask) { throw new Error('A task is already running'); } @@ -80,7 +80,7 @@ const useAgentJob = (initParams: AgentJobSpec): AgentJob => { } const startTask = async (name: string, params: any = {}) => { - console.log("JOB TASK START -------- TASK PARAMS", params); + //console.log("JOB TASK START -------- TASK PARAMS", params); if (state.get().isRunningTask) { throw new Error('A task is already running'); } @@ -88,7 +88,7 @@ const useAgentJob = (initParams: AgentJobSpec): AgentJob => { } const reStartTask = async (name: string) => { - console.log("JOB TASK RERSTART", name); + //console.log("JOB TASK RERSTART", name); if (state.get().isRunningTask) { throw new Error('A task is already running'); } @@ -96,7 +96,7 @@ const useAgentJob = (initParams: AgentJobSpec): AgentJob => { } const finishTask = async (completed: boolean, data?: any) => { - console.log("FINISH TASK", data); + //console.log("FINISH TASK", data); const task = getTaskById(state.get().runningTask); task.finish(completed, data); state.setKey("isRunningTask", false); diff --git a/packages/jobs/src/task.ts b/packages/jobs/src/task.ts index 555e23b..7e3acac 100644 --- a/packages/jobs/src/task.ts +++ b/packages/jobs/src/task.ts @@ -1,7 +1,6 @@ import { map } from 'nanostores'; import { AgentTask, AgentTaskState, type AgentTaskSpec } from "./jobsinterfaces.js"; - const useAgentTask = (spec: AgentTaskSpec): AgentTask => { //console.log("Init task:", JSON.stringify(spec, null, " ")); //console.log("F", spec.run) @@ -18,7 +17,7 @@ const useAgentTask = (spec: AgentTaskSpec): AgentTask => { }); const _run = async (params: any, autoComplete: boolean): Promise> => { - console.log("TASK run task", id, autoComplete, params); + //console.log("TASK run task", id, autoComplete, params); //console.log("RUN F", runFunc.name); state.setKey("isRunning", true); let data: Record = {}; @@ -27,7 +26,7 @@ const useAgentTask = (spec: AgentTaskSpec): AgentTask => { data = d; } if (autoComplete) { - console.log("AUTOCOMPLETE TASK", id); + //console.log("AUTOCOMPLETE TASK", id); state.setKey("isRunning", false); state.setKey("isCompleted", true); } @@ -43,7 +42,7 @@ const useAgentTask = (spec: AgentTaskSpec): AgentTask => { } const finish = (completed: boolean, data?: any): void => { - console.log("TASK finish task", id, completed, data); + //console.log("TASK finish task", id, completed, data); state.setKey("isRunning", false); state.setKey("isCompleted", completed); if (data) { diff --git a/packages/smem/package.json b/packages/smem/package.json new file mode 100644 index 0000000..483f6e3 --- /dev/null +++ b/packages/smem/package.json @@ -0,0 +1,46 @@ +{ + "name": "@agent-smith/smem", + "version": "0.0.1", + "description": "An api to create human friendly agents: the semantic memory", + "repository": "https://github.com/synw/agent-smith", + "scripts": { + "buildrl": "rm -rf dist/* && rollup -c", + "build": "rm -rf dist/* && tsc", + "test": "jest --coverage", + "docs": "typedoc --entryPointStrategy expand" + }, + "dependencies": { + "@xenova/transformers": "^2.15.1", + "apache-arrow": "^15.0.1", + "vectordb": "^0.4.12" + }, + "devDependencies": { + "@rollup/plugin-node-resolve": "^15.2.3", + "@rollup/plugin-terser": "^0.4.4", + "@rollup/plugin-typescript": "^11.1.6", + "@types/node": "^20.11.20", + "markdown-it-replace-link": "^1.2.1", + "rollup": "^4.12.0", + "tslib": "^2.6.2", + "typedoc": "^0.25.8", + "typedoc-plugin-markdown": "^3.17.1", + "typedoc-plugin-rename-defaults": "^0.7.0", + "typescript": "^5.3.3" + }, + "files": [ + "dist" + ], + "module": "./dist/main.js", + "types": "./dist/main.d.ts", + "type": "module", + "exports": { + ".": { + "import": "./dist/main.js" + } + }, + "publishConfig": { + "access": "public", + "registry": "https://registry.npmjs.org/" + }, + "license": "MIT" +} \ No newline at end of file diff --git a/packages/smem/rollup.config.js b/packages/smem/rollup.config.js new file mode 100644 index 0000000..96077b8 --- /dev/null +++ b/packages/smem/rollup.config.js @@ -0,0 +1,28 @@ +import resolve from '@rollup/plugin-node-resolve'; +import typescript from '@rollup/plugin-typescript'; +import terser from '@rollup/plugin-terser'; + +//const isProduction = !process.env.ROLLUP_WATCH; + +export default { + input: 'src/main.ts', + output: [ + { + file: 'dist/api.es.js', + format: 'esm' + }, + { + file: 'dist/api.min.js', + format: 'iife', + name: '$agentbrain', + plugins: [terser()] + }], + plugins: [ + typescript(), + resolve({ + jsnext: true, + main: true, + browser: true, + }), + ], +}; \ No newline at end of file diff --git a/packages/smem/src/main.ts b/packages/smem/src/main.ts new file mode 100644 index 0000000..5ef6823 --- /dev/null +++ b/packages/smem/src/main.ts @@ -0,0 +1,17 @@ +import { useSmem } from "./useSmem.js"; +import { useSnode } from "./useSnode.js"; +import { + SmemNodeFieldSchema, + SmemNodeSchema, + SmemNode, + Smem, +} from "./smeminterfaces.js" + +export { + useSmem, + useSnode, + SmemNodeFieldSchema, + SmemNodeSchema, + SmemNode, + Smem, +} \ No newline at end of file diff --git a/packages/smem/src/smeminterfaces.ts b/packages/smem/src/smeminterfaces.ts new file mode 100644 index 0000000..5339b4b --- /dev/null +++ b/packages/smem/src/smeminterfaces.ts @@ -0,0 +1,40 @@ +import { Connection, Table } from "vectordb"; +import { Schema } from "apache-arrow"; + +interface SmemNodeFieldSchema { + name: string; + type: FieldDataType, + nullable?: boolean; +} + +interface SmemNode { + table: Table; + vectorSourceCol: string; + open: () => Promise; + add: (data: Array>) => Promise; + addRaw: (data: Array>) => Promise; + upsert: (data: Array>, idCol?: string) => Promise; + upsertRaw: (data: Array>, idCol?: string) => Promise; +} + +interface Smem { + nodes: Record; + init: (dbpath: string) => Promise; + node: (name: string, schema: SmemNodeSchema, vectorSourceCol: string) => Promise; + nodeNames: () => Promise; + nodeFromSchema: (name: string, schema: Schema, vectorSourceCol: string) => Promise; + openTable: (name: string, sourceCol: string) => Promise
; + vector: (text: string) => Promise; + embed: (data: unknown[]) => Promise; +} + +type SmemNodeSchema = Array; + +type FieldDataType = "string" | "int" | "float" | "boolean"; + +export { + SmemNodeFieldSchema, + SmemNodeSchema, + SmemNode, + Smem, +} \ No newline at end of file diff --git a/packages/smem/src/useSmem.ts b/packages/smem/src/useSmem.ts new file mode 100644 index 0000000..06c8de6 --- /dev/null +++ b/packages/smem/src/useSmem.ts @@ -0,0 +1,142 @@ +import { Connection, connect, Table } from "vectordb"; +import { FeatureExtractionPipeline, pipeline } from "@xenova/transformers"; +import { Schema, Field, Float64, Int32, Utf8, FixedSizeList, Bool } from "apache-arrow"; +import { useSnode } from "./useSnode.js"; +import { SmemNodeSchema, SmemNode, Smem } from "./smeminterfaces.js"; + +const useSmem = (isVerbose = true): Smem => { + const tables: Record = {}; + + let pipe: typeof FeatureExtractionPipeline; + let db: Connection; + + const embed: (data: unknown[]) => Promise = async (batch) => { + //console.log("BATCH", batch); + const result: Array> = []; + for (const text of batch) { + //console.log("EMB", text) + const res = await pipe(`${text}`, { pooling: 'mean', normalize: true }) + result.push(Array.from(res['data'])) + } + return (result) + } + + const init = async (dbpath: string): Promise => { + if (isVerbose) { + console.log("Initializing db", dbpath); + } + pipe = await pipeline('feature-extraction', 'Xenova/all-MiniLM-L6-v2'); + if (isVerbose) { + console.log("Feature extraction pipeline ready"); + } + db = await connect(dbpath); + if (isVerbose) { + console.log("Database ready"); + } + return db + } + + const nodeFromSchema = async ( + name: string, + schema: Schema, + vectorSourceCol: string + ): Promise => { + return await _initNode(name, schema, vectorSourceCol) + } + + const node = async ( + name: string, + schema: SmemNodeSchema, + vectorSourceCol: string + ): Promise => { + return await _initNode(name, _createSchema(schema), vectorSourceCol) + } + + const nodeNames = async () => { + _assertDbIsConnected("Create table"); + return db.tableNames() + } + + const openTable = async (name: string, sourceCol: string): Promise
=> { + _assertDbIsConnected("Open table"); + return await db.openTable(name); + } + + const vector = async (text: string): Promise> => (await embed([text]))[0]; + + const _initNode = async ( + name: string, + schema: Schema, + vectorSourceCol: string + ): Promise => { + _assertDbIsConnected("Init node"); + if (isVerbose) { + console.log("Initializing node", name); + } + const tn = await db.tableNames(); + if (tn.includes(name)) { + if (isVerbose) { + console.log("Opening node") + } + const tbl = await db.openTable(name); + const t = useSnode(db, tbl, vectorSourceCol, vector, isVerbose); + tables[tbl.name] = t; + return t + } + if (isVerbose) { + console.log("Creating node") + } + const tbl = await db.createTable({ name: name, schema: schema }); + const t = useSnode(db, tbl, vectorSourceCol, vector, isVerbose); + tables[name] = t; + return t + } + + + function _createSchema(nodeSchema: SmemNodeSchema): Schema { + const fields = new Array(); + nodeSchema.forEach((f) => { + switch (f.type) { + case "string": + fields.push(new Field(f.name, new Utf8(), f.nullable ?? false)) + break; + case "int": + fields.push(new Field(f.name, new Int32(), f.nullable ?? false)) + break; + case "float": + fields.push(new Field(f.name, new Float64(), f.nullable ?? false)) + break; + case "boolean": + fields.push(new Field(f.name, new Bool(), f.nullable ?? false)) + break; + }; + }); + fields.push(new Field( + "vector", + new FixedSizeList(384, new Field("value", new Float64())), + false + )); + return new Schema(fields) + } + + function _assertDbIsConnected(from: string, value: Connection = db): asserts value is NonNullable { + if (value === undefined || value === null) { + throw new Error(`${from}: the database is not initialized`) + } + } + + return { + get nodes() { + return tables + }, + init, + node, + nodeNames, + nodeFromSchema, + openTable, + vector, + embed, + } +} + +export { useSmem } diff --git a/packages/smem/src/useSnode.ts b/packages/smem/src/useSnode.ts new file mode 100644 index 0000000..50bd48c --- /dev/null +++ b/packages/smem/src/useSnode.ts @@ -0,0 +1,95 @@ +import { Connection, Table } from "vectordb"; +import { SmemNode } from "./smeminterfaces.js"; + +const useSnode = ( + db: Connection, + table: Table, + vectorSourceCol: string, + vector: (text: string) => Promise>, + isVerbose: boolean, +): SmemNode => { + + const open = async (): Promise
=> { + _assertDbIsConnected("Open table"); + table = await db.openTable(table.name); + return table + } + + const addRaw = async (data: Array>) => { + if (isVerbose) { + console.log(`Adding ${data.length} raw datapoints`) + } + // auto open + if (!table) { + await open(); + } + await table.add(data) + } + + const add = async (data: Array>) => { + if (isVerbose) { + console.log(`Adding ${data.length} datapoints`) + } + // auto open + if (!table) { + await open(); + } + const vectorData: Array> = []; + data.forEach(async (row) => vectorData.push({ + ...row, + vector: await vector(`${row[vectorSourceCol]}`) + })); + await table.add(vectorData) + } + + const upsertRaw = async (data: Array>, idCol = "id") => { + if (isVerbose) { + console.log(`Upserting ${data.length} raw datapoints`) + } + // auto open + if (!table) { + table = await open(); + } + await table.mergeInsert(idCol, data, { + whenMatchedUpdateAll: true, + whenNotMatchedInsertAll: true, + }); + } + + const upsert = async (data: Array>, idCol = "id") => { + if (isVerbose) { + console.log(`Upserting ${data.length} datapoints`) + } + // auto open + if (!table) { + table = await open(); + } + const vectorData: Array> = []; + data.forEach(async (row) => vectorData.push({ + ...row, + vector: await vector(`${row[vectorSourceCol]}`) + })); + await table.mergeInsert(idCol, vectorData, { + whenMatchedUpdateAll: true, + whenNotMatchedInsertAll: true, + }); + } + + function _assertDbIsConnected(from: string, value: Connection = db): asserts value is NonNullable { + if (value === undefined || value === null) { + throw new Error(`${from}: the database is not initialized`) + } + } + + return { + table, + vectorSourceCol, + open, + add, + addRaw, + upsert, + upsertRaw, + } +} + +export { useSnode } \ No newline at end of file diff --git a/packages/smem/tsconfig.json b/packages/smem/tsconfig.json new file mode 100644 index 0000000..742035e --- /dev/null +++ b/packages/smem/tsconfig.json @@ -0,0 +1,56 @@ +{ + "compilerOptions": { + "declaration": true, + "outDir": "./dist", + "removeComments": true, + "strictFunctionTypes": true, + "target": "ES2022", + "module": "Node16", + "sourceMap": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true, + "allowJs": true, + "allowSyntheticDefaultImports": true, + "moduleResolution": "Node16", + "resolveJsonModule": true, + "types": [ + "node" + ], + "lib": [ + "ES2020", + "dom" + ], + "baseUrl": ".", + "paths": { + "@/*": [ + "src/*" + ], + "*": [ + "src/*", + "node_modules/*" + ] + } + }, + "include": [ + "src/**/*.ts", + "src/**/*.d.ts", + "src/**/*.vue", + "types/**/*.d.ts", + ], + "exclude": [ + "node_modules", + "dist", + "test" + ], + "typedocOptions": { + "name": "Agent Smith documentation", + "readme": "none", + "entryPoints": [ + "src/interfaces.ts", + "src/main.ts", + ], + "out": "docsite/public/apidoc/auto", + } +} \ No newline at end of file diff --git a/packages/smem/types/transformers.d.ts b/packages/smem/types/transformers.d.ts new file mode 100644 index 0000000..cccfa02 --- /dev/null +++ b/packages/smem/types/transformers.d.ts @@ -0,0 +1 @@ +declare module '@xenova/transformers'; \ No newline at end of file diff --git a/packages/tmem-jobs/package.json b/packages/tmem-jobs/package.json index e8293b2..912b35d 100644 --- a/packages/tmem-jobs/package.json +++ b/packages/tmem-jobs/package.json @@ -1,6 +1,6 @@ { "name": "@agent-smith/tmem-jobs", - "version": "0.0.2", + "version": "0.0.3", "description": "An api to ceate human friendly agents: the transient memory for jobs", "repository": "https://github.com/synw/agent-smith", "scripts": { @@ -10,8 +10,7 @@ "docs": "typedoc --entryPointStrategy expand" }, "dependencies": { - "@agent-smith/tmem": "^0.0.2", - "localforage": "^1.10.0" + "@agent-smith/tmem": "^0.0.3" }, "devDependencies": { "@rollup/plugin-node-resolve": "^15.2.3", diff --git a/packages/tmem-jobs/src/main.ts b/packages/tmem-jobs/src/main.ts index 8efe822..cbca135 100644 --- a/packages/tmem-jobs/src/main.ts +++ b/packages/tmem-jobs/src/main.ts @@ -3,7 +3,7 @@ import { TaskMem, TmemJobs } from "./tmemjobsinterfaces.js"; -import { useTmemJobs } from "./tmem_jobs"; +import { useTmemJobs } from "./tmem_jobs.js"; export { useTmemJobs, diff --git a/packages/tmem-jobs/src/tmem_jobs.ts b/packages/tmem-jobs/src/tmem_jobs.ts index 9be5a6f..c49dd7d 100644 --- a/packages/tmem-jobs/src/tmem_jobs.ts +++ b/packages/tmem-jobs/src/tmem_jobs.ts @@ -33,7 +33,7 @@ const useTmemJobs = (isVerbose = false): TmemJobs => { await jMem.set("isRunning", false); } - const _runTask = async (id: string, params: Record, isRestart: boolean) => { + const _runTask = async (id: string, params: any, isRestart: boolean) => { //console.log("TMEM run task", id, params); const t = await tMem.get(id); // update the job state @@ -50,7 +50,7 @@ const useTmemJobs = (isVerbose = false): TmemJobs => { //console.log("RES", JSON.stringify(res, null, " ")) } - const runTask = async (id: string, params: Record) => { + const runTask = async (id: string, params: any) => { return await _runTask(id, params, false) } diff --git a/packages/tmem-jobs/src/tmemjobsinterfaces.ts b/packages/tmem-jobs/src/tmemjobsinterfaces.ts index 1b3acc7..b963f1e 100644 --- a/packages/tmem-jobs/src/tmemjobsinterfaces.ts +++ b/packages/tmem-jobs/src/tmemjobsinterfaces.ts @@ -9,7 +9,7 @@ interface JobMem { interface TaskMem { isCompleted: boolean; - params: Record; + params: any; data: any; } @@ -19,7 +19,7 @@ interface TmemJobs { init: () => Promise; start: (name: string, tasks: Array>) => Promise; finish: () => Promise; - runTask: (id: string, params: Record) => Promise; + runTask: (id: string, params: any) => Promise; reRunTask: (id: string) => Promise; finishTask: (id: string, completed: boolean, data?: any) => Promise; } diff --git a/packages/tmem/package.json b/packages/tmem/package.json index ab1a5e2..5734bcb 100644 --- a/packages/tmem/package.json +++ b/packages/tmem/package.json @@ -1,6 +1,6 @@ { "name": "@agent-smith/tmem", - "version": "0.0.2", + "version": "0.0.3", "description": "An api to ceate human friendly agents: the transient memory module", "repository": "https://github.com/synw/agent-smith", "scripts": { diff --git a/packages/tmem/src/tmem.ts b/packages/tmem/src/tmem.ts index 844da3f..b3d7c30 100644 --- a/packages/tmem/src/tmem.ts +++ b/packages/tmem/src/tmem.ts @@ -1,7 +1,9 @@ import * as localForage from "localforage"; import { Tmem } from "./tmeminterfaces.js"; -const useTmem = = Record>(name: string, initial: S, verbose = false) => { +const useTmem = = Record>( + name: string, initial: S, verbose = false +): Tmem => { const db = localForage.createInstance({ name: "tmem", driver: localForage.INDEXEDDB,