zeitlich 0.2.28 → 0.2.30
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 +121 -13
- package/dist/{activities-3xj_fEJK.d.ts → activities-BeveyY9b.d.cts} +2 -3
- package/dist/{activities-BzYq6jf7.d.cts → activities-NT3rcw66.d.ts} +2 -3
- package/dist/adapters/sandbox/bedrock/index.cjs.map +1 -1
- package/dist/adapters/sandbox/bedrock/index.d.cts +3 -3
- package/dist/adapters/sandbox/bedrock/index.d.ts +3 -3
- package/dist/adapters/sandbox/bedrock/index.js.map +1 -1
- package/dist/adapters/sandbox/bedrock/workflow.d.cts +2 -2
- package/dist/adapters/sandbox/bedrock/workflow.d.ts +2 -2
- package/dist/adapters/sandbox/daytona/index.cjs.map +1 -1
- package/dist/adapters/sandbox/daytona/index.d.cts +1 -1
- package/dist/adapters/sandbox/daytona/index.d.ts +1 -1
- package/dist/adapters/sandbox/daytona/index.js.map +1 -1
- package/dist/adapters/sandbox/daytona/workflow.d.cts +1 -1
- package/dist/adapters/sandbox/daytona/workflow.d.ts +1 -1
- package/dist/adapters/sandbox/e2b/index.cjs.map +1 -1
- package/dist/adapters/sandbox/e2b/index.d.cts +1 -1
- package/dist/adapters/sandbox/e2b/index.d.ts +1 -1
- package/dist/adapters/sandbox/e2b/index.js.map +1 -1
- package/dist/adapters/sandbox/e2b/workflow.d.cts +1 -1
- package/dist/adapters/sandbox/e2b/workflow.d.ts +1 -1
- package/dist/adapters/sandbox/inmemory/index.cjs.map +1 -1
- package/dist/adapters/sandbox/inmemory/index.d.cts +1 -1
- package/dist/adapters/sandbox/inmemory/index.d.ts +1 -1
- package/dist/adapters/sandbox/inmemory/index.js.map +1 -1
- package/dist/adapters/sandbox/inmemory/workflow.d.cts +1 -1
- package/dist/adapters/sandbox/inmemory/workflow.d.ts +1 -1
- package/dist/adapters/thread/anthropic/index.cjs +0 -1
- package/dist/adapters/thread/anthropic/index.cjs.map +1 -1
- package/dist/adapters/thread/anthropic/index.d.cts +6 -7
- package/dist/adapters/thread/anthropic/index.d.ts +6 -7
- package/dist/adapters/thread/anthropic/index.js +0 -1
- package/dist/adapters/thread/anthropic/index.js.map +1 -1
- package/dist/adapters/thread/anthropic/workflow.d.cts +5 -6
- package/dist/adapters/thread/anthropic/workflow.d.ts +5 -6
- package/dist/adapters/thread/google-genai/index.cjs +0 -1
- package/dist/adapters/thread/google-genai/index.cjs.map +1 -1
- package/dist/adapters/thread/google-genai/index.d.cts +6 -7
- package/dist/adapters/thread/google-genai/index.d.ts +6 -7
- package/dist/adapters/thread/google-genai/index.js +0 -1
- package/dist/adapters/thread/google-genai/index.js.map +1 -1
- package/dist/adapters/thread/google-genai/workflow.d.cts +5 -6
- package/dist/adapters/thread/google-genai/workflow.d.ts +5 -6
- package/dist/adapters/thread/langchain/index.cjs +0 -1
- package/dist/adapters/thread/langchain/index.cjs.map +1 -1
- package/dist/adapters/thread/langchain/index.d.cts +6 -7
- package/dist/adapters/thread/langchain/index.d.ts +6 -7
- package/dist/adapters/thread/langchain/index.js +0 -1
- package/dist/adapters/thread/langchain/index.js.map +1 -1
- package/dist/adapters/thread/langchain/workflow.d.cts +5 -6
- package/dist/adapters/thread/langchain/workflow.d.ts +5 -6
- package/dist/index.cjs +558 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +136 -22
- package/dist/index.d.ts +136 -22
- package/dist/index.js +554 -52
- package/dist/index.js.map +1 -1
- package/dist/{proxy-7e7v8ccg.d.ts → proxy-BgswT47M.d.ts} +1 -1
- package/dist/{proxy-CsB8r0RR.d.cts → proxy-OJihshQF.d.cts} +1 -1
- package/dist/{thread-manager-D8C5QvLi.d.ts → thread-manager-BS477gj8.d.ts} +1 -1
- package/dist/{thread-manager-DdVFl1IY.d.cts → thread-manager-DH0zv05W.d.cts} +1 -1
- package/dist/{thread-manager-B5qA4v7V.d.ts → thread-manager-iUplxEZt.d.ts} +1 -1
- package/dist/{thread-manager-DFJ3sKKU.d.cts → thread-manager-lfN0V-gH.d.cts} +1 -1
- package/dist/{types-ChAMwU3q.d.cts → types-AujBIMMn.d.cts} +5 -8
- package/dist/{types-ChAMwU3q.d.ts → types-AujBIMMn.d.ts} +5 -8
- package/dist/{types-BZ75HpYd.d.ts → types-CCIc7Eam.d.ts} +1 -1
- package/dist/types-D90Q5aOh.d.ts +1212 -0
- package/dist/{types-BdCdR41N.d.ts → types-DBk-C8zM.d.ts} +1 -1
- package/dist/{types-ZHs2v9Ap.d.cts → types-DUvEZSDe.d.cts} +1 -1
- package/dist/types-DVdT5ybA.d.cts +1212 -0
- package/dist/{types-HbjqzyJH.d.cts → types-DgIVPOa1.d.cts} +1 -1
- package/dist/workflow-Cj4DxGdM.d.cts +750 -0
- package/dist/workflow-CzrBdCcJ.d.ts +750 -0
- package/dist/workflow.cjs +194 -40
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +5 -579
- package/dist/workflow.d.ts +5 -579
- package/dist/workflow.js +193 -42
- package/dist/workflow.js.map +1 -1
- package/package.json +3 -23
- package/src/adapters/thread/anthropic/thread-manager.ts +6 -6
- package/src/adapters/thread/google-genai/thread-manager.ts +6 -6
- package/src/adapters/thread/langchain/thread-manager.ts +6 -6
- package/src/index.ts +8 -0
- package/src/lib/lifecycle.ts +8 -3
- package/src/lib/observability/hooks.ts +117 -0
- package/src/lib/observability/index.ts +13 -0
- package/src/lib/observability/sinks.ts +88 -0
- package/src/lib/sandbox/index.ts +2 -4
- package/src/lib/sandbox/manager.ts +131 -16
- package/src/lib/sandbox/sandbox.test.ts +136 -16
- package/src/lib/sandbox/types.ts +6 -5
- package/src/lib/session/session-edge-cases.integration.test.ts +1 -0
- package/src/lib/session/session.integration.test.ts +7 -39
- package/src/lib/session/session.ts +119 -42
- package/src/lib/session/types.ts +39 -9
- package/src/lib/state/manager.integration.test.ts +1 -0
- package/src/lib/state/types.ts +9 -6
- package/src/lib/subagent/handler.ts +35 -12
- package/src/lib/subagent/register.ts +11 -12
- package/src/lib/subagent/subagent.integration.test.ts +1 -0
- package/src/lib/tool-router/router-edge-cases.integration.test.ts +2 -0
- package/src/lib/tool-router/router.integration.test.ts +2 -0
- package/src/lib/tool-router/router.ts +24 -2
- package/src/lib/types.ts +2 -0
- package/src/{adapters/sandbox/virtual → lib/virtual-fs}/filesystem.ts +4 -4
- package/src/lib/virtual-fs/index.ts +18 -0
- package/src/lib/virtual-fs/manager.ts +48 -0
- package/src/lib/virtual-fs/proxy.ts +45 -0
- package/src/{adapters/sandbox/virtual → lib/virtual-fs}/types.ts +41 -37
- package/src/{adapters/sandbox/virtual/virtual-sandbox.test.ts → lib/virtual-fs/virtual-fs.test.ts} +15 -130
- package/src/lib/virtual-fs/with-virtual-fs.ts +94 -0
- package/src/tools/bash/bash.test.ts +2 -1
- package/src/workflow.ts +25 -8
- package/tsup.config.ts +0 -2
- package/dist/adapters/sandbox/virtual/index.cjs +0 -487
- package/dist/adapters/sandbox/virtual/index.cjs.map +0 -1
- package/dist/adapters/sandbox/virtual/index.d.cts +0 -90
- package/dist/adapters/sandbox/virtual/index.d.ts +0 -90
- package/dist/adapters/sandbox/virtual/index.js +0 -479
- package/dist/adapters/sandbox/virtual/index.js.map +0 -1
- package/dist/adapters/sandbox/virtual/workflow.cjs +0 -33
- package/dist/adapters/sandbox/virtual/workflow.cjs.map +0 -1
- package/dist/adapters/sandbox/virtual/workflow.d.cts +0 -28
- package/dist/adapters/sandbox/virtual/workflow.d.ts +0 -28
- package/dist/adapters/sandbox/virtual/workflow.js +0 -31
- package/dist/adapters/sandbox/virtual/workflow.js.map +0 -1
- package/dist/queries-DVnukByF.d.cts +0 -44
- package/dist/queries-kjlvsUfz.d.ts +0 -44
- package/dist/types-BclYm5Ic.d.cts +0 -581
- package/dist/types-BclYm5Ic.d.ts +0 -581
- package/dist/types-BgsAwN3L.d.cts +0 -125
- package/dist/types-BtqbM1bO.d.ts +0 -490
- package/dist/types-BuCEZ4dF.d.cts +0 -490
- package/dist/types-yU5AINiP.d.ts +0 -125
- package/src/adapters/sandbox/virtual/index.ts +0 -92
- package/src/adapters/sandbox/virtual/provider.ts +0 -121
- package/src/adapters/sandbox/virtual/proxy.ts +0 -53
- package/src/adapters/sandbox/virtual/with-virtual-sandbox.ts +0 -97
- package/src/lib/.env +0 -1
- package/src/tools/bash/.env +0 -1
- /package/src/{adapters/sandbox/virtual → lib/virtual-fs}/mutations.ts +0 -0
- /package/src/{adapters/sandbox/virtual → lib/virtual-fs}/queries.ts +0 -0
- /package/src/{adapters/sandbox/virtual → lib/virtual-fs}/tree.ts +0 -0
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Sandbox,
|
|
3
|
-
SandboxCapabilities,
|
|
4
|
-
ExecOptions,
|
|
5
|
-
ExecResult,
|
|
6
|
-
} from "../../../lib/sandbox/types";
|
|
7
|
-
import { SandboxNotSupportedError } from "../../../lib/sandbox/types";
|
|
8
|
-
import { VirtualSandboxFileSystem } from "./filesystem";
|
|
9
|
-
import type {
|
|
10
|
-
FileEntry,
|
|
11
|
-
FileEntryMetadata,
|
|
12
|
-
FileResolver,
|
|
13
|
-
VirtualSandbox,
|
|
14
|
-
} from "./types";
|
|
15
|
-
|
|
16
|
-
// ============================================================================
|
|
17
|
-
// VirtualSandbox
|
|
18
|
-
// ============================================================================
|
|
19
|
-
|
|
20
|
-
class VirtualSandboxImpl<
|
|
21
|
-
TCtx = unknown,
|
|
22
|
-
TMeta = FileEntryMetadata,
|
|
23
|
-
> implements Sandbox
|
|
24
|
-
{
|
|
25
|
-
readonly capabilities: SandboxCapabilities = {
|
|
26
|
-
filesystem: true,
|
|
27
|
-
execution: false,
|
|
28
|
-
persistence: true,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
readonly fs: VirtualSandboxFileSystem<TCtx, TMeta>;
|
|
32
|
-
|
|
33
|
-
constructor(
|
|
34
|
-
readonly id: string,
|
|
35
|
-
tree: FileEntry<TMeta>[],
|
|
36
|
-
resolver: FileResolver<TCtx, TMeta>,
|
|
37
|
-
ctx: TCtx,
|
|
38
|
-
workspaceBase = "/",
|
|
39
|
-
) {
|
|
40
|
-
this.fs = new VirtualSandboxFileSystem(tree, resolver, ctx, workspaceBase);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async exec(_command: string, _options?: ExecOptions): Promise<ExecResult> {
|
|
44
|
-
throw new SandboxNotSupportedError("exec");
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async destroy(): Promise<void> {
|
|
48
|
-
// Ephemeral — nothing to clean up
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// ============================================================================
|
|
53
|
-
// Factory
|
|
54
|
-
// ============================================================================
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Create an ephemeral {@link Sandbox} from a file tree and resolver.
|
|
58
|
-
*
|
|
59
|
-
* Used internally by {@link withVirtualSandbox} and
|
|
60
|
-
* {@link VirtualSandboxProvider}; consumers can also call this directly
|
|
61
|
-
* if they need a sandbox outside the wrapper pattern.
|
|
62
|
-
*/
|
|
63
|
-
export function createVirtualSandbox<
|
|
64
|
-
TCtx,
|
|
65
|
-
TMeta = FileEntryMetadata,
|
|
66
|
-
>(
|
|
67
|
-
id: string,
|
|
68
|
-
tree: FileEntry<TMeta>[],
|
|
69
|
-
resolver: FileResolver<TCtx, TMeta>,
|
|
70
|
-
ctx: TCtx,
|
|
71
|
-
workspaceBase = "/",
|
|
72
|
-
): VirtualSandbox<TCtx, TMeta> {
|
|
73
|
-
return new VirtualSandboxImpl(id, tree, resolver, ctx, workspaceBase);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Re-exports for convenience
|
|
77
|
-
export { VirtualSandboxFileSystem } from "./filesystem";
|
|
78
|
-
export { VirtualSandboxProvider } from "./provider";
|
|
79
|
-
export { withVirtualSandbox } from "./with-virtual-sandbox";
|
|
80
|
-
export { hasFileWithMimeType, filesWithMimeType, hasDirectory } from "./queries";
|
|
81
|
-
export type { FileTreeAccessor } from "./queries";
|
|
82
|
-
export type {
|
|
83
|
-
FileEntry,
|
|
84
|
-
FileEntryMetadata,
|
|
85
|
-
FileResolver,
|
|
86
|
-
VirtualFileTree,
|
|
87
|
-
VirtualSandboxCreateOptions,
|
|
88
|
-
VirtualSandboxState,
|
|
89
|
-
VirtualSandboxContext,
|
|
90
|
-
VirtualSandbox,
|
|
91
|
-
TreeMutation,
|
|
92
|
-
} from "./types";
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
SandboxCapabilities,
|
|
3
|
-
SandboxCreateResult,
|
|
4
|
-
SandboxProvider,
|
|
5
|
-
} from "../../../lib/sandbox/types";
|
|
6
|
-
import { SandboxNotSupportedError } from "../../../lib/sandbox/types";
|
|
7
|
-
import { getShortId } from "../../../lib/thread/id";
|
|
8
|
-
import { createVirtualSandbox } from "./index";
|
|
9
|
-
import type {
|
|
10
|
-
FileEntryMetadata,
|
|
11
|
-
FileResolver,
|
|
12
|
-
VirtualSandboxCreateOptions,
|
|
13
|
-
} from "./types";
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Stateless {@link SandboxProvider} backed by a {@link FileResolver}.
|
|
17
|
-
*
|
|
18
|
-
* The provider holds **no internal state**. All sandbox state (sandboxId,
|
|
19
|
-
* fileTree, resolverContext, workspaceBase) is returned as a `stateUpdate` from
|
|
20
|
-
* {@link create} and merged into the workflow's `AgentState` by the session.
|
|
21
|
-
* {@link withVirtualSandbox} reads this state back on every tool invocation.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* const provider = new VirtualSandboxProvider(resolver);
|
|
26
|
-
* const manager = new SandboxManager(provider);
|
|
27
|
-
*
|
|
28
|
-
* export const activities = {
|
|
29
|
-
* ...manager.createActivities("CodingAgent"),
|
|
30
|
-
* readFile: withVirtualSandbox(client, provider, readHandler),
|
|
31
|
-
* };
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
export class VirtualSandboxProvider<
|
|
35
|
-
TCtx = unknown,
|
|
36
|
-
TMeta = FileEntryMetadata,
|
|
37
|
-
> implements SandboxProvider<VirtualSandboxCreateOptions<TCtx>> {
|
|
38
|
-
readonly id = "virtual";
|
|
39
|
-
readonly capabilities: SandboxCapabilities = {
|
|
40
|
-
filesystem: true,
|
|
41
|
-
execution: false,
|
|
42
|
-
persistence: true,
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
readonly resolver: FileResolver<TCtx, TMeta>;
|
|
46
|
-
|
|
47
|
-
constructor(resolver: FileResolver<TCtx, TMeta>) {
|
|
48
|
-
this.resolver = resolver;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async create(
|
|
52
|
-
options?: VirtualSandboxCreateOptions<TCtx>
|
|
53
|
-
): Promise<SandboxCreateResult> {
|
|
54
|
-
if (!options || !("resolverContext" in options)) {
|
|
55
|
-
throw new Error("VirtualSandboxProvider.create requires resolverContext");
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const sandboxId = options.id ?? getShortId();
|
|
59
|
-
const fileTree = await this.resolver.resolveEntries(
|
|
60
|
-
options.resolverContext
|
|
61
|
-
);
|
|
62
|
-
const workspaceBase = options.workspaceBase ?? "/";
|
|
63
|
-
|
|
64
|
-
const sandbox = createVirtualSandbox(
|
|
65
|
-
sandboxId,
|
|
66
|
-
fileTree,
|
|
67
|
-
this.resolver,
|
|
68
|
-
options.resolverContext,
|
|
69
|
-
workspaceBase,
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
if (options.initialFiles) {
|
|
73
|
-
for (const [path, content] of Object.entries(options.initialFiles)) {
|
|
74
|
-
await sandbox.fs.writeFile(path, content);
|
|
75
|
-
}
|
|
76
|
-
for (const m of sandbox.fs.getMutations()) {
|
|
77
|
-
if (m.type === "add") fileTree.push(m.entry);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
sandbox,
|
|
83
|
-
stateUpdate: {
|
|
84
|
-
sandboxId,
|
|
85
|
-
fileTree,
|
|
86
|
-
resolverContext: options.resolverContext,
|
|
87
|
-
workspaceBase,
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async get(): Promise<never> {
|
|
93
|
-
throw new SandboxNotSupportedError(
|
|
94
|
-
"get (virtual sandbox state lives in workflow AgentState)"
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
async destroy(): Promise<void> {
|
|
99
|
-
// No-op — no internal state to clean up
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async pause(): Promise<void> {
|
|
103
|
-
// No-op — virtual sandbox state lives in workflow AgentState
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async fork(_sandboxId: string): Promise<never> {
|
|
107
|
-
throw new Error("Not implemented");
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
async snapshot(): Promise<never> {
|
|
111
|
-
throw new SandboxNotSupportedError(
|
|
112
|
-
"snapshot (virtual sandbox state lives in workflow AgentState)"
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
async restore(): Promise<never> {
|
|
117
|
-
throw new SandboxNotSupportedError(
|
|
118
|
-
"restore (virtual sandbox state lives in workflow AgentState)"
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Workflow-safe proxy for virtual sandbox operations.
|
|
3
|
-
*
|
|
4
|
-
* Import this from `zeitlich/adapters/sandbox/virtual/workflow`
|
|
5
|
-
* in your Temporal workflow files.
|
|
6
|
-
*
|
|
7
|
-
* By default the scope is derived from `workflowInfo().workflowType`,
|
|
8
|
-
* so activities are automatically namespaced per workflow.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* import { proxyVirtualSandboxOps } from 'zeitlich/adapters/sandbox/virtual/workflow';
|
|
13
|
-
*
|
|
14
|
-
* const sandbox = proxyVirtualSandboxOps();
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
import { proxyActivities, workflowInfo } from "@temporalio/workflow";
|
|
18
|
-
import type { SandboxOps } from "../../../lib/sandbox/types";
|
|
19
|
-
import type { VirtualSandboxCreateOptions } from "./types";
|
|
20
|
-
|
|
21
|
-
const ADAPTER_PREFIX = "virtual";
|
|
22
|
-
|
|
23
|
-
export function proxyVirtualSandboxOps(
|
|
24
|
-
scope?: string,
|
|
25
|
-
options?: Parameters<typeof proxyActivities>[0]
|
|
26
|
-
): SandboxOps<VirtualSandboxCreateOptions<unknown>> {
|
|
27
|
-
const resolvedScope = scope ?? workflowInfo().workflowType;
|
|
28
|
-
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
-
const acts = proxyActivities<Record<string, (...args: any[]) => any>>(
|
|
31
|
-
options ?? {
|
|
32
|
-
startToCloseTimeout: "30s",
|
|
33
|
-
retry: {
|
|
34
|
-
maximumAttempts: 3,
|
|
35
|
-
initialInterval: "2s",
|
|
36
|
-
maximumInterval: "30s",
|
|
37
|
-
backoffCoefficient: 2,
|
|
38
|
-
},
|
|
39
|
-
}
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
const prefix = `${ADAPTER_PREFIX}${resolvedScope.charAt(0).toUpperCase()}${resolvedScope.slice(1)}`;
|
|
43
|
-
const p = (key: string): string =>
|
|
44
|
-
`${prefix}${key.charAt(0).toUpperCase()}${key.slice(1)}`;
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
createSandbox: acts[p("createSandbox")],
|
|
48
|
-
destroySandbox: acts[p("destroySandbox")],
|
|
49
|
-
pauseSandbox: acts[p("pauseSandbox")],
|
|
50
|
-
snapshotSandbox: acts[p("snapshotSandbox")],
|
|
51
|
-
forkSandbox: acts[p("forkSandbox")],
|
|
52
|
-
} as SandboxOps<VirtualSandboxCreateOptions<unknown>>;
|
|
53
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import type { WorkflowClient } from "@temporalio/client";
|
|
2
|
-
import { queryParentWorkflowState } from "../../../lib/activity";
|
|
3
|
-
import type { JsonValue } from "../../../lib/state/types";
|
|
4
|
-
import type { ActivityToolHandler, RouterContext } from "../../../lib/tool-router/types";
|
|
5
|
-
import type {
|
|
6
|
-
FileEntryMetadata,
|
|
7
|
-
TreeMutation,
|
|
8
|
-
VirtualSandboxContext,
|
|
9
|
-
VirtualSandboxState,
|
|
10
|
-
} from "./types";
|
|
11
|
-
import type { VirtualSandboxProvider } from "./provider";
|
|
12
|
-
import { createVirtualSandbox } from "./index";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Wraps a tool handler that needs a virtual sandbox, automatically querying
|
|
16
|
-
* the parent workflow for the current file tree and resolver context.
|
|
17
|
-
*
|
|
18
|
-
* On each invocation the wrapper:
|
|
19
|
-
* 1. Queries the workflow's `AgentState` for `fileTree`, `resolverContext`, and `workspaceBase`
|
|
20
|
-
* 2. Creates an ephemeral {@link VirtualSandbox} from tree + provider's resolver
|
|
21
|
-
* 3. Runs the inner handler
|
|
22
|
-
* 4. Returns the handler's result together with any {@link TreeMutation}s
|
|
23
|
-
*
|
|
24
|
-
* The consumer applies mutations back to workflow state via a post-tool hook.
|
|
25
|
-
*
|
|
26
|
-
* @param client - Temporal `WorkflowClient` for querying the parent workflow
|
|
27
|
-
* @param agentName - Agent name (used to derive the state query name)
|
|
28
|
-
* @param provider - {@link VirtualSandboxProvider} (wraps the resolver)
|
|
29
|
-
* @param handler - Inner handler expecting a {@link VirtualSandboxContext}
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```typescript
|
|
33
|
-
* import { withVirtualSandbox, type VirtualSandboxContext } from 'zeitlich';
|
|
34
|
-
*
|
|
35
|
-
* const readHandler: ActivityToolHandler<FileReadArgs, ReadResult, VirtualSandboxContext> =
|
|
36
|
-
* async (args, { sandbox }) => {
|
|
37
|
-
* const content = await sandbox.fs.readFile(args.path);
|
|
38
|
-
* return { toolResponse: content, data: { path: args.path, content } };
|
|
39
|
-
* };
|
|
40
|
-
*
|
|
41
|
-
* // At activity registration:
|
|
42
|
-
* const provider = new VirtualSandboxProvider(resolver);
|
|
43
|
-
* const handler = withVirtualSandbox(client, "myAgent", provider, readHandler);
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
export function withVirtualSandbox<
|
|
47
|
-
TArgs,
|
|
48
|
-
TResult,
|
|
49
|
-
TCtx,
|
|
50
|
-
TMeta = FileEntryMetadata,
|
|
51
|
-
TToolResponse = JsonValue,
|
|
52
|
-
>(
|
|
53
|
-
client: WorkflowClient,
|
|
54
|
-
provider: VirtualSandboxProvider<TCtx, TMeta>,
|
|
55
|
-
handler: ActivityToolHandler<
|
|
56
|
-
TArgs,
|
|
57
|
-
TResult,
|
|
58
|
-
VirtualSandboxContext<TCtx, TMeta>,
|
|
59
|
-
TToolResponse
|
|
60
|
-
>
|
|
61
|
-
): ActivityToolHandler<
|
|
62
|
-
TArgs,
|
|
63
|
-
(TResult & { treeMutations: TreeMutation<TMeta>[] }) | null,
|
|
64
|
-
RouterContext,
|
|
65
|
-
TToolResponse | string
|
|
66
|
-
> {
|
|
67
|
-
return async (args, context) => {
|
|
68
|
-
const state =
|
|
69
|
-
await queryParentWorkflowState<VirtualSandboxState<TCtx, TMeta>>(client);
|
|
70
|
-
|
|
71
|
-
const { sandboxId, fileTree, resolverContext, workspaceBase } = state;
|
|
72
|
-
if (!fileTree || !sandboxId) {
|
|
73
|
-
return {
|
|
74
|
-
toolResponse: `Error: No fileTree/sandboxId in agent state. The ${context.toolName} tool requires a virtual sandbox.`,
|
|
75
|
-
data: null,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const sandbox = createVirtualSandbox(
|
|
80
|
-
sandboxId,
|
|
81
|
-
fileTree,
|
|
82
|
-
provider.resolver,
|
|
83
|
-
resolverContext,
|
|
84
|
-
workspaceBase ?? "/",
|
|
85
|
-
);
|
|
86
|
-
const response = await handler(args, { ...context, sandbox });
|
|
87
|
-
const mutations = sandbox.fs.getMutations();
|
|
88
|
-
|
|
89
|
-
return {
|
|
90
|
-
toolResponse: response.toolResponse,
|
|
91
|
-
data: {
|
|
92
|
-
...(response.data ?? {}),
|
|
93
|
-
treeMutations: mutations,
|
|
94
|
-
} as TResult & { treeMutations: TreeMutation<TMeta>[] },
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
}
|
package/src/lib/.env
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
E2B_API_KEY=e2b_39af116424059782e2aee6942fd70237cc2126c9
|
package/src/tools/bash/.env
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
E2B_API_KEY=e2b_39af116424059782e2aee6942fd70237cc2126c9
|
|
File without changes
|
|
File without changes
|
|
File without changes
|