@deepagents/context 0.10.2 → 0.11.0

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.
Files changed (42) hide show
  1. package/README.md +114 -119
  2. package/dist/example-error-recovery.d.ts +2 -0
  3. package/dist/example-error-recovery.d.ts.map +1 -0
  4. package/dist/index.d.ts +16 -388
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +2391 -1062
  7. package/dist/index.js.map +4 -4
  8. package/dist/lib/agent.d.ts +86 -12
  9. package/dist/lib/agent.d.ts.map +1 -1
  10. package/dist/lib/engine.d.ts +323 -0
  11. package/dist/lib/engine.d.ts.map +1 -0
  12. package/dist/lib/estimate.d.ts +1 -1
  13. package/dist/lib/estimate.d.ts.map +1 -1
  14. package/dist/lib/fragments/domain.d.ts +440 -0
  15. package/dist/lib/fragments/domain.d.ts.map +1 -0
  16. package/dist/lib/fragments/user.d.ts +122 -0
  17. package/dist/lib/fragments/user.d.ts.map +1 -0
  18. package/dist/lib/fragments.d.ts +107 -0
  19. package/dist/lib/fragments.d.ts.map +1 -0
  20. package/dist/lib/guardrail.d.ts +138 -0
  21. package/dist/lib/guardrail.d.ts.map +1 -0
  22. package/dist/lib/renderers/abstract.renderer.d.ts +1 -1
  23. package/dist/lib/renderers/abstract.renderer.d.ts.map +1 -1
  24. package/dist/lib/sandbox/binary-bridges.d.ts +31 -0
  25. package/dist/lib/sandbox/binary-bridges.d.ts.map +1 -0
  26. package/dist/lib/sandbox/container-tool.d.ts +134 -0
  27. package/dist/lib/sandbox/container-tool.d.ts.map +1 -0
  28. package/dist/lib/sandbox/docker-sandbox.d.ts +471 -0
  29. package/dist/lib/sandbox/docker-sandbox.d.ts.map +1 -0
  30. package/dist/lib/sandbox/index.d.ts +4 -0
  31. package/dist/lib/sandbox/index.d.ts.map +1 -0
  32. package/dist/lib/skills/fragments.d.ts +24 -0
  33. package/dist/lib/skills/fragments.d.ts.map +1 -0
  34. package/dist/lib/skills/index.d.ts +31 -0
  35. package/dist/lib/skills/index.d.ts.map +1 -0
  36. package/dist/lib/skills/loader.d.ts +28 -0
  37. package/dist/lib/skills/loader.d.ts.map +1 -0
  38. package/dist/lib/skills/types.d.ts +40 -0
  39. package/dist/lib/skills/types.d.ts.map +1 -0
  40. package/package.json +7 -3
  41. package/dist/lib/context.d.ts +0 -56
  42. package/dist/lib/context.d.ts.map +0 -1
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Guardrail system for real-time stream interception and self-correction.
3
+ *
4
+ * Guardrails inspect streaming parts and can either:
5
+ * - `pass(part)`: Allow the part through (optionally modified)
6
+ * - `fail(feedback)`: Abort the stream and retry with self-correction feedback
7
+ *
8
+ * When a guardrail fails, the accumulated text is combined with the feedback
9
+ * to create a "self-correction" that appears as if the agent caught itself.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const safetyGuardrail: Guardrail = {
14
+ * id: 'safety',
15
+ * name: 'Safety Filter',
16
+ * handle: (part, context) => {
17
+ * if (part.type === 'text-delta' && part.delta.includes('unsafe')) {
18
+ * return fail('I should not provide this information. Let me help differently.');
19
+ * }
20
+ * if (part.type === 'error' && context.availableTools.length > 0) {
21
+ * return fail(`Try using: ${context.availableTools.join(', ')}`);
22
+ * }
23
+ * return pass(part);
24
+ * },
25
+ * };
26
+ *
27
+ * const agent = agent({
28
+ * name: 'safe_assistant',
29
+ * context,
30
+ * model,
31
+ * guardrails: [safetyGuardrail],
32
+ * });
33
+ * ```
34
+ */
35
+ import type { InferUIMessageChunk, UIDataTypes, UIMessage } from 'ai';
36
+ /**
37
+ * Type alias for stream parts from the AI SDK's UI message stream.
38
+ * This is the full chunk type that includes text-delta, error, reasoning-delta, etc.
39
+ */
40
+ export type StreamPart = InferUIMessageChunk<UIMessage<unknown, UIDataTypes, Record<string, never>>>;
41
+ /**
42
+ * Result of a guardrail check.
43
+ * - `pass`: The part is allowed through (optionally modified)
44
+ * - `fail`: The stream should abort and retry with feedback
45
+ */
46
+ export type GuardrailResult = {
47
+ type: 'pass';
48
+ part: StreamPart;
49
+ } | {
50
+ type: 'fail';
51
+ feedback: string;
52
+ };
53
+ /**
54
+ * Context passed to guardrails during stream processing.
55
+ * Provides information about the agent's capabilities.
56
+ */
57
+ export interface GuardrailContext {
58
+ /** Names of tools available to the agent */
59
+ availableTools: string[];
60
+ }
61
+ /**
62
+ * A guardrail that inspects streaming parts.
63
+ */
64
+ export interface Guardrail {
65
+ /** Unique identifier for this guardrail */
66
+ id: string;
67
+ /** Human-readable name for logging/debugging */
68
+ name: string;
69
+ /**
70
+ * Handle a stream part.
71
+ *
72
+ * @param part - The full stream part to inspect (text-delta, error, etc.)
73
+ * @param context - Context with agent capabilities (available tools, etc.)
74
+ * @returns Either `pass(part)` to allow or `fail(feedback)` to abort and retry
75
+ */
76
+ handle: (part: StreamPart, context: GuardrailContext) => GuardrailResult;
77
+ }
78
+ /**
79
+ * Configuration for guardrail behavior.
80
+ */
81
+ export interface GuardrailConfig {
82
+ /** Maximum number of retry attempts when guardrails fail (default: 3) */
83
+ maxRetries?: number;
84
+ }
85
+ /**
86
+ * Allow a part to pass through the guardrail.
87
+ *
88
+ * @param part - The part to pass (can be modified from original)
89
+ * @returns A pass result
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * handle: (part) => {
94
+ * // Pass through unchanged
95
+ * return pass(part);
96
+ *
97
+ * // Or modify text-delta before passing
98
+ * if (part.type === 'text-delta') {
99
+ * return pass({ ...part, delta: part.delta.replace('bad', 'good') });
100
+ * }
101
+ * return pass(part);
102
+ * }
103
+ * ```
104
+ */
105
+ export declare function pass(part: StreamPart): GuardrailResult;
106
+ /**
107
+ * Fail the guardrail check and trigger a retry with feedback.
108
+ *
109
+ * The feedback will be appended to the accumulated assistant text,
110
+ * making it appear as if the agent "caught itself" and self-corrected.
111
+ *
112
+ * @param feedback - The self-correction feedback to append
113
+ * @returns A fail result
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * handle: (part) => {
118
+ * if (part.type === 'text-delta' && part.delta.includes('hack')) {
119
+ * return fail('I should not provide hacking instructions. Let me suggest ethical alternatives.');
120
+ * }
121
+ * if (part.type === 'error') {
122
+ * return fail('An error occurred. Let me try a different approach.');
123
+ * }
124
+ * return pass(part);
125
+ * }
126
+ * ```
127
+ */
128
+ export declare function fail(feedback: string): GuardrailResult;
129
+ /**
130
+ * Run a part through a chain of guardrails sequentially.
131
+ *
132
+ * @param part - The stream part to check
133
+ * @param guardrails - Array of guardrails to run in order
134
+ * @param context - Context with agent capabilities (available tools, etc.)
135
+ * @returns The final result after all guardrails pass, or the first failure
136
+ */
137
+ export declare function runGuardrailChain(part: StreamPart, guardrails: Guardrail[], context: GuardrailContext): GuardrailResult;
138
+ //# sourceMappingURL=guardrail.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardrail.d.ts","sourceRoot":"","sources":["../../src/lib/guardrail.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAEtE;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,mBAAmB,CAC1C,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CACvD,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvC;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4CAA4C;IAC5C,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,2CAA2C;IAC3C,EAAE,EAAE,MAAM,CAAC;IACX,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;IACb;;;;;;OAMG;IACH,MAAM,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,gBAAgB,KAAK,eAAe,CAAC;CAC1E;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,yEAAyE;IACzE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,eAAe,CAEtD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe,CAEtD;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,UAAU,EAChB,UAAU,EAAE,SAAS,EAAE,EACvB,OAAO,EAAE,gBAAgB,GACxB,eAAe,CAejB"}
@@ -1,4 +1,4 @@
1
- import { type ContextFragment, type FragmentData, type FragmentObject } from '../context.ts';
1
+ import { type ContextFragment, type FragmentData, type FragmentObject } from '../fragments.ts';
2
2
  /**
3
3
  * Render context passed through the template method.
4
4
  */
@@ -1 +1 @@
1
- {"version":3,"file":"abstract.renderer.d.ts","sourceRoot":"","sources":["../../../src/lib/renderers/abstract.renderer.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,cAAc,EAGpB,MAAM,eAAe,CAAC;AAEvB;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;GAGG;AACH,8BAAsB,eAAe;IACnC,SAAS,CAAC,OAAO,EAAE,eAAe,CAAC;gBAEvB,OAAO,GAAE,eAAoB;IAIzC,QAAQ,CA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SAAS,CAAC,YAAY,CACpB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,cAAc,EACnB,GAAG,EAAE,aAAa,GACjB,MAAM;IA4BT,SAAS,CAAC,cAAc,CACtB,QAAQ,EAAE,eAAe,EACzB,GAAG,EAAE,aAAa,GACjB,MAAM;CAkDV;AAED;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,eAAe;;IAC/C,MAAM,CAAC,SAAS,EAAE,eAAe,EAAE,GAAG,MAAM;IAsL5C,SAAS,CAAC,cAAc,CACtB,QAAQ,EAAE,eAAe,EACzB,GAAG,EAAE,aAAa,GACjB,MAAM;IAyBT,SAAS,CAAC,eAAe,CACvB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,aAAa,GACjB,MAAM;IAIT,SAAS,CAAC,WAAW,CACnB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,YAAY,EAAE,EACrB,GAAG,EAAE,aAAa,GACjB,MAAM;IAIT,SAAS,CAAC,YAAY,CACpB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,cAAc,EACnB,GAAG,EAAE,aAAa,GACjB,MAAM;CAkDV"}
1
+ {"version":3,"file":"abstract.renderer.d.ts","sourceRoot":"","sources":["../../../src/lib/renderers/abstract.renderer.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,cAAc,EAGpB,MAAM,iBAAiB,CAAC;AAEzB;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;GAGG;AACH,8BAAsB,eAAe;IACnC,SAAS,CAAC,OAAO,EAAE,eAAe,CAAC;gBAEvB,OAAO,GAAE,eAAoB;IAIzC,QAAQ,CAAC,MA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CAAC,YAAY,CACpB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,cAAc,EACnB,GAAG,EAAE,aAAa,GACjB,MAAM;IA4BT,SAAS,CAAC,cAAc,CACtB,QAAQ,EAAE,eAAe,EACzB,GAAG,EAAE,aAAa,GACjB,MAAM;CAkDV;AAED;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,eAAe;;IAC/C,MAAM,CAAC,SAAS,EAAE,eAAe,EAAE,GAAG,MAAM;IAsL5C,SAAS,CAAC,cAAc,CACtB,QAAQ,EAAE,eAAe,EACzB,GAAG,EAAE,aAAa,GACjB,MAAM;IAyBT,SAAS,CAAC,eAAe,CACvB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,aAAa,GACjB,MAAM;IAIT,SAAS,CAAC,WAAW,CACnB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,YAAY,EAAE,EACrB,GAAG,EAAE,aAAa,GACjB,MAAM;IAIT,SAAS,CAAC,YAAY,CACpB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,cAAc,EACnB,GAAG,EAAE,aAAa,GACjB,MAAM;CAkDV"}
@@ -0,0 +1,31 @@
1
+ import { type CustomCommand } from 'just-bash';
2
+ export interface BinaryBridgeConfig {
3
+ /** Command name in the sandbox (what the agent types) */
4
+ name: string;
5
+ /** Actual binary path on the host system (defaults to name) */
6
+ binaryPath?: string;
7
+ /** Optional regex to restrict allowed arguments for security */
8
+ allowedArgs?: RegExp;
9
+ }
10
+ export type BinaryBridgeInput = string | BinaryBridgeConfig;
11
+ /**
12
+ * Creates custom commands that bridge to real system binaries.
13
+ *
14
+ * This allows just-bash sandboxed environments to execute specific
15
+ * host system binaries while maintaining control over which binaries
16
+ * are accessible.
17
+ *
18
+ * @example
19
+ * // Simple - just strings (name === binaryPath)
20
+ * createBinaryBridges('presenterm', 'node', 'cargo')
21
+ *
22
+ * @example
23
+ * // Mixed - strings and config objects
24
+ * createBinaryBridges(
25
+ * 'presenterm',
26
+ * { name: 'python', binaryPath: 'python3' },
27
+ * { name: 'git', allowedArgs: /^(status|log|diff)/ }
28
+ * )
29
+ */
30
+ export declare function createBinaryBridges(...binaries: BinaryBridgeInput[]): CustomCommand[];
31
+ //# sourceMappingURL=binary-bridges.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binary-bridges.d.ts","sourceRoot":"","sources":["../../../src/lib/sandbox/binary-bridges.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAK9D,MAAM,WAAW,kBAAkB;IACjC,yDAAyD;IACzD,IAAI,EAAE,MAAM,CAAC;IACb,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gEAAgE;IAChE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,kBAAkB,CAAC;AAE5D;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,QAAQ,EAAE,iBAAiB,EAAE,GAC/B,aAAa,EAAE,CA0FjB"}
@@ -0,0 +1,134 @@
1
+ import { type CreateBashToolOptions, type BashToolkit } from 'bash-tool';
2
+ import { type BinaryInstall, type DockerMount, type DockerResources, type DockerSandbox } from './docker-sandbox.ts';
3
+ /**
4
+ * Base options shared by RuntimeContainerToolOptions and DockerfileContainerToolOptions.
5
+ */
6
+ interface BaseContainerToolOptions extends Omit<CreateBashToolOptions, 'sandbox' | 'uploadDirectory'> {
7
+ /** Directories to mount from host into the container */
8
+ mounts?: DockerMount[];
9
+ /** Resource limits for the container */
10
+ resources?: DockerResources;
11
+ }
12
+ /**
13
+ * Options for container tool using RuntimeStrategy.
14
+ * Installs packages/binaries at container runtime.
15
+ */
16
+ export interface RuntimeContainerToolOptions extends BaseContainerToolOptions {
17
+ /** Docker image to use (default: 'alpine:latest') */
18
+ image?: string;
19
+ /** Packages to install in the container via package manager (apk/apt) */
20
+ packages?: string[];
21
+ /** Binaries to install from URLs (for tools not in package managers) */
22
+ binaries?: BinaryInstall[];
23
+ }
24
+ /**
25
+ * Options for container tool using DockerfileStrategy.
26
+ * Builds custom image from Dockerfile (with caching).
27
+ */
28
+ export interface DockerfileContainerToolOptions extends BaseContainerToolOptions {
29
+ /** Dockerfile content (if contains newlines) or path to Dockerfile */
30
+ dockerfile: string;
31
+ /** Build context directory (default: '.') */
32
+ context?: string;
33
+ }
34
+ /**
35
+ * Options for container tool using ComposeStrategy.
36
+ * Manages multi-container environments via Docker Compose.
37
+ */
38
+ export interface ComposeContainerToolOptions extends Omit<CreateBashToolOptions, 'sandbox' | 'uploadDirectory'> {
39
+ /** Path to docker-compose.yml file */
40
+ compose: string;
41
+ /** Service name to execute commands in (required) */
42
+ service: string;
43
+ /** Resource limits for the container */
44
+ resources?: DockerResources;
45
+ }
46
+ /**
47
+ * Union type for container tool options.
48
+ * - RuntimeContainerToolOptions: Runtime package/binary installation
49
+ * - DockerfileContainerToolOptions: Pre-built images from Dockerfile
50
+ * - ComposeContainerToolOptions: Multi-container environments via Docker Compose
51
+ */
52
+ export type ContainerToolOptions = RuntimeContainerToolOptions | DockerfileContainerToolOptions | ComposeContainerToolOptions;
53
+ /**
54
+ * Result of creating a container tool.
55
+ * Extends BashToolkit but with DockerSandbox (which has dispose()) instead of base Sandbox.
56
+ */
57
+ export type ContainerToolResult = Omit<BashToolkit, 'sandbox'> & {
58
+ sandbox: DockerSandbox;
59
+ };
60
+ /**
61
+ * Creates a bash tool that runs in a Docker container.
62
+ *
63
+ * This is a high-level wrapper that combines `createDockerSandbox()` and
64
+ * `createBashTool()` into a single call. It provides a convenient way to
65
+ * get a bash tool that executes real binaries in an isolated container.
66
+ *
67
+ * Supports three strategies:
68
+ * - **RuntimeStrategy**: Uses existing image, installs packages/binaries at runtime
69
+ * - **DockerfileStrategy**: Builds custom image from Dockerfile (with caching)
70
+ * - **ComposeStrategy**: Multi-container environments via Docker Compose
71
+ *
72
+ * @example RuntimeStrategy (default)
73
+ * ```typescript
74
+ * const { bash, tools, sandbox } = await createContainerTool({
75
+ * packages: ['curl', 'jq'],
76
+ * mounts: [{
77
+ * hostPath: process.cwd(),
78
+ * containerPath: '/workspace',
79
+ * readOnly: false,
80
+ * }],
81
+ * });
82
+ *
83
+ * // Use with AI SDK
84
+ * const response = await generateText({
85
+ * model: yourModel,
86
+ * tools,
87
+ * prompt: 'Fetch the weather data and parse it with jq',
88
+ * });
89
+ *
90
+ * // Clean up when done
91
+ * await sandbox.dispose();
92
+ * ```
93
+ *
94
+ * @example DockerfileStrategy
95
+ * ```typescript
96
+ * const { bash, tools, sandbox } = await createContainerTool({
97
+ * dockerfile: `
98
+ * FROM python:3.11-slim
99
+ * RUN pip install pandas numpy
100
+ * `,
101
+ * context: '.',
102
+ * mounts: [{
103
+ * hostPath: process.cwd(),
104
+ * containerPath: '/workspace',
105
+ * }],
106
+ * });
107
+ * ```
108
+ *
109
+ * @example ComposeStrategy
110
+ * ```typescript
111
+ * const { bash, tools, sandbox } = await createContainerTool({
112
+ * compose: './docker-compose.yml',
113
+ * service: 'app',
114
+ * });
115
+ * // Commands run in the 'app' service, can reach other services by name
116
+ * await sandbox.dispose(); // Stops ALL services
117
+ * ```
118
+ *
119
+ * @example With hooks for logging
120
+ * ```typescript
121
+ * const { bash, sandbox } = await createContainerTool({
122
+ * packages: ['python3'],
123
+ * onBeforeBashCall: ({ command }) => {
124
+ * console.log('Running:', command);
125
+ * },
126
+ * onAfterBashCall: ({ command, result }) => {
127
+ * console.log(`Exit code: ${result.exitCode}`);
128
+ * },
129
+ * });
130
+ * ```
131
+ */
132
+ export declare function createContainerTool(options?: ContainerToolOptions): Promise<ContainerToolResult>;
133
+ export {};
134
+ //# sourceMappingURL=container-tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"container-tool.d.ts","sourceRoot":"","sources":["../../../src/lib/sandbox/container-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KA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