@deepagents/context 0.10.2 → 0.12.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.
- package/README.md +114 -119
- package/dist/example-error-recovery.d.ts +2 -0
- package/dist/example-error-recovery.d.ts.map +1 -0
- package/dist/index.d.ts +18 -388
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2765 -1091
- package/dist/index.js.map +4 -4
- package/dist/lib/agent.d.ts +87 -12
- package/dist/lib/agent.d.ts.map +1 -1
- package/dist/lib/engine.d.ts +325 -0
- package/dist/lib/engine.d.ts.map +1 -0
- package/dist/lib/estimate.d.ts +1 -1
- package/dist/lib/estimate.d.ts.map +1 -1
- package/dist/lib/fragments/domain.d.ts +537 -0
- package/dist/lib/fragments/domain.d.ts.map +1 -0
- package/dist/lib/fragments/user.d.ts +122 -0
- package/dist/lib/fragments/user.d.ts.map +1 -0
- package/dist/lib/fragments.d.ts +103 -0
- package/dist/lib/fragments.d.ts.map +1 -0
- package/dist/lib/guardrail.d.ts +138 -0
- package/dist/lib/guardrail.d.ts.map +1 -0
- package/dist/lib/guardrails/error-recovery.guardrail.d.ts +3 -0
- package/dist/lib/guardrails/error-recovery.guardrail.d.ts.map +1 -0
- package/dist/lib/render.d.ts +21 -0
- package/dist/lib/render.d.ts.map +1 -0
- package/dist/lib/renderers/abstract.renderer.d.ts +11 -3
- package/dist/lib/renderers/abstract.renderer.d.ts.map +1 -1
- package/dist/lib/sandbox/binary-bridges.d.ts +31 -0
- package/dist/lib/sandbox/binary-bridges.d.ts.map +1 -0
- package/dist/lib/sandbox/container-tool.d.ts +134 -0
- package/dist/lib/sandbox/container-tool.d.ts.map +1 -0
- package/dist/lib/sandbox/docker-sandbox.d.ts +471 -0
- package/dist/lib/sandbox/docker-sandbox.d.ts.map +1 -0
- package/dist/lib/sandbox/index.d.ts +4 -0
- package/dist/lib/sandbox/index.d.ts.map +1 -0
- package/dist/lib/skills/fragments.d.ts +24 -0
- package/dist/lib/skills/fragments.d.ts.map +1 -0
- package/dist/lib/skills/index.d.ts +31 -0
- package/dist/lib/skills/index.d.ts.map +1 -0
- package/dist/lib/skills/loader.d.ts +28 -0
- package/dist/lib/skills/loader.d.ts.map +1 -0
- package/dist/lib/skills/types.d.ts +40 -0
- package/dist/lib/skills/types.d.ts.map +1 -0
- package/dist/lib/store/sqlite.store.d.ts +4 -2
- package/dist/lib/store/sqlite.store.d.ts.map +1 -1
- package/dist/lib/store/store.d.ts +36 -2
- package/dist/lib/store/store.d.ts.map +1 -1
- package/package.json +8 -4
- package/dist/lib/context.d.ts +0 -56
- package/dist/lib/context.d.ts.map +0 -1
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { type UIMessage } from 'ai';
|
|
2
|
+
import type { FragmentCodec } from './codec.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Fragment type identifier.
|
|
5
|
+
* - 'fragment': Regular context fragment (default)
|
|
6
|
+
* - 'message': Conversation message (user/assistant)
|
|
7
|
+
*/
|
|
8
|
+
export type FragmentType = 'fragment' | 'message';
|
|
9
|
+
/**
|
|
10
|
+
* A context fragment containing a name and associated data.
|
|
11
|
+
*/
|
|
12
|
+
export interface ContextFragment<T extends FragmentData = FragmentData> {
|
|
13
|
+
/**
|
|
14
|
+
* Unique identifier for this fragment.
|
|
15
|
+
* Auto-generated for user/assistant messages, optional for other fragments.
|
|
16
|
+
*/
|
|
17
|
+
id?: string;
|
|
18
|
+
name: string;
|
|
19
|
+
data: T;
|
|
20
|
+
/**
|
|
21
|
+
* Fragment type for categorization.
|
|
22
|
+
* Messages use 'message' type and are handled separately during resolve().
|
|
23
|
+
*/
|
|
24
|
+
type?: FragmentType;
|
|
25
|
+
/**
|
|
26
|
+
* When true, this fragment will be persisted to the store on save().
|
|
27
|
+
*/
|
|
28
|
+
persist?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Codec for encoding/decoding this fragment.
|
|
31
|
+
* Used by resolve() to convert to AI SDK format.
|
|
32
|
+
*/
|
|
33
|
+
codec?: FragmentCodec;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Fragment data can be a primitive, array, object, or nested fragment.
|
|
37
|
+
*/
|
|
38
|
+
export type FragmentData = string | number | null | undefined | boolean | ContextFragment | FragmentData[] | {
|
|
39
|
+
[key: string]: FragmentData;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Type guard to check if data is a ContextFragment.
|
|
43
|
+
*/
|
|
44
|
+
export declare function isFragment(data: unknown): data is ContextFragment;
|
|
45
|
+
/**
|
|
46
|
+
* A plain object with string keys and FragmentData values.
|
|
47
|
+
*/
|
|
48
|
+
export type FragmentObject = Record<string, FragmentData>;
|
|
49
|
+
/**
|
|
50
|
+
* Type guard to check if data is a plain object (not array, not fragment, not primitive).
|
|
51
|
+
*/
|
|
52
|
+
export declare function isFragmentObject(data: unknown): data is FragmentObject;
|
|
53
|
+
/**
|
|
54
|
+
* Type guard to check if a fragment is a message fragment.
|
|
55
|
+
*/
|
|
56
|
+
export declare function isMessageFragment(fragment: ContextFragment): boolean;
|
|
57
|
+
export declare function fragment(name: string, ...children: FragmentData[]): ContextFragment;
|
|
58
|
+
/**
|
|
59
|
+
* Create a user message fragment.
|
|
60
|
+
* Message fragments are separated from regular fragments during resolve().
|
|
61
|
+
*
|
|
62
|
+
* @param content - The message content
|
|
63
|
+
* @param options - Optional settings (id)
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* context.set(user('Hello')); // Auto-generated ID
|
|
68
|
+
* context.set(user('Hello', { id: 'msg-1' })); // Custom ID
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function user(content: string | UIMessage): ContextFragment;
|
|
72
|
+
/**
|
|
73
|
+
* Create an assistant message fragment.
|
|
74
|
+
* Message fragments are separated from regular fragments during resolve().
|
|
75
|
+
*
|
|
76
|
+
* @param message - The message content
|
|
77
|
+
* @param options - Optional settings (id)
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* context.set(assistant('Hi there!')); // Auto-generated ID
|
|
82
|
+
* context.set(assistant('Hi there!', { id: 'resp-1' })); // Custom ID
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare function assistant(message: UIMessage): ContextFragment;
|
|
86
|
+
export declare function message(content: string | UIMessage): ContextFragment;
|
|
87
|
+
/**
|
|
88
|
+
* Create an assistant message fragment from text content.
|
|
89
|
+
* Convenience wrapper that creates a UIMessage internally.
|
|
90
|
+
*
|
|
91
|
+
* @param content - The message text content
|
|
92
|
+
* @param options - Optional settings (id)
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* context.set(assistantText('Hi there!')); // Auto-generated ID
|
|
97
|
+
* context.set(assistantText('Hi there!', { id: 'resp-1' })); // Custom ID
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare function assistantText(content: string, options?: {
|
|
101
|
+
id?: string;
|
|
102
|
+
}): ContextFragment;
|
|
103
|
+
//# sourceMappingURL=fragments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fragments.d.ts","sourceRoot":"","sources":["../../src/lib/fragments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAc,MAAM,IAAI,CAAC;AAEhD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,SAAS,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY;IACpE;;;OAGG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,CAAC,CAAC;IACR;;;OAGG;IACH,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB;;OAEG;IACH,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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":[],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Ae,CAejB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-recovery.guardrail.d.ts","sourceRoot":"","sources":["../../../src/lib/guardrails/error-recovery.guardrail.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjD,eAAO,MAAM,sBAAsB,EAAE,SAsFpC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ContextFragment } from './fragments.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Render fragments to XML.
|
|
4
|
+
*
|
|
5
|
+
* Wraps fragments in a parent tag and renders using XmlRenderer.
|
|
6
|
+
*
|
|
7
|
+
* @param tag - Parent tag name (e.g., 'instructions')
|
|
8
|
+
* @param fragments - Fragments to render
|
|
9
|
+
* @returns XML string
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const xml = render(
|
|
14
|
+
* 'instructions',
|
|
15
|
+
* persona({ name: 'Freya', role: 'Data Assistant' }),
|
|
16
|
+
* guardrail({ rule: 'Never expose PII' }),
|
|
17
|
+
* );
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function render(tag: string, ...fragments: ContextFragment[]): string;
|
|
21
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/lib/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAY,MAAM,gBAAgB,CAAC;AAGhE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,eAAe,EAAE,GAAG,MAAM,CAQ3E"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ContextFragment, type FragmentData, type FragmentObject } from '../
|
|
1
|
+
import { type ContextFragment, type FragmentData, type FragmentObject } from '../fragments.ts';
|
|
2
2
|
/**
|
|
3
3
|
* Render context passed through the template method.
|
|
4
4
|
*/
|
|
@@ -32,6 +32,14 @@ export declare abstract class ContextRenderer {
|
|
|
32
32
|
* Group fragments by name for groupFragments option.
|
|
33
33
|
*/
|
|
34
34
|
protected groupByName(fragments: ContextFragment[]): Map<string, ContextFragment[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Remove null/undefined from fragments and fragment data recursively.
|
|
37
|
+
* This protects renderers from nullish values and ensures they are ignored
|
|
38
|
+
* consistently across all output formats.
|
|
39
|
+
*/
|
|
40
|
+
protected sanitizeFragments(fragments: ContextFragment[]): ContextFragment[];
|
|
41
|
+
protected sanitizeFragment(fragment: ContextFragment, seen: WeakSet<object>): ContextFragment | null;
|
|
42
|
+
protected sanitizeData(data: FragmentData, seen: WeakSet<object>): FragmentData | undefined;
|
|
35
43
|
/**
|
|
36
44
|
* Template method - dispatches value to appropriate handler.
|
|
37
45
|
*/
|
|
@@ -80,8 +88,8 @@ export declare class TomlRenderer extends ContextRenderer {
|
|
|
80
88
|
* Override renderValue to preserve type information for TOML formatting.
|
|
81
89
|
*/
|
|
82
90
|
protected renderValue(key: string, value: unknown, ctx: RenderContext): string;
|
|
83
|
-
protected renderPrimitive(key: string, value: string,
|
|
84
|
-
protected renderArray(key: string, items: FragmentData[],
|
|
91
|
+
protected renderPrimitive(key: string, value: string, ctx: RenderContext): string;
|
|
92
|
+
protected renderArray(key: string, items: FragmentData[], ctx: RenderContext): string;
|
|
85
93
|
protected renderObject(key: string, obj: FragmentObject, ctx: RenderContext): string;
|
|
86
94
|
protected renderFragment(fragment: ContextFragment, ctx: RenderContext): string;
|
|
87
95
|
}
|
|
@@ -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,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AAM;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":"AACA,OAAO,EAAE,KAAK,aAAa,EAAiB,MAAM,WAAW,CAAC;AAI9D,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,CA2GjB"}
|
|
@@ -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,KAAK,qBAAqB,EAC1B,KAAK,WAAW,EACjB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAIL,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,aAAa,EAEnB,MAAM,qBAAqB,CAAC;AAE7B;;GAEG;AACH,UAAU,wBACR,SAAQ,IAAI,CAAC,qBAAqB,EAAE,SAAS,GAAG,iBAAiB,CAAC;IAClE,wDAAwD;IACxD,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;IACvB,wCAAwC;IACxC,SAAS,CAAC,EAAE,eAAe,CA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