zeitlich 0.2.13 → 0.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -50
- package/dist/adapters/sandbox/daytona/index.cjs +205 -0
- package/dist/adapters/sandbox/daytona/index.cjs.map +1 -0
- package/dist/adapters/sandbox/daytona/index.d.cts +86 -0
- package/dist/adapters/sandbox/daytona/index.d.ts +86 -0
- package/dist/adapters/sandbox/daytona/index.js +202 -0
- package/dist/adapters/sandbox/daytona/index.js.map +1 -0
- package/dist/adapters/sandbox/inmemory/index.cjs +174 -0
- package/dist/adapters/sandbox/inmemory/index.cjs.map +1 -0
- package/dist/adapters/sandbox/inmemory/index.d.cts +28 -0
- package/dist/adapters/sandbox/inmemory/index.d.ts +28 -0
- package/dist/adapters/sandbox/inmemory/index.js +172 -0
- package/dist/adapters/sandbox/inmemory/index.js.map +1 -0
- package/dist/adapters/sandbox/virtual/index.cjs +405 -0
- package/dist/adapters/sandbox/virtual/index.cjs.map +1 -0
- package/dist/adapters/sandbox/virtual/index.d.cts +85 -0
- package/dist/adapters/sandbox/virtual/index.d.ts +85 -0
- package/dist/adapters/sandbox/virtual/index.js +400 -0
- package/dist/adapters/sandbox/virtual/index.js.map +1 -0
- package/dist/adapters/thread/google-genai/index.cjs +306 -0
- package/dist/adapters/thread/google-genai/index.cjs.map +1 -0
- package/dist/adapters/thread/google-genai/index.d.cts +145 -0
- package/dist/adapters/thread/google-genai/index.d.ts +145 -0
- package/dist/adapters/thread/google-genai/index.js +300 -0
- package/dist/adapters/thread/google-genai/index.js.map +1 -0
- package/dist/adapters/{langchain → thread/langchain}/index.cjs +29 -9
- package/dist/adapters/thread/langchain/index.cjs.map +1 -0
- package/dist/adapters/{langchain → thread/langchain}/index.d.cts +17 -21
- package/dist/adapters/{langchain → thread/langchain}/index.d.ts +17 -21
- package/dist/adapters/{langchain → thread/langchain}/index.js +29 -9
- package/dist/adapters/thread/langchain/index.js.map +1 -0
- package/dist/index.cjs +866 -567
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +235 -74
- package/dist/index.d.ts +235 -74
- package/dist/index.js +854 -562
- package/dist/index.js.map +1 -1
- package/dist/{thread-manager-qc0g5Rvd.d.cts → types-35POpVfa.d.cts} +7 -6
- package/dist/{thread-manager-qc0g5Rvd.d.ts → types-35POpVfa.d.ts} +7 -6
- package/dist/types-BMXzv7TN.d.cts +476 -0
- package/dist/types-BMXzv7TN.d.ts +476 -0
- package/dist/types-BVP87m_W.d.cts +121 -0
- package/dist/types-BWvIYK28.d.ts +391 -0
- package/dist/types-CDubRtad.d.cts +115 -0
- package/dist/types-CDubRtad.d.ts +115 -0
- package/dist/types-CwwgQ_9H.d.ts +121 -0
- package/dist/types-Dje1TdH6.d.cts +391 -0
- package/dist/workflow.cjs +460 -321
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +271 -222
- package/dist/workflow.d.ts +271 -222
- package/dist/workflow.js +456 -319
- package/dist/workflow.js.map +1 -1
- package/package.json +65 -8
- package/src/adapters/sandbox/daytona/filesystem.ts +136 -0
- package/src/adapters/sandbox/daytona/index.ts +149 -0
- package/src/adapters/sandbox/daytona/types.ts +34 -0
- package/src/adapters/sandbox/inmemory/index.ts +213 -0
- package/src/adapters/sandbox/virtual/filesystem.ts +345 -0
- package/src/adapters/sandbox/virtual/index.ts +88 -0
- package/src/adapters/sandbox/virtual/mutations.ts +38 -0
- package/src/adapters/sandbox/virtual/provider.ts +101 -0
- package/src/adapters/sandbox/virtual/tree.ts +82 -0
- package/src/adapters/sandbox/virtual/types.ts +127 -0
- package/src/adapters/sandbox/virtual/virtual-sandbox.test.ts +523 -0
- package/src/adapters/sandbox/virtual/with-virtual-sandbox.ts +91 -0
- package/src/adapters/thread/google-genai/activities.ts +132 -0
- package/src/adapters/thread/google-genai/index.ts +41 -0
- package/src/adapters/thread/google-genai/model-invoker.ts +154 -0
- package/src/adapters/thread/google-genai/thread-manager.ts +169 -0
- package/src/adapters/{langchain → thread/langchain}/activities.ts +22 -15
- package/src/adapters/{langchain → thread/langchain}/index.ts +1 -1
- package/src/adapters/{langchain → thread/langchain}/model-invoker.ts +15 -18
- package/src/adapters/{langchain → thread/langchain}/thread-manager.ts +1 -1
- package/src/index.ts +32 -24
- package/src/lib/activity.ts +87 -0
- package/src/lib/hooks/index.ts +11 -0
- package/src/lib/hooks/types.ts +98 -0
- package/src/lib/model/helpers.ts +6 -0
- package/src/lib/model/index.ts +13 -0
- package/src/lib/{model-invoker.ts → model/types.ts} +18 -1
- package/src/lib/sandbox/index.ts +19 -0
- package/src/lib/sandbox/manager.ts +76 -0
- package/src/lib/sandbox/sandbox.test.ts +158 -0
- package/src/lib/{fs.ts → sandbox/tree.ts} +6 -6
- package/src/lib/sandbox/types.ts +164 -0
- package/src/lib/session/index.ts +11 -0
- package/src/lib/{session.ts → session/session.ts} +83 -50
- package/src/lib/session/types.ts +95 -0
- package/src/lib/skills/fs-provider.ts +16 -15
- package/src/lib/skills/handler.ts +31 -0
- package/src/lib/skills/index.ts +5 -1
- package/src/lib/skills/register.ts +20 -0
- package/src/lib/skills/tool.ts +47 -0
- package/src/lib/state/index.ts +9 -0
- package/src/lib/{state-manager.ts → state/manager.ts} +10 -147
- package/src/lib/state/types.ts +134 -0
- package/src/lib/subagent/define.ts +71 -0
- package/src/lib/subagent/handler.ts +99 -0
- package/src/lib/subagent/index.ts +13 -0
- package/src/lib/subagent/register.ts +68 -0
- package/src/lib/subagent/tool.ts +80 -0
- package/src/lib/subagent/types.ts +92 -0
- package/src/lib/thread/index.ts +7 -0
- package/src/lib/{thread-manager.ts → thread/manager.ts} +20 -33
- package/src/lib/thread/types.ts +39 -0
- package/src/lib/tool-router/auto-append.ts +55 -0
- package/src/lib/tool-router/index.ts +41 -0
- package/src/lib/tool-router/router.ts +462 -0
- package/src/lib/tool-router/types.ts +478 -0
- package/src/lib/tool-router/with-sandbox.ts +70 -0
- package/src/lib/types.ts +5 -382
- package/src/tools/bash/bash.test.ts +53 -55
- package/src/tools/bash/handler.ts +23 -51
- package/src/tools/edit/handler.ts +67 -81
- package/src/tools/glob/handler.ts +60 -17
- package/src/tools/read-file/handler.ts +67 -0
- package/src/tools/read-skill/handler.ts +1 -31
- package/src/tools/read-skill/tool.ts +5 -47
- package/src/tools/subagent/handler.ts +1 -100
- package/src/tools/subagent/tool.ts +5 -93
- package/src/tools/task-create/handler.ts +1 -1
- package/src/tools/task-get/handler.ts +1 -1
- package/src/tools/task-list/handler.ts +1 -1
- package/src/tools/task-update/handler.ts +1 -1
- package/src/tools/write-file/handler.ts +47 -0
- package/src/workflow.ts +88 -47
- package/tsup.config.ts +8 -1
- package/dist/adapters/langchain/index.cjs.map +0 -1
- package/dist/adapters/langchain/index.js.map +0 -1
- package/dist/model-invoker-y_zlyMqu.d.cts +0 -892
- package/dist/model-invoker-y_zlyMqu.d.ts +0 -892
- package/src/lib/tool-router.ts +0 -977
- package/src/lib/workflow-helpers.ts +0 -50
- /package/src/lib/{thread-id.ts → thread/id.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/sandbox/types.ts","../../../../src/adapters/sandbox/virtual/filesystem.ts","../../../../src/lib/thread/id.ts","../../../../src/adapters/sandbox/virtual/provider.ts","../../../../src/lib/activity.ts","../../../../src/adapters/sandbox/virtual/with-virtual-sandbox.ts","../../../../src/adapters/sandbox/virtual/index.ts"],"names":["ApplicationFailure","uuid4","Context"],"mappings":";;;;;;;AAqJO,IAAM,wBAAA,GAAN,cAAuCA,yBAAA,CAAmB;AAAA,EAC/D,YAAY,SAAA,EAAmB;AAC7B,IAAA,KAAA;AAAA,MACE,6BAA6B,SAAS,CAAA,CAAA;AAAA,MACtC,0BAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AACF,CAAA;;;AC5IA,SAAS,cAAc,CAAA,EAAmB;AACxC,EAAA,IAAI,CAAC,CAAA,CAAE,UAAA,CAAW,GAAG,CAAA,MAAO,GAA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AAAA,MACL,cAAc,QAAA,CAAS,YAAA;AAAA,MACvB,IAAA,EAAM;AAAA,QACJ,GAAI,QAAA,CAAS,IAAA,IAAQ,EAAC;AAAA,QACtB,aAAA,EAAe;AAAA;AACjB,KACF;AAAA,EACF,CAAA;AACF;;;ACvEA,IAAM,qBAAN,MAIA;AAAA,EASE,WAAA,CACW,EAAA,EACT,IAAA,EACA,QAAA,EACA,GAAA,EACA;AAJS,IAAA,IAAA,CAAA,EAAA,GAAA,EAAA;AAKT,IAAA,IAAA,CAAK,EAAA,GAAK,IAAI,wBAAA,CAAyB,IAAA,EAAM,UAAU,GAAG,CAAA;AAAA,EAC5D;AAAA,EAfS,YAAA,GAAoC;AAAA,IAC3C,UAAA,EAAY,IAAA;AAAA,IACZ,SAAA,EAAW,KAAA;AAAA,IACX,WAAA,EAAa;AAAA,GACf;AAAA,EAES,EAAA;AAAA,EAWT,MAAM,IAAA,CAAK,QAAA,EAAkB,QAAA,EAA6C;AACxE,IAAA,MAAM,IAAI,yBAAyB,MAAM,CAAA;AAAA,EAC3C;AAAA,EAEA,MAAM,OAAA,GAAyB;AAAA,EAE/B;AACF,CAAA;AAaO,SAAS,oBAAA,CAId,EAAA,EACA,IAAA,EACA,QAAA,EACA,GAAA,EAC6B;AAC7B,EAAA,OAAO,IAAI,kBAAA,CAAmB,EAAA,EAAI,IAAA,EAAM,UAAU,GAAG,CAAA;AACvD","file":"index.cjs","sourcesContent":["// ============================================================================\n// Sandbox Filesystem\n// ============================================================================\n\nexport interface DirentEntry {\n name: string;\n isFile: boolean;\n isDirectory: boolean;\n isSymbolicLink: boolean;\n}\n\nexport interface FileStat {\n isFile: boolean;\n isDirectory: boolean;\n isSymbolicLink: boolean;\n size: number;\n mtime: Date;\n}\n\n/**\n * Provider-agnostic filesystem interface.\n *\n * Implementations that don't support a method should throw\n * {@link SandboxNotSupportedError}.\n */\nexport interface SandboxFileSystem {\n readFile(path: string): Promise<string>;\n readFileBuffer(path: string): Promise<Uint8Array>;\n writeFile(path: string, content: string | Uint8Array): Promise<void>;\n appendFile(path: string, content: string | Uint8Array): Promise<void>;\n exists(path: string): Promise<boolean>;\n stat(path: string): Promise<FileStat>;\n mkdir(path: string, options?: { recursive?: boolean }): Promise<void>;\n readdir(path: string): Promise<string[]>;\n readdirWithFileTypes(path: string): Promise<DirentEntry[]>;\n rm(path: string, options?: { recursive?: boolean; force?: boolean }): Promise<void>;\n cp(src: string, dest: string, options?: { recursive?: boolean }): Promise<void>;\n mv(src: string, dest: string): Promise<void>;\n readlink(path: string): Promise<string>;\n resolvePath(base: string, path: string): string;\n}\n\n// ============================================================================\n// Execution\n// ============================================================================\n\nexport interface ExecOptions {\n timeout?: number;\n cwd?: string;\n env?: Record<string, string>;\n}\n\nexport interface ExecResult {\n exitCode: number;\n stdout: string;\n stderr: string;\n}\n\n// ============================================================================\n// Capabilities\n// ============================================================================\n\nexport interface SandboxCapabilities {\n /** Sandbox supports filesystem operations */\n filesystem: boolean;\n /** Sandbox supports shell/command execution */\n execution: boolean;\n /** Sandbox state can be persisted and restored */\n persistence: boolean;\n}\n\n// ============================================================================\n// Sandbox\n// ============================================================================\n\nexport interface Sandbox {\n readonly id: string;\n readonly capabilities: SandboxCapabilities;\n readonly fs: SandboxFileSystem;\n\n exec(command: string, options?: ExecOptions): Promise<ExecResult>;\n destroy(): Promise<void>;\n}\n\n// ============================================================================\n// Snapshots\n// ============================================================================\n\nexport interface SandboxSnapshot {\n sandboxId: string;\n providerId: string;\n /** Provider-specific serialised state */\n data: unknown;\n createdAt: string;\n}\n\n// ============================================================================\n// Provider\n// ============================================================================\n\nexport interface SandboxCreateOptions {\n /** Preferred sandbox ID (provider may ignore) */\n id?: string;\n /** Seed the filesystem with these files */\n initialFiles?: Record<string, string | Uint8Array>;\n /** Environment variables available inside the sandbox */\n env?: Record<string, string>;\n}\n\nexport interface SandboxCreateResult {\n sandbox: Sandbox;\n /** Optional state to merge into the workflow's `AgentState` via the session. */\n stateUpdate?: Record<string, unknown>;\n}\n\nexport interface SandboxProvider<\n TOptions extends SandboxCreateOptions = SandboxCreateOptions,\n TSandbox extends Sandbox = Sandbox,\n> {\n readonly id: string;\n readonly capabilities: SandboxCapabilities;\n\n create(options?: TOptions): Promise<SandboxCreateResult>;\n get(sandboxId: string): Promise<TSandbox>;\n destroy(sandboxId: string): Promise<void>;\n snapshot(sandboxId: string): Promise<SandboxSnapshot>;\n restore(snapshot: SandboxSnapshot): Promise<Sandbox>;\n}\n\n// ============================================================================\n// SandboxOps — workflow-side activity interface (like ThreadOps)\n// ============================================================================\n\nexport interface SandboxOps<\n TOptions extends SandboxCreateOptions = SandboxCreateOptions,\n> {\n createSandbox(\n options?: TOptions,\n ): Promise<{ sandboxId: string; stateUpdate?: Record<string, unknown> }>;\n destroySandbox(sandboxId: string): Promise<void>;\n snapshotSandbox(sandboxId: string): Promise<SandboxSnapshot>;\n}\n\n// ============================================================================\n// Errors\n// ============================================================================\n\nimport { ApplicationFailure } from \"@temporalio/common\";\n\nexport class SandboxNotSupportedError extends ApplicationFailure {\n constructor(operation: string) {\n super(\n `Sandbox does not support: ${operation}`,\n \"SandboxNotSupportedError\",\n true,\n );\n }\n}\n\nexport class SandboxNotFoundError extends ApplicationFailure {\n constructor(sandboxId: string) {\n super(`Sandbox not found: ${sandboxId}`, \"SandboxNotFoundError\", true);\n }\n}\n","import type {\n SandboxFileSystem,\n DirentEntry,\n FileStat,\n} from \"../../../lib/sandbox/types\";\nimport { SandboxNotSupportedError } from \"../../../lib/sandbox/types\";\nimport type {\n FileEntry,\n FileEntryMetadata,\n FileResolver,\n TreeMutation,\n} from \"./types\";\n\n/**\n * Normalise a virtual path to a canonical form: absolute, no trailing slash\n * (except root), no double slashes.\n */\nfunction normalisePath(p: string): string {\n if (!p.startsWith(\"/\")) p = \"/\" + p;\n p = p.replace(/\\/+/g, \"/\");\n if (p.length > 1 && p.endsWith(\"/\")) p = p.slice(0, -1);\n return p;\n}\n\n/** Return the parent directory of a normalised path (\"/a/b\" → \"/a\"). */\nfunction parentDir(p: string): string {\n const idx = p.lastIndexOf(\"/\");\n return idx <= 0 ? \"/\" : p.slice(0, idx);\n}\n\n/**\n * Collect the set of implicit directory paths from a flat file list.\n * E.g. \"/a/b/c.ts\" contributes \"/a/b\", \"/a\", \"/\".\n */\nfunction inferDirectories(entries: { path: string }[]): Set<string> {\n const dirs = new Set<string>();\n dirs.add(\"/\");\n for (const entry of entries) {\n let dir = parentDir(normalisePath(entry.path));\n while (dir !== \"/\" && !dirs.has(dir)) {\n dirs.add(dir);\n dir = parentDir(dir);\n }\n dirs.add(\"/\");\n }\n return dirs;\n}\n\n/**\n * Ephemeral {@link SandboxFileSystem} backed by a {@link FileResolver}.\n *\n * Created fresh for each tool invocation from the current workflow file tree.\n * Directory structure is inferred from file paths. All mutations are tracked\n * and can be retrieved via {@link getMutations} after the handler completes.\n */\nexport class VirtualSandboxFileSystem<\n TCtx = unknown,\n TMeta = FileEntryMetadata,\n> implements SandboxFileSystem\n{\n private entries: Map<string, FileEntry<TMeta>>;\n private directories: Set<string>;\n private mutations: TreeMutation<TMeta>[] = [];\n\n constructor(\n tree: FileEntry<TMeta>[],\n private resolver: FileResolver<TCtx, TMeta>,\n private ctx: TCtx,\n ) {\n this.entries = new Map(\n tree.map((e) => [normalisePath(e.path), e]),\n );\n this.directories = inferDirectories(tree);\n }\n\n /** Return all mutations accumulated during this invocation. */\n getMutations(): TreeMutation<TMeta>[] {\n return this.mutations;\n }\n\n /** Look up a file entry by virtual path. */\n getEntry(path: string): FileEntry<TMeta> | undefined {\n return this.entries.get(normalisePath(path));\n }\n\n // --------------------------------------------------------------------------\n // Read operations — delegate to resolver lazily\n // --------------------------------------------------------------------------\n\n async readFile(path: string): Promise<string> {\n const entry = this.entries.get(normalisePath(path));\n if (!entry) throw new Error(`ENOENT: no such file: ${path}`);\n return this.resolver.readFile(entry.id, this.ctx);\n }\n\n async readFileBuffer(path: string): Promise<Uint8Array> {\n const entry = this.entries.get(normalisePath(path));\n if (!entry) throw new Error(`ENOENT: no such file: ${path}`);\n return this.resolver.readFileBuffer(entry.id, this.ctx);\n }\n\n // --------------------------------------------------------------------------\n // Metadata operations — pure, resolved from the tree\n // --------------------------------------------------------------------------\n\n async exists(path: string): Promise<boolean> {\n const norm = normalisePath(path);\n return this.entries.has(norm) || this.directories.has(norm);\n }\n\n async stat(path: string): Promise<FileStat> {\n const norm = normalisePath(path);\n const entry = this.entries.get(norm);\n if (entry) {\n return {\n isFile: true,\n isDirectory: false,\n isSymbolicLink: false,\n size: entry.size,\n mtime: new Date(entry.mtime),\n };\n }\n if (this.directories.has(norm)) {\n return {\n isFile: false,\n isDirectory: true,\n isSymbolicLink: false,\n size: 0,\n mtime: new Date(),\n };\n }\n throw new Error(`ENOENT: no such file or directory: ${path}`);\n }\n\n async readdir(path: string): Promise<string[]> {\n const norm = normalisePath(path);\n if (!this.directories.has(norm)) {\n throw new Error(`ENOENT: no such directory: ${path}`);\n }\n const prefix = norm === \"/\" ? \"/\" : norm + \"/\";\n const names = new Set<string>();\n\n for (const p of this.entries.keys()) {\n if (p.startsWith(prefix)) {\n const rest = p.slice(prefix.length);\n const seg = rest.split(\"/\")[0];\n if (seg) names.add(seg);\n }\n }\n for (const d of this.directories) {\n if (d.startsWith(prefix) && d !== norm) {\n const rest = d.slice(prefix.length);\n const seg = rest.split(\"/\")[0];\n if (seg) names.add(seg);\n }\n }\n return [...names].sort();\n }\n\n async readdirWithFileTypes(path: string): Promise<DirentEntry[]> {\n const names = await this.readdir(path);\n const norm = normalisePath(path);\n const prefix = norm === \"/\" ? \"/\" : norm + \"/\";\n\n return names.map((name) => {\n const full = prefix + name;\n const isFile = this.entries.has(full);\n const isDirectory = this.directories.has(full);\n return { name, isFile, isDirectory, isSymbolicLink: false };\n });\n }\n\n // --------------------------------------------------------------------------\n // Write operations — delegate to resolver, record mutations\n // --------------------------------------------------------------------------\n\n async writeFile(path: string, content: string | Uint8Array): Promise<void> {\n const norm = normalisePath(path);\n const existing = this.entries.get(norm);\n\n if (existing) {\n await this.resolver.writeFile(existing.id, content, this.ctx);\n const size =\n typeof content === \"string\"\n ? new TextEncoder().encode(content).byteLength\n : content.byteLength;\n const updated: FileEntry<TMeta> = {\n ...existing,\n size,\n mtime: new Date().toISOString(),\n };\n this.entries.set(norm, updated);\n this.mutations.push({ type: \"update\", path: norm, entry: updated });\n } else {\n const entry = await this.resolver.createFile(norm, content, this.ctx);\n const normalised = { ...entry, path: norm };\n this.entries.set(norm, normalised);\n this.addParentDirectories(norm);\n this.mutations.push({ type: \"add\", entry: normalised });\n }\n }\n\n async appendFile(path: string, content: string | Uint8Array): Promise<void> {\n const norm = normalisePath(path);\n const existing = this.entries.get(norm);\n\n if (!existing) {\n return this.writeFile(path, content);\n }\n\n const current = await this.resolver.readFile(existing.id, this.ctx);\n const appended =\n typeof content === \"string\"\n ? current + content\n : current + new TextDecoder().decode(content);\n await this.resolver.writeFile(existing.id, appended, this.ctx);\n\n const size = new TextEncoder().encode(appended).byteLength;\n const updated: FileEntry<TMeta> = {\n ...existing,\n size,\n mtime: new Date().toISOString(),\n };\n this.entries.set(norm, updated);\n this.mutations.push({ type: \"update\", path: norm, entry: updated });\n }\n\n async mkdir(_path: string, _options?: { recursive?: boolean }): Promise<void> {\n const norm = normalisePath(_path);\n if (this.directories.has(norm)) return;\n\n if (_options?.recursive) {\n this.addParentDirectories(norm + \"/placeholder\");\n this.directories.add(norm);\n } else {\n const parent = parentDir(norm);\n if (!this.directories.has(parent)) {\n throw new Error(`ENOENT: no such directory: ${parent}`);\n }\n this.directories.add(norm);\n }\n }\n\n async rm(\n path: string,\n options?: { recursive?: boolean; force?: boolean },\n ): Promise<void> {\n const norm = normalisePath(path);\n const entry = this.entries.get(norm);\n\n if (entry) {\n await this.resolver.deleteFile(entry.id, this.ctx);\n this.entries.delete(norm);\n this.mutations.push({ type: \"remove\", path: norm });\n return;\n }\n\n if (this.directories.has(norm)) {\n if (!options?.recursive) {\n throw new Error(`EISDIR: is a directory (use recursive): ${path}`);\n }\n const prefix = norm === \"/\" ? \"/\" : norm + \"/\";\n for (const [p, e] of this.entries) {\n if (p.startsWith(prefix)) {\n await this.resolver.deleteFile(e.id, this.ctx);\n this.entries.delete(p);\n this.mutations.push({ type: \"remove\", path: p });\n }\n }\n for (const d of this.directories) {\n if (d.startsWith(prefix)) this.directories.delete(d);\n }\n this.directories.delete(norm);\n return;\n }\n\n if (!options?.force) {\n throw new Error(`ENOENT: no such file or directory: ${path}`);\n }\n }\n\n async cp(\n src: string,\n dest: string,\n _options?: { recursive?: boolean },\n ): Promise<void> {\n const normSrc = normalisePath(src);\n const normDest = normalisePath(dest);\n\n const entry = this.entries.get(normSrc);\n if (entry) {\n const content = await this.resolver.readFile(entry.id, this.ctx);\n await this.writeFile(normDest, content);\n return;\n }\n\n if (!this.directories.has(normSrc)) {\n throw new Error(`ENOENT: no such file or directory: ${src}`);\n }\n if (!_options?.recursive) {\n throw new Error(`EISDIR: is a directory (use recursive): ${src}`);\n }\n\n const prefix = normSrc === \"/\" ? \"/\" : normSrc + \"/\";\n for (const [p, e] of this.entries) {\n if (p.startsWith(prefix)) {\n const relative = p.slice(normSrc.length);\n const content = await this.resolver.readFile(e.id, this.ctx);\n await this.writeFile(normDest + relative, content);\n }\n }\n }\n\n async mv(src: string, dest: string): Promise<void> {\n await this.cp(src, dest, { recursive: true });\n await this.rm(src, { recursive: true });\n }\n\n // --------------------------------------------------------------------------\n // Unsupported\n // --------------------------------------------------------------------------\n\n async readlink(_path: string): Promise<string> {\n throw new SandboxNotSupportedError(\"readlink\");\n }\n\n resolvePath(base: string, path: string): string {\n if (path.startsWith(\"/\")) return normalisePath(path);\n const combined =\n base.endsWith(\"/\") ? base + path : base + \"/\" + path;\n return normalisePath(combined);\n }\n\n // --------------------------------------------------------------------------\n // Helpers\n // --------------------------------------------------------------------------\n\n private addParentDirectories(filePath: string): void {\n let dir = parentDir(normalisePath(filePath));\n while (!this.directories.has(dir)) {\n this.directories.add(dir);\n dir = parentDir(dir);\n }\n }\n}\n","import { uuid4 } from \"@temporalio/workflow\";\n\nconst BASE62 =\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\";\n\n/**\n * Generate a compact, workflow-deterministic identifier.\n *\n * Uses Temporal's `uuid4()` internally (seeded by the workflow's RNG),\n * then re-encodes the hex bytes into a base-62 alphabet for a shorter,\n * more token-efficient identifier (~3 tokens vs ~10 for a full UUID).\n *\n * Suitable for thread IDs, child workflow IDs, or any workflow-scoped identifier.\n *\n * @param length - Number of base-62 characters (default 12, ~71 bits of entropy)\n */\nexport function getShortId(length = 12): string {\n const hex = uuid4().replace(/-/g, \"\");\n let result = \"\";\n for (let i = 0; i < length; i++) {\n const byte = parseInt(hex.slice(i * 2, i * 2 + 2), 16);\n result += BASE62[byte % BASE62.length];\n }\n return result;\n}\n","import type {\n SandboxCapabilities,\n SandboxCreateResult,\n SandboxProvider,\n} from \"../../../lib/sandbox/types\";\nimport { SandboxNotSupportedError } from \"../../../lib/sandbox/types\";\nimport { getShortId } from \"../../../lib/thread/id\";\nimport { createVirtualSandbox } from \"./index\";\nimport type {\n FileEntryMetadata,\n FileResolver,\n VirtualSandboxCreateOptions,\n} from \"./types\";\n\n/**\n * Stateless {@link SandboxProvider} backed by a {@link FileResolver}.\n *\n * The provider holds **no internal state**. All sandbox state (sandboxId,\n * fileTree, resolverContext) is returned as a `stateUpdate` from\n * {@link create} and merged into the workflow's `AgentState` by the session.\n * {@link withVirtualSandbox} reads this state back on every tool invocation.\n *\n * @example\n * ```typescript\n * const provider = new VirtualSandboxProvider(resolver);\n * const manager = new SandboxManager(provider);\n *\n * export const activities = {\n * ...manager.createActivities(),\n * readFile: withVirtualSandbox(client, provider, readHandler),\n * };\n * ```\n */\nexport class VirtualSandboxProvider<\n TCtx = unknown,\n TMeta = FileEntryMetadata,\n> implements SandboxProvider<VirtualSandboxCreateOptions<TCtx>> {\n readonly id = \"virtual\";\n readonly capabilities: SandboxCapabilities = {\n filesystem: true,\n execution: false,\n persistence: true,\n };\n\n readonly resolver: FileResolver<TCtx, TMeta>;\n\n constructor(resolver: FileResolver<TCtx, TMeta>) {\n this.resolver = resolver;\n }\n\n async create(\n options?: VirtualSandboxCreateOptions<TCtx>\n ): Promise<SandboxCreateResult> {\n if (!options || !(\"resolverContext\" in options)) {\n throw new Error(\"VirtualSandboxProvider.create requires resolverContext\");\n }\n\n const sandboxId = options.id ?? getShortId();\n const fileTree = await this.resolver.resolveEntries(\n options.resolverContext\n );\n\n const sandbox = createVirtualSandbox(\n sandboxId,\n fileTree,\n this.resolver,\n options.resolverContext\n );\n\n return {\n sandbox,\n stateUpdate: {\n sandboxId,\n fileTree,\n resolverContext: options.resolverContext,\n },\n };\n }\n\n async get(): Promise<never> {\n throw new SandboxNotSupportedError(\n \"get (virtual sandbox state lives in workflow AgentState)\"\n );\n }\n\n async destroy(): Promise<void> {\n // No-op — no internal state to clean up\n }\n\n async snapshot(): Promise<never> {\n throw new SandboxNotSupportedError(\n \"snapshot (virtual sandbox state lives in workflow AgentState)\"\n );\n }\n\n async restore(): Promise<never> {\n throw new SandboxNotSupportedError(\n \"restore (virtual sandbox state lives in workflow AgentState)\"\n );\n }\n}\n","import { Context } from \"@temporalio/activity\";\nimport type { WorkflowClient } from \"@temporalio/client\";\nimport type { BaseAgentState, RunAgentConfig } from \"./types\";\nimport type {\n ActivityToolHandler,\n RouterContext,\n ToolHandlerResponse,\n} from \"./tool-router/types\";\n\n/**\n * Query the parent workflow's state from within an activity.\n * Resolves the workflow handle from the current activity context.\n */\nexport async function queryParentWorkflowState<T>(\n client: WorkflowClient\n): Promise<T> {\n const { workflowExecution } = Context.current().info;\n const handle = client.getHandle(\n workflowExecution.workflowId,\n workflowExecution.runId\n );\n return handle.query<T>(\"getAgentState\");\n}\n\n/**\n * Wraps a handler into a `RunAgentActivity` by auto-fetching the parent\n * workflow's agent state before each invocation.\n *\n * @example\n * ```typescript\n * import { createRunAgentActivity } from 'zeitlich';\n * import { createLangChainModelInvoker } from 'zeitlich/adapters/thread/langchain';\n *\n * const invoker = createLangChainModelInvoker({ redis, model });\n * return { runAgent: createRunAgentActivity(client, invoker) };\n * ```\n */\nexport function createRunAgentActivity<R, S extends BaseAgentState = BaseAgentState>(\n client: WorkflowClient,\n handler: (config: RunAgentConfig & { state: S }) => Promise<R>,\n): (config: RunAgentConfig) => Promise<R> {\n return async (config: RunAgentConfig) => {\n const state = await queryParentWorkflowState<S>(client);\n return handler({ ...config, state });\n };\n}\n\n/**\n * Context injected into tool handlers created via {@link withParentWorkflowState}.\n */\nexport interface AgentStateContext<S extends BaseAgentState = BaseAgentState> extends RouterContext {\n state: S;\n}\n\n/**\n * Wraps a tool handler into an `ActivityToolHandler` by auto-fetching the\n * parent workflow's agent state before each invocation.\n *\n * @typeParam S - Custom agent state type (defaults to `BaseAgentState`)\n *\n * @example\n * ```typescript\n * import { withParentWorkflowState, type AgentStateContext } from 'zeitlich';\n *\n * // With custom state:\n * interface MyState extends BaseAgentState { customField: string }\n * const myHandler = withParentWorkflowState<MyArgs, MyResult, MyState>(\n * client,\n * async (args, ctx) => {\n * console.log(ctx.state.customField);\n * return { toolResponse: 'done', data: null };\n * },\n * );\n * ```\n */\nexport function withParentWorkflowState<TArgs, TResult, S extends BaseAgentState = BaseAgentState>(\n client: WorkflowClient,\n handler: (\n args: TArgs,\n context: AgentStateContext<S>,\n ) => Promise<ToolHandlerResponse<TResult>>,\n): ActivityToolHandler<TArgs, TResult> {\n return async (args, context) => {\n const state = await queryParentWorkflowState<S>(client);\n return handler(args, { ...context, state });\n };\n}\n","import type { WorkflowClient } from \"@temporalio/client\";\nimport { queryParentWorkflowState } from \"../../../lib/activity\";\nimport type { ActivityToolHandler } from \"../../../lib/tool-router/types\";\nimport type {\n FileEntryMetadata,\n TreeMutation,\n VirtualSandboxContext,\n VirtualSandboxState,\n} from \"./types\";\nimport type { VirtualSandboxProvider } from \"./provider\";\nimport { createVirtualSandbox } from \"./index\";\n\n/**\n * Wraps a tool handler that needs a virtual sandbox, automatically querying\n * the parent workflow for the current file tree and resolver context.\n *\n * On each invocation the wrapper:\n * 1. Queries the workflow's `AgentState` for `fileTree` and `resolverContext`\n * 2. Creates an ephemeral {@link VirtualSandbox} from tree + provider's resolver\n * 3. Runs the inner handler\n * 4. Returns the handler's result together with any {@link TreeMutation}s\n *\n * The consumer applies mutations back to workflow state via a post-tool hook.\n *\n * @param client - Temporal `WorkflowClient` for querying the parent workflow\n * @param agentName - Agent name (used to derive the state query name)\n * @param provider - {@link VirtualSandboxProvider} (wraps the resolver)\n * @param handler - Inner handler expecting a {@link VirtualSandboxContext}\n *\n * @example\n * ```typescript\n * import { withVirtualSandbox, type VirtualSandboxContext } from 'zeitlich';\n *\n * const readHandler: ActivityToolHandler<FileReadArgs, ReadResult, VirtualSandboxContext> =\n * async (args, { sandbox }) => {\n * const content = await sandbox.fs.readFile(args.path);\n * return { toolResponse: content, data: { path: args.path, content } };\n * };\n *\n * // At activity registration:\n * const provider = new VirtualSandboxProvider(resolver);\n * const handler = withVirtualSandbox(client, \"myAgent\", provider, readHandler);\n * ```\n */\nexport function withVirtualSandbox<\n TArgs,\n TResult,\n TCtx,\n TMeta = FileEntryMetadata,\n>(\n client: WorkflowClient,\n provider: VirtualSandboxProvider<TCtx, TMeta>,\n handler: ActivityToolHandler<\n TArgs,\n TResult,\n VirtualSandboxContext<TCtx, TMeta>\n >\n): ActivityToolHandler<\n TArgs,\n (TResult & { treeMutations: TreeMutation<TMeta>[] }) | null\n> {\n return async (args, context) => {\n const state =\n await queryParentWorkflowState<VirtualSandboxState<TCtx, TMeta>>(client);\n\n const { sandboxId, fileTree, resolverContext } = state;\n if (!fileTree || !sandboxId) {\n return {\n toolResponse: `Error: No fileTree/sandboxId in agent state. The ${context.toolName} tool requires a virtual sandbox.`,\n data: null,\n };\n }\n\n const sandbox = createVirtualSandbox(\n sandboxId,\n fileTree,\n provider.resolver,\n resolverContext\n );\n const response = await handler(args, { ...context, sandbox });\n const mutations = sandbox.fs.getMutations();\n\n return {\n toolResponse: response.toolResponse,\n data: {\n ...(response.data ?? {}),\n treeMutations: mutations,\n } as TResult & { treeMutations: TreeMutation<TMeta>[] },\n };\n };\n}\n","import type {\n Sandbox,\n SandboxCapabilities,\n ExecOptions,\n ExecResult,\n} from \"../../../lib/sandbox/types\";\nimport { SandboxNotSupportedError } from \"../../../lib/sandbox/types\";\nimport { VirtualSandboxFileSystem } from \"./filesystem\";\nimport type {\n FileEntry,\n FileEntryMetadata,\n FileResolver,\n VirtualSandbox,\n} from \"./types\";\n\n// ============================================================================\n// VirtualSandbox\n// ============================================================================\n\nclass VirtualSandboxImpl<\n TCtx = unknown,\n TMeta = FileEntryMetadata,\n> implements Sandbox\n{\n readonly capabilities: SandboxCapabilities = {\n filesystem: true,\n execution: false,\n persistence: true,\n };\n\n readonly fs: VirtualSandboxFileSystem<TCtx, TMeta>;\n\n constructor(\n readonly id: string,\n tree: FileEntry<TMeta>[],\n resolver: FileResolver<TCtx, TMeta>,\n ctx: TCtx\n ) {\n this.fs = new VirtualSandboxFileSystem(tree, resolver, ctx);\n }\n\n async exec(_command: string, _options?: ExecOptions): Promise<ExecResult> {\n throw new SandboxNotSupportedError(\"exec\");\n }\n\n async destroy(): Promise<void> {\n // Ephemeral — nothing to clean up\n }\n}\n\n// ============================================================================\n// Factory\n// ============================================================================\n\n/**\n * Create an ephemeral {@link Sandbox} from a file tree and resolver.\n *\n * Used internally by {@link withVirtualSandbox} and\n * {@link VirtualSandboxProvider}; consumers can also call this directly\n * if they need a sandbox outside the wrapper pattern.\n */\nexport function createVirtualSandbox<\n TCtx,\n TMeta = FileEntryMetadata,\n>(\n id: string,\n tree: FileEntry<TMeta>[],\n resolver: FileResolver<TCtx, TMeta>,\n ctx: TCtx,\n): VirtualSandbox<TCtx, TMeta> {\n return new VirtualSandboxImpl(id, tree, resolver, ctx);\n}\n\n// Re-exports for convenience\nexport { VirtualSandboxFileSystem } from \"./filesystem\";\nexport { VirtualSandboxProvider } from \"./provider\";\nexport { withVirtualSandbox } from \"./with-virtual-sandbox\";\nexport type {\n FileEntry,\n FileEntryMetadata,\n FileResolver,\n VirtualFileTree,\n VirtualSandboxCreateOptions,\n VirtualSandboxState,\n VirtualSandboxContext,\n VirtualSandbox,\n TreeMutation,\n} from \"./types\";\n"]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { F as FileEntryMetadata, V as VirtualSandboxCreateOptions, a as FileResolver, b as VirtualSandboxContext, T as TreeMutation, c as FileEntry, d as VirtualSandbox } from '../../../types-BVP87m_W.cjs';
|
|
2
|
+
export { e as VirtualFileTree, f as VirtualSandboxFileSystem, g as VirtualSandboxState } from '../../../types-BVP87m_W.cjs';
|
|
3
|
+
import { b as SandboxProvider, c as SandboxCapabilities, e as SandboxCreateResult } from '../../../types-CDubRtad.cjs';
|
|
4
|
+
import { WorkflowClient } from '@temporalio/client';
|
|
5
|
+
import { A as ActivityToolHandler } from '../../../types-BMXzv7TN.cjs';
|
|
6
|
+
import '@temporalio/common';
|
|
7
|
+
import 'zod';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Stateless {@link SandboxProvider} backed by a {@link FileResolver}.
|
|
11
|
+
*
|
|
12
|
+
* The provider holds **no internal state**. All sandbox state (sandboxId,
|
|
13
|
+
* fileTree, resolverContext) is returned as a `stateUpdate` from
|
|
14
|
+
* {@link create} and merged into the workflow's `AgentState` by the session.
|
|
15
|
+
* {@link withVirtualSandbox} reads this state back on every tool invocation.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const provider = new VirtualSandboxProvider(resolver);
|
|
20
|
+
* const manager = new SandboxManager(provider);
|
|
21
|
+
*
|
|
22
|
+
* export const activities = {
|
|
23
|
+
* ...manager.createActivities(),
|
|
24
|
+
* readFile: withVirtualSandbox(client, provider, readHandler),
|
|
25
|
+
* };
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare class VirtualSandboxProvider<TCtx = unknown, TMeta = FileEntryMetadata> implements SandboxProvider<VirtualSandboxCreateOptions<TCtx>> {
|
|
29
|
+
readonly id = "virtual";
|
|
30
|
+
readonly capabilities: SandboxCapabilities;
|
|
31
|
+
readonly resolver: FileResolver<TCtx, TMeta>;
|
|
32
|
+
constructor(resolver: FileResolver<TCtx, TMeta>);
|
|
33
|
+
create(options?: VirtualSandboxCreateOptions<TCtx>): Promise<SandboxCreateResult>;
|
|
34
|
+
get(): Promise<never>;
|
|
35
|
+
destroy(): Promise<void>;
|
|
36
|
+
snapshot(): Promise<never>;
|
|
37
|
+
restore(): Promise<never>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Wraps a tool handler that needs a virtual sandbox, automatically querying
|
|
42
|
+
* the parent workflow for the current file tree and resolver context.
|
|
43
|
+
*
|
|
44
|
+
* On each invocation the wrapper:
|
|
45
|
+
* 1. Queries the workflow's `AgentState` for `fileTree` and `resolverContext`
|
|
46
|
+
* 2. Creates an ephemeral {@link VirtualSandbox} from tree + provider's resolver
|
|
47
|
+
* 3. Runs the inner handler
|
|
48
|
+
* 4. Returns the handler's result together with any {@link TreeMutation}s
|
|
49
|
+
*
|
|
50
|
+
* The consumer applies mutations back to workflow state via a post-tool hook.
|
|
51
|
+
*
|
|
52
|
+
* @param client - Temporal `WorkflowClient` for querying the parent workflow
|
|
53
|
+
* @param agentName - Agent name (used to derive the state query name)
|
|
54
|
+
* @param provider - {@link VirtualSandboxProvider} (wraps the resolver)
|
|
55
|
+
* @param handler - Inner handler expecting a {@link VirtualSandboxContext}
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* import { withVirtualSandbox, type VirtualSandboxContext } from 'zeitlich';
|
|
60
|
+
*
|
|
61
|
+
* const readHandler: ActivityToolHandler<FileReadArgs, ReadResult, VirtualSandboxContext> =
|
|
62
|
+
* async (args, { sandbox }) => {
|
|
63
|
+
* const content = await sandbox.fs.readFile(args.path);
|
|
64
|
+
* return { toolResponse: content, data: { path: args.path, content } };
|
|
65
|
+
* };
|
|
66
|
+
*
|
|
67
|
+
* // At activity registration:
|
|
68
|
+
* const provider = new VirtualSandboxProvider(resolver);
|
|
69
|
+
* const handler = withVirtualSandbox(client, "myAgent", provider, readHandler);
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
declare function withVirtualSandbox<TArgs, TResult, TCtx, TMeta = FileEntryMetadata>(client: WorkflowClient, provider: VirtualSandboxProvider<TCtx, TMeta>, handler: ActivityToolHandler<TArgs, TResult, VirtualSandboxContext<TCtx, TMeta>>): ActivityToolHandler<TArgs, (TResult & {
|
|
73
|
+
treeMutations: TreeMutation<TMeta>[];
|
|
74
|
+
}) | null>;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Create an ephemeral {@link Sandbox} from a file tree and resolver.
|
|
78
|
+
*
|
|
79
|
+
* Used internally by {@link withVirtualSandbox} and
|
|
80
|
+
* {@link VirtualSandboxProvider}; consumers can also call this directly
|
|
81
|
+
* if they need a sandbox outside the wrapper pattern.
|
|
82
|
+
*/
|
|
83
|
+
declare function createVirtualSandbox<TCtx, TMeta = FileEntryMetadata>(id: string, tree: FileEntry<TMeta>[], resolver: FileResolver<TCtx, TMeta>, ctx: TCtx): VirtualSandbox<TCtx, TMeta>;
|
|
84
|
+
|
|
85
|
+
export { FileEntry, FileEntryMetadata, FileResolver, TreeMutation, VirtualSandbox, VirtualSandboxContext, VirtualSandboxCreateOptions, VirtualSandboxProvider, createVirtualSandbox, withVirtualSandbox };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { F as FileEntryMetadata, V as VirtualSandboxCreateOptions, a as FileResolver, b as VirtualSandboxContext, T as TreeMutation, c as FileEntry, d as VirtualSandbox } from '../../../types-CwwgQ_9H.js';
|
|
2
|
+
export { e as VirtualFileTree, f as VirtualSandboxFileSystem, g as VirtualSandboxState } from '../../../types-CwwgQ_9H.js';
|
|
3
|
+
import { b as SandboxProvider, c as SandboxCapabilities, e as SandboxCreateResult } from '../../../types-CDubRtad.js';
|
|
4
|
+
import { WorkflowClient } from '@temporalio/client';
|
|
5
|
+
import { A as ActivityToolHandler } from '../../../types-BMXzv7TN.js';
|
|
6
|
+
import '@temporalio/common';
|
|
7
|
+
import 'zod';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Stateless {@link SandboxProvider} backed by a {@link FileResolver}.
|
|
11
|
+
*
|
|
12
|
+
* The provider holds **no internal state**. All sandbox state (sandboxId,
|
|
13
|
+
* fileTree, resolverContext) is returned as a `stateUpdate` from
|
|
14
|
+
* {@link create} and merged into the workflow's `AgentState` by the session.
|
|
15
|
+
* {@link withVirtualSandbox} reads this state back on every tool invocation.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const provider = new VirtualSandboxProvider(resolver);
|
|
20
|
+
* const manager = new SandboxManager(provider);
|
|
21
|
+
*
|
|
22
|
+
* export const activities = {
|
|
23
|
+
* ...manager.createActivities(),
|
|
24
|
+
* readFile: withVirtualSandbox(client, provider, readHandler),
|
|
25
|
+
* };
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare class VirtualSandboxProvider<TCtx = unknown, TMeta = FileEntryMetadata> implements SandboxProvider<VirtualSandboxCreateOptions<TCtx>> {
|
|
29
|
+
readonly id = "virtual";
|
|
30
|
+
readonly capabilities: SandboxCapabilities;
|
|
31
|
+
readonly resolver: FileResolver<TCtx, TMeta>;
|
|
32
|
+
constructor(resolver: FileResolver<TCtx, TMeta>);
|
|
33
|
+
create(options?: VirtualSandboxCreateOptions<TCtx>): Promise<SandboxCreateResult>;
|
|
34
|
+
get(): Promise<never>;
|
|
35
|
+
destroy(): Promise<void>;
|
|
36
|
+
snapshot(): Promise<never>;
|
|
37
|
+
restore(): Promise<never>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Wraps a tool handler that needs a virtual sandbox, automatically querying
|
|
42
|
+
* the parent workflow for the current file tree and resolver context.
|
|
43
|
+
*
|
|
44
|
+
* On each invocation the wrapper:
|
|
45
|
+
* 1. Queries the workflow's `AgentState` for `fileTree` and `resolverContext`
|
|
46
|
+
* 2. Creates an ephemeral {@link VirtualSandbox} from tree + provider's resolver
|
|
47
|
+
* 3. Runs the inner handler
|
|
48
|
+
* 4. Returns the handler's result together with any {@link TreeMutation}s
|
|
49
|
+
*
|
|
50
|
+
* The consumer applies mutations back to workflow state via a post-tool hook.
|
|
51
|
+
*
|
|
52
|
+
* @param client - Temporal `WorkflowClient` for querying the parent workflow
|
|
53
|
+
* @param agentName - Agent name (used to derive the state query name)
|
|
54
|
+
* @param provider - {@link VirtualSandboxProvider} (wraps the resolver)
|
|
55
|
+
* @param handler - Inner handler expecting a {@link VirtualSandboxContext}
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* import { withVirtualSandbox, type VirtualSandboxContext } from 'zeitlich';
|
|
60
|
+
*
|
|
61
|
+
* const readHandler: ActivityToolHandler<FileReadArgs, ReadResult, VirtualSandboxContext> =
|
|
62
|
+
* async (args, { sandbox }) => {
|
|
63
|
+
* const content = await sandbox.fs.readFile(args.path);
|
|
64
|
+
* return { toolResponse: content, data: { path: args.path, content } };
|
|
65
|
+
* };
|
|
66
|
+
*
|
|
67
|
+
* // At activity registration:
|
|
68
|
+
* const provider = new VirtualSandboxProvider(resolver);
|
|
69
|
+
* const handler = withVirtualSandbox(client, "myAgent", provider, readHandler);
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
declare function withVirtualSandbox<TArgs, TResult, TCtx, TMeta = FileEntryMetadata>(client: WorkflowClient, provider: VirtualSandboxProvider<TCtx, TMeta>, handler: ActivityToolHandler<TArgs, TResult, VirtualSandboxContext<TCtx, TMeta>>): ActivityToolHandler<TArgs, (TResult & {
|
|
73
|
+
treeMutations: TreeMutation<TMeta>[];
|
|
74
|
+
}) | null>;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Create an ephemeral {@link Sandbox} from a file tree and resolver.
|
|
78
|
+
*
|
|
79
|
+
* Used internally by {@link withVirtualSandbox} and
|
|
80
|
+
* {@link VirtualSandboxProvider}; consumers can also call this directly
|
|
81
|
+
* if they need a sandbox outside the wrapper pattern.
|
|
82
|
+
*/
|
|
83
|
+
declare function createVirtualSandbox<TCtx, TMeta = FileEntryMetadata>(id: string, tree: FileEntry<TMeta>[], resolver: FileResolver<TCtx, TMeta>, ctx: TCtx): VirtualSandbox<TCtx, TMeta>;
|
|
84
|
+
|
|
85
|
+
export { FileEntry, FileEntryMetadata, FileResolver, TreeMutation, VirtualSandbox, VirtualSandboxContext, VirtualSandboxCreateOptions, VirtualSandboxProvider, createVirtualSandbox, withVirtualSandbox };
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import { ApplicationFailure } from '@temporalio/common';
|
|
2
|
+
import { uuid4 } from '@temporalio/workflow';
|
|
3
|
+
import { Context } from '@temporalio/activity';
|
|
4
|
+
|
|
5
|
+
// src/lib/sandbox/types.ts
|
|
6
|
+
var SandboxNotSupportedError = class extends ApplicationFailure {
|
|
7
|
+
constructor(operation) {
|
|
8
|
+
super(
|
|
9
|
+
`Sandbox does not support: ${operation}`,
|
|
10
|
+
"SandboxNotSupportedError",
|
|
11
|
+
true
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// src/adapters/sandbox/virtual/filesystem.ts
|
|
17
|
+
function normalisePath(p) {
|
|
18
|
+
if (!p.startsWith("/")) p = "/" + p;
|
|
19
|
+
p = p.replace(/\/+/g, "/");
|
|
20
|
+
if (p.length > 1 && p.endsWith("/")) p = p.slice(0, -1);
|
|
21
|
+
return p;
|
|
22
|
+
}
|
|
23
|
+
function parentDir(p) {
|
|
24
|
+
const idx = p.lastIndexOf("/");
|
|
25
|
+
return idx <= 0 ? "/" : p.slice(0, idx);
|
|
26
|
+
}
|
|
27
|
+
function inferDirectories(entries) {
|
|
28
|
+
const dirs = /* @__PURE__ */ new Set();
|
|
29
|
+
dirs.add("/");
|
|
30
|
+
for (const entry of entries) {
|
|
31
|
+
let dir = parentDir(normalisePath(entry.path));
|
|
32
|
+
while (dir !== "/" && !dirs.has(dir)) {
|
|
33
|
+
dirs.add(dir);
|
|
34
|
+
dir = parentDir(dir);
|
|
35
|
+
}
|
|
36
|
+
dirs.add("/");
|
|
37
|
+
}
|
|
38
|
+
return dirs;
|
|
39
|
+
}
|
|
40
|
+
var VirtualSandboxFileSystem = class {
|
|
41
|
+
constructor(tree, resolver, ctx) {
|
|
42
|
+
this.resolver = resolver;
|
|
43
|
+
this.ctx = ctx;
|
|
44
|
+
this.entries = new Map(
|
|
45
|
+
tree.map((e) => [normalisePath(e.path), e])
|
|
46
|
+
);
|
|
47
|
+
this.directories = inferDirectories(tree);
|
|
48
|
+
}
|
|
49
|
+
entries;
|
|
50
|
+
directories;
|
|
51
|
+
mutations = [];
|
|
52
|
+
/** Return all mutations accumulated during this invocation. */
|
|
53
|
+
getMutations() {
|
|
54
|
+
return this.mutations;
|
|
55
|
+
}
|
|
56
|
+
/** Look up a file entry by virtual path. */
|
|
57
|
+
getEntry(path) {
|
|
58
|
+
return this.entries.get(normalisePath(path));
|
|
59
|
+
}
|
|
60
|
+
// --------------------------------------------------------------------------
|
|
61
|
+
// Read operations — delegate to resolver lazily
|
|
62
|
+
// --------------------------------------------------------------------------
|
|
63
|
+
async readFile(path) {
|
|
64
|
+
const entry = this.entries.get(normalisePath(path));
|
|
65
|
+
if (!entry) throw new Error(`ENOENT: no such file: ${path}`);
|
|
66
|
+
return this.resolver.readFile(entry.id, this.ctx);
|
|
67
|
+
}
|
|
68
|
+
async readFileBuffer(path) {
|
|
69
|
+
const entry = this.entries.get(normalisePath(path));
|
|
70
|
+
if (!entry) throw new Error(`ENOENT: no such file: ${path}`);
|
|
71
|
+
return this.resolver.readFileBuffer(entry.id, this.ctx);
|
|
72
|
+
}
|
|
73
|
+
// --------------------------------------------------------------------------
|
|
74
|
+
// Metadata operations — pure, resolved from the tree
|
|
75
|
+
// --------------------------------------------------------------------------
|
|
76
|
+
async exists(path) {
|
|
77
|
+
const norm = normalisePath(path);
|
|
78
|
+
return this.entries.has(norm) || this.directories.has(norm);
|
|
79
|
+
}
|
|
80
|
+
async stat(path) {
|
|
81
|
+
const norm = normalisePath(path);
|
|
82
|
+
const entry = this.entries.get(norm);
|
|
83
|
+
if (entry) {
|
|
84
|
+
return {
|
|
85
|
+
isFile: true,
|
|
86
|
+
isDirectory: false,
|
|
87
|
+
isSymbolicLink: false,
|
|
88
|
+
size: entry.size,
|
|
89
|
+
mtime: new Date(entry.mtime)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (this.directories.has(norm)) {
|
|
93
|
+
return {
|
|
94
|
+
isFile: false,
|
|
95
|
+
isDirectory: true,
|
|
96
|
+
isSymbolicLink: false,
|
|
97
|
+
size: 0,
|
|
98
|
+
mtime: /* @__PURE__ */ new Date()
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
throw new Error(`ENOENT: no such file or directory: ${path}`);
|
|
102
|
+
}
|
|
103
|
+
async readdir(path) {
|
|
104
|
+
const norm = normalisePath(path);
|
|
105
|
+
if (!this.directories.has(norm)) {
|
|
106
|
+
throw new Error(`ENOENT: no such directory: ${path}`);
|
|
107
|
+
}
|
|
108
|
+
const prefix = norm === "/" ? "/" : norm + "/";
|
|
109
|
+
const names = /* @__PURE__ */ new Set();
|
|
110
|
+
for (const p of this.entries.keys()) {
|
|
111
|
+
if (p.startsWith(prefix)) {
|
|
112
|
+
const rest = p.slice(prefix.length);
|
|
113
|
+
const seg = rest.split("/")[0];
|
|
114
|
+
if (seg) names.add(seg);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
for (const d of this.directories) {
|
|
118
|
+
if (d.startsWith(prefix) && d !== norm) {
|
|
119
|
+
const rest = d.slice(prefix.length);
|
|
120
|
+
const seg = rest.split("/")[0];
|
|
121
|
+
if (seg) names.add(seg);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return [...names].sort();
|
|
125
|
+
}
|
|
126
|
+
async readdirWithFileTypes(path) {
|
|
127
|
+
const names = await this.readdir(path);
|
|
128
|
+
const norm = normalisePath(path);
|
|
129
|
+
const prefix = norm === "/" ? "/" : norm + "/";
|
|
130
|
+
return names.map((name) => {
|
|
131
|
+
const full = prefix + name;
|
|
132
|
+
const isFile = this.entries.has(full);
|
|
133
|
+
const isDirectory = this.directories.has(full);
|
|
134
|
+
return { name, isFile, isDirectory, isSymbolicLink: false };
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
// --------------------------------------------------------------------------
|
|
138
|
+
// Write operations — delegate to resolver, record mutations
|
|
139
|
+
// --------------------------------------------------------------------------
|
|
140
|
+
async writeFile(path, content) {
|
|
141
|
+
const norm = normalisePath(path);
|
|
142
|
+
const existing = this.entries.get(norm);
|
|
143
|
+
if (existing) {
|
|
144
|
+
await this.resolver.writeFile(existing.id, content, this.ctx);
|
|
145
|
+
const size = typeof content === "string" ? new TextEncoder().encode(content).byteLength : content.byteLength;
|
|
146
|
+
const updated = {
|
|
147
|
+
...existing,
|
|
148
|
+
size,
|
|
149
|
+
mtime: (/* @__PURE__ */ new Date()).toISOString()
|
|
150
|
+
};
|
|
151
|
+
this.entries.set(norm, updated);
|
|
152
|
+
this.mutations.push({ type: "update", path: norm, entry: updated });
|
|
153
|
+
} else {
|
|
154
|
+
const entry = await this.resolver.createFile(norm, content, this.ctx);
|
|
155
|
+
const normalised = { ...entry, path: norm };
|
|
156
|
+
this.entries.set(norm, normalised);
|
|
157
|
+
this.addParentDirectories(norm);
|
|
158
|
+
this.mutations.push({ type: "add", entry: normalised });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async appendFile(path, content) {
|
|
162
|
+
const norm = normalisePath(path);
|
|
163
|
+
const existing = this.entries.get(norm);
|
|
164
|
+
if (!existing) {
|
|
165
|
+
return this.writeFile(path, content);
|
|
166
|
+
}
|
|
167
|
+
const current = await this.resolver.readFile(existing.id, this.ctx);
|
|
168
|
+
const appended = typeof content === "string" ? current + content : current + new TextDecoder().decode(content);
|
|
169
|
+
await this.resolver.writeFile(existing.id, appended, this.ctx);
|
|
170
|
+
const size = new TextEncoder().encode(appended).byteLength;
|
|
171
|
+
const updated = {
|
|
172
|
+
...existing,
|
|
173
|
+
size,
|
|
174
|
+
mtime: (/* @__PURE__ */ new Date()).toISOString()
|
|
175
|
+
};
|
|
176
|
+
this.entries.set(norm, updated);
|
|
177
|
+
this.mutations.push({ type: "update", path: norm, entry: updated });
|
|
178
|
+
}
|
|
179
|
+
async mkdir(_path, _options) {
|
|
180
|
+
const norm = normalisePath(_path);
|
|
181
|
+
if (this.directories.has(norm)) return;
|
|
182
|
+
if (_options?.recursive) {
|
|
183
|
+
this.addParentDirectories(norm + "/placeholder");
|
|
184
|
+
this.directories.add(norm);
|
|
185
|
+
} else {
|
|
186
|
+
const parent = parentDir(norm);
|
|
187
|
+
if (!this.directories.has(parent)) {
|
|
188
|
+
throw new Error(`ENOENT: no such directory: ${parent}`);
|
|
189
|
+
}
|
|
190
|
+
this.directories.add(norm);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
async rm(path, options) {
|
|
194
|
+
const norm = normalisePath(path);
|
|
195
|
+
const entry = this.entries.get(norm);
|
|
196
|
+
if (entry) {
|
|
197
|
+
await this.resolver.deleteFile(entry.id, this.ctx);
|
|
198
|
+
this.entries.delete(norm);
|
|
199
|
+
this.mutations.push({ type: "remove", path: norm });
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (this.directories.has(norm)) {
|
|
203
|
+
if (!options?.recursive) {
|
|
204
|
+
throw new Error(`EISDIR: is a directory (use recursive): ${path}`);
|
|
205
|
+
}
|
|
206
|
+
const prefix = norm === "/" ? "/" : norm + "/";
|
|
207
|
+
for (const [p, e] of this.entries) {
|
|
208
|
+
if (p.startsWith(prefix)) {
|
|
209
|
+
await this.resolver.deleteFile(e.id, this.ctx);
|
|
210
|
+
this.entries.delete(p);
|
|
211
|
+
this.mutations.push({ type: "remove", path: p });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
for (const d of this.directories) {
|
|
215
|
+
if (d.startsWith(prefix)) this.directories.delete(d);
|
|
216
|
+
}
|
|
217
|
+
this.directories.delete(norm);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (!options?.force) {
|
|
221
|
+
throw new Error(`ENOENT: no such file or directory: ${path}`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
async cp(src, dest, _options) {
|
|
225
|
+
const normSrc = normalisePath(src);
|
|
226
|
+
const normDest = normalisePath(dest);
|
|
227
|
+
const entry = this.entries.get(normSrc);
|
|
228
|
+
if (entry) {
|
|
229
|
+
const content = await this.resolver.readFile(entry.id, this.ctx);
|
|
230
|
+
await this.writeFile(normDest, content);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (!this.directories.has(normSrc)) {
|
|
234
|
+
throw new Error(`ENOENT: no such file or directory: ${src}`);
|
|
235
|
+
}
|
|
236
|
+
if (!_options?.recursive) {
|
|
237
|
+
throw new Error(`EISDIR: is a directory (use recursive): ${src}`);
|
|
238
|
+
}
|
|
239
|
+
const prefix = normSrc === "/" ? "/" : normSrc + "/";
|
|
240
|
+
for (const [p, e] of this.entries) {
|
|
241
|
+
if (p.startsWith(prefix)) {
|
|
242
|
+
const relative = p.slice(normSrc.length);
|
|
243
|
+
const content = await this.resolver.readFile(e.id, this.ctx);
|
|
244
|
+
await this.writeFile(normDest + relative, content);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
async mv(src, dest) {
|
|
249
|
+
await this.cp(src, dest, { recursive: true });
|
|
250
|
+
await this.rm(src, { recursive: true });
|
|
251
|
+
}
|
|
252
|
+
// --------------------------------------------------------------------------
|
|
253
|
+
// Unsupported
|
|
254
|
+
// --------------------------------------------------------------------------
|
|
255
|
+
async readlink(_path) {
|
|
256
|
+
throw new SandboxNotSupportedError("readlink");
|
|
257
|
+
}
|
|
258
|
+
resolvePath(base, path) {
|
|
259
|
+
if (path.startsWith("/")) return normalisePath(path);
|
|
260
|
+
const combined = base.endsWith("/") ? base + path : base + "/" + path;
|
|
261
|
+
return normalisePath(combined);
|
|
262
|
+
}
|
|
263
|
+
// --------------------------------------------------------------------------
|
|
264
|
+
// Helpers
|
|
265
|
+
// --------------------------------------------------------------------------
|
|
266
|
+
addParentDirectories(filePath) {
|
|
267
|
+
let dir = parentDir(normalisePath(filePath));
|
|
268
|
+
while (!this.directories.has(dir)) {
|
|
269
|
+
this.directories.add(dir);
|
|
270
|
+
dir = parentDir(dir);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
var BASE62 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
275
|
+
function getShortId(length = 12) {
|
|
276
|
+
const hex = uuid4().replace(/-/g, "");
|
|
277
|
+
let result = "";
|
|
278
|
+
for (let i = 0; i < length; i++) {
|
|
279
|
+
const byte = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
280
|
+
result += BASE62[byte % BASE62.length];
|
|
281
|
+
}
|
|
282
|
+
return result;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// src/adapters/sandbox/virtual/provider.ts
|
|
286
|
+
var VirtualSandboxProvider = class {
|
|
287
|
+
id = "virtual";
|
|
288
|
+
capabilities = {
|
|
289
|
+
filesystem: true,
|
|
290
|
+
execution: false,
|
|
291
|
+
persistence: true
|
|
292
|
+
};
|
|
293
|
+
resolver;
|
|
294
|
+
constructor(resolver) {
|
|
295
|
+
this.resolver = resolver;
|
|
296
|
+
}
|
|
297
|
+
async create(options) {
|
|
298
|
+
if (!options || !("resolverContext" in options)) {
|
|
299
|
+
throw new Error("VirtualSandboxProvider.create requires resolverContext");
|
|
300
|
+
}
|
|
301
|
+
const sandboxId = options.id ?? getShortId();
|
|
302
|
+
const fileTree = await this.resolver.resolveEntries(
|
|
303
|
+
options.resolverContext
|
|
304
|
+
);
|
|
305
|
+
const sandbox = createVirtualSandbox(
|
|
306
|
+
sandboxId,
|
|
307
|
+
fileTree,
|
|
308
|
+
this.resolver,
|
|
309
|
+
options.resolverContext
|
|
310
|
+
);
|
|
311
|
+
return {
|
|
312
|
+
sandbox,
|
|
313
|
+
stateUpdate: {
|
|
314
|
+
sandboxId,
|
|
315
|
+
fileTree,
|
|
316
|
+
resolverContext: options.resolverContext
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
async get() {
|
|
321
|
+
throw new SandboxNotSupportedError(
|
|
322
|
+
"get (virtual sandbox state lives in workflow AgentState)"
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
async destroy() {
|
|
326
|
+
}
|
|
327
|
+
async snapshot() {
|
|
328
|
+
throw new SandboxNotSupportedError(
|
|
329
|
+
"snapshot (virtual sandbox state lives in workflow AgentState)"
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
async restore() {
|
|
333
|
+
throw new SandboxNotSupportedError(
|
|
334
|
+
"restore (virtual sandbox state lives in workflow AgentState)"
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
async function queryParentWorkflowState(client) {
|
|
339
|
+
const { workflowExecution } = Context.current().info;
|
|
340
|
+
const handle = client.getHandle(
|
|
341
|
+
workflowExecution.workflowId,
|
|
342
|
+
workflowExecution.runId
|
|
343
|
+
);
|
|
344
|
+
return handle.query("getAgentState");
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// src/adapters/sandbox/virtual/with-virtual-sandbox.ts
|
|
348
|
+
function withVirtualSandbox(client, provider, handler) {
|
|
349
|
+
return async (args, context) => {
|
|
350
|
+
const state = await queryParentWorkflowState(client);
|
|
351
|
+
const { sandboxId, fileTree, resolverContext } = state;
|
|
352
|
+
if (!fileTree || !sandboxId) {
|
|
353
|
+
return {
|
|
354
|
+
toolResponse: `Error: No fileTree/sandboxId in agent state. The ${context.toolName} tool requires a virtual sandbox.`,
|
|
355
|
+
data: null
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
const sandbox = createVirtualSandbox(
|
|
359
|
+
sandboxId,
|
|
360
|
+
fileTree,
|
|
361
|
+
provider.resolver,
|
|
362
|
+
resolverContext
|
|
363
|
+
);
|
|
364
|
+
const response = await handler(args, { ...context, sandbox });
|
|
365
|
+
const mutations = sandbox.fs.getMutations();
|
|
366
|
+
return {
|
|
367
|
+
toolResponse: response.toolResponse,
|
|
368
|
+
data: {
|
|
369
|
+
...response.data ?? {},
|
|
370
|
+
treeMutations: mutations
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// src/adapters/sandbox/virtual/index.ts
|
|
377
|
+
var VirtualSandboxImpl = class {
|
|
378
|
+
constructor(id, tree, resolver, ctx) {
|
|
379
|
+
this.id = id;
|
|
380
|
+
this.fs = new VirtualSandboxFileSystem(tree, resolver, ctx);
|
|
381
|
+
}
|
|
382
|
+
capabilities = {
|
|
383
|
+
filesystem: true,
|
|
384
|
+
execution: false,
|
|
385
|
+
persistence: true
|
|
386
|
+
};
|
|
387
|
+
fs;
|
|
388
|
+
async exec(_command, _options) {
|
|
389
|
+
throw new SandboxNotSupportedError("exec");
|
|
390
|
+
}
|
|
391
|
+
async destroy() {
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
function createVirtualSandbox(id, tree, resolver, ctx) {
|
|
395
|
+
return new VirtualSandboxImpl(id, tree, resolver, ctx);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
export { VirtualSandboxFileSystem, VirtualSandboxProvider, createVirtualSandbox, withVirtualSandbox };
|
|
399
|
+
//# sourceMappingURL=index.js.map
|
|
400
|
+
//# sourceMappingURL=index.js.map
|