@shipfox/api-workflows-dto 2.0.0 → 6.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shipfox/api-workflows-dto",
3
3
  "license": "MIT",
4
- "version": "2.0.0",
4
+ "version": "6.0.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/ShipfoxHQ/shipfox.git",
@@ -13,34 +13,30 @@
13
13
  "types": "dist/index.d.ts",
14
14
  "imports": {
15
15
  "#test/*": "./test/*",
16
- "#*": {
17
- "workspace-source": "./src/*",
18
- "development": "./src/*",
19
- "default": "./dist/*"
20
- }
16
+ "#*": "./dist/*"
21
17
  },
22
18
  "exports": {
23
19
  ".": {
24
- "development": {
25
- "types": "./src/index.ts",
26
- "default": "./src/index.ts"
27
- },
28
- "default": {
29
- "types": "./dist/index.d.ts",
30
- "default": "./dist/index.js"
31
- }
20
+ "types": "./dist/index.d.ts",
21
+ "default": "./dist/index.js"
22
+ },
23
+ "./inter-module": {
24
+ "types": "./dist/inter-module.d.ts",
25
+ "default": "./dist/inter-module.js"
32
26
  }
33
27
  },
34
28
  "dependencies": {
35
- "zod": "^4.4.3"
29
+ "zod": "^4.4.3",
30
+ "@shipfox/api-agent-dto": "6.0.0",
31
+ "@shipfox/inter-module": "0.2.0"
36
32
  },
37
33
  "devDependencies": {
34
+ "@shipfox/biome": "1.8.2",
35
+ "@shipfox/depcruise": "1.0.2",
36
+ "@shipfox/swc": "1.2.6",
38
37
  "@shipfox/ts-config": "1.3.8",
39
- "@shipfox/depcruise": "1.0.1",
40
- "@shipfox/swc": "1.2.5",
41
- "@shipfox/biome": "1.8.1",
42
- "@shipfox/typescript": "1.1.6",
43
- "@shipfox/vitest": "1.2.2"
38
+ "@shipfox/typescript": "1.1.7",
39
+ "@shipfox/vitest": "1.2.3"
44
40
  },
45
41
  "scripts": {
46
42
  "build": "shipfox-swc",
@@ -0,0 +1,87 @@
1
+ import {workflowsInterModuleContract} from './inter-module.js';
2
+
3
+ describe('workflowsInterModuleContract', () => {
4
+ test('accepts trigger commands and listener deliveries', () => {
5
+ const start = workflowsInterModuleContract.methods.startRunFromTrigger.input.parse({
6
+ workspaceId: '00000000-0000-4000-8000-000000000001',
7
+ projectId: '00000000-0000-4000-8000-000000000002',
8
+ definitionId: '00000000-0000-4000-8000-000000000003',
9
+ triggerPayload: {
10
+ provider: 'github',
11
+ source: 'github',
12
+ event: 'push',
13
+ deliveryId: 'delivery-1',
14
+ data: {ref: 'refs/heads/main'},
15
+ },
16
+ idempotencyKey: 'subscription-1:event-1',
17
+ });
18
+ const delivery = workflowsInterModuleContract.methods.deliverEventToJobListener.input.parse({
19
+ jobId: '00000000-0000-4000-8000-000000000004',
20
+ disposition: 'fire',
21
+ eventRef: 'event-1',
22
+ deliveryId: 'delivery-1',
23
+ source: 'github',
24
+ event: 'push',
25
+ provider: 'github',
26
+ payload: {ref: 'refs/heads/main'},
27
+ receivedAt: '2026-07-20T12:00:00.000Z',
28
+ });
29
+
30
+ expect(start.idempotencyKey).toBe('subscription-1:event-1');
31
+ expect(delivery.disposition).toBe('fire');
32
+ });
33
+
34
+ test('accepts the minimal Logs and agent-tools query payloads', () => {
35
+ const stepId = '00000000-0000-4000-8000-000000000006';
36
+ const logContext = workflowsInterModuleContract.methods.getStepLogContext.input.parse({stepId});
37
+ const agentTools = workflowsInterModuleContract.methods.getLeasedAgentToolContext.input.parse({
38
+ jobId: '00000000-0000-4000-8000-000000000007',
39
+ jobExecutionId: '00000000-0000-4000-8000-000000000008',
40
+ runnerSessionId: '00000000-0000-4000-8000-000000000009',
41
+ stepId,
42
+ attempt: 1,
43
+ });
44
+
45
+ expect(logContext).toEqual({stepId});
46
+ expect(agentTools.attempt).toBe(1);
47
+ });
48
+
49
+ test.each([
50
+ ['definition-not-found', {definitionId: '00000000-0000-4000-8000-000000000001'}],
51
+ ['project-mismatch', {}],
52
+ ['agent-config-unresolvable', {definitionId: '00000000-0000-4000-8000-000000000001'}],
53
+ ['agent-integration-materialization-failed', {}],
54
+ [
55
+ 'interpolation-unresolvable',
56
+ {
57
+ definitionId: '00000000-0000-4000-8000-000000000001',
58
+ field: 'env',
59
+ source: 'event.ref',
60
+ envKey: 'REF',
61
+ },
62
+ ],
63
+ ['invalid-job-runner-labels', {labels: ['linux', 'gpu']}],
64
+ ] as const)('defines the %s start-run failure', (code, details) => {
65
+ const schema = workflowsInterModuleContract.methods.startRunFromTrigger.errors[code];
66
+ const parsed = schema.parse(details);
67
+
68
+ expect(parsed).toEqual(details);
69
+ });
70
+
71
+ test.each([
72
+ 'lease-not-active',
73
+ 'step-not-found',
74
+ 'job-not-found',
75
+ 'step-attempt-mismatch',
76
+ 'step-not-running',
77
+ 'leased-step-not-agent',
78
+ 'agent-step-config-invalid',
79
+ ])('defines the %s agent-tools failure', (code) => {
80
+ const schema =
81
+ workflowsInterModuleContract.methods.getLeasedAgentToolContext.errors[
82
+ code as keyof typeof workflowsInterModuleContract.methods.getLeasedAgentToolContext.errors
83
+ ];
84
+
85
+ expect(schema.parse({})).toEqual({});
86
+ });
87
+ });
@@ -0,0 +1,116 @@
1
+ import {harnessSchema, materializedAgentIntegrationSchema} from '@shipfox/api-agent-dto';
2
+ import {defineInterModuleContract, type InterModuleClient} from '@shipfox/inter-module';
3
+ import {z} from 'zod';
4
+
5
+ const idSchema = z.string().uuid();
6
+ const triggerPayloadSchema = z.union([
7
+ z.object({
8
+ provider: z.literal('manual').optional(),
9
+ source: z.literal('manual'),
10
+ event: z.literal('fire'),
11
+ subscriptionId: idSchema,
12
+ userId: idSchema,
13
+ }),
14
+ z.object({
15
+ provider: z.literal('cron').optional(),
16
+ source: z.literal('cron'),
17
+ event: z.literal('tick'),
18
+ scheduleId: idSchema,
19
+ }),
20
+ z.object({
21
+ provider: z.string(),
22
+ source: z.string(),
23
+ event: z.string(),
24
+ deliveryId: z.string(),
25
+ data: z.unknown(),
26
+ }),
27
+ ]);
28
+
29
+ const interpolationFieldSchema = z.enum([
30
+ 'run',
31
+ 'env',
32
+ 'agent.prompt',
33
+ 'agent.model',
34
+ 'agent.provider',
35
+ 'job.runner',
36
+ 'job.outputs',
37
+ 'job.name',
38
+ 'step.name',
39
+ 'step.feedback',
40
+ ]);
41
+
42
+ /**
43
+ * Producer-owned Workflows commands used by synchronous callers. Commands carry
44
+ * stable identities whenever a retry could create a duplicate run.
45
+ */
46
+ export const workflowsInterModuleContract = defineInterModuleContract({
47
+ module: 'workflows',
48
+ methods: {
49
+ startRunFromTrigger: {
50
+ input: z.object({
51
+ workspaceId: idSchema,
52
+ projectId: idSchema,
53
+ definitionId: idSchema,
54
+ triggerPayload: triggerPayloadSchema,
55
+ inputs: z.record(z.string(), z.unknown()).optional(),
56
+ idempotencyKey: z.string().min(1),
57
+ }),
58
+ output: z.object({id: idSchema, name: z.string()}),
59
+ errors: {
60
+ 'definition-not-found': z.object({definitionId: idSchema}),
61
+ 'project-mismatch': z.object({}),
62
+ 'agent-config-unresolvable': z.object({definitionId: idSchema}),
63
+ 'agent-integration-materialization-failed': z.object({}),
64
+ 'interpolation-unresolvable': z.object({
65
+ definitionId: idSchema,
66
+ field: interpolationFieldSchema,
67
+ source: z.string(),
68
+ envKey: z.string().optional(),
69
+ }),
70
+ 'invalid-job-runner-labels': z.object({labels: z.array(z.string())}),
71
+ },
72
+ },
73
+ deliverEventToJobListener: {
74
+ input: z.object({
75
+ jobId: idSchema,
76
+ disposition: z.enum(['fire', 'resolve']),
77
+ eventRef: z.string().min(1),
78
+ deliveryId: z.string().min(1),
79
+ source: z.string().min(1),
80
+ event: z.string().min(1),
81
+ provider: z.string().min(1),
82
+ payload: z.unknown(),
83
+ receivedAt: z.string().datetime(),
84
+ }),
85
+ output: z.object({buffered: z.boolean(), skipped: z.boolean()}),
86
+ },
87
+ getStepLogContext: {
88
+ input: z.object({stepId: idSchema}),
89
+ output: z.object({harness: harnessSchema}),
90
+ },
91
+ getLeasedAgentToolContext: {
92
+ input: z.object({
93
+ jobId: idSchema,
94
+ jobExecutionId: idSchema,
95
+ runnerSessionId: idSchema,
96
+ stepId: idSchema,
97
+ attempt: z.number().int().positive(),
98
+ }),
99
+ output: z.object({
100
+ workspaceId: idSchema,
101
+ integrations: z.array(materializedAgentIntegrationSchema),
102
+ }),
103
+ errors: {
104
+ 'lease-not-active': z.object({}),
105
+ 'step-not-found': z.object({}),
106
+ 'job-not-found': z.object({}),
107
+ 'step-attempt-mismatch': z.object({}),
108
+ 'step-not-running': z.object({}),
109
+ 'leased-step-not-agent': z.object({}),
110
+ 'agent-step-config-invalid': z.object({}),
111
+ },
112
+ },
113
+ },
114
+ });
115
+
116
+ export type WorkflowsModuleClient = InterModuleClient<typeof workflowsInterModuleContract>;