@fabric-harness/sdk 2.7.0 → 3.0.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 +6 -6
- package/dist/agent-definition.d.ts +33 -57
- package/dist/agent-definition.d.ts.map +1 -1
- package/dist/agent-definition.js +129 -147
- package/dist/agent-definition.js.map +1 -1
- package/dist/cloudflare-source.d.ts +2 -2
- package/dist/cloudflare-source.js +2 -2
- package/dist/dispatch.d.ts +3 -14
- package/dist/dispatch.d.ts.map +1 -1
- package/dist/dispatch.js +5 -6
- package/dist/dispatch.js.map +1 -1
- package/dist/filesystem-source.d.ts +2 -2
- package/dist/filesystem-source.js +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -4
- package/dist/index.js.map +1 -1
- package/dist/job-invoke.d.ts +3 -3
- package/dist/job-invoke.d.ts.map +1 -1
- package/dist/job-invoke.js +9 -9
- package/dist/job-invoke.js.map +1 -1
- package/dist/persistent-agent.d.ts +1 -1
- package/dist/strict.d.ts +3 -3
- package/dist/strict.d.ts.map +1 -1
- package/dist/strict.js +2 -2
- package/dist/strict.js.map +1 -1
- package/dist/submission-runner.d.ts.map +1 -1
- package/dist/submission-runner.js +1 -6
- package/dist/submission-runner.js.map +1 -1
- package/dist/submission-store-contract.d.ts.map +1 -1
- package/dist/submission-store-contract.js +0 -1
- package/dist/submission-store-contract.js.map +1 -1
- package/dist/webhook-subscription.d.ts +2 -2
- package/dist/webhook-subscription.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,9 +15,9 @@ pnpm add @fabric-harness/sdk
|
|
|
15
15
|
### Minimal — bare import, headless defaults (8 lines)
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
|
-
import {
|
|
18
|
+
import { defineAgent } from '@fabric-harness/sdk';
|
|
19
19
|
|
|
20
|
-
export default
|
|
20
|
+
export default defineAgent<{ message: string }>({
|
|
21
21
|
name: 'echo',
|
|
22
22
|
triggers: { webhook: true },
|
|
23
23
|
run: async ({ init, input }) => {
|
|
@@ -32,9 +32,9 @@ export default agent<{ message: string }>({
|
|
|
32
32
|
### With typed I/O + capability policy + skills (same import)
|
|
33
33
|
|
|
34
34
|
```ts
|
|
35
|
-
import {
|
|
35
|
+
import { defineAgent, schema } from '@fabric-harness/sdk';
|
|
36
36
|
|
|
37
|
-
export default
|
|
37
|
+
export default defineAgent({
|
|
38
38
|
name: 'triage',
|
|
39
39
|
input: schema.object({ issueNumber: schema.number(), title: schema.string() }),
|
|
40
40
|
output: schema.object({ severity: schema.enum(['low','medium','high']), summary: schema.string() }),
|
|
@@ -50,7 +50,7 @@ Both forms share the same `init()`, `session.prompt()` / `skill()` / `task()` /
|
|
|
50
50
|
|
|
51
51
|
## One SDK, one import
|
|
52
52
|
|
|
53
|
-
`@fabric-harness/sdk` is the single import everyone uses. `
|
|
53
|
+
`@fabric-harness/sdk` is the single import everyone uses. `defineAgent({...})` from the bare import auto-injects headless defaults (`runtime: 'stateless'`, `sandbox: 'virtual'`, `loopRuntime: pi-agent-core`, `compaction: { enabled: true }`) on every `init()` call. Override any of them by passing values to `init()`. Add typed `input`/`output` schemas, `policy`, artifacts, custom stores, telemetry — they're all options on the same `defineAgent({...})`/`init()` shape.
|
|
54
54
|
|
|
55
55
|
For Temporal-backed durable agents or compliance workloads where no implicit behaviour is wanted, use `@fabric-harness/sdk/strict` — same call shape, no defaults injected.
|
|
56
56
|
|
|
@@ -64,7 +64,7 @@ Runtime (`stateless`, `inline`, or `temporal`) controls persistence and durabili
|
|
|
64
64
|
- **`session.approval.request({ reason, risk?, timeoutMs? })`** — custom approval gate. Returns `true` on approval; throws `APPROVAL_DENIED` / `APPROVAL_REQUIRED` on denial / timeout.
|
|
65
65
|
- **`ApprovalResponse.grant`** — durable approved responses carry the call/input/principal-bound
|
|
66
66
|
grant; denied responses never do.
|
|
67
|
-
- **`
|
|
67
|
+
- **`defineAgent({...})`** — single builder. Same call shape from the bare `@fabric-harness/sdk` import and from `@fabric-harness/sdk/strict`; the import you choose controls whether headless defaults are injected at runtime.
|
|
68
68
|
- **`defineCommand`** — bind a privileged CLI (`gh`, `npm`, …) with secrets at the command level, never in model context.
|
|
69
69
|
- **`withFilesystemSources`** / **`session.mount()`** — two ways to mount read-only content into a sandbox; agent's built-in `grep` / `glob` / `read` tools see it as ordinary files.
|
|
70
70
|
- **`runtime: 'inline' | 'stateless' | 'temporal'`** + **`sessionRuntime`** — pick by persistence needs. Pair `runtime: 'temporal'` with `temporalSessionRuntime({...})` from `@fabric-harness/temporal` to route every session call through durable workflows.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { AgentInit, FabricContext, JsonObject, PromptOptions, SessionOptions, ShellOptions, ShellResult, Skill, SkillOptions, TaskOptions } from
|
|
2
|
-
import type { FabricSession } from
|
|
3
|
-
import type { Schema } from
|
|
4
|
-
import type { WebhookSubscriptionDefinition } from
|
|
5
|
-
import type { ToolDef } from
|
|
6
|
-
import
|
|
7
|
-
import { invoke as invokeJob, type JobInvocationContext } from
|
|
1
|
+
import type { AgentInit, FabricContext, JsonObject, PromptOptions, SessionOptions, ShellOptions, ShellResult, Skill, SkillOptions, TaskOptions } from "./types.js";
|
|
2
|
+
import type { FabricSession } from "./session.js";
|
|
3
|
+
import type { Schema } from "./schema.js";
|
|
4
|
+
import type { WebhookSubscriptionDefinition } from "./webhook-subscription.js";
|
|
5
|
+
import type { ToolDef } from "./tools.js";
|
|
6
|
+
import type { CapabilityPolicy } from "./policy.js";
|
|
7
|
+
import { invoke as invokeJob, type JobInvocationContext } from "./job-invoke.js";
|
|
8
8
|
export interface AgentTriggers {
|
|
9
9
|
webhook?: boolean;
|
|
10
10
|
schedule?: string | string[];
|
|
@@ -18,13 +18,17 @@ export interface AgentDefinition<TInput = JsonObject, TOutput = unknown> {
|
|
|
18
18
|
input?: Schema<TInput>;
|
|
19
19
|
output?: Schema<TOutput>;
|
|
20
20
|
model?: string;
|
|
21
|
-
target?:
|
|
21
|
+
target?: "node" | "temporal-worker";
|
|
22
22
|
skills?: Skill[];
|
|
23
23
|
tools?: ToolDef[];
|
|
24
24
|
triggers?: AgentTriggers;
|
|
25
|
-
policy?: import(
|
|
26
|
-
costBudget?: import(
|
|
27
|
-
approvals?: import(
|
|
25
|
+
policy?: import("./policy.js").CapabilityPolicy;
|
|
26
|
+
costBudget?: import("./cost-budget.js").CostLimit;
|
|
27
|
+
approvals?: import("./types.js").ApprovalOptions;
|
|
28
|
+
/** Options applied when the agent lazily initializes its runtime. */
|
|
29
|
+
init?: AgentInit;
|
|
30
|
+
/** Ordered wrappers for logging, tracing, authorization, and shared concerns. */
|
|
31
|
+
middleware?: readonly AgentMiddleware<TInput, TOutput>[];
|
|
28
32
|
/**
|
|
29
33
|
* Webhook subscription definitions. Each subscription gets its own HTTP
|
|
30
34
|
* route (`/agents/<name>/subscriptions/<id>`) on the Node server and wakes the
|
|
@@ -32,12 +36,10 @@ export interface AgentDefinition<TInput = JsonObject, TOutput = unknown> {
|
|
|
32
36
|
* land here — fabric-harness has no opinion on the upstream taxonomy.
|
|
33
37
|
*/
|
|
34
38
|
subscriptions?: WebhookSubscriptionDefinition<unknown>[];
|
|
35
|
-
run: (context:
|
|
36
|
-
input: TInput;
|
|
37
|
-
}) => Promise<TOutput> | TOutput;
|
|
39
|
+
run: (context: AgentRunContext<TInput>) => Promise<TOutput> | TOutput;
|
|
38
40
|
}
|
|
39
|
-
/** Runtime-ready context for finite
|
|
40
|
-
export interface
|
|
41
|
+
/** Runtime-ready context for finite agents. The default session is initialized lazily. */
|
|
42
|
+
export interface AgentRunContext<TInput = JsonObject> extends FabricContext<TInput> {
|
|
41
43
|
input: TInput;
|
|
42
44
|
/** Stable server-side run identity, available when admitted through a job runtime. */
|
|
43
45
|
run?: JobInvocationContext;
|
|
@@ -49,26 +51,18 @@ export interface JobContext<TInput = JsonObject> extends FabricContext<TInput> {
|
|
|
49
51
|
/** Admit a child finite job without an HTTP round trip. */
|
|
50
52
|
invoke: typeof invokeJob;
|
|
51
53
|
}
|
|
52
|
-
export type
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
init?: AgentInit;
|
|
56
|
-
/** Ordered wrappers for logging, tracing, authorization, and shared job concerns. */
|
|
57
|
-
middleware?: readonly JobMiddleware<TInput, TOutput>[];
|
|
58
|
-
run: (context: JobContext<TInput>) => Promise<TOutput> | TOutput;
|
|
59
|
-
}
|
|
54
|
+
export type AgentMiddleware<TInput = JsonObject, TOutput = unknown> = {
|
|
55
|
+
bivarianceHack(context: AgentRunContext<TInput>, next: () => Promise<TOutput>): Promise<TOutput> | TOutput;
|
|
56
|
+
}["bivarianceHack"];
|
|
60
57
|
declare const definitionSymbol: unique symbol;
|
|
58
|
+
type AgentDefinitionMetadata<TInput> = Omit<AgentDefinition<TInput, unknown>, "middleware" | "run"> & {
|
|
59
|
+
middleware?: readonly AgentMiddleware<TInput, unknown>[];
|
|
60
|
+
run: (context: AgentRunContext<TInput>) => unknown;
|
|
61
|
+
};
|
|
61
62
|
export type DefinedAgent<TInput = JsonObject, TOutput = unknown> = ((context: FabricContext<TInput>) => Promise<TOutput> | TOutput) & {
|
|
62
|
-
readonly [definitionSymbol]:
|
|
63
|
-
readonly __fabricAgent?:
|
|
63
|
+
readonly [definitionSymbol]: AgentDefinitionMetadata<TInput>;
|
|
64
|
+
readonly __fabricAgent?: AgentDefinitionMetadata<TInput>;
|
|
64
65
|
};
|
|
65
|
-
/**
|
|
66
|
-
* No-defaults agent builder. Exported as `agent` from
|
|
67
|
-
* `@fabric-harness/sdk/strict`. Every `init()` option must be declared
|
|
68
|
-
* explicitly — useful for Temporal replay determinism and audit/compliance
|
|
69
|
-
* workloads where implicit behaviour is unwelcome.
|
|
70
|
-
*/
|
|
71
|
-
export declare function agent<TInput = JsonObject, TOutput = unknown>(definition: AgentDefinition<TInput, TOutput>): DefinedAgent<TInput, TOutput>;
|
|
72
66
|
/**
|
|
73
67
|
* No-defaults finite-agent builder with lazy default-session helpers.
|
|
74
68
|
*
|
|
@@ -76,32 +70,14 @@ export declare function agent<TInput = JsonObject, TOutput = unknown>(definition
|
|
|
76
70
|
* but authors define an agent. Use {@link createAgent} for a persistent,
|
|
77
71
|
* URL-addressable agent whose sessions span multiple submissions.
|
|
78
72
|
*/
|
|
79
|
-
export declare function defineAgent<TInput = JsonObject, TOutput = unknown>(definition:
|
|
80
|
-
/** @deprecated Persistent definitions should call `createAgent(initializer)` directly. */
|
|
81
|
-
export declare function defineAgent<TEnv = Record<string, string | undefined>>(initialize: (context: PersistentAgentContext<TEnv>) => PersistentAgentConfig | Promise<PersistentAgentConfig>): CreatedAgent<TEnv>;
|
|
82
|
-
/** @deprecated Use {@link defineAgent}. */
|
|
83
|
-
export declare const defineJob: <TInput = JsonObject, TOutput = unknown>(definition: JobDefinition<TInput, TOutput>) => DefinedAgent<TInput, TOutput>;
|
|
73
|
+
export declare function defineAgent<TInput = JsonObject, TOutput = unknown>(definition: AgentDefinition<TInput, TOutput>): DefinedAgent<TInput, TOutput>;
|
|
84
74
|
/** Defaults-injecting finite-agent builder exported from the bare SDK entry point. */
|
|
85
|
-
export declare function defineAgentWithDefaults<TInput = JsonObject, TOutput = unknown>(definition:
|
|
86
|
-
/** @deprecated Persistent definitions should call `createAgent(initializer)` directly. */
|
|
87
|
-
export declare function defineAgentWithDefaults<TEnv = Record<string, string | undefined>>(initialize: (context: PersistentAgentContext<TEnv>) => PersistentAgentConfig | Promise<PersistentAgentConfig>): CreatedAgent<TEnv>;
|
|
88
|
-
/** @deprecated Use {@link defineAgentWithDefaults}. */
|
|
89
|
-
export declare const defineJobWithDefaults: <TInput = JsonObject, TOutput = unknown>(definition: JobDefinition<TInput, TOutput>) => DefinedAgent<TInput, TOutput>;
|
|
90
|
-
export declare function getAgentDefinition(value: unknown): AgentDefinition<unknown, unknown> | undefined;
|
|
75
|
+
export declare function defineAgentWithDefaults<TInput = JsonObject, TOutput = unknown>(definition: AgentDefinition<TInput, TOutput>): DefinedAgent<TInput, TOutput>;
|
|
91
76
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* defaults are applied unless the caller overrides them:
|
|
95
|
-
*
|
|
96
|
-
* - `runtime: 'stateless'`
|
|
97
|
-
* - `sandbox: 'virtual'`
|
|
98
|
-
* - `loopRuntime: pi-agent-core`
|
|
99
|
-
* - `compaction: { enabled: true }`
|
|
100
|
-
*
|
|
101
|
-
* If `runtime: 'temporal'` is selected from this builder, a one-time
|
|
102
|
-
* `console.warn` is emitted because auto-compaction is non-deterministic
|
|
103
|
-
* across Temporal replay. Use `@fabric-harness/sdk/strict` for Temporal.
|
|
77
|
+
* Treat a definition policy as a security floor. Invocation policy can add
|
|
78
|
+
* denials and approval requirements, but cannot replace definition allowlists.
|
|
104
79
|
*/
|
|
105
|
-
export declare function
|
|
80
|
+
export declare function mergeCapabilityPolicies(definition: CapabilityPolicy | undefined, invocation: CapabilityPolicy | undefined): CapabilityPolicy | undefined;
|
|
81
|
+
export declare function getAgentDefinition(value: unknown): AgentDefinition<unknown, unknown> | undefined;
|
|
106
82
|
export {};
|
|
107
83
|
//# sourceMappingURL=agent-definition.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-definition.d.ts","sourceRoot":"","sources":["../src/agent-definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EACb,UAAU,EACV,aAAa,EACb,cAAc,EACd,YAAY,EACZ,WAAW,EACX,KAAK,EACL,YAAY,EACZ,WAAW,EACZ,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE/E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"agent-definition.d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AG,UAAU,EAAE,OAAO,GAAG,OAAO,EAChE,UAAU,EAAE,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3C,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAE/B;AAED,sFAAsF;AACtF,wBAAgB,uBAAuB,CAAC,MAAM,GAAG,UAAU,EAAE,OAAO,GAAG,OAAO,EAC5E,UAAU,EAAE,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3C,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAE/B;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,gBAAgB,GAAG,SAAS,EACxC,UAAU,EAAE,gBAAgB,GAAG,SAAS,GACvC,gBAAgB,GAAG,SAAS,CAkE9B;AAuMD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,SAAS,CAShG"}
|
package/dist/agent-definition.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { getLogger } from
|
|
2
|
-
import {
|
|
3
|
-
import { currentJobInvocation, invoke as invokeJob, } from './job-invoke.js';
|
|
1
|
+
import { getLogger } from "./logger.js";
|
|
2
|
+
import { currentJobInvocation, invoke as invokeJob, } from "./job-invoke.js";
|
|
4
3
|
/**
|
|
5
4
|
* Lazy singleton: the bare-import default loop runtime is `pi-agent-core`.
|
|
6
5
|
* Constructed on first defaults-injecting `init()` so users who only import
|
|
@@ -9,7 +8,7 @@ import { currentJobInvocation, invoke as invokeJob, } from './job-invoke.js';
|
|
|
9
8
|
let _defaultLoopRuntime;
|
|
10
9
|
async function getDefaultLoopRuntime() {
|
|
11
10
|
if (!_defaultLoopRuntime) {
|
|
12
|
-
const { createPiAgentLoopRuntime } = await import(
|
|
11
|
+
const { createPiAgentLoopRuntime } = await import("./pi-loop-runtime.js");
|
|
13
12
|
_defaultLoopRuntime = createPiAgentLoopRuntime();
|
|
14
13
|
}
|
|
15
14
|
return _defaultLoopRuntime;
|
|
@@ -21,20 +20,16 @@ function warnTemporalOnBare() {
|
|
|
21
20
|
return;
|
|
22
21
|
_warnedTemporalOnBare = true;
|
|
23
22
|
getLogger().warn('runtime: "temporal" was selected from the bare `@fabric-harness/sdk` import. ' +
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
"The bare import injects `compaction: { enabled: true }` by default, which is non-deterministic " +
|
|
24
|
+
"across Temporal replay. Use `@fabric-harness/sdk/strict` (no defaults) for Temporal workflows, " +
|
|
25
|
+
"or pass `compaction: { enabled: false }` explicitly to silence this warning.");
|
|
27
26
|
}
|
|
28
|
-
const definitionSymbol = Symbol.for(
|
|
29
|
-
|
|
30
|
-
* No-defaults agent builder. Exported as `agent` from
|
|
31
|
-
* `@fabric-harness/sdk/strict`. Every `init()` option must be declared
|
|
32
|
-
* explicitly — useful for Temporal replay determinism and audit/compliance
|
|
33
|
-
* workloads where implicit behaviour is unwelcome.
|
|
34
|
-
*/
|
|
35
|
-
export function agent(definition) {
|
|
27
|
+
const definitionSymbol = Symbol.for("fabric-harness.agent-definition");
|
|
28
|
+
function createDefinedAgent(definition, injectDefaults) {
|
|
36
29
|
const handler = (async (context) => {
|
|
37
|
-
const parsedInput = definition.input
|
|
30
|
+
const parsedInput = definition.input
|
|
31
|
+
? definition.input.parse(context.payload, "$")
|
|
32
|
+
: context.payload;
|
|
38
33
|
const wrappedContext = {
|
|
39
34
|
...context,
|
|
40
35
|
payload: parsedInput,
|
|
@@ -43,94 +38,106 @@ export function agent(definition) {
|
|
|
43
38
|
const policy = mergeCapabilityPolicies(definition.policy, options.policy);
|
|
44
39
|
const costLimit = mergeCostLimits(definition.costBudget, options.costLimit);
|
|
45
40
|
const approvalTimeoutMs = minimumDefined(definition.approvals?.timeoutMs, options.approvalTimeoutMs);
|
|
46
|
-
|
|
41
|
+
const merged = {
|
|
47
42
|
...(definition.model && options.model === undefined ? { model: definition.model } : {}),
|
|
48
43
|
...options,
|
|
49
44
|
...(definition.name && options.name === undefined ? { name: definition.name } : {}),
|
|
50
45
|
...(definition.instructions !== undefined && options.role === undefined
|
|
51
|
-
? {
|
|
46
|
+
? {
|
|
47
|
+
role: { name: definition.name ?? "instructions", content: definition.instructions },
|
|
48
|
+
}
|
|
49
|
+
: {}),
|
|
50
|
+
...(definition.skills || options.skills
|
|
51
|
+
? { skills: [...(definition.skills ?? []), ...(options.skills ?? [])] }
|
|
52
|
+
: {}),
|
|
53
|
+
...(definition.tools || options.tools
|
|
54
|
+
? { tools: [...(definition.tools ?? []), ...(options.tools ?? [])] }
|
|
52
55
|
: {}),
|
|
53
|
-
...(definition.skills || options.skills ? { skills: [...(definition.skills ?? []), ...(options.skills ?? [])] } : {}),
|
|
54
|
-
...(definition.tools || options.tools ? { tools: [...(definition.tools ?? []), ...(options.tools ?? [])] } : {}),
|
|
55
56
|
...(policy ? { policy } : {}),
|
|
56
57
|
...(costLimit ? { costLimit } : {}),
|
|
57
58
|
...(approvalTimeoutMs !== undefined ? { approvalTimeoutMs } : {}),
|
|
58
|
-
}
|
|
59
|
+
};
|
|
60
|
+
if (injectDefaults) {
|
|
61
|
+
if (merged.runtime === "temporal" && merged.compaction === undefined)
|
|
62
|
+
warnTemporalOnBare();
|
|
63
|
+
return context.init({
|
|
64
|
+
...merged,
|
|
65
|
+
runtime: merged.runtime ?? "stateless",
|
|
66
|
+
sandbox: merged.sandbox ?? "virtual",
|
|
67
|
+
loopRuntime: merged.loopRuntime ?? (await getDefaultLoopRuntime()),
|
|
68
|
+
compaction: merged.compaction ?? { enabled: true },
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return context.init(merged);
|
|
59
72
|
},
|
|
60
73
|
};
|
|
61
|
-
const
|
|
62
|
-
|
|
74
|
+
const runContext = createAgentRunContext(wrappedContext, definition.init);
|
|
75
|
+
let execute = () => Promise.resolve(definition.run(runContext));
|
|
76
|
+
for (const item of [...(definition.middleware ?? [])].reverse()) {
|
|
77
|
+
const next = execute;
|
|
78
|
+
execute = () => {
|
|
79
|
+
let called = false;
|
|
80
|
+
return Promise.resolve(item(runContext, () => {
|
|
81
|
+
if (called)
|
|
82
|
+
throw new Error("[fabric-harness] Agent middleware next() may only be called once.");
|
|
83
|
+
called = true;
|
|
84
|
+
return next();
|
|
85
|
+
}));
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const output = await execute();
|
|
89
|
+
return definition.output ? definition.output.parse(output, "$") : output;
|
|
63
90
|
});
|
|
64
91
|
Object.defineProperty(handler, definitionSymbol, { value: definition, enumerable: false });
|
|
65
|
-
Object.defineProperty(handler,
|
|
92
|
+
Object.defineProperty(handler, "__fabricAgent", { value: definition, enumerable: false });
|
|
66
93
|
return handler;
|
|
67
94
|
}
|
|
95
|
+
function createAgentRunContext(context, initOptions) {
|
|
96
|
+
let agentPromise;
|
|
97
|
+
let defaultSessionPromise;
|
|
98
|
+
const getAgent = () => {
|
|
99
|
+
agentPromise ??= context.init(initOptions);
|
|
100
|
+
return agentPromise;
|
|
101
|
+
};
|
|
102
|
+
const session = (id, options) => {
|
|
103
|
+
if (id === undefined && options === undefined) {
|
|
104
|
+
defaultSessionPromise ??= getAgent().then((fabric) => fabric.session());
|
|
105
|
+
return defaultSessionPromise;
|
|
106
|
+
}
|
|
107
|
+
return getAgent().then((fabric) => fabric.session(id, options));
|
|
108
|
+
};
|
|
109
|
+
const invocation = currentJobInvocation();
|
|
110
|
+
return {
|
|
111
|
+
...context,
|
|
112
|
+
input: context.input,
|
|
113
|
+
...(invocation ? { run: invocation } : {}),
|
|
114
|
+
session,
|
|
115
|
+
prompt: async (text, options) => (await session()).prompt(text, options),
|
|
116
|
+
skill: async (name, options) => (await session()).skill(name, options),
|
|
117
|
+
task: async (text, options) => (await session()).task(text, options),
|
|
118
|
+
shell: async (command, options) => (await session()).shell(command, options),
|
|
119
|
+
invoke: invokeJob,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* No-defaults finite-agent builder with lazy default-session helpers.
|
|
124
|
+
*
|
|
125
|
+
* The runtime admits these finite definitions through its job/run protocol,
|
|
126
|
+
* but authors define an agent. Use {@link createAgent} for a persistent,
|
|
127
|
+
* URL-addressable agent whose sessions span multiple submissions.
|
|
128
|
+
*/
|
|
68
129
|
export function defineAgent(definition) {
|
|
69
|
-
|
|
70
|
-
return createAgent(definition);
|
|
71
|
-
return agent(toAgentDefinition(definition));
|
|
130
|
+
return createDefinedAgent(definition, false);
|
|
72
131
|
}
|
|
73
|
-
/**
|
|
74
|
-
export const defineJob = defineAgent;
|
|
132
|
+
/** Defaults-injecting finite-agent builder exported from the bare SDK entry point. */
|
|
75
133
|
export function defineAgentWithDefaults(definition) {
|
|
76
|
-
|
|
77
|
-
return createAgent(definition);
|
|
78
|
-
return agentWithDefaults(toAgentDefinition(definition));
|
|
79
|
-
}
|
|
80
|
-
/** @deprecated Use {@link defineAgentWithDefaults}. */
|
|
81
|
-
export const defineJobWithDefaults = defineAgentWithDefaults;
|
|
82
|
-
function toAgentDefinition(definition) {
|
|
83
|
-
const { run, init: initOptions, middleware = [], ...metadata } = definition;
|
|
84
|
-
return {
|
|
85
|
-
...metadata,
|
|
86
|
-
async run(context) {
|
|
87
|
-
let agentPromise;
|
|
88
|
-
let defaultSessionPromise;
|
|
89
|
-
const getAgent = () => {
|
|
90
|
-
agentPromise ??= context.init(initOptions);
|
|
91
|
-
return agentPromise;
|
|
92
|
-
};
|
|
93
|
-
const session = (id, options) => {
|
|
94
|
-
if (id === undefined && options === undefined) {
|
|
95
|
-
defaultSessionPromise ??= getAgent().then((fabric) => fabric.session());
|
|
96
|
-
return defaultSessionPromise;
|
|
97
|
-
}
|
|
98
|
-
return getAgent().then((fabric) => fabric.session(id, options));
|
|
99
|
-
};
|
|
100
|
-
const invocation = currentJobInvocation();
|
|
101
|
-
const jobContext = {
|
|
102
|
-
...context,
|
|
103
|
-
input: context.input,
|
|
104
|
-
...(invocation ? { run: invocation } : {}),
|
|
105
|
-
session,
|
|
106
|
-
prompt: async (text, options) => (await session()).prompt(text, options),
|
|
107
|
-
skill: async (name, options) => (await session()).skill(name, options),
|
|
108
|
-
task: async (text, options) => (await session()).task(text, options),
|
|
109
|
-
shell: async (command, options) => (await session()).shell(command, options),
|
|
110
|
-
invoke: invokeJob,
|
|
111
|
-
};
|
|
112
|
-
let execute = () => Promise.resolve(run(jobContext));
|
|
113
|
-
for (const item of [...middleware].reverse()) {
|
|
114
|
-
const next = execute;
|
|
115
|
-
execute = () => {
|
|
116
|
-
let called = false;
|
|
117
|
-
return Promise.resolve(item(jobContext, () => {
|
|
118
|
-
if (called)
|
|
119
|
-
throw new Error('[fabric-harness] Job middleware next() may only be called once.');
|
|
120
|
-
called = true;
|
|
121
|
-
return next();
|
|
122
|
-
}));
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
return execute();
|
|
126
|
-
},
|
|
127
|
-
};
|
|
134
|
+
return createDefinedAgent(definition, true);
|
|
128
135
|
}
|
|
129
136
|
/**
|
|
130
137
|
* Treat a definition policy as a security floor. Invocation policy can add
|
|
131
138
|
* denials and approval requirements, but cannot replace definition allowlists.
|
|
132
139
|
*/
|
|
133
|
-
function mergeCapabilityPolicies(definition, invocation) {
|
|
140
|
+
export function mergeCapabilityPolicies(definition, invocation) {
|
|
134
141
|
if (!definition)
|
|
135
142
|
return invocation;
|
|
136
143
|
if (!invocation)
|
|
@@ -138,7 +145,7 @@ function mergeCapabilityPolicies(definition, invocation) {
|
|
|
138
145
|
const commandAllow = intersectAllowPatterns(definition.commands, invocation.commands, true);
|
|
139
146
|
let commandPolicy = mergeNamedPolicy(definition.commandPolicy, invocation.commandPolicy);
|
|
140
147
|
if (commandAllow) {
|
|
141
|
-
commandPolicy = mergeNamedPolicy(commandPolicy, commandAllow.length > 0 ? { allow: commandAllow } : { deny: [
|
|
148
|
+
commandPolicy = mergeNamedPolicy(commandPolicy, commandAllow.length > 0 ? { allow: commandAllow } : { deny: ["*"] });
|
|
142
149
|
}
|
|
143
150
|
const toolPolicy = mergeNamedPolicy(definition.toolPolicy, invocation.toolPolicy);
|
|
144
151
|
const read = intersectAllowPatterns(definition.filesystem?.read, invocation.filesystem?.read);
|
|
@@ -147,8 +154,8 @@ function mergeCapabilityPolicies(definition, invocation) {
|
|
|
147
154
|
? {
|
|
148
155
|
read: read?.length ? read : undefined,
|
|
149
156
|
write: write?.length ? write : undefined,
|
|
150
|
-
readDeny: union(union(definition.filesystem?.readDeny, invocation.filesystem?.readDeny), read && read.length === 0 ? [
|
|
151
|
-
writeDeny: union(union(definition.filesystem?.writeDeny, invocation.filesystem?.writeDeny), write && write.length === 0 ? [
|
|
157
|
+
readDeny: union(union(definition.filesystem?.readDeny, invocation.filesystem?.readDeny), read && read.length === 0 ? ["**"] : undefined),
|
|
158
|
+
writeDeny: union(union(definition.filesystem?.writeDeny, invocation.filesystem?.writeDeny), write && write.length === 0 ? ["**"] : undefined),
|
|
152
159
|
readRequireApproval: union(definition.filesystem?.readRequireApproval, invocation.filesystem?.readRequireApproval),
|
|
153
160
|
writeRequireApproval: union(definition.filesystem?.writeRequireApproval, invocation.filesystem?.writeRequireApproval),
|
|
154
161
|
}
|
|
@@ -181,7 +188,7 @@ function mergeNamedPolicy(definition, invocation) {
|
|
|
181
188
|
const allow = intersectAllowPatterns(definition.allow, invocation.allow, true);
|
|
182
189
|
return compactObject({
|
|
183
190
|
allow: allow?.length ? allow : undefined,
|
|
184
|
-
deny: union(union(definition.deny, invocation.deny), allow && allow.length === 0 ? [
|
|
191
|
+
deny: union(union(definition.deny, invocation.deny), allow && allow.length === 0 ? ["*"] : undefined),
|
|
185
192
|
requireApproval: union(definition.requireApproval, invocation.requireApproval),
|
|
186
193
|
approvalRules: [...(definition.approvalRules ?? []), ...(invocation.approvalRules ?? [])],
|
|
187
194
|
});
|
|
@@ -194,24 +201,31 @@ function mergeNetworkPolicy(definition, invocation) {
|
|
|
194
201
|
const definitionMode = effectiveNetworkMode(definition);
|
|
195
202
|
const invocationMode = effectiveNetworkMode(invocation);
|
|
196
203
|
const controls = {
|
|
197
|
-
...(
|
|
198
|
-
...(
|
|
204
|
+
...(definition.resolveDns || invocation.resolveDns ? { resolveDns: true } : {}),
|
|
205
|
+
...(definition.allowPrivateNetwork === true && invocation.allowPrivateNetwork === true
|
|
206
|
+
? { allowPrivateNetwork: true }
|
|
207
|
+
: {}),
|
|
199
208
|
};
|
|
200
|
-
if (definitionMode ===
|
|
201
|
-
return { mode:
|
|
209
|
+
if (definitionMode === "none" || invocationMode === "none")
|
|
210
|
+
return { mode: "none", ...controls };
|
|
202
211
|
const protocols = intersect(definition.protocols, invocation.protocols);
|
|
203
|
-
if (definitionMode ===
|
|
204
|
-
const definitionAllows = definitionMode ===
|
|
205
|
-
const invocationAllows = invocationMode ===
|
|
212
|
+
if (definitionMode === "allowlist" || invocationMode === "allowlist") {
|
|
213
|
+
const definitionAllows = definitionMode === "allowlist" ? (definition.hosts ?? []) : undefined;
|
|
214
|
+
const invocationAllows = invocationMode === "allowlist" ? (invocation.hosts ?? []) : undefined;
|
|
206
215
|
let hosts = intersectAllowPatterns(definitionAllows, invocationAllows, true) ?? [];
|
|
207
|
-
const denied = union(definitionMode ===
|
|
216
|
+
const denied = union(definitionMode === "denylist" ? definition.hosts : undefined, invocationMode === "denylist" ? invocation.hosts : undefined);
|
|
208
217
|
if (denied?.length)
|
|
209
218
|
hosts = subtractDeniedPatterns(hosts, denied);
|
|
210
|
-
return compactObject({
|
|
219
|
+
return compactObject({
|
|
220
|
+
mode: "allowlist",
|
|
221
|
+
hosts,
|
|
222
|
+
protocols,
|
|
223
|
+
...controls,
|
|
224
|
+
});
|
|
211
225
|
}
|
|
212
|
-
if (definitionMode ===
|
|
226
|
+
if (definitionMode === "denylist" || invocationMode === "denylist") {
|
|
213
227
|
return compactObject({
|
|
214
|
-
mode:
|
|
228
|
+
mode: "denylist",
|
|
215
229
|
hosts: union(definition.hosts, invocation.hosts),
|
|
216
230
|
protocols,
|
|
217
231
|
...controls,
|
|
@@ -223,7 +237,7 @@ function mergeNetworkPolicy(definition, invocation) {
|
|
|
223
237
|
});
|
|
224
238
|
}
|
|
225
239
|
function effectiveNetworkMode(policy) {
|
|
226
|
-
return policy.mode ?? (policy.hosts && policy.hosts.length > 0 ?
|
|
240
|
+
return policy.mode ?? (policy.hosts && policy.hosts.length > 0 ? "allowlist" : undefined);
|
|
227
241
|
}
|
|
228
242
|
function subtractDeniedPatterns(allowed, denied) {
|
|
229
243
|
return allowed.filter((allowPattern) => !denied.some((denyPattern) => patternsMayOverlap(allowPattern, denyPattern, true)));
|
|
@@ -240,7 +254,9 @@ function mergeCostLimits(definition, invocation) {
|
|
|
240
254
|
perScope: definitionOwnsScope ? definition.perScope : invocation.perScope,
|
|
241
255
|
scopeKey: definitionOwnsScope ? definition.scopeKey : invocation.scopeKey,
|
|
242
256
|
store: definitionOwnsScope ? definition.store : invocation.store,
|
|
243
|
-
onExceed: definition.onExceed ===
|
|
257
|
+
onExceed: definition.onExceed === "throw" || invocation.onExceed === "throw"
|
|
258
|
+
? "throw"
|
|
259
|
+
: (definition.onExceed ?? invocation.onExceed),
|
|
244
260
|
scopeSource: definitionOwnsScope ? definition.scopeSource : invocation.scopeSource,
|
|
245
261
|
actualSource: definitionOwnsScope ? definition.actualSource : invocation.actualSource,
|
|
246
262
|
actualsCacheTtlMs: minimumDefined(definition.actualsCacheTtlMs, invocation.actualsCacheTtlMs),
|
|
@@ -285,36 +301,36 @@ function patternsMayOverlap(left, right, loose) {
|
|
|
285
301
|
return true;
|
|
286
302
|
// Exact glob intersection is not representable in CapabilityPolicy. When
|
|
287
303
|
// both sides are patterns and neither is provably disjoint, deny safely.
|
|
288
|
-
return left.includes(
|
|
304
|
+
return left.includes("*") && right.includes("*");
|
|
289
305
|
}
|
|
290
306
|
function patternCovers(broader, narrower, loose) {
|
|
291
|
-
if (broader === narrower || broader ===
|
|
307
|
+
if (broader === narrower || broader === "*" || broader === "**")
|
|
292
308
|
return true;
|
|
293
|
-
if (!narrower.includes(
|
|
309
|
+
if (!narrower.includes("*"))
|
|
294
310
|
return matchesPolicyPattern(narrower, broader, loose);
|
|
295
|
-
const firstWildcard = broader.indexOf(
|
|
311
|
+
const firstWildcard = broader.indexOf("*");
|
|
296
312
|
if (firstWildcard < 0)
|
|
297
313
|
return false;
|
|
298
314
|
const suffix = broader.slice(firstWildcard);
|
|
299
|
-
if (suffix !==
|
|
315
|
+
if (suffix !== "*" && suffix !== "**")
|
|
300
316
|
return false;
|
|
301
317
|
return narrower.startsWith(broader.slice(0, firstWildcard));
|
|
302
318
|
}
|
|
303
319
|
function matchesPolicyPattern(value, pattern, loose) {
|
|
304
|
-
if (pattern === value || pattern ===
|
|
320
|
+
if (pattern === value || pattern === "*")
|
|
305
321
|
return true;
|
|
306
|
-
let source =
|
|
322
|
+
let source = "";
|
|
307
323
|
for (let index = 0; index < pattern.length; index += 1) {
|
|
308
324
|
const char = pattern[index];
|
|
309
|
-
if (char ===
|
|
310
|
-
source +=
|
|
325
|
+
if (char === "*" && pattern[index + 1] === "*") {
|
|
326
|
+
source += ".*";
|
|
311
327
|
index += 1;
|
|
312
328
|
}
|
|
313
|
-
else if (char ===
|
|
314
|
-
source += loose ?
|
|
329
|
+
else if (char === "*") {
|
|
330
|
+
source += loose ? ".*" : "[^/]*";
|
|
315
331
|
}
|
|
316
332
|
else {
|
|
317
|
-
source += (char ??
|
|
333
|
+
source += (char ?? "").replace(/[|\\{}()[\]^$+?.]/g, "\\$&");
|
|
318
334
|
}
|
|
319
335
|
}
|
|
320
336
|
return new RegExp(`^${source}$`).test(value);
|
|
@@ -342,43 +358,9 @@ function maximumRisk(left, right) {
|
|
|
342
358
|
return rank[left] >= rank[right] ? left : right;
|
|
343
359
|
}
|
|
344
360
|
export function getAgentDefinition(value) {
|
|
345
|
-
if (typeof value !==
|
|
361
|
+
if (typeof value !== "function")
|
|
346
362
|
return undefined;
|
|
347
363
|
const candidate = value;
|
|
348
|
-
return candidate[definitionSymbol] ?? candidate.__fabricAgent;
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* Defaults-injecting agent builder. Exported as `agent` from the bare
|
|
352
|
-
* `@fabric-harness/sdk` entry point. Wraps `init()` so the headless
|
|
353
|
-
* defaults are applied unless the caller overrides them:
|
|
354
|
-
*
|
|
355
|
-
* - `runtime: 'stateless'`
|
|
356
|
-
* - `sandbox: 'virtual'`
|
|
357
|
-
* - `loopRuntime: pi-agent-core`
|
|
358
|
-
* - `compaction: { enabled: true }`
|
|
359
|
-
*
|
|
360
|
-
* If `runtime: 'temporal'` is selected from this builder, a one-time
|
|
361
|
-
* `console.warn` is emitted because auto-compaction is non-deterministic
|
|
362
|
-
* across Temporal replay. Use `@fabric-harness/sdk/strict` for Temporal.
|
|
363
|
-
*/
|
|
364
|
-
export function agentWithDefaults(definition) {
|
|
365
|
-
const wrappedRun = async (context) => {
|
|
366
|
-
const wrappedContext = {
|
|
367
|
-
...context,
|
|
368
|
-
init: async (init = {}) => {
|
|
369
|
-
if (init.runtime === 'temporal' && init.compaction === undefined)
|
|
370
|
-
warnTemporalOnBare();
|
|
371
|
-
return context.init({
|
|
372
|
-
...init,
|
|
373
|
-
runtime: init.runtime ?? 'stateless',
|
|
374
|
-
sandbox: init.sandbox ?? 'virtual',
|
|
375
|
-
loopRuntime: init.loopRuntime ?? (await getDefaultLoopRuntime()),
|
|
376
|
-
compaction: init.compaction ?? { enabled: true },
|
|
377
|
-
});
|
|
378
|
-
},
|
|
379
|
-
};
|
|
380
|
-
return definition.run(wrappedContext);
|
|
381
|
-
};
|
|
382
|
-
return agent({ ...definition, run: wrappedRun });
|
|
364
|
+
return (candidate[definitionSymbol] ?? candidate.__fabricAgent);
|
|
383
365
|
}
|
|
384
366
|
//# sourceMappingURL=agent-definition.js.map
|