@becomposable/memory
Advanced tools
Comparing version 0.38.0 to 0.38.1
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -7,2 +10,3 @@ exports.Builder = void 0; | ||
const fs_1 = require("fs"); | ||
const os_1 = __importDefault(require("os")); | ||
const path_1 = require("path"); | ||
@@ -38,3 +42,3 @@ const copy_js_1 = require("./commands/copy.js"); | ||
if (!this._tmpdir) { | ||
this._tmpdir = (0, fs_1.mkdtempSync)('becomposable-memo-'); | ||
this._tmpdir = (0, fs_1.mkdtempSync)((0, path_1.join)(os_1.default.tmpdir(), 'becomposable-memo-')); | ||
} | ||
@@ -107,18 +111,18 @@ return this._tmpdir; | ||
try { | ||
const { baseName, publishName } = this._getOutputNames(); | ||
let { fileName, publishName } = this._getOutputNames(); | ||
// resolve all content objects values from the conext object | ||
object = await resolveContextObject(object); | ||
// write the memory to a file | ||
let file = await this.memory.build(baseName, object); | ||
fileName = await this.memory.build(fileName, object); | ||
let target = fileName; | ||
if (publishName) { | ||
const tarFile = file; | ||
try { | ||
file = await this.options.publish(tarFile, publishName); | ||
target = await this.options.publish(fileName, publishName); | ||
} | ||
finally { | ||
(0, fs_1.rmSync)(tarFile); | ||
(0, fs_1.rmSync)(fileName); | ||
} | ||
} | ||
this.options.quiet || console.log(`Memory saved to ${file}`); | ||
return file; | ||
this.options.quiet || console.log(`Memory saved to ${target}`); | ||
return target; | ||
} | ||
@@ -134,5 +138,5 @@ finally { | ||
if (!options.out) { | ||
options.out = "memory"; | ||
options.out = "memory.tar"; | ||
} | ||
let baseName; | ||
let fileName; | ||
let publishName; | ||
@@ -147,9 +151,9 @@ const out = options.out; | ||
// create a temporary path for the output | ||
baseName = createTmpBaseName(this.tmpdir()); | ||
fileName = createTmpBaseName(this.tmpdir()); | ||
publishName = out.substring("memory:".length); | ||
} | ||
else { | ||
baseName = (0, path_1.resolve)(out || 'memory'); | ||
fileName = (0, path_1.resolve)(out); | ||
} | ||
return { baseName, publishName }; | ||
return { fileName, publishName }; | ||
} | ||
@@ -169,3 +173,3 @@ } | ||
function createTmpBaseName(tmpdir) { | ||
return (0, path_1.join)(tmpdir, `.composable-memory-${Date.now()}`); | ||
return (0, path_1.join)(tmpdir, `.composable-memory-${Date.now()}.tar`); | ||
} | ||
@@ -172,0 +176,0 @@ function buildMemoryPack(recipeFn, options) { |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MemoryPackBuilder = void 0; | ||
const promises_1 = require("fs/promises"); | ||
const MemoryPack_js_1 = require("./MemoryPack.js"); | ||
const tar_js_1 = require("./utils/tar.js"); | ||
const node_fs_1 = require("node:fs"); | ||
const promises_2 = require("node:stream/promises"); | ||
const node_zlib_1 = __importDefault(require("node:zlib")); | ||
const stream_1 = require("stream"); | ||
class MemoryPackBuilder { | ||
@@ -38,3 +30,6 @@ builder; | ||
} | ||
async _buildTar(file, context) { | ||
async build(file, context) { | ||
if (!file.endsWith('.tar')) { | ||
file += '.tar'; | ||
} | ||
if (this.builder.options.gzip) { | ||
@@ -53,26 +48,4 @@ file += ".gz"; | ||
} | ||
async _buildJson(file, context) { | ||
const buffer = Buffer.from(this.stringifyContext(context), "utf-8"); | ||
if (this.builder.options.gzip) { | ||
file += ".gz"; | ||
await (0, promises_2.pipeline)(stream_1.Readable.from(buffer), node_zlib_1.default.createGzip(), (0, node_fs_1.createWriteStream)(file)); | ||
} | ||
else { | ||
await (0, promises_1.writeFile)(file, buffer); | ||
} | ||
return file; | ||
} | ||
build(baseName, context = {}) { | ||
if (this.baseContext) { | ||
context = Object.assign({}, this.baseContext, context); | ||
} | ||
if (!Object.keys(this.entries).length) { | ||
return this._buildJson(baseName + '.json', context); | ||
} | ||
else { | ||
return this._buildTar(baseName + '.tar', context); | ||
} | ||
} | ||
} | ||
exports.MemoryPackBuilder = MemoryPackBuilder; | ||
//# sourceMappingURL=MemoryPackBuilder.js.map |
import { AsyncObjectWalker } from "@becomposable/json"; | ||
import { mkdtempSync, rmSync } from "fs"; | ||
import os from "os"; | ||
import { join, resolve } from "path"; | ||
@@ -33,3 +34,3 @@ import { copy } from "./commands/copy.js"; | ||
if (!this._tmpdir) { | ||
this._tmpdir = mkdtempSync('becomposable-memo-'); | ||
this._tmpdir = mkdtempSync(join(os.tmpdir(), 'becomposable-memo-')); | ||
} | ||
@@ -102,18 +103,18 @@ return this._tmpdir; | ||
try { | ||
const { baseName, publishName } = this._getOutputNames(); | ||
let { fileName, publishName } = this._getOutputNames(); | ||
// resolve all content objects values from the conext object | ||
object = await resolveContextObject(object); | ||
// write the memory to a file | ||
let file = await this.memory.build(baseName, object); | ||
fileName = await this.memory.build(fileName, object); | ||
let target = fileName; | ||
if (publishName) { | ||
const tarFile = file; | ||
try { | ||
file = await this.options.publish(tarFile, publishName); | ||
target = await this.options.publish(fileName, publishName); | ||
} | ||
finally { | ||
rmSync(tarFile); | ||
rmSync(fileName); | ||
} | ||
} | ||
this.options.quiet || console.log(`Memory saved to ${file}`); | ||
return file; | ||
this.options.quiet || console.log(`Memory saved to ${target}`); | ||
return target; | ||
} | ||
@@ -129,5 +130,5 @@ finally { | ||
if (!options.out) { | ||
options.out = "memory"; | ||
options.out = "memory.tar"; | ||
} | ||
let baseName; | ||
let fileName; | ||
let publishName; | ||
@@ -142,9 +143,9 @@ const out = options.out; | ||
// create a temporary path for the output | ||
baseName = createTmpBaseName(this.tmpdir()); | ||
fileName = createTmpBaseName(this.tmpdir()); | ||
publishName = out.substring("memory:".length); | ||
} | ||
else { | ||
baseName = resolve(out || 'memory'); | ||
fileName = resolve(out); | ||
} | ||
return { baseName, publishName }; | ||
return { fileName, publishName }; | ||
} | ||
@@ -163,3 +164,3 @@ } | ||
function createTmpBaseName(tmpdir) { | ||
return join(tmpdir, `.composable-memory-${Date.now()}`); | ||
return join(tmpdir, `.composable-memory-${Date.now()}.tar`); | ||
} | ||
@@ -166,0 +167,0 @@ export function buildMemoryPack(recipeFn, options) { |
@@ -1,8 +0,3 @@ | ||
import { writeFile } from "fs/promises"; | ||
import { MEMORY_METADATA_ENTRY } from "./MemoryPack.js"; | ||
import { normalizePath, TarBuilder } from "./utils/tar.js"; | ||
import { createWriteStream } from 'node:fs'; | ||
import { pipeline } from 'node:stream/promises'; | ||
import zlib from 'node:zlib'; | ||
import { Readable } from "stream"; | ||
export class MemoryPackBuilder { | ||
@@ -32,3 +27,6 @@ builder; | ||
} | ||
async _buildTar(file, context) { | ||
async build(file, context) { | ||
if (!file.endsWith('.tar')) { | ||
file += '.tar'; | ||
} | ||
if (this.builder.options.gzip) { | ||
@@ -47,25 +45,3 @@ file += ".gz"; | ||
} | ||
async _buildJson(file, context) { | ||
const buffer = Buffer.from(this.stringifyContext(context), "utf-8"); | ||
if (this.builder.options.gzip) { | ||
file += ".gz"; | ||
await pipeline(Readable.from(buffer), zlib.createGzip(), createWriteStream(file)); | ||
} | ||
else { | ||
await writeFile(file, buffer); | ||
} | ||
return file; | ||
} | ||
build(baseName, context = {}) { | ||
if (this.baseContext) { | ||
context = Object.assign({}, this.baseContext, context); | ||
} | ||
if (!Object.keys(this.entries).length) { | ||
return this._buildJson(baseName + '.json', context); | ||
} | ||
else { | ||
return this._buildTar(baseName + '.tar', context); | ||
} | ||
} | ||
} | ||
//# sourceMappingURL=MemoryPackBuilder.js.map |
@@ -9,5 +9,4 @@ import { CopyOptions } from "./commands/copy.js"; | ||
/** | ||
* the path to save the output. Defualts to 'memory' | ||
* The path should not contain the file extension. The extension will be chosen based on the content. | ||
* It will be either .json or .tar (if media files are present) | ||
* the path to save the output. Defaults to 'memory.tar'. | ||
* If no .tar extension is present it will be added | ||
*/ | ||
@@ -75,2 +74,1 @@ out?: string; | ||
export declare function buildMemoryPack(recipeFn: (commands: Commands) => Promise<Record<string, any>>, options: BuildOptions): Promise<string>; | ||
//# sourceMappingURL=Builder.d.ts.map |
@@ -9,2 +9,1 @@ import { Builder } from "../Builder.js"; | ||
export declare function copy(builder: Builder, source: SourceSpec, toPath: string, options?: CopyOptions): void; | ||
//# sourceMappingURL=copy.d.ts.map |
@@ -8,2 +8,1 @@ import { Writable } from 'stream'; | ||
export declare function executePipe(commands: Command[], finalOutput: Writable | undefined, verbose?: boolean): Promise<unknown>; | ||
//# sourceMappingURL=exec.d.ts.map |
@@ -44,2 +44,1 @@ import fs from "fs"; | ||
} | ||
//# sourceMappingURL=ContentObject.d.ts.map |
@@ -33,2 +33,1 @@ export interface ContentSource { | ||
} | ||
//# sourceMappingURL=ContentSource.d.ts.map |
@@ -15,2 +15,1 @@ export { Builder, buildMemoryPack } from "./Builder.js"; | ||
export type { TarEntry, TarEntryIndex } from './utils/tar.js'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -58,2 +58,1 @@ import { AbstractContentSource } from "./ContentSource.js"; | ||
export declare function loadMemoryPack(location: string, type?: 'tar' | 'json'): Promise<MemoryPack>; | ||
//# sourceMappingURL=MemoryPack.d.ts.map |
@@ -18,6 +18,3 @@ import { Builder } from "./Builder.js"; | ||
stringifyContext(context: object): string; | ||
private _buildTar; | ||
private _buildJson; | ||
build(baseName: string, context?: Record<string, any>): Promise<string>; | ||
build(file: string, context: object): Promise<string>; | ||
} | ||
//# sourceMappingURL=MemoryPackBuilder.d.ts.map |
@@ -11,2 +11,1 @@ export declare function splitCommandLine(text: string): string[]; | ||
export declare function splitPipeCommands(text: string): CommandPipe; | ||
//# sourceMappingURL=cmdline.d.ts.map |
@@ -39,2 +39,1 @@ /** | ||
} | ||
//# sourceMappingURL=rewrite.d.ts.map |
@@ -10,2 +10,1 @@ import { Writable } from "stream"; | ||
} | ||
//# sourceMappingURL=stream.d.ts.map |
@@ -41,2 +41,1 @@ import fs from "fs"; | ||
export declare function normalizePath(path: string): string; | ||
//# sourceMappingURL=tar.d.ts.map |
{ | ||
"name": "@becomposable/memory", | ||
"description": "Manipulate memory images for LLMs", | ||
"version": "0.38.0", | ||
"version": "0.38.1", | ||
"type": "module", | ||
@@ -24,5 +24,5 @@ "types": "./lib/types/index.d.ts", | ||
"typescript": "^5.0.2", | ||
"@becomposable/client": "0.38.0", | ||
"@becomposable/json": "0.38.0", | ||
"@becomposable/converters": "0.38.0" | ||
"@becomposable/client": "0.38.1", | ||
"@becomposable/converters": "0.38.1", | ||
"@becomposable/json": "0.38.1" | ||
}, | ||
@@ -29,0 +29,0 @@ "ts_dual_module": { |
@@ -6,3 +6,3 @@ # Memory Pack | ||
A memory pack is an indexed tar file containing media or text files and a `metadata.json` file which is defining the properties of a memory pack. The metadata is used to describe the memory and the other files in the tar can be used to hold the additional content you need in order to create a context for the interaction with a target LLM. | ||
A memory pack is an indexed tar file containing a `metadata.json` and other random files (images, documents, text files etc.). The `metadata.json` file is defining the properties of a memory pack. The metadata is used to describe the memory and the other files in the tar can be used to hold the additional content you need in order to create a context for the interaction with a target LLM. | ||
@@ -252,5 +252,4 @@ To build a memory pack you must use the memory pack API or the `memo` application provided by `@becomposable/memory-cli` package. The tar contains a special file named `.index` which is used to index the tar content so that the tar entries can be quickly extracted from the tar without nneeding to untar the entire content. | ||
/** | ||
* the path to save the output. Defaults to 'memory' | ||
* The path should not contain the file extension. The extension will be chosen based on the content. | ||
* It will be either .json or .tar (if media files are present) | ||
* the path to save the output. Defaults to 'memory.tar'. | ||
* If no .tar extension is present it will be added | ||
*/ | ||
@@ -257,0 +256,0 @@ out?: string; |
import { AsyncObjectWalker } from "@becomposable/json"; | ||
import { mkdtempSync, rmSync } from "fs"; | ||
import os from "os"; | ||
import { join, resolve } from "path"; | ||
@@ -14,7 +15,7 @@ import { copy, CopyOptions } from "./commands/copy.js"; | ||
/** | ||
* the path to save the output. Defualts to 'memory' | ||
* The path should not contain the file extension. The extension will be chosen based on the content. | ||
* It will be either .json or .tar (if media files are present) | ||
* the path to save the output. Defaults to 'memory.tar'. | ||
* If no .tar extension is present it will be added | ||
*/ | ||
out?: string; | ||
/** | ||
@@ -88,3 +89,3 @@ * If set, suppress logs. Defaults to false. | ||
if (!this._tmpdir) { | ||
this._tmpdir = mkdtempSync('becomposable-memo-'); | ||
this._tmpdir = mkdtempSync(join(os.tmpdir(), 'becomposable-memo-')); | ||
} | ||
@@ -163,17 +164,17 @@ return this._tmpdir; | ||
try { | ||
const { baseName, publishName } = this._getOutputNames(); | ||
let { fileName, publishName } = this._getOutputNames(); | ||
// resolve all content objects values from the conext object | ||
object = await resolveContextObject(object); | ||
// write the memory to a file | ||
let file = await this.memory.build(baseName, object); | ||
fileName = await this.memory.build(fileName, object); | ||
let target: string = fileName; | ||
if (publishName) { | ||
const tarFile = file; | ||
try { | ||
file = await this.options.publish!(tarFile, publishName); | ||
target = await this.options.publish!(fileName, publishName); | ||
} finally { | ||
rmSync(tarFile); | ||
rmSync(fileName); | ||
} | ||
} | ||
this.options.quiet || console.log(`Memory saved to ${file}`); | ||
return file; | ||
this.options.quiet || console.log(`Memory saved to ${target}`); | ||
return target; | ||
} finally { | ||
@@ -186,8 +187,8 @@ if (this._tmpdir) { | ||
private _getOutputNames(): { baseName: string, publishName: string | undefined } { | ||
private _getOutputNames(): { fileName: string, publishName: string | undefined } { | ||
const options = this.options; | ||
if (!options.out) { | ||
options.out = "memory"; | ||
options.out = "memory.tar"; | ||
} | ||
let baseName: string; | ||
let fileName: string; | ||
let publishName: string | undefined; | ||
@@ -202,8 +203,8 @@ const out = options.out; | ||
// create a temporary path for the output | ||
baseName = createTmpBaseName(this.tmpdir()); | ||
fileName = createTmpBaseName(this.tmpdir()); | ||
publishName = out.substring("memory:".length); | ||
} else { | ||
baseName = resolve(out || 'memory'); | ||
fileName = resolve(out); | ||
} | ||
return { baseName, publishName }; | ||
return { fileName, publishName }; | ||
} | ||
@@ -224,3 +225,3 @@ | ||
function createTmpBaseName(tmpdir: string) { | ||
return join(tmpdir, `.composable-memory-${Date.now()}`); | ||
return join(tmpdir, `.composable-memory-${Date.now()}.tar`); | ||
} | ||
@@ -227,0 +228,0 @@ |
@@ -1,2 +0,1 @@ | ||
import { writeFile } from "fs/promises"; | ||
import { Builder } from "./Builder.js"; | ||
@@ -6,6 +5,2 @@ import { ContentSource } from "./ContentSource.js"; | ||
import { normalizePath, TarBuilder } from "./utils/tar.js"; | ||
import { createWriteStream } from 'node:fs'; | ||
import { pipeline } from 'node:stream/promises'; | ||
import zlib from 'node:zlib'; | ||
import { Readable } from "stream"; | ||
@@ -44,3 +39,6 @@ export interface FromOptions { | ||
private async _buildTar(file: string, context: object) { | ||
async build(file: string, context: object) { | ||
if (!file.endsWith('.tar')) { | ||
file += '.tar'; | ||
} | ||
if (this.builder.options.gzip) { | ||
@@ -59,28 +57,2 @@ file += ".gz"; | ||
} | ||
private async _buildJson(file: string, context: object) { | ||
const buffer = Buffer.from(this.stringifyContext(context), "utf-8"); | ||
if (this.builder.options.gzip) { | ||
file += ".gz"; | ||
await pipeline( | ||
Readable.from(buffer), | ||
zlib.createGzip(), | ||
createWriteStream(file) | ||
); | ||
} else { | ||
await writeFile(file, buffer); | ||
} | ||
return file; | ||
} | ||
build(baseName: string, context: Record<string, any> = {}) { | ||
if (this.baseContext) { | ||
context = Object.assign({}, this.baseContext, context); | ||
} | ||
if (!Object.keys(this.entries).length) { | ||
return this._buildJson(baseName + '.json', context); | ||
} else { | ||
return this._buildTar(baseName + '.tar', context); | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
311054
17
4449
421
+ Added@becomposable/api-fetch-client@0.38.1(transitive)
+ Added@becomposable/client@0.38.1(transitive)
+ Added@becomposable/common@0.38.1(transitive)
+ Added@becomposable/converters@0.38.1(transitive)
+ Added@becomposable/json@0.38.1(transitive)
- Removed@becomposable/api-fetch-client@0.38.0(transitive)
- Removed@becomposable/client@0.38.0(transitive)
- Removed@becomposable/common@0.38.0(transitive)
- Removed@becomposable/converters@0.38.0(transitive)
- Removed@becomposable/json@0.38.0(transitive)
Updated@becomposable/client@0.38.1
Updated@becomposable/json@0.38.1