@artemiskit/sdk 0.4.6 → 0.6.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/CHANGELOG.md +40 -0
- package/README.md +25 -0
- package/dist/artemiskit.d.ts +5 -1
- package/dist/artemiskit.d.ts.map +1 -1
- package/dist/builders/index.js +66 -20
- package/dist/contracts/index.js +50 -4
- package/dist/guardian/action-validator.d.ts +1 -1
- package/dist/guardian/circuit-breaker.d.ts +1 -1
- package/dist/guardian/guardian.d.ts +5 -5
- package/dist/guardian/guardrails.d.ts +1 -1
- package/dist/guardian/index.d.ts +9 -9
- package/dist/guardian/intent-classifier.d.ts +1 -1
- package/dist/guardian/interceptor.d.ts +1 -1
- package/dist/guardian/policy.d.ts +1 -1
- package/dist/guardian/semantic-validator.d.ts +1 -1
- package/dist/index.d.ts +12 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3192 -46894
- package/dist/matchers/core.d.ts +1 -1
- package/dist/matchers/index.d.ts +1 -1
- package/dist/matchers/index.js +60 -14
- package/dist/matchers/jest.d.ts +14 -14
- package/dist/matchers/jest.js +47 -1
- package/dist/matchers/vitest.d.ts +14 -14
- package/dist/matchers/vitest.js +47 -1
- package/dist/types-only.d.ts +7 -6
- package/dist/types-only.d.ts.map +1 -1
- package/dist/types-only.js +0 -1
- package/dist/types.d.ts +12 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +58 -12
- package/dist/workflow.d.ts +4 -0
- package/dist/workflow.d.ts.map +1 -0
- package/package.json +18 -18
- package/src/__tests__/workflow.test.ts +244 -0
- package/src/artemiskit.ts +12 -0
- package/src/index.ts +49 -0
- package/src/types-only.ts +30 -0
- package/src/types.ts +16 -0
- package/src/workflow.ts +51 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { afterEach, describe, expect, test } from 'bun:test';
|
|
2
|
+
import { mkdtemp, readdir, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import {
|
|
7
|
+
type AgentTarget,
|
|
8
|
+
type AgentWorkflow,
|
|
9
|
+
type AgentWorkflowEvent,
|
|
10
|
+
createSimulatedWorkflowEnvironment,
|
|
11
|
+
validateAgentWorkflow,
|
|
12
|
+
} from '@artemiskit/core';
|
|
13
|
+
import { OpenAIAdapter } from '../../../adapters/openai/src/client';
|
|
14
|
+
import { ArtemisKit } from '../artemiskit';
|
|
15
|
+
import type { WorkflowRunOptions } from '../types-only';
|
|
16
|
+
|
|
17
|
+
const servers: ReturnType<typeof Bun.serve>[] = [];
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
for (const server of servers.splice(0)) server.stop(true);
|
|
20
|
+
});
|
|
21
|
+
function workflow(): AgentWorkflow {
|
|
22
|
+
return validateAgentWorkflow({
|
|
23
|
+
version: '1',
|
|
24
|
+
kind: 'agent_workflow',
|
|
25
|
+
name: 'sdk-workflow',
|
|
26
|
+
target: {
|
|
27
|
+
provider: 'openai',
|
|
28
|
+
model: 'workflow-authoritative',
|
|
29
|
+
generation: { max_tokens: 256 },
|
|
30
|
+
},
|
|
31
|
+
environment: {
|
|
32
|
+
type: 'simulated',
|
|
33
|
+
policy: {
|
|
34
|
+
network: 'denied',
|
|
35
|
+
side_effects: 'denied',
|
|
36
|
+
permissions: { files: 'write' },
|
|
37
|
+
budgets: { max_actions: 10, max_tokens: 4096, timeout_ms: 1000 },
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
tools: ['write_file'],
|
|
41
|
+
workflow: {
|
|
42
|
+
system_instructions: 'PRIVATE-INSTRUCTIONS',
|
|
43
|
+
initial_state: { files: {} },
|
|
44
|
+
turns: [{ role: 'user', content: 'PRIVATE-PROMPT' }],
|
|
45
|
+
},
|
|
46
|
+
outcomes: { deterministic: [{ type: 'file', path: 'result.txt', exists: true }] },
|
|
47
|
+
evidence: { trace: 'summary', artifacts: 'checksums', redact: true },
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function target(): AgentTarget {
|
|
51
|
+
return {
|
|
52
|
+
provider: 'custom',
|
|
53
|
+
capabilities: async () => ({ status: 'available', toolUse: true, transportCancellation: true }),
|
|
54
|
+
turn: async () => ({
|
|
55
|
+
status: 'completed',
|
|
56
|
+
id: 'fixture',
|
|
57
|
+
model: 'fixture',
|
|
58
|
+
message: { role: 'assistant', content: 'PRIVATE-ANSWER' },
|
|
59
|
+
tokens: { prompt: 2, completion: 1, total: 3 },
|
|
60
|
+
latencyMs: 1,
|
|
61
|
+
}),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
describe('SDK native workflow session', () => {
|
|
66
|
+
test('configured adapter uses workflow identity and zero retries with real loopback multi-turn execution', async () => {
|
|
67
|
+
const bodies: Record<string, unknown>[] = [];
|
|
68
|
+
const server = Bun.serve({
|
|
69
|
+
hostname: '127.0.0.1',
|
|
70
|
+
port: 0,
|
|
71
|
+
async fetch(request) {
|
|
72
|
+
bodies.push(await request.json());
|
|
73
|
+
const first = bodies.length === 1;
|
|
74
|
+
return Response.json({
|
|
75
|
+
id: 'fixture',
|
|
76
|
+
model: 'observed-model',
|
|
77
|
+
choices: [
|
|
78
|
+
{
|
|
79
|
+
index: 0,
|
|
80
|
+
message: {
|
|
81
|
+
role: 'assistant',
|
|
82
|
+
content: first ? null : 'PRIVATE-ANSWER',
|
|
83
|
+
...(first
|
|
84
|
+
? {
|
|
85
|
+
tool_calls: [
|
|
86
|
+
{
|
|
87
|
+
id: 'private-id',
|
|
88
|
+
type: 'function',
|
|
89
|
+
function: {
|
|
90
|
+
name: 'write_file',
|
|
91
|
+
arguments: '{"path":"result.txt","content":"PRIVATE-STATE"}',
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
}
|
|
96
|
+
: {}),
|
|
97
|
+
},
|
|
98
|
+
finish_reason: first ? 'tool_calls' : 'stop',
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
usage: { prompt_tokens: 2, completion_tokens: 1, total_tokens: 3 },
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
servers.push(server);
|
|
106
|
+
// Legacy SDK tests mock the core factory globally; qualify the real public boundary in a fresh process.
|
|
107
|
+
const directory = await mkdtemp(join(tmpdir(), 'artemis-sdk-client-'));
|
|
108
|
+
const workflowPath = join(directory, 'workflow.json');
|
|
109
|
+
await writeFile(workflowPath, JSON.stringify(workflow()));
|
|
110
|
+
const child = Bun.spawn(
|
|
111
|
+
[
|
|
112
|
+
process.execPath,
|
|
113
|
+
'-e',
|
|
114
|
+
`
|
|
115
|
+
import { ArtemisKit } from ${JSON.stringify(fileURLToPath(new URL('../artemiskit.ts', import.meta.url)))};
|
|
116
|
+
import { registerAdapter } from '@artemiskit/core';
|
|
117
|
+
import { OpenAIAdapter } from '@artemiskit/adapter-openai';
|
|
118
|
+
import assert from 'node:assert/strict';
|
|
119
|
+
registerAdapter('openai', async (config) => {
|
|
120
|
+
assert.equal(config.provider, 'openai');
|
|
121
|
+
assert.equal(config.defaultModel, 'workflow-authoritative');
|
|
122
|
+
assert.equal(config.maxRetries, 0);
|
|
123
|
+
return new OpenAIAdapter(config);
|
|
124
|
+
});
|
|
125
|
+
const kit = new ArtemisKit({ provider: 'anthropic', model: 'wrong', providerConfig: {
|
|
126
|
+
provider: 'openai', defaultModel: 'wrong-config', apiKey: 'dummy-only',
|
|
127
|
+
baseUrl: ${JSON.stringify(`http://127.0.0.1:${server.port}/v1`)}, maxRetries: 9,
|
|
128
|
+
}});
|
|
129
|
+
const events = [];
|
|
130
|
+
const result = await kit.runWorkflow({ workflow: ${JSON.stringify(workflowPath)}, onEvent: (event) => events.push(event) });
|
|
131
|
+
registerAdapter('openai', async () => { throw new Error('SYNTHETIC_PRIVATE_CONSTRUCTION_DETAIL'); });
|
|
132
|
+
await assert.rejects(kit.createWorkflowSession({ workflow: ${JSON.stringify(workflowPath)} }),
|
|
133
|
+
(error) => error.code === 'PROVIDER_UNAVAILABLE' &&
|
|
134
|
+
error.message === 'Unable to initialize workflow target' && error.cause === undefined);
|
|
135
|
+
console.log(JSON.stringify({ result, events }));
|
|
136
|
+
`,
|
|
137
|
+
],
|
|
138
|
+
{
|
|
139
|
+
cwd: fileURLToPath(new URL('../', import.meta.url)),
|
|
140
|
+
stdin: 'ignore',
|
|
141
|
+
stdout: 'pipe',
|
|
142
|
+
stderr: 'pipe',
|
|
143
|
+
env: { PATH: process.env.PATH },
|
|
144
|
+
}
|
|
145
|
+
);
|
|
146
|
+
const timer = setTimeout(() => child.kill(), 10000);
|
|
147
|
+
const [exit, stdout, stderr] = await Promise.all([
|
|
148
|
+
child.exited,
|
|
149
|
+
new Response(child.stdout).text(),
|
|
150
|
+
new Response(child.stderr).text(),
|
|
151
|
+
]);
|
|
152
|
+
clearTimeout(timer);
|
|
153
|
+
expect({ exit, stderr }).toEqual({ exit: 0, stderr: '' });
|
|
154
|
+
const { result, events } = JSON.parse(stdout);
|
|
155
|
+
expect(bodies[0].model).toBe('workflow-authoritative');
|
|
156
|
+
expect(result.record.execution).toBe('completed');
|
|
157
|
+
expect(result.record.taskVerification).toBe('unavailable');
|
|
158
|
+
expect(result.record.budgets).toMatchObject({ modelRequests: 2, toolCalls: 1 });
|
|
159
|
+
expect(result.state?.files).toEqual({ 'result.txt': 'PRIVATE-STATE' });
|
|
160
|
+
expect(JSON.stringify(result.record)).not.toContain('PRIVATE-');
|
|
161
|
+
expect(events.some((event) => event.type === 'tool_completed')).toBe(true);
|
|
162
|
+
});
|
|
163
|
+
test('file fixture roots, session events and environment overrides use the same engine without persistence', async () => {
|
|
164
|
+
const directory = await mkdtemp(join(tmpdir(), 'artemis-sdk-workflow-'));
|
|
165
|
+
const scenario = workflow();
|
|
166
|
+
scenario.workflow.initial_state = 'fixture.json';
|
|
167
|
+
await writeFile(join(directory, 'fixture.json'), '{"files":{"initial.txt":"PRIVATE"}}');
|
|
168
|
+
await writeFile(join(directory, 'workflow.json'), JSON.stringify(scenario));
|
|
169
|
+
let factories = 0;
|
|
170
|
+
const options: WorkflowRunOptions = {
|
|
171
|
+
workflow: join(directory, 'workflow.json'),
|
|
172
|
+
target: target(),
|
|
173
|
+
environmentFactory: async (args) => {
|
|
174
|
+
factories++;
|
|
175
|
+
return createSimulatedWorkflowEnvironment(args);
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
const session = await new ArtemisKit().createWorkflowSession(options);
|
|
179
|
+
expect(session.state).toBe('idle');
|
|
180
|
+
expect(factories).toBe(0);
|
|
181
|
+
const stream = (async () => {
|
|
182
|
+
const events: AgentWorkflowEvent[] = [];
|
|
183
|
+
for await (const event of session.events()) events.push(event);
|
|
184
|
+
return events;
|
|
185
|
+
})();
|
|
186
|
+
const result = await session.run();
|
|
187
|
+
expect(session.state).toBe('completed');
|
|
188
|
+
expect(result.state?.files).toEqual({ 'initial.txt': 'PRIVATE' });
|
|
189
|
+
expect(factories).toBe(1);
|
|
190
|
+
expect((await stream).at(-1)?.type).toBe('finished');
|
|
191
|
+
expect((await readdir(directory)).sort()).toEqual(['fixture.json', 'workflow.json']);
|
|
192
|
+
});
|
|
193
|
+
test('supports explicit client, rejects client+target and custom unsupported capabilities', async () => {
|
|
194
|
+
const unsupported = target();
|
|
195
|
+
unsupported.capabilities = async () => ({
|
|
196
|
+
status: 'available',
|
|
197
|
+
toolUse: false,
|
|
198
|
+
transportCancellation: false,
|
|
199
|
+
});
|
|
200
|
+
const kit = new ArtemisKit();
|
|
201
|
+
const client = new OpenAIAdapter({
|
|
202
|
+
provider: 'openai',
|
|
203
|
+
apiKey: 'dummy-only',
|
|
204
|
+
baseUrl: 'http://127.0.0.1:1',
|
|
205
|
+
maxRetries: 0,
|
|
206
|
+
});
|
|
207
|
+
await expect(
|
|
208
|
+
kit.createWorkflowSession({ workflow: workflow(), client, target: unsupported })
|
|
209
|
+
).rejects.toThrow('client or target');
|
|
210
|
+
expect(
|
|
211
|
+
(await kit.runWorkflow({ workflow: workflow(), target: unsupported })).record.execution
|
|
212
|
+
).toBe('unsupported');
|
|
213
|
+
const aborted = new AbortController();
|
|
214
|
+
aborted.abort();
|
|
215
|
+
expect(
|
|
216
|
+
(await kit.runWorkflow({ workflow: workflow(), client, signal: aborted.signal })).record
|
|
217
|
+
.execution
|
|
218
|
+
).toBe('cancelled');
|
|
219
|
+
});
|
|
220
|
+
test('cancellation and all SDK engine options stay host controlled', async () => {
|
|
221
|
+
let resolveStarted!: () => void;
|
|
222
|
+
const started = new Promise<void>((resolve) => {
|
|
223
|
+
resolveStarted = resolve;
|
|
224
|
+
});
|
|
225
|
+
const custom = target();
|
|
226
|
+
custom.turn = async (_request, signal) => {
|
|
227
|
+
resolveStarted();
|
|
228
|
+
await new Promise<void>((resolve) =>
|
|
229
|
+
signal?.addEventListener('abort', () => resolve(), { once: true })
|
|
230
|
+
);
|
|
231
|
+
return { status: 'error', code: 'aborted' };
|
|
232
|
+
};
|
|
233
|
+
const session = await new ArtemisKit().createWorkflowSession({
|
|
234
|
+
workflow: workflow(),
|
|
235
|
+
target: custom,
|
|
236
|
+
cleanupTimeoutMs: 20,
|
|
237
|
+
});
|
|
238
|
+
const result = session.run();
|
|
239
|
+
await started;
|
|
240
|
+
session.cancel();
|
|
241
|
+
expect((await result).record.execution).toBe('cancelled');
|
|
242
|
+
expect(session.state).toBe('completed');
|
|
243
|
+
});
|
|
244
|
+
});
|
package/src/artemiskit.ts
CHANGED
|
@@ -41,6 +41,7 @@ import {
|
|
|
41
41
|
UnsafeResponseDetector,
|
|
42
42
|
} from '@artemiskit/redteam';
|
|
43
43
|
import { nanoid } from 'nanoid';
|
|
44
|
+
import { prepareWorkflowSession } from './workflow';
|
|
44
45
|
|
|
45
46
|
import type {
|
|
46
47
|
ArtemisKitConfig,
|
|
@@ -62,6 +63,7 @@ import type {
|
|
|
62
63
|
StressResult,
|
|
63
64
|
ValidateOptions,
|
|
64
65
|
ValidationResult,
|
|
66
|
+
WorkflowRunOptions,
|
|
65
67
|
} from './types';
|
|
66
68
|
|
|
67
69
|
/**
|
|
@@ -125,6 +127,16 @@ export class ArtemisKit {
|
|
|
125
127
|
}
|
|
126
128
|
}
|
|
127
129
|
|
|
130
|
+
/** Create a cancellable native session without executing model turns or persisting results. */
|
|
131
|
+
async createWorkflowSession(options: WorkflowRunOptions) {
|
|
132
|
+
return prepareWorkflowSession(options, this.config);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Execute a workflow; task verification is explicitly unavailable until outcome scoring. */
|
|
136
|
+
async runWorkflow(options: WorkflowRunOptions) {
|
|
137
|
+
return (await this.createWorkflowSession(options)).run();
|
|
138
|
+
}
|
|
139
|
+
|
|
128
140
|
// ==========================================================================
|
|
129
141
|
// Event Emitter Methods
|
|
130
142
|
// ==========================================================================
|
package/src/index.ts
CHANGED
|
@@ -6,10 +6,59 @@
|
|
|
6
6
|
// Main class
|
|
7
7
|
export { ArtemisKit } from './artemiskit';
|
|
8
8
|
|
|
9
|
+
// Workflow authoring, controlled native execution and tool primitives.
|
|
10
|
+
export {
|
|
11
|
+
AgentWorkflowSchema,
|
|
12
|
+
WorkflowPolicySchema,
|
|
13
|
+
WORKFLOW_TOOL_IDS,
|
|
14
|
+
validateAgentWorkflow,
|
|
15
|
+
parseAgentWorkflow,
|
|
16
|
+
loadAgentWorkflow,
|
|
17
|
+
listWorkflowTools,
|
|
18
|
+
getWorkflowTool,
|
|
19
|
+
executeSimulatedTool,
|
|
20
|
+
createModelClientTarget,
|
|
21
|
+
createAgentWorkflowSession,
|
|
22
|
+
runAgentWorkflow,
|
|
23
|
+
createSimulatedWorkflowEnvironment,
|
|
24
|
+
createDockerWorkflowEnvironment,
|
|
25
|
+
createDockerWorkflowEnvironmentFactory,
|
|
26
|
+
WORKFLOW_SANDBOX_IMAGE,
|
|
27
|
+
WorkflowEnvironmentInitializationError,
|
|
28
|
+
} from '@artemiskit/core';
|
|
29
|
+
export type {
|
|
30
|
+
AgentWorkflow,
|
|
31
|
+
WorkflowPolicy,
|
|
32
|
+
WorkflowJson,
|
|
33
|
+
WorkflowToolId,
|
|
34
|
+
WorkflowResource,
|
|
35
|
+
WorkflowToolDescriptor,
|
|
36
|
+
SimulatedToolEvidence,
|
|
37
|
+
SimulatedToolResult,
|
|
38
|
+
AgentTarget,
|
|
39
|
+
AgentTurnRequest,
|
|
40
|
+
AgentTurnResult,
|
|
41
|
+
AgentTargetCapabilities,
|
|
42
|
+
AgentTargetFailure,
|
|
43
|
+
AgentWorkflowExecution,
|
|
44
|
+
AgentWorkflowReason,
|
|
45
|
+
AgentWorkflowEvent,
|
|
46
|
+
AgentWorkflowRecord,
|
|
47
|
+
AgentWorkflowResult,
|
|
48
|
+
AgentWorkflowSessionOptions,
|
|
49
|
+
AgentWorkflowSession,
|
|
50
|
+
WorkflowState,
|
|
51
|
+
WorkflowEnvironment,
|
|
52
|
+
WorkflowEnvironmentFactory,
|
|
53
|
+
WorkflowEnvironmentCleanup,
|
|
54
|
+
DockerWorkflowEnvironmentOptions,
|
|
55
|
+
} from '@artemiskit/core';
|
|
56
|
+
|
|
9
57
|
// Types
|
|
10
58
|
export type {
|
|
11
59
|
// Configuration
|
|
12
60
|
ArtemisKitConfig,
|
|
61
|
+
WorkflowRunOptions,
|
|
13
62
|
RunOptions,
|
|
14
63
|
RedTeamOptions,
|
|
15
64
|
StressOptions,
|
package/src/types-only.ts
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
export type {
|
|
24
24
|
// Configuration
|
|
25
25
|
ArtemisKitConfig,
|
|
26
|
+
WorkflowRunOptions,
|
|
26
27
|
RunOptions,
|
|
27
28
|
RedTeamOptions,
|
|
28
29
|
StressOptions,
|
|
@@ -274,3 +275,32 @@ export type {
|
|
|
274
275
|
// ============================================================================
|
|
275
276
|
|
|
276
277
|
export type { ScenarioBuilder, TestCaseBuilder } from './builders';
|
|
278
|
+
|
|
279
|
+
export type {
|
|
280
|
+
AgentWorkflow,
|
|
281
|
+
WorkflowPolicy,
|
|
282
|
+
WorkflowJson,
|
|
283
|
+
WorkflowToolId,
|
|
284
|
+
WorkflowResource,
|
|
285
|
+
WorkflowToolDescriptor,
|
|
286
|
+
SimulatedToolEvidence,
|
|
287
|
+
SimulatedToolResult,
|
|
288
|
+
AgentTarget,
|
|
289
|
+
AgentTurnRequest,
|
|
290
|
+
AgentTurnResult,
|
|
291
|
+
AgentTargetCapabilities,
|
|
292
|
+
AgentTargetFailure,
|
|
293
|
+
AgentWorkflowExecution,
|
|
294
|
+
AgentWorkflowReason,
|
|
295
|
+
AgentWorkflowEvent,
|
|
296
|
+
AgentWorkflowRecord,
|
|
297
|
+
AgentWorkflowResult,
|
|
298
|
+
AgentWorkflowSessionOptions,
|
|
299
|
+
AgentWorkflowSession,
|
|
300
|
+
WorkflowState,
|
|
301
|
+
WorkflowEnvironment,
|
|
302
|
+
WorkflowEnvironmentFactory,
|
|
303
|
+
WorkflowEnvironmentCleanup,
|
|
304
|
+
DockerWorkflowEnvironmentOptions,
|
|
305
|
+
WorkflowEnvironmentInitializationError,
|
|
306
|
+
} from '@artemiskit/core';
|
package/src/types.ts
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
import type {
|
|
7
7
|
AdapterConfig,
|
|
8
|
+
AgentTarget,
|
|
9
|
+
AgentWorkflow,
|
|
10
|
+
AgentWorkflowSessionOptions,
|
|
8
11
|
CaseResult,
|
|
9
12
|
ComparisonEligibility,
|
|
10
13
|
ModelClient,
|
|
@@ -448,3 +451,16 @@ export interface CompareResult {
|
|
|
448
451
|
/** Threshold used for regression detection */
|
|
449
452
|
threshold: number;
|
|
450
453
|
}
|
|
454
|
+
|
|
455
|
+
/** Controlled workflow execution. Text/state remain in memory unless the caller explicitly saves them. */
|
|
456
|
+
export interface WorkflowRunOptions
|
|
457
|
+
extends Omit<AgentWorkflowSessionOptions, 'workflow' | 'target'> {
|
|
458
|
+
/** Workflow object or YAML path. File fixtures default to the workflow file's directory. */
|
|
459
|
+
workflow: AgentWorkflow | string;
|
|
460
|
+
/** Explicit host-owned client. Its transport retry behavior remains the caller's responsibility. */
|
|
461
|
+
client?: ModelClient;
|
|
462
|
+
/** Explicit custom target, mutually exclusive with client. */
|
|
463
|
+
target?: AgentTarget;
|
|
464
|
+
/** Trusted transport configuration; workflow provider/model and zero retries remain authoritative. */
|
|
465
|
+
providerConfig?: Partial<AdapterConfig>;
|
|
466
|
+
}
|
package/src/workflow.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { dirname, resolve } from 'node:path';
|
|
2
|
+
import {
|
|
3
|
+
type AdapterConfig,
|
|
4
|
+
type AgentWorkflowSession,
|
|
5
|
+
ArtemisError,
|
|
6
|
+
createAdapter,
|
|
7
|
+
createAgentWorkflowSession,
|
|
8
|
+
createModelClientTarget,
|
|
9
|
+
loadAgentWorkflow,
|
|
10
|
+
validateAgentWorkflow,
|
|
11
|
+
} from '@artemiskit/core';
|
|
12
|
+
import type { ArtemisKitConfig, WorkflowRunOptions } from './types';
|
|
13
|
+
|
|
14
|
+
export async function prepareWorkflowSession(
|
|
15
|
+
options: WorkflowRunOptions,
|
|
16
|
+
config: ArtemisKitConfig
|
|
17
|
+
): Promise<AgentWorkflowSession> {
|
|
18
|
+
if (options.client && options.target) throw new Error('Choose a workflow client or target');
|
|
19
|
+
const file = typeof options.workflow === 'string' ? resolve(options.workflow) : undefined;
|
|
20
|
+
const workflow = file ? await loadAgentWorkflow(file) : validateAgentWorkflow(options.workflow);
|
|
21
|
+
let target = options.target;
|
|
22
|
+
if (!target) {
|
|
23
|
+
let client = options.client;
|
|
24
|
+
if (!client) {
|
|
25
|
+
try {
|
|
26
|
+
client = await createAdapter({
|
|
27
|
+
...config.providerConfig,
|
|
28
|
+
...options.providerConfig,
|
|
29
|
+
provider: workflow.target.provider,
|
|
30
|
+
defaultModel: workflow.target.model,
|
|
31
|
+
maxRetries: 0,
|
|
32
|
+
} as AdapterConfig);
|
|
33
|
+
} catch {
|
|
34
|
+
// Provider factories may put credentials or configuration values in their diagnostics.
|
|
35
|
+
throw new ArtemisError('Unable to initialize workflow target', 'PROVIDER_UNAVAILABLE');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
target = createModelClientTarget(client);
|
|
39
|
+
}
|
|
40
|
+
return createAgentWorkflowSession({
|
|
41
|
+
workflow,
|
|
42
|
+
target,
|
|
43
|
+
fixtureRoot: options.fixtureRoot ?? (file ? dirname(file) : undefined),
|
|
44
|
+
environmentFactory: options.environmentFactory,
|
|
45
|
+
preflight: options.preflight,
|
|
46
|
+
preflightOnly: options.preflightOnly,
|
|
47
|
+
signal: options.signal,
|
|
48
|
+
cleanupTimeoutMs: options.cleanupTimeoutMs,
|
|
49
|
+
onEvent: options.onEvent,
|
|
50
|
+
});
|
|
51
|
+
}
|