@xyne/workflow-sdk 3.2.34 → 3.2.36
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/dist/agents/agent-step.d.ts +8 -8
- package/dist/agents/agent-step.d.ts.map +1 -1
- package/dist/agents/agent-step.js +12 -128
- package/dist/agents/agent-step.js.map +1 -1
- package/dist/agents/contract.d.ts +225 -0
- package/dist/agents/contract.d.ts.map +1 -0
- package/dist/agents/contract.js +196 -0
- package/dist/agents/contract.js.map +1 -0
- package/dist/agents/host-agent-step.d.ts +222 -0
- package/dist/agents/host-agent-step.d.ts.map +1 -0
- package/dist/agents/host-agent-step.js +352 -0
- package/dist/agents/host-agent-step.js.map +1 -0
- package/dist/agents/host.d.ts +9 -0
- package/dist/agents/host.d.ts.map +1 -0
- package/dist/agents/host.js +20 -0
- package/dist/agents/host.js.map +1 -0
- package/dist/agents/index.d.ts +6 -0
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +9 -0
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/provider.d.ts +227 -0
- package/dist/agents/provider.d.ts.map +1 -0
- package/dist/agents/provider.js +72 -0
- package/dist/agents/provider.js.map +1 -0
- package/dist/agents/types.d.ts +2 -21
- package/dist/agents/types.d.ts.map +1 -1
- package/dist/authz/attributes.d.ts +23 -0
- package/dist/authz/attributes.d.ts.map +1 -1
- package/dist/router/workflow-router.d.ts.map +1 -1
- package/dist/router/workflow-router.js +13 -9
- package/dist/router/workflow-router.js.map +1 -1
- package/dist/steps/builtin/http-request.step.d.ts +29 -29
- package/dist/steps/builtin/http-request.step.js +1 -1
- package/dist/steps/builtin/http-request.step.js.map +1 -1
- package/dist/storage/types.d.ts +11 -3
- package/dist/storage/types.d.ts.map +1 -1
- package/package.json +6 -2
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent contract — the half of an agent step that holds regardless of who
|
|
3
|
+
* actually runs the agent.
|
|
4
|
+
*
|
|
5
|
+
* An agent step has two halves:
|
|
6
|
+
*
|
|
7
|
+
* - The **provider half** is specific to the agent platform behind the step:
|
|
8
|
+
* prompts, tools and turn limits for an SDK-driven LLM ({@link AgentStep});
|
|
9
|
+
* an agent id for a host that owns its own agent lifecycle
|
|
10
|
+
* ({@link HostAgentStep}).
|
|
11
|
+
* - The **contract half** is the workflow's agreement with the step: what
|
|
12
|
+
* shape the output takes, whether it must be JSON, whether it carries
|
|
13
|
+
* citations, and how many times an unusable response is re-prompted before
|
|
14
|
+
* the step gives up. That is what lives here.
|
|
15
|
+
*
|
|
16
|
+
* Both steps compose the same {@link agentContractFields} and produce the same
|
|
17
|
+
* {@link AgentResult}, so a workflow can move between them without rewriting
|
|
18
|
+
* downstream `{{steps.x.output.response}}` refs.
|
|
19
|
+
*
|
|
20
|
+
* Deliberately free of pi-mono imports: a host-backed agent step must be able
|
|
21
|
+
* to use this without pulling the LLM runtime into the bundle.
|
|
22
|
+
*/
|
|
23
|
+
import { z } from 'zod';
|
|
24
|
+
import { AttachmentSchema, ATTACHMENT_ARRAY_JSON_SCHEMA } from '../common/attachment.js';
|
|
25
|
+
import { variableRef } from '../types/workflow-config.js';
|
|
26
|
+
import { splitCitedResponse } from './citation-resolve.js';
|
|
27
|
+
// ─── Contract Config Fields ───
|
|
28
|
+
/**
|
|
29
|
+
* The contract fields whose wording is identical for every agent step.
|
|
30
|
+
*
|
|
31
|
+
* Exposed as a field map rather than a `z.object` so each step can interleave
|
|
32
|
+
* them with its own fields in whatever order reads best in the form — the
|
|
33
|
+
* generic renderer follows declaration order, so composing with `.merge()`
|
|
34
|
+
* would force all contract fields to the bottom.
|
|
35
|
+
*/
|
|
36
|
+
export const agentContractFields = {
|
|
37
|
+
outputType: z.enum(['string', 'json']).default('string')
|
|
38
|
+
.describe('Shape of the agent response: free text, or a JSON object matching outputSchema'),
|
|
39
|
+
outputSchema: variableRef(z.record(z.unknown())).optional()
|
|
40
|
+
.describe('When outputType is "json", the JSON Schema the response object should match'),
|
|
41
|
+
cite: z.boolean().default(false)
|
|
42
|
+
.describe('Require the agent to cite the source of every data point it produces'),
|
|
43
|
+
timeoutMs: z.number().int().positive().default(1_200_000)
|
|
44
|
+
.describe('Max wall-clock time for the agent run in milliseconds. Default: 1200000 (20 minutes).'),
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Input documents field. The type is shared; the copy is not — how an agent
|
|
48
|
+
* receives its documents differs by provider (the SDK's LLM step mounts them
|
|
49
|
+
* into a sandbox; a host agent is handed refs), and the field's help text is
|
|
50
|
+
* the only place an author learns which.
|
|
51
|
+
*/
|
|
52
|
+
export function attachmentsField(description) {
|
|
53
|
+
return variableRef(z.array(AttachmentSchema).describe(description)).optional();
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Repair budget field. Same reasoning as {@link attachmentsField}: the bound
|
|
57
|
+
* and default are the contract, the description names the mechanism, which
|
|
58
|
+
* differs (re-prompting one conversation vs. re-running an agent).
|
|
59
|
+
*/
|
|
60
|
+
export function jsonRepairRetriesField(description) {
|
|
61
|
+
return z.number().int().min(0).default(3).describe(description);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The output shape both agent steps declare. Downstream refs bind against
|
|
65
|
+
* this, so it must not diverge between them.
|
|
66
|
+
*/
|
|
67
|
+
export const AgentResultSchema = z.object({
|
|
68
|
+
response: z.union([z.string(), z.record(z.unknown())]),
|
|
69
|
+
toolCalls: z.array(z.object({
|
|
70
|
+
name: z.string(),
|
|
71
|
+
args: z.record(z.unknown()),
|
|
72
|
+
result: z.unknown(),
|
|
73
|
+
durationMs: z.number(),
|
|
74
|
+
})),
|
|
75
|
+
turnCount: z.number(),
|
|
76
|
+
usage: z.object({
|
|
77
|
+
inputTokens: z.number(),
|
|
78
|
+
outputTokens: z.number(),
|
|
79
|
+
}),
|
|
80
|
+
attachments: z.array(AttachmentSchema),
|
|
81
|
+
});
|
|
82
|
+
// ─── Utility ───
|
|
83
|
+
export function isRecord(value) {
|
|
84
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Reject `promise` if it has not settled within `timeoutMs`.
|
|
88
|
+
*
|
|
89
|
+
* `label` names what timed out — tool execution for the LLM step, the whole
|
|
90
|
+
* agent run for a host-backed one — so the error text stays accurate wherever
|
|
91
|
+
* this is applied.
|
|
92
|
+
*/
|
|
93
|
+
export function withTimeout(promise, timeoutMs, label = 'Tool execution') {
|
|
94
|
+
return Promise.race([
|
|
95
|
+
promise,
|
|
96
|
+
new Promise((_resolve, reject) => {
|
|
97
|
+
const timer = setTimeout(() => { reject(new Error(`${label} timed out after ${timeoutMs}ms`)); }, timeoutMs);
|
|
98
|
+
// Don't block Node from exiting
|
|
99
|
+
if (typeof timer === 'object' && 'unref' in timer) {
|
|
100
|
+
timer.unref();
|
|
101
|
+
}
|
|
102
|
+
}),
|
|
103
|
+
]);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Classify a response for the repair loop: `ok`, or not-ok with the reason —
|
|
107
|
+
* `empty` (nothing to parse) or `unparseable` (JSON.parse threw, with the
|
|
108
|
+
* error text so it can be fed back to the model).
|
|
109
|
+
*/
|
|
110
|
+
export function classifyResponse(raw, expectJson) {
|
|
111
|
+
const trimmed = raw.trim();
|
|
112
|
+
// An empty response is always a failure — regardless of output type.
|
|
113
|
+
if (trimmed.length === 0)
|
|
114
|
+
return { ok: false, reason: 'empty' };
|
|
115
|
+
// For non-JSON outputs, any non-empty text is acceptable.
|
|
116
|
+
if (!expectJson)
|
|
117
|
+
return { ok: true };
|
|
118
|
+
const unfenced = stripCodeFence(trimmed);
|
|
119
|
+
if (unfenced.length === 0)
|
|
120
|
+
return { ok: false, reason: 'empty' };
|
|
121
|
+
try {
|
|
122
|
+
JSON.parse(unfenced);
|
|
123
|
+
return { ok: true };
|
|
124
|
+
}
|
|
125
|
+
catch (e) {
|
|
126
|
+
return { ok: false, reason: 'unparseable', error: e instanceof Error ? e.message : String(e) };
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Parse a JSON-mode agent response into an object. Strips Markdown code fences
|
|
131
|
+
* the model may wrap around the JSON. Falls back to `{ text }` if the response
|
|
132
|
+
* isn't valid JSON or isn't an object, so the output always matches the
|
|
133
|
+
* declared object shape.
|
|
134
|
+
*/
|
|
135
|
+
export function parseJsonResponse(raw) {
|
|
136
|
+
const unfenced = stripCodeFence(raw.trim());
|
|
137
|
+
try {
|
|
138
|
+
const parsed = JSON.parse(unfenced);
|
|
139
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
140
|
+
return parsed;
|
|
141
|
+
}
|
|
142
|
+
return { value: parsed };
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
return { text: raw };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function stripCodeFence(text) {
|
|
149
|
+
return text
|
|
150
|
+
.replace(/^```(?:json)?\s*/i, '')
|
|
151
|
+
.replace(/\s*```$/, '')
|
|
152
|
+
.trim();
|
|
153
|
+
}
|
|
154
|
+
// ─── Output Shaping ───
|
|
155
|
+
/**
|
|
156
|
+
* Shape a raw agent response per `outputType` — parse JSON when requested, and
|
|
157
|
+
* split out citations when `cite` is on.
|
|
158
|
+
*/
|
|
159
|
+
export function shapeAgentResponse(raw, opts, log) {
|
|
160
|
+
if (opts.outputType !== 'json' || typeof raw !== 'string')
|
|
161
|
+
return raw;
|
|
162
|
+
const parsed = parseJsonResponse(raw);
|
|
163
|
+
return opts.cite ? splitCitedResponse(parsed, log) : parsed;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Resolve the declared output JSON Schema for an agent step instance.
|
|
167
|
+
*
|
|
168
|
+
* With citations on the agent returns `{value, citation}`, so downstream refs
|
|
169
|
+
* and layouts address `output.response.value.*`. Gating the schema on the same
|
|
170
|
+
* flag as the runtime split keeps the declared and actual shapes in step —
|
|
171
|
+
* they flip together, per step, or not at all.
|
|
172
|
+
*/
|
|
173
|
+
export function resolveAgentOutputJsonSchema(config) {
|
|
174
|
+
const outputType = config['outputType'] === 'json' ? 'json' : 'string';
|
|
175
|
+
const rawSchema = config['outputSchema'];
|
|
176
|
+
const userSchema = isRecord(rawSchema) ? rawSchema : undefined;
|
|
177
|
+
let response = outputType === 'json'
|
|
178
|
+
? (userSchema && Object.keys(userSchema).length > 0 ? userSchema : { type: 'object' })
|
|
179
|
+
: { type: 'string' };
|
|
180
|
+
if (outputType === 'json' && config['cite'] === true) {
|
|
181
|
+
response = {
|
|
182
|
+
type: 'object',
|
|
183
|
+
properties: { value: response, citation: { type: 'object' } },
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
return {
|
|
187
|
+
type: 'object',
|
|
188
|
+
properties: {
|
|
189
|
+
response,
|
|
190
|
+
attachments: ATTACHMENT_ARRAY_JSON_SCHEMA,
|
|
191
|
+
toolCalls: { type: 'array' },
|
|
192
|
+
usage: { type: 'object' },
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/agents/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AAEzF,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,iCAAiC;AAEjC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,C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AAI,MAAM,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;QACrD,QAAQ,GAAG;YACT,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;SAC9D,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,QAAQ;YACR,WAAW,EAAE,4BAA4B;YACzC,SAAS,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;YAC5B,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SAC1B;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HostAgentStep — runs an agent the *host* owns, rather than one the SDK
|
|
3
|
+
* drives.
|
|
4
|
+
*
|
|
5
|
+
* Where {@link AgentStep} asks an author to construct an agent (system prompt,
|
|
6
|
+
* tools, model, turn budget), this asks them to choose one and give it a task.
|
|
7
|
+
* Everything about how that agent behaves — its prompt, its tools, its MCP
|
|
8
|
+
* connections — is resolved by the host's own agent platform behind a
|
|
9
|
+
* {@link BaseAgentProvider}.
|
|
10
|
+
*
|
|
11
|
+
* What stays here is the workflow's contract with the step, and it is identical
|
|
12
|
+
* to the LLM step's: the declared output shape, JSON repair, citation
|
|
13
|
+
* splitting, and artifact persistence. Both steps emit the same
|
|
14
|
+
* {@link AgentResult}, so downstream `{{steps.x.output.response}}` refs bind
|
|
15
|
+
* the same way against either.
|
|
16
|
+
*
|
|
17
|
+
* Registered by the host with its own naming, so a deployment shows the step
|
|
18
|
+
* in the author's vocabulary:
|
|
19
|
+
*
|
|
20
|
+
* new HostAgentStep(new ClawAgentProvider(deps), {
|
|
21
|
+
* type: 'RUN_XYNE_AGENT',
|
|
22
|
+
* name: 'Run Xyne Agent',
|
|
23
|
+
* description: 'Run an agent from your workspace',
|
|
24
|
+
* })
|
|
25
|
+
*
|
|
26
|
+
* Free of pi-mono imports — a host registering only this step does not pull the
|
|
27
|
+
* LLM runtime into its bundle.
|
|
28
|
+
*/
|
|
29
|
+
import { z } from 'zod';
|
|
30
|
+
import { BaseActionStep } from '../steps/base-step.js';
|
|
31
|
+
import type { StepExecutionContext } from '../steps/base-step.js';
|
|
32
|
+
import type { StepType } from '../types/step-types.js';
|
|
33
|
+
import type { StepCategory } from '../types/categories.js';
|
|
34
|
+
import type { AgentResult } from './contract.js';
|
|
35
|
+
import type { BaseAgentProvider } from './provider.js';
|
|
36
|
+
declare const HostAgentBaseSchema: z.ZodObject<{
|
|
37
|
+
attachments: z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodObject<{
|
|
38
|
+
name: z.ZodString;
|
|
39
|
+
mimeType: z.ZodString;
|
|
40
|
+
data: z.ZodString;
|
|
41
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
42
|
+
}, "strip", z.ZodTypeAny, {
|
|
43
|
+
name: string;
|
|
44
|
+
mimeType: string;
|
|
45
|
+
data: string;
|
|
46
|
+
size?: number | undefined;
|
|
47
|
+
}, {
|
|
48
|
+
name: string;
|
|
49
|
+
mimeType: string;
|
|
50
|
+
data: string;
|
|
51
|
+
size?: number | undefined;
|
|
52
|
+
}>, "many">, z.ZodString]>>;
|
|
53
|
+
outputType: z.ZodDefault<z.ZodEnum<["string", "json"]>>;
|
|
54
|
+
outputSchema: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodString]>>;
|
|
55
|
+
cite: z.ZodDefault<z.ZodBoolean>;
|
|
56
|
+
jsonRepairRetries: z.ZodDefault<z.ZodNumber>;
|
|
57
|
+
timeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
58
|
+
task: z.ZodString;
|
|
59
|
+
mode: z.ZodDefault<z.ZodEnum<["sync", "async"]>>;
|
|
60
|
+
}, "strip", z.ZodTypeAny, {
|
|
61
|
+
timeoutMs: number;
|
|
62
|
+
mode: "sync" | "async";
|
|
63
|
+
outputType: "string" | "json";
|
|
64
|
+
cite: boolean;
|
|
65
|
+
jsonRepairRetries: number;
|
|
66
|
+
task: string;
|
|
67
|
+
outputSchema?: string | Record<string, unknown> | undefined;
|
|
68
|
+
attachments?: string | {
|
|
69
|
+
name: string;
|
|
70
|
+
mimeType: string;
|
|
71
|
+
data: string;
|
|
72
|
+
size?: number | undefined;
|
|
73
|
+
}[] | undefined;
|
|
74
|
+
}, {
|
|
75
|
+
task: string;
|
|
76
|
+
timeoutMs?: number | undefined;
|
|
77
|
+
mode?: "sync" | "async" | undefined;
|
|
78
|
+
outputSchema?: string | Record<string, unknown> | undefined;
|
|
79
|
+
attachments?: string | {
|
|
80
|
+
name: string;
|
|
81
|
+
mimeType: string;
|
|
82
|
+
data: string;
|
|
83
|
+
size?: number | undefined;
|
|
84
|
+
}[] | undefined;
|
|
85
|
+
outputType?: "string" | "json" | undefined;
|
|
86
|
+
cite?: boolean | undefined;
|
|
87
|
+
jsonRepairRetries?: number | undefined;
|
|
88
|
+
}>;
|
|
89
|
+
export type HostAgentBaseConfig = z.infer<typeof HostAgentBaseSchema>;
|
|
90
|
+
/**
|
|
91
|
+
* How the step presents itself in the builder. All optional — the defaults
|
|
92
|
+
* describe a generic host agent, which is right when a deployment registers
|
|
93
|
+
* exactly one.
|
|
94
|
+
*/
|
|
95
|
+
export interface HostAgentStepOptions {
|
|
96
|
+
type?: StepType;
|
|
97
|
+
name?: string;
|
|
98
|
+
description?: string;
|
|
99
|
+
icon?: string;
|
|
100
|
+
category?: StepCategory;
|
|
101
|
+
}
|
|
102
|
+
export declare class HostAgentStep<TProviderConfig extends z.AnyZodObject = z.AnyZodObject> extends BaseActionStep<z.AnyZodObject, AgentResult> {
|
|
103
|
+
private readonly provider;
|
|
104
|
+
readonly type: StepType;
|
|
105
|
+
readonly name: string;
|
|
106
|
+
readonly description: string;
|
|
107
|
+
readonly category: StepCategory;
|
|
108
|
+
readonly icon?: string;
|
|
109
|
+
readonly configSchema: z.AnyZodObject;
|
|
110
|
+
readonly outputSchema: z.ZodObject<{
|
|
111
|
+
response: z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>;
|
|
112
|
+
toolCalls: z.ZodArray<z.ZodObject<{
|
|
113
|
+
name: z.ZodString;
|
|
114
|
+
args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
115
|
+
result: z.ZodUnknown;
|
|
116
|
+
durationMs: z.ZodNumber;
|
|
117
|
+
}, "strip", z.ZodTypeAny, {
|
|
118
|
+
name: string;
|
|
119
|
+
args: Record<string, unknown>;
|
|
120
|
+
durationMs: number;
|
|
121
|
+
result?: unknown;
|
|
122
|
+
}, {
|
|
123
|
+
name: string;
|
|
124
|
+
args: Record<string, unknown>;
|
|
125
|
+
durationMs: number;
|
|
126
|
+
result?: unknown;
|
|
127
|
+
}>, "many">;
|
|
128
|
+
turnCount: z.ZodNumber;
|
|
129
|
+
usage: z.ZodObject<{
|
|
130
|
+
inputTokens: z.ZodNumber;
|
|
131
|
+
outputTokens: z.ZodNumber;
|
|
132
|
+
}, "strip", z.ZodTypeAny, {
|
|
133
|
+
inputTokens: number;
|
|
134
|
+
outputTokens: number;
|
|
135
|
+
}, {
|
|
136
|
+
inputTokens: number;
|
|
137
|
+
outputTokens: number;
|
|
138
|
+
}>;
|
|
139
|
+
attachments: z.ZodArray<z.ZodObject<{
|
|
140
|
+
name: z.ZodString;
|
|
141
|
+
mimeType: z.ZodString;
|
|
142
|
+
data: z.ZodString;
|
|
143
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
144
|
+
}, "strip", z.ZodTypeAny, {
|
|
145
|
+
name: string;
|
|
146
|
+
mimeType: string;
|
|
147
|
+
data: string;
|
|
148
|
+
size?: number | undefined;
|
|
149
|
+
}, {
|
|
150
|
+
name: string;
|
|
151
|
+
mimeType: string;
|
|
152
|
+
data: string;
|
|
153
|
+
size?: number | undefined;
|
|
154
|
+
}>, "many">;
|
|
155
|
+
}, "strip", z.ZodTypeAny, {
|
|
156
|
+
response: string | Record<string, unknown>;
|
|
157
|
+
attachments: {
|
|
158
|
+
name: string;
|
|
159
|
+
mimeType: string;
|
|
160
|
+
data: string;
|
|
161
|
+
size?: number | undefined;
|
|
162
|
+
}[];
|
|
163
|
+
toolCalls: {
|
|
164
|
+
name: string;
|
|
165
|
+
args: Record<string, unknown>;
|
|
166
|
+
durationMs: number;
|
|
167
|
+
result?: unknown;
|
|
168
|
+
}[];
|
|
169
|
+
turnCount: number;
|
|
170
|
+
usage: {
|
|
171
|
+
inputTokens: number;
|
|
172
|
+
outputTokens: number;
|
|
173
|
+
};
|
|
174
|
+
}, {
|
|
175
|
+
response: string | Record<string, unknown>;
|
|
176
|
+
attachments: {
|
|
177
|
+
name: string;
|
|
178
|
+
mimeType: string;
|
|
179
|
+
data: string;
|
|
180
|
+
size?: number | undefined;
|
|
181
|
+
}[];
|
|
182
|
+
toolCalls: {
|
|
183
|
+
name: string;
|
|
184
|
+
args: Record<string, unknown>;
|
|
185
|
+
durationMs: number;
|
|
186
|
+
result?: unknown;
|
|
187
|
+
}[];
|
|
188
|
+
turnCount: number;
|
|
189
|
+
usage: {
|
|
190
|
+
inputTokens: number;
|
|
191
|
+
outputTokens: number;
|
|
192
|
+
};
|
|
193
|
+
}>;
|
|
194
|
+
constructor(provider: BaseAgentProvider<TProviderConfig, unknown>, options?: HostAgentStepOptions);
|
|
195
|
+
decorateConfigSchema(jsonSchema: Record<string, unknown>): Record<string, unknown>;
|
|
196
|
+
resolveOutputJsonSchema(config: Record<string, unknown>): Record<string, unknown>;
|
|
197
|
+
execute(rawConfig: Record<string, unknown>, ctx: StepExecutionContext): Promise<AgentResult>;
|
|
198
|
+
/**
|
|
199
|
+
* Resume after a dispatched run reported back.
|
|
200
|
+
*
|
|
201
|
+
* This is where the repair loop lives for background runs. It cannot be a
|
|
202
|
+
* loop the way the streaming path is — each attempt crosses a pause boundary,
|
|
203
|
+
* so the budget is carried on the step record and the loop is re-entry.
|
|
204
|
+
*/
|
|
205
|
+
onResume(rowData: Record<string, unknown>, rawConfig: Record<string, unknown>, ctx: StepExecutionContext): Promise<AgentResult>;
|
|
206
|
+
/**
|
|
207
|
+
* Hand the run to the provider and park the step. Never returns — `ctx.pause`
|
|
208
|
+
* throws, releasing the worker slot until the host calls back.
|
|
209
|
+
*/
|
|
210
|
+
private dispatch;
|
|
211
|
+
/** Run the agent inline, streaming progress, repairing in a loop. */
|
|
212
|
+
private runStreaming;
|
|
213
|
+
private buildInput;
|
|
214
|
+
private finalize;
|
|
215
|
+
/**
|
|
216
|
+
* Drive one streamed run to completion: forward progress to the execution
|
|
217
|
+
* viewer, persist artifacts, and return the result the provider reported.
|
|
218
|
+
*/
|
|
219
|
+
private consume;
|
|
220
|
+
}
|
|
221
|
+
export {};
|
|
222
|
+
//# sourceMappingURL=host-agent-step.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-agent-step.d.ts","sourceRoot":"","sources":["../../src/agents/host-agent-step.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAa3D,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,eAAe,CAAC;AAGjE,OAAO,KAAK,EAKV,iBAAiB,EAClB,MAAM,eAAe,CAAC;AAoCvB,QAAA,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAIvB,CAAC;AAEH,MAAM,MAAM,mBAAmB,GAAG,CAA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