@shipfox/api-workflows 16.1.0 → 17.1.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/.turbo/turbo-build.log +4 -4
- package/.turbo/turbo-type.log +0 -1
- package/CHANGELOG.md +35 -0
- package/dist/presentation/inter-module.d.ts.map +1 -1
- package/dist/presentation/inter-module.js +80 -19
- package/dist/presentation/inter-module.js.map +1 -1
- package/dist/tsconfig.test.tsbuildinfo +1 -1
- package/package.json +9 -9
- package/src/presentation/inter-module.test.ts +197 -0
- package/src/presentation/inter-module.ts +97 -23
- package/tsconfig.build.tsbuildinfo +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
$ shipfox-swc && shipfox-temporal-bundle dist/temporal/workflows/index.js
|
|
2
|
-
Successfully compiled: 123 files with swc (
|
|
3
|
-
2026-08-
|
|
2
|
+
Successfully compiled: 123 files with swc (183.53ms)
|
|
3
|
+
2026-08-26T13:34:02.010Z [INFO] asset workflow-bundle-4d88ac6c229f6c77759a.js 3.31 MiB [emitted] [immutable] (name: main)
|
|
4
4
|
orphan modules 33.5 KiB [orphan] 21 modules
|
|
5
5
|
runtime modules 1.13 KiB 5 modules
|
|
6
6
|
modules by path ../../../node_modules/.pnpm/ 970 KiB 196 modules
|
|
@@ -16,6 +16,6 @@ optional modules 30 bytes [optional]
|
|
|
16
16
|
__temporal_custom_payload_converter (ignored) 15 bytes [optional] [built] [code generated]
|
|
17
17
|
__temporal_custom_failure_converter (ignored) 15 bytes [optional] [built] [code generated]
|
|
18
18
|
../../shared/node/temporal/dist/workflow-error-interceptor.js 1.21 KiB [built] [code generated]
|
|
19
|
-
webpack 5.107.2 compiled successfully in
|
|
20
|
-
2026-08-
|
|
19
|
+
webpack 5.107.2 compiled successfully in 7731 ms
|
|
20
|
+
2026-08-26T13:34:02.038Z [INFO] Workflow bundle created { size: '3.31MB' }
|
|
21
21
|
/home/runner/work/shipfox/shipfox/libs/api/workflows/dist/temporal/workflows/index.js: 3469609 bytes
|
package/.turbo/turbo-type.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# @shipfox/api-workflows
|
|
2
2
|
|
|
3
|
+
## 17.1.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [fd6cee5]
|
|
8
|
+
- @shipfox/api-agent-dto@17.1.0
|
|
9
|
+
- @shipfox/api-workflows-dto@17.1.0
|
|
10
|
+
|
|
11
|
+
## 17.0.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- ed4981e: Adds the lease-authed agent session transcript transport: `GET /runs/jobs/current/steps/:stepId/session` returns the decrypted, still-gzipped head snapshot with manifest headers (or a 204 no-head marker), and `POST .../session?attempt=N&base_segment=S` commits segment `S + 1` under the claim/base CAS with idempotent-retry acks and 409 conflicts. The routes resolve the leased step through a new workflows inter-module method (`getLeasedAgentSessionContext`); the artifact store enforces the session blob cap.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [a4f56ff]
|
|
20
|
+
- Updated dependencies [5ae8b3d]
|
|
21
|
+
- Updated dependencies [ed4981e]
|
|
22
|
+
- Updated dependencies [a591e8a]
|
|
23
|
+
- Updated dependencies [918d84a]
|
|
24
|
+
- Updated dependencies [9f898d9]
|
|
25
|
+
- Updated dependencies [9f898d9]
|
|
26
|
+
- Updated dependencies [9fdba44]
|
|
27
|
+
- Updated dependencies [be5fb95]
|
|
28
|
+
- @shipfox/api-auth-context@17.0.0
|
|
29
|
+
- @shipfox/api-auth-dto@17.0.0
|
|
30
|
+
- @shipfox/api-agent-dto@17.0.0
|
|
31
|
+
- @shipfox/api-workflows-dto@17.0.0
|
|
32
|
+
- @shipfox/node-postgres@0.5.1
|
|
33
|
+
- @shipfox/workflow-document@3.3.1
|
|
34
|
+
- @shipfox/node-outbox@0.2.6
|
|
35
|
+
- @shipfox/api-definitions-dto@17.0.0
|
|
36
|
+
- @shipfox/expression@2.4.1
|
|
37
|
+
|
|
3
38
|
## 16.1.0
|
|
4
39
|
|
|
5
40
|
### Minor Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inter-module.d.ts","sourceRoot":"","sources":["../../src/presentation/inter-module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"inter-module.d.ts","sourceRoot":"","sources":["../../src/presentation/inter-module.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,sBAAsB,EAAC,MAAM,qCAAqC,CAAC;AAChF,OAAO,KAAK,EAAC,4BAA4B,EAAC,MAAM,2CAA2C,CAAC;AAC5F,OAAO,KAAK,EAAC,wBAAwB,EAAC,MAAM,gDAAgD,CAAC;AAC7F,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,wCAAwC,CAAC;AACjF,OAAO,KAAK,EAAC,wBAAwB,EAAC,MAAM,uCAAuC,CAAC;AACpF,OAAO,KAAK,EAAC,wBAAwB,EAAC,MAAM,uCAAuC,CAAC;AACpF,OAAO,EAAC,4BAA4B,EAAC,MAAM,yCAAyC,CAAC;AACrF,OAAO,KAAK,EAAC,2BAA2B,EAAC,MAAM,0CAA0C,CAAC;AAC1F,OAAO,EAIL,KAAK,uBAAuB,EAC7B,MAAM,uBAAuB,CAAC;AAkC/B,wBAAgB,sCAAsC,CAAC,MAAM,EAAE;IAC7D,KAAK,EAAE,sBAAsB,CAAC;IAC9B,WAAW,EAAE,4BAA4B,CAAC;IAC1C,UAAU,EAAE,2BAA2B,CAAC;IACxC,OAAO,EAAE,IAAI,CAAC,wBAAwB,EAAE,yBAAyB,CAAC,CAAC;IACnE,OAAO,EAAE,wBAAwB,CAAC;IAClC,YAAY,EAAE,wBAAwB,CAAC;IACvC,QAAQ,EAAE,oBAAoB,CAAC;CAChC,GAAG,uBAAuB,CAAC,OAAO,4BAA4B,CAAC,CAgN/D;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAWlF;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAE/D"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { materializedAgentStepConfigSchema } from '@shipfox/api-agent-dto';
|
|
1
|
+
import { agentSessionDescriptorSchema, materializedAgentStepConfigSchema } from '@shipfox/api-agent-dto';
|
|
2
2
|
import { workflowsInterModuleContract } from '@shipfox/api-workflows-dto/inter-module';
|
|
3
3
|
import { createInterModuleKnownError, defineInterModulePresentation } from '@shipfox/inter-module';
|
|
4
4
|
import { DEFAULT_HARNESS, harnessSchema } from '@shipfox/workflow-document';
|
|
@@ -6,9 +6,49 @@ import { InvalidJobRunnerLabelsError, WorkspaceDeletedError, WorkspaceNotFoundEr
|
|
|
6
6
|
import { AgentConfigUnresolvableError, AgentIntegrationMaterializationError, DefinitionNotFoundError, InterpolationUnresolvableError, ProjectMismatchError, runDevWorkflow, runWorkflow } from '#core/index.js';
|
|
7
7
|
import { resolveWorkflowRunTriggerReference } from '#core/resolve-trigger-reference.js';
|
|
8
8
|
import { assertWorkspaceAdmitsNewJobs } from '#core/workspace-admission.js';
|
|
9
|
-
import { getJobScope, getStepById, getStepByIdForJobExecution, listStepAttemptIdsByJobId } from '#db/index.js';
|
|
9
|
+
import { getJobScope, getStepAttemptDetail, getStepById, getStepByIdForJobExecution, listStepAttemptIdsByJobId } from '#db/index.js';
|
|
10
10
|
import { deliverEventToListener } from '#db/job-listener-events.js';
|
|
11
11
|
export function createWorkflowsInterModulePresentation(params) {
|
|
12
|
+
/**
|
|
13
|
+
* Shared lease + running-agent-step resolution for the lease-authed
|
|
14
|
+
* inter-module methods (`getLeasedAgentToolContext` and
|
|
15
|
+
* `getLeasedAgentSessionContext`): verifies the runner lease, resolves the
|
|
16
|
+
* step for the job execution, then validates the job scope, attempt, status,
|
|
17
|
+
* and agent type in one canonical order. The two seams previously
|
|
18
|
+
* copy-pasted this chain with diverging check orders (the tool method
|
|
19
|
+
* resolved the job scope before the attempt/status checks, the session
|
|
20
|
+
* method after), so the same underlying state surfaced different errors
|
|
21
|
+
* depending on the method; a single helper keeps error codes and check
|
|
22
|
+
* ordering from drifting.
|
|
23
|
+
*
|
|
24
|
+
* `loadRunningLeasedStep` (routes) deliberately keeps its own copy: it
|
|
25
|
+
* returns the run scope (trigger reference/origin state), skips the
|
|
26
|
+
* agent-type check, and speaks HTTP `ClientError`s instead of contract
|
|
27
|
+
* known errors.
|
|
28
|
+
*/ async function resolveLeasedAgentStep(resolution) {
|
|
29
|
+
const { active: leaseIsActive } = await params.runners.getLeaseState({
|
|
30
|
+
jobId: resolution.input.jobId,
|
|
31
|
+
jobExecutionId: resolution.input.jobExecutionId,
|
|
32
|
+
runnerSessionId: resolution.input.runnerSessionId
|
|
33
|
+
});
|
|
34
|
+
if (!leaseIsActive) throw createInterModuleKnownError(resolution.method, 'lease-not-active', {});
|
|
35
|
+
const step = await getStepByIdForJobExecution({
|
|
36
|
+
stepId: resolution.input.stepId,
|
|
37
|
+
jobExecutionId: resolution.input.jobExecutionId
|
|
38
|
+
});
|
|
39
|
+
if (!step) throw createInterModuleKnownError(resolution.method, 'step-not-found', {});
|
|
40
|
+
const scope = await getJobScope(resolution.input.jobId);
|
|
41
|
+
if (!scope) throw createInterModuleKnownError(resolution.method, 'job-not-found', {});
|
|
42
|
+
if (step.currentAttempt !== resolution.input.attempt) {
|
|
43
|
+
throw createInterModuleKnownError(resolution.method, 'step-attempt-mismatch', {});
|
|
44
|
+
}
|
|
45
|
+
if (step.status !== 'running') throw createInterModuleKnownError(resolution.method, 'step-not-running', {});
|
|
46
|
+
if (step.type !== 'agent') throw createInterModuleKnownError(resolution.method, 'leased-step-not-agent', {});
|
|
47
|
+
return {
|
|
48
|
+
step,
|
|
49
|
+
scope
|
|
50
|
+
};
|
|
51
|
+
}
|
|
12
52
|
return defineInterModulePresentation(workflowsInterModuleContract, {
|
|
13
53
|
startRunFromTrigger: async (input)=>{
|
|
14
54
|
try {
|
|
@@ -121,24 +161,10 @@ export function createWorkflowsInterModulePresentation(params) {
|
|
|
121
161
|
},
|
|
122
162
|
getLeasedAgentToolContext: async (input)=>{
|
|
123
163
|
const method = workflowsInterModuleContract.methods.getLeasedAgentToolContext;
|
|
124
|
-
const {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
runnerSessionId: input.runnerSessionId
|
|
164
|
+
const { step, scope } = await resolveLeasedAgentStep({
|
|
165
|
+
method,
|
|
166
|
+
input
|
|
128
167
|
});
|
|
129
|
-
if (!leaseIsActive) throw createInterModuleKnownError(method, 'lease-not-active', {});
|
|
130
|
-
const step = await getStepByIdForJobExecution({
|
|
131
|
-
stepId: input.stepId,
|
|
132
|
-
jobExecutionId: input.jobExecutionId
|
|
133
|
-
});
|
|
134
|
-
if (!step) throw createInterModuleKnownError(method, 'step-not-found', {});
|
|
135
|
-
const scope = await getJobScope(input.jobId);
|
|
136
|
-
if (!scope) throw createInterModuleKnownError(method, 'job-not-found', {});
|
|
137
|
-
if (step.currentAttempt !== input.attempt) {
|
|
138
|
-
throw createInterModuleKnownError(method, 'step-attempt-mismatch', {});
|
|
139
|
-
}
|
|
140
|
-
if (step.status !== 'running') throw createInterModuleKnownError(method, 'step-not-running', {});
|
|
141
|
-
if (step.type !== 'agent') throw createInterModuleKnownError(method, 'leased-step-not-agent', {});
|
|
142
168
|
const config = materializedAgentStepConfigSchema.safeParse(step.config);
|
|
143
169
|
if (!config.success) {
|
|
144
170
|
throw createInterModuleKnownError(method, 'agent-step-config-invalid', {});
|
|
@@ -147,6 +173,41 @@ export function createWorkflowsInterModulePresentation(params) {
|
|
|
147
173
|
workspaceId: scope.workspaceId,
|
|
148
174
|
integrations: config.data.integrations ?? []
|
|
149
175
|
};
|
|
176
|
+
},
|
|
177
|
+
getLeasedAgentSessionContext: async (input)=>{
|
|
178
|
+
const method = workflowsInterModuleContract.methods.getLeasedAgentSessionContext;
|
|
179
|
+
const { scope } = await resolveLeasedAgentStep({
|
|
180
|
+
method,
|
|
181
|
+
input
|
|
182
|
+
});
|
|
183
|
+
const detail = await getStepAttemptDetail({
|
|
184
|
+
stepId: input.stepId,
|
|
185
|
+
attempt: input.attempt
|
|
186
|
+
});
|
|
187
|
+
if (!detail) throw createInterModuleKnownError(method, 'step-attempt-mismatch', {});
|
|
188
|
+
// The dispatch integration records the resolved descriptor on the step
|
|
189
|
+
// attempt's config; anything else is a recording we cannot trust.
|
|
190
|
+
const recorded = detail.attempt.config?.session;
|
|
191
|
+
if (recorded === undefined || recorded === null) {
|
|
192
|
+
return {
|
|
193
|
+
workspaceId: scope.workspaceId,
|
|
194
|
+
projectId: scope.projectId,
|
|
195
|
+
workflowRunAttemptId: detail.workflowRunAttemptId,
|
|
196
|
+
stepAttemptId: detail.attempt.id,
|
|
197
|
+
session: null
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
const parsed = agentSessionDescriptorSchema.safeParse(recorded);
|
|
201
|
+
if (!parsed.success) {
|
|
202
|
+
throw createInterModuleKnownError(method, 'step-session-config-invalid', {});
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
workspaceId: scope.workspaceId,
|
|
206
|
+
projectId: scope.projectId,
|
|
207
|
+
workflowRunAttemptId: detail.workflowRunAttemptId,
|
|
208
|
+
stepAttemptId: detail.attempt.id,
|
|
209
|
+
session: parsed.data
|
|
210
|
+
};
|
|
150
211
|
}
|
|
151
212
|
});
|
|
152
213
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/presentation/inter-module.ts"],"sourcesContent":["import {materializedAgentStepConfigSchema} from '@shipfox/api-agent-dto';\nimport type {AgentInterModuleClient} from '@shipfox/api-agent-dto/inter-module';\nimport type {DefinitionsInterModuleClient} from '@shipfox/api-definitions-dto/inter-module';\nimport type {IntegrationsModuleClient} from '@shipfox/api-integration-core-dto/inter-module';\nimport type {ProjectsModuleClient} from '@shipfox/api-projects-dto/inter-module';\nimport type {RunnersInterModuleClient} from '@shipfox/api-runners-dto/inter-module';\nimport type {SecretsInterModuleClient} from '@shipfox/api-secrets-dto/inter-module';\nimport {workflowsInterModuleContract} from '@shipfox/api-workflows-dto/inter-module';\nimport type {WorkspacesInterModuleClient} from '@shipfox/api-workspaces-dto/inter-module';\nimport {\n createInterModuleKnownError,\n defineInterModulePresentation,\n type InterModuleKnownErrorFor,\n type InterModulePresentation,\n} from '@shipfox/inter-module';\nimport {DEFAULT_HARNESS, harnessSchema} from '@shipfox/workflow-document';\nimport type {WorkflowRunTriggerReference} from '#core/entities/workflow-run.js';\nimport {\n InvalidJobRunnerLabelsError,\n WorkspaceDeletedError,\n WorkspaceNotFoundError,\n WorkspaceSuspendedError,\n} from '#core/errors.js';\nimport {\n AgentConfigUnresolvableError,\n AgentIntegrationMaterializationError,\n DefinitionNotFoundError,\n InterpolationUnresolvableError,\n ProjectMismatchError,\n runDevWorkflow,\n runWorkflow,\n} from '#core/index.js';\nimport {resolveWorkflowRunTriggerReference} from '#core/resolve-trigger-reference.js';\nimport {assertWorkspaceAdmitsNewJobs} from '#core/workspace-admission.js';\nimport {\n getJobScope,\n getStepById,\n getStepByIdForJobExecution,\n listStepAttemptIdsByJobId,\n} from '#db/index.js';\nimport {deliverEventToListener} from '#db/job-listener-events.js';\n\ntype WorkspaceAdmissionKnownError = InterModuleKnownErrorFor<\n typeof workflowsInterModuleContract.methods.deliverEventToJobListener\n>;\n\nexport function createWorkflowsInterModulePresentation(params: {\n agent: AgentInterModuleClient;\n definitions: DefinitionsInterModuleClient;\n workspaces: WorkspacesInterModuleClient;\n secrets: Pick<SecretsInterModuleClient, 'getVariablesByNamespace'>;\n runners: RunnersInterModuleClient;\n integrations: IntegrationsModuleClient;\n projects: ProjectsModuleClient;\n}): InterModulePresentation<typeof workflowsInterModuleContract> {\n return defineInterModulePresentation(workflowsInterModuleContract, {\n startRunFromTrigger: async (input) => {\n try {\n await assertWorkspaceAdmitsNewJobs(params.workspaces, input.workspaceId);\n const run = await runWorkflow(\n params.definitions,\n {\n agent: params.agent,\n workspaceId: input.workspaceId,\n projectId: input.projectId,\n definitionId: input.definitionId,\n triggerPayload: input.triggerPayload,\n triggerConnectionId: input.triggerConnectionId,\n inputs: input.inputs,\n triggerIdempotencyKey: input.idempotencyKey,\n integrations: params.integrations,\n projects: params.projects,\n },\n {secrets: params.secrets},\n );\n return {id: run.id, name: run.name};\n } catch (error) {\n throw toStartRunKnownError(error, input.definitionId);\n }\n },\n startDevRun: async (input) => {\n try {\n await assertWorkspaceAdmitsNewJobs(params.workspaces, input.workspaceId);\n const run = await runDevWorkflow(\n params.agent,\n {\n workspaceId: input.workspaceId,\n projectId: input.projectId,\n workflowId: input.workflowId,\n model: input.model,\n sourceSnapshot: input.sourceSnapshot,\n devSource: {\n ...input.devSource,\n replayOfEventId: input.devSource.replayOfEventId ?? null,\n },\n triggerPayload: input.triggerPayload,\n triggerConnectionId: input.triggerConnectionId,\n inputs: input.inputs,\n integrations: params.integrations,\n projects: params.projects,\n },\n {secrets: params.secrets},\n );\n return {id: run.id, name: run.name};\n } catch (error) {\n throw toStartDevRunKnownError(error);\n }\n },\n resolveWorkflowRunTriggerReference: async (input) =>\n await resolveWorkflowRunTriggerReference({\n workspaceId: input.workspaceId,\n triggerConnectionId: input.triggerConnectionId,\n triggerPayload: input.triggerPayload,\n integrations: params.integrations,\n projects: params.projects,\n }),\n deliverEventToJobListener: async (input) => {\n const method = workflowsInterModuleContract.methods.deliverEventToJobListener;\n try {\n const scope = input.disposition === 'fire' ? await getJobScope(input.jobId) : undefined;\n if (scope) {\n await assertWorkspaceAdmitsNewJobs(params.workspaces, scope.workspaceId);\n }\n\n let triggerReference: WorkflowRunTriggerReference | null = null;\n if (input.triggerReference !== undefined) {\n triggerReference = input.triggerReference;\n } else if (scope) {\n triggerReference = await resolveWorkflowRunTriggerReference({\n workspaceId: scope.workspaceId,\n triggerConnectionId: input.triggerConnectionId,\n triggerPayload: {\n provider: input.provider,\n source: input.source,\n event: input.event,\n deliveryId: input.deliveryId,\n data: input.payload,\n },\n integrations: params.integrations,\n projects: params.projects,\n });\n }\n return await deliverEventToListener({\n ...input,\n triggerReference,\n receivedAt: new Date(input.receivedAt),\n });\n } catch (error) {\n const workspaceError = toWorkspaceAdmissionKnownError(method, error);\n if (workspaceError !== undefined) throw workspaceError;\n throw error;\n }\n },\n getStepLogContext: async ({stepId}) => {\n const step = await getStepById(stepId);\n const parsed = harnessSchema.safeParse(step?.config.harness);\n return {harness: parsed.success ? parsed.data : DEFAULT_HARNESS};\n },\n listJobStepAttempts: async ({jobId}) => {\n return {stepAttemptIds: await listStepAttemptIdsByJobId(jobId)};\n },\n getLeasedAgentToolContext: async (input) => {\n const method = workflowsInterModuleContract.methods.getLeasedAgentToolContext;\n const {active: leaseIsActive} = await params.runners.getLeaseState({\n jobId: input.jobId,\n jobExecutionId: input.jobExecutionId,\n runnerSessionId: input.runnerSessionId,\n });\n if (!leaseIsActive) throw createInterModuleKnownError(method, 'lease-not-active', {});\n\n const step = await getStepByIdForJobExecution({\n stepId: input.stepId,\n jobExecutionId: input.jobExecutionId,\n });\n if (!step) throw createInterModuleKnownError(method, 'step-not-found', {});\n\n const scope = await getJobScope(input.jobId);\n if (!scope) throw createInterModuleKnownError(method, 'job-not-found', {});\n if (step.currentAttempt !== input.attempt) {\n throw createInterModuleKnownError(method, 'step-attempt-mismatch', {});\n }\n if (step.status !== 'running')\n throw createInterModuleKnownError(method, 'step-not-running', {});\n if (step.type !== 'agent')\n throw createInterModuleKnownError(method, 'leased-step-not-agent', {});\n\n const config = materializedAgentStepConfigSchema.safeParse(step.config);\n if (!config.success) {\n throw createInterModuleKnownError(method, 'agent-step-config-invalid', {});\n }\n return {workspaceId: scope.workspaceId, integrations: config.data.integrations ?? []};\n },\n });\n}\n\nexport function toStartRunKnownError(error: unknown, definitionId: string): unknown {\n const method = workflowsInterModuleContract.methods.startRunFromTrigger;\n const mapped = toRunCreationKnownError(method, error);\n if (mapped !== undefined) return mapped;\n if (error instanceof DefinitionNotFoundError) {\n return createInterModuleKnownError(method, 'definition-not-found', {definitionId});\n }\n if (error instanceof ProjectMismatchError) {\n return createInterModuleKnownError(method, 'project-mismatch', {});\n }\n return error;\n}\n\nexport function toStartDevRunKnownError(error: unknown): unknown {\n return toRunCreationKnownError(workflowsInterModuleContract.methods.startDevRun, error) ?? error;\n}\n\nfunction toRunCreationKnownError(\n method:\n | typeof workflowsInterModuleContract.methods.startRunFromTrigger\n | typeof workflowsInterModuleContract.methods.startDevRun,\n error: unknown,\n): unknown {\n const workspaceError = toWorkspaceAdmissionKnownError(method, error);\n if (workspaceError !== undefined) return workspaceError;\n if (error instanceof AgentConfigUnresolvableError) {\n return createInterModuleKnownError(method, 'agent-config-unresolvable', {\n definitionId: error.definitionId,\n });\n }\n if (error instanceof AgentIntegrationMaterializationError) {\n return createInterModuleKnownError(method, 'agent-integration-materialization-failed', {});\n }\n if (error instanceof InterpolationUnresolvableError) {\n return createInterModuleKnownError(method, 'interpolation-unresolvable', {\n definitionId: error.definitionId,\n field: error.field,\n source: error.source,\n ...(error.envKey === undefined ? {} : {envKey: error.envKey}),\n });\n }\n if (error instanceof InvalidJobRunnerLabelsError) {\n return createInterModuleKnownError(method, 'invalid-job-runner-labels', {\n labels: [...error.labels],\n });\n }\n return undefined;\n}\n\nfunction toWorkspaceAdmissionKnownError(\n method:\n | typeof workflowsInterModuleContract.methods.startRunFromTrigger\n | typeof workflowsInterModuleContract.methods.startDevRun\n | typeof workflowsInterModuleContract.methods.deliverEventToJobListener,\n error: unknown,\n): WorkspaceAdmissionKnownError | undefined {\n if (error instanceof WorkspaceSuspendedError) {\n return createInterModuleKnownError(method, 'workspace-suspended', {\n workspaceId: error.workspaceId,\n });\n }\n if (error instanceof WorkspaceDeletedError) {\n return createInterModuleKnownError(method, 'workspace-deleted', {\n workspaceId: error.workspaceId,\n });\n }\n if (error instanceof WorkspaceNotFoundError) {\n return createInterModuleKnownError(method, 'workspace-not-found', {\n workspaceId: error.workspaceId,\n });\n }\n return undefined;\n}\n"],"names":["materializedAgentStepConfigSchema","workflowsInterModuleContract","createInterModuleKnownError","defineInterModulePresentation","DEFAULT_HARNESS","harnessSchema","InvalidJobRunnerLabelsError","WorkspaceDeletedError","WorkspaceNotFoundError","WorkspaceSuspendedError","AgentConfigUnresolvableError","AgentIntegrationMaterializationError","DefinitionNotFoundError","InterpolationUnresolvableError","ProjectMismatchError","runDevWorkflow","runWorkflow","resolveWorkflowRunTriggerReference","assertWorkspaceAdmitsNewJobs","getJobScope","getStepById","getStepByIdForJobExecution","listStepAttemptIdsByJobId","deliverEventToListener","createWorkflowsInterModulePresentation","params","startRunFromTrigger","input","workspaces","workspaceId","run","definitions","agent","projectId","definitionId","triggerPayload","triggerConnectionId","inputs","triggerIdempotencyKey","idempotencyKey","integrations","projects","secrets","id","name","error","toStartRunKnownError","startDevRun","workflowId","model","sourceSnapshot","devSource","replayOfEventId","toStartDevRunKnownError","deliverEventToJobListener","method","methods","scope","disposition","jobId","undefined","triggerReference","provider","source","event","deliveryId","data","payload","receivedAt","Date","workspaceError","toWorkspaceAdmissionKnownError","getStepLogContext","stepId","step","parsed","safeParse","config","harness","success","listJobStepAttempts","stepAttemptIds","getLeasedAgentToolContext","active","leaseIsActive","runners","getLeaseState","jobExecutionId","runnerSessionId","currentAttempt","attempt","status","type","mapped","toRunCreationKnownError","field","envKey","labels"],"mappings":"AAAA,SAAQA,iCAAiC,QAAO,yBAAyB;AAOzE,SAAQC,4BAA4B,QAAO,0CAA0C;AAErF,SACEC,2BAA2B,EAC3BC,6BAA6B,QAGxB,wBAAwB;AAC/B,SAAQC,eAAe,EAAEC,aAAa,QAAO,6BAA6B;AAE1E,SACEC,2BAA2B,EAC3BC,qBAAqB,EACrBC,sBAAsB,EACtBC,uBAAuB,QAClB,kBAAkB;AACzB,SACEC,4BAA4B,EAC5BC,oCAAoC,EACpCC,uBAAu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ACPvC,MAE2D,EAC3DV,KAAc;IAEd,MAAMyB,iBAAiBC,+BAA+BhB,QAAQV;IAC9D,IAAIyB,mBAAmBV,WAAW,OAAOU;IACzC,IAAIzB,iBAAiBnC,8BAA8B;QACjD,OAAOR,4BAA4BqD,QAAQ,6BAA6B;YACtErB,cAAcW,MAAMX,YAAY;QAClC;IACF;IACA,IAAIW,iBAAiBlC,sCAAsC;QACzD,OAAOT,4BAA4BqD,QAAQ,4CAA4C,CAAC;IAC1F;IACA,IAAIV,iBAAiBhC,gCAAgC;QACnD,OAAOX,4BAA4BqD,QAAQ,8BAA8B;YACvErB,cAAcW,MAAMX,YAAY;YAChC6D,OAAOlD,MAAMkD,KAAK;YAClBhC,QAAQlB,MAAMkB,MAAM;YACpB,GAAIlB,MAAMmD,MAAM,KAAKpC,YAAY,CAAC,IAAI;gBAACoC,QAAQnD,MAAMmD,MAAM;YAAA,CAAC;QAC9D;IACF;IACA,IAAInD,iBAAiBvC,6BAA6B;QAChD,OAAOJ,4BAA4BqD,QAAQ,6BAA6B;YACtE0C,QAAQ;mBAAIpD,MAAMoD,MAAM;aAAC;QAC3B;IACF;IACA,OAAOrC;AACT;AAEA,SAASW,+BACPhB,MAGyE,EACzEV,KAAc;IAEd,IAAIA,iBAAiBpC,yBAAyB;QAC5C,OAAOP,4BAA4BqD,QAAQ,uBAAuB;YAChE1B,aAAagB,MAAMhB,WAAW;QAChC;IACF;IACA,IAAIgB,iBAAiBtC,uBAAuB;QAC1C,OAAOL,4BAA4BqD,QAAQ,qBAAqB;YAC9D1B,aAAagB,MAAMhB,WAAW;QAChC;IACF;IACA,IAAIgB,iBAAiBrC,wBAAwB;QAC3C,OAAON,4BAA4BqD,QAAQ,uBAAuB;YAChE1B,aAAagB,MAAMhB,WAAW;QAChC;IACF;IACA,OAAO+B;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../src/presentation/inter-module.ts"],"sourcesContent":["import {\n agentSessionDescriptorSchema,\n materializedAgentStepConfigSchema,\n} from '@shipfox/api-agent-dto';\nimport type {AgentInterModuleClient} from '@shipfox/api-agent-dto/inter-module';\nimport type {DefinitionsInterModuleClient} from '@shipfox/api-definitions-dto/inter-module';\nimport type {IntegrationsModuleClient} from '@shipfox/api-integration-core-dto/inter-module';\nimport type {ProjectsModuleClient} from '@shipfox/api-projects-dto/inter-module';\nimport type {RunnersInterModuleClient} from '@shipfox/api-runners-dto/inter-module';\nimport type {SecretsInterModuleClient} from '@shipfox/api-secrets-dto/inter-module';\nimport {workflowsInterModuleContract} from '@shipfox/api-workflows-dto/inter-module';\nimport type {WorkspacesInterModuleClient} from '@shipfox/api-workspaces-dto/inter-module';\nimport {\n createInterModuleKnownError,\n defineInterModulePresentation,\n type InterModuleKnownErrorFor,\n type InterModulePresentation,\n} from '@shipfox/inter-module';\nimport {DEFAULT_HARNESS, harnessSchema} from '@shipfox/workflow-document';\nimport type {Step} from '#core/entities/step.js';\nimport type {WorkflowRunTriggerReference} from '#core/entities/workflow-run.js';\nimport {\n InvalidJobRunnerLabelsError,\n WorkspaceDeletedError,\n WorkspaceNotFoundError,\n WorkspaceSuspendedError,\n} from '#core/errors.js';\nimport {\n AgentConfigUnresolvableError,\n AgentIntegrationMaterializationError,\n DefinitionNotFoundError,\n InterpolationUnresolvableError,\n ProjectMismatchError,\n runDevWorkflow,\n runWorkflow,\n} from '#core/index.js';\nimport {resolveWorkflowRunTriggerReference} from '#core/resolve-trigger-reference.js';\nimport {assertWorkspaceAdmitsNewJobs} from '#core/workspace-admission.js';\nimport {\n getJobScope,\n getStepAttemptDetail,\n getStepById,\n getStepByIdForJobExecution,\n listStepAttemptIdsByJobId,\n} from '#db/index.js';\nimport {deliverEventToListener} from '#db/job-listener-events.js';\n\ntype WorkspaceAdmissionKnownError = InterModuleKnownErrorFor<\n typeof workflowsInterModuleContract.methods.deliverEventToJobListener\n>;\n\nexport function createWorkflowsInterModulePresentation(params: {\n agent: AgentInterModuleClient;\n definitions: DefinitionsInterModuleClient;\n workspaces: WorkspacesInterModuleClient;\n secrets: Pick<SecretsInterModuleClient, 'getVariablesByNamespace'>;\n runners: RunnersInterModuleClient;\n integrations: IntegrationsModuleClient;\n projects: ProjectsModuleClient;\n}): InterModulePresentation<typeof workflowsInterModuleContract> {\n /**\n * Shared lease + running-agent-step resolution for the lease-authed\n * inter-module methods (`getLeasedAgentToolContext` and\n * `getLeasedAgentSessionContext`): verifies the runner lease, resolves the\n * step for the job execution, then validates the job scope, attempt, status,\n * and agent type in one canonical order. The two seams previously\n * copy-pasted this chain with diverging check orders (the tool method\n * resolved the job scope before the attempt/status checks, the session\n * method after), so the same underlying state surfaced different errors\n * depending on the method; a single helper keeps error codes and check\n * ordering from drifting.\n *\n * `loadRunningLeasedStep` (routes) deliberately keeps its own copy: it\n * returns the run scope (trigger reference/origin state), skips the\n * agent-type check, and speaks HTTP `ClientError`s instead of contract\n * known errors.\n */\n async function resolveLeasedAgentStep(resolution: {\n method:\n | typeof workflowsInterModuleContract.methods.getLeasedAgentToolContext\n | typeof workflowsInterModuleContract.methods.getLeasedAgentSessionContext;\n input: {\n jobId: string;\n jobExecutionId: string;\n runnerSessionId: string;\n stepId: string;\n attempt: number;\n };\n }): Promise<{\n step: Step;\n scope: NonNullable<Awaited<ReturnType<typeof getJobScope>>>;\n }> {\n const {active: leaseIsActive} = await params.runners.getLeaseState({\n jobId: resolution.input.jobId,\n jobExecutionId: resolution.input.jobExecutionId,\n runnerSessionId: resolution.input.runnerSessionId,\n });\n if (!leaseIsActive)\n throw createInterModuleKnownError(resolution.method, 'lease-not-active', {});\n\n const step = await getStepByIdForJobExecution({\n stepId: resolution.input.stepId,\n jobExecutionId: resolution.input.jobExecutionId,\n });\n if (!step) throw createInterModuleKnownError(resolution.method, 'step-not-found', {});\n\n const scope = await getJobScope(resolution.input.jobId);\n if (!scope) throw createInterModuleKnownError(resolution.method, 'job-not-found', {});\n if (step.currentAttempt !== resolution.input.attempt) {\n throw createInterModuleKnownError(resolution.method, 'step-attempt-mismatch', {});\n }\n if (step.status !== 'running')\n throw createInterModuleKnownError(resolution.method, 'step-not-running', {});\n if (step.type !== 'agent')\n throw createInterModuleKnownError(resolution.method, 'leased-step-not-agent', {});\n\n return {step, scope};\n }\n\n return defineInterModulePresentation(workflowsInterModuleContract, {\n startRunFromTrigger: async (input) => {\n try {\n await assertWorkspaceAdmitsNewJobs(params.workspaces, input.workspaceId);\n const run = await runWorkflow(\n params.definitions,\n {\n agent: params.agent,\n workspaceId: input.workspaceId,\n projectId: input.projectId,\n definitionId: input.definitionId,\n triggerPayload: input.triggerPayload,\n triggerConnectionId: input.triggerConnectionId,\n inputs: input.inputs,\n triggerIdempotencyKey: input.idempotencyKey,\n integrations: params.integrations,\n projects: params.projects,\n },\n {secrets: params.secrets},\n );\n return {id: run.id, name: run.name};\n } catch (error) {\n throw toStartRunKnownError(error, input.definitionId);\n }\n },\n startDevRun: async (input) => {\n try {\n await assertWorkspaceAdmitsNewJobs(params.workspaces, input.workspaceId);\n const run = await runDevWorkflow(\n params.agent,\n {\n workspaceId: input.workspaceId,\n projectId: input.projectId,\n workflowId: input.workflowId,\n model: input.model,\n sourceSnapshot: input.sourceSnapshot,\n devSource: {\n ...input.devSource,\n replayOfEventId: input.devSource.replayOfEventId ?? null,\n },\n triggerPayload: input.triggerPayload,\n triggerConnectionId: input.triggerConnectionId,\n inputs: input.inputs,\n integrations: params.integrations,\n projects: params.projects,\n },\n {secrets: params.secrets},\n );\n return {id: run.id, name: run.name};\n } catch (error) {\n throw toStartDevRunKnownError(error);\n }\n },\n resolveWorkflowRunTriggerReference: async (input) =>\n await resolveWorkflowRunTriggerReference({\n workspaceId: input.workspaceId,\n triggerConnectionId: input.triggerConnectionId,\n triggerPayload: input.triggerPayload,\n integrations: params.integrations,\n projects: params.projects,\n }),\n deliverEventToJobListener: async (input) => {\n const method = workflowsInterModuleContract.methods.deliverEventToJobListener;\n try {\n const scope = input.disposition === 'fire' ? await getJobScope(input.jobId) : undefined;\n if (scope) {\n await assertWorkspaceAdmitsNewJobs(params.workspaces, scope.workspaceId);\n }\n\n let triggerReference: WorkflowRunTriggerReference | null = null;\n if (input.triggerReference !== undefined) {\n triggerReference = input.triggerReference;\n } else if (scope) {\n triggerReference = await resolveWorkflowRunTriggerReference({\n workspaceId: scope.workspaceId,\n triggerConnectionId: input.triggerConnectionId,\n triggerPayload: {\n provider: input.provider,\n source: input.source,\n event: input.event,\n deliveryId: input.deliveryId,\n data: input.payload,\n },\n integrations: params.integrations,\n projects: params.projects,\n });\n }\n return await deliverEventToListener({\n ...input,\n triggerReference,\n receivedAt: new Date(input.receivedAt),\n });\n } catch (error) {\n const workspaceError = toWorkspaceAdmissionKnownError(method, error);\n if (workspaceError !== undefined) throw workspaceError;\n throw error;\n }\n },\n getStepLogContext: async ({stepId}) => {\n const step = await getStepById(stepId);\n const parsed = harnessSchema.safeParse(step?.config.harness);\n return {harness: parsed.success ? parsed.data : DEFAULT_HARNESS};\n },\n listJobStepAttempts: async ({jobId}) => {\n return {stepAttemptIds: await listStepAttemptIdsByJobId(jobId)};\n },\n getLeasedAgentToolContext: async (input) => {\n const method = workflowsInterModuleContract.methods.getLeasedAgentToolContext;\n const {step, scope} = await resolveLeasedAgentStep({method, input});\n\n const config = materializedAgentStepConfigSchema.safeParse(step.config);\n if (!config.success) {\n throw createInterModuleKnownError(method, 'agent-step-config-invalid', {});\n }\n return {workspaceId: scope.workspaceId, integrations: config.data.integrations ?? []};\n },\n getLeasedAgentSessionContext: async (input) => {\n const method = workflowsInterModuleContract.methods.getLeasedAgentSessionContext;\n const {scope} = await resolveLeasedAgentStep({method, input});\n\n const detail = await getStepAttemptDetail({stepId: input.stepId, attempt: input.attempt});\n if (!detail) throw createInterModuleKnownError(method, 'step-attempt-mismatch', {});\n\n // The dispatch integration records the resolved descriptor on the step\n // attempt's config; anything else is a recording we cannot trust.\n const recorded = detail.attempt.config?.session;\n if (recorded === undefined || recorded === null) {\n return {\n workspaceId: scope.workspaceId,\n projectId: scope.projectId,\n workflowRunAttemptId: detail.workflowRunAttemptId,\n stepAttemptId: detail.attempt.id,\n session: null,\n };\n }\n const parsed = agentSessionDescriptorSchema.safeParse(recorded);\n if (!parsed.success) {\n throw createInterModuleKnownError(method, 'step-session-config-invalid', {});\n }\n return {\n workspaceId: scope.workspaceId,\n projectId: scope.projectId,\n workflowRunAttemptId: detail.workflowRunAttemptId,\n stepAttemptId: detail.attempt.id,\n session: parsed.data,\n };\n },\n });\n}\n\nexport function toStartRunKnownError(error: unknown, definitionId: string): unknown {\n const method = workflowsInterModuleContract.methods.startRunFromTrigger;\n const mapped = toRunCreationKnownError(method, error);\n if (mapped !== undefined) return mapped;\n if (error instanceof DefinitionNotFoundError) {\n return createInterModuleKnownError(method, 'definition-not-found', {definitionId});\n }\n if (error instanceof ProjectMismatchError) {\n return createInterModuleKnownError(method, 'project-mismatch', {});\n }\n return error;\n}\n\nexport function toStartDevRunKnownError(error: unknown): unknown {\n return toRunCreationKnownError(workflowsInterModuleContract.methods.startDevRun, error) ?? error;\n}\n\nfunction toRunCreationKnownError(\n method:\n | typeof workflowsInterModuleContract.methods.startRunFromTrigger\n | typeof workflowsInterModuleContract.methods.startDevRun,\n error: unknown,\n): unknown {\n const workspaceError = toWorkspaceAdmissionKnownError(method, error);\n if (workspaceError !== undefined) return workspaceError;\n if (error instanceof AgentConfigUnresolvableError) {\n return createInterModuleKnownError(method, 'agent-config-unresolvable', {\n definitionId: error.definitionId,\n });\n }\n if (error instanceof AgentIntegrationMaterializationError) {\n return createInterModuleKnownError(method, 'agent-integration-materialization-failed', {});\n }\n if (error instanceof InterpolationUnresolvableError) {\n return createInterModuleKnownError(method, 'interpolation-unresolvable', {\n definitionId: error.definitionId,\n field: error.field,\n source: error.source,\n ...(error.envKey === undefined ? {} : {envKey: error.envKey}),\n });\n }\n if (error instanceof InvalidJobRunnerLabelsError) {\n return createInterModuleKnownError(method, 'invalid-job-runner-labels', {\n labels: [...error.labels],\n });\n }\n return undefined;\n}\n\nfunction toWorkspaceAdmissionKnownError(\n method:\n | typeof workflowsInterModuleContract.methods.startRunFromTrigger\n | typeof workflowsInterModuleContract.methods.startDevRun\n | typeof workflowsInterModuleContract.methods.deliverEventToJobListener,\n error: unknown,\n): WorkspaceAdmissionKnownError | undefined {\n if (error instanceof WorkspaceSuspendedError) {\n return createInterModuleKnownError(method, 'workspace-suspended', {\n workspaceId: error.workspaceId,\n });\n }\n if (error instanceof WorkspaceDeletedError) {\n return createInterModuleKnownError(method, 'workspace-deleted', {\n workspaceId: error.workspaceId,\n });\n }\n if (error instanceof WorkspaceNotFoundError) {\n return createInterModuleKnownError(method, 'workspace-not-found', {\n workspaceId: error.workspaceId,\n });\n }\n return undefined;\n}\n"],"names":["agentSessionDescriptorSchema","materializedAgentStepConfigSchema","workflowsInterModuleContract","createInterModuleKnownError","defineInterModulePresentation","DEFAULT_HARNESS","harnessSchema","InvalidJobRunnerLabelsError","WorkspaceDeletedError","WorkspaceNotFoundError","WorkspaceSuspendedError","AgentConfigUnresolvableError","AgentIntegrationMaterializationError","DefinitionNotFoundError","InterpolationUnresolvableError","ProjectMismatchError","runDevWorkflow","runWorkflow","resolveWorkflowRunTriggerReference","assertWorkspaceAdmitsNewJobs","getJobScope","getStepAttemptDetail","getStepById","getStepByIdForJobExecution","listStepAttemptIdsByJobId","deliverEventToListener","createWorkflowsInterModulePresentation","params","resolveLeasedAgentStep","resolution","active","leaseIsActive","runners","getLeaseState","jobId","input","jobExecutionId","runnerSessionId","method","step","stepId","scope","currentAttempt","attempt","status","type","startRunFromTrigger","workspaces","workspaceId","run","definitions","agent","projectId","definitionId","triggerPayload","triggerConnectionId","inputs","triggerIdempotencyKey","idempotencyKey","integrations","projects","secrets","id","name","error","toStartRunKnownError","startDevRun","workflowId","model","sourceSnapshot","devSource","replayOfEventId","toStartDevRunKnownError","deliverEventToJobListener","methods","disposition","undefined","triggerReference","provider","source","event","deliveryId","data","payload","receivedAt","Date","workspaceError","toWorkspaceAdmissionKnownError","getStepLogContext","parsed","safeParse","config","harness","success","listJobStepAttempts","stepAttemptIds","getLeasedAgentToolContext","getLeasedAgentSessionContext","detail","recorded","session","workflowRunAttemptId","stepAttemptId","mapped","toRunCreationKnownError","field","envKey","labels"],"mappings":"AAAA,SACEA,4BAA4B,EAC5BC,iCAAiC,QAC5B,yBAAyB;AAOhC,SAAQC,4BAA4B,QAAO,0CAA0C;AAErF,SACEC,2BAA2B,EAC3BC,6BAA6B,QAGxB,wBAAwB;AAC/B,SAAQC,eAAe,EAAEC,aAAa,QAAO,6BAA6B;AAG1E,SACEC,2BAA2B,EAC3BC,qBAAqB,EACrBC,sBAAsB,EACtBC,uBAAuB,QAClB,kBAAkB;AACzB,SACEC,4BAA4B,EAC5BC,oCAAoC,EACpCC,uBAAuB,EACvBC,8BAA8B,EAC9BC,oBAAoB,EACpBC,cAAc,EACdC,WAAW,QACN,iBAAiB;AACxB,SAAQC,kCAAkC,QAAO,qCAAqC;AACtF,SAAQC,4BAA4B,QAAO,+BAA+B;AAC1E,SACEC,WAAW,EACXC,oBAAoB,EACpBC,WAAW,EACXC,0BAA0B,EAC1BC,yBAAyB,QACpB,eAAe;AACtB,SAAQC,sBAAsB,QAAO,6BAA6B;AAMlE,OAAO,SAASC,uCAAuCC,MAQtD;IACC;;;;;;;;;;;;;;;;GAgBC,GACD,eAAeC,uBAAuBC,UAWrC;QAIC,MAAM,EAACC,QAAQC,aAAa,EAAC,GAAG,MAAMJ,OAAOK,OAAO,CAACC,aAAa,CAAC;YACjEC,OAAOL,WAAWM,KAAK,CAACD,KAAK;YAC7BE,gBAAgBP,WAAWM,KAAK,CAACC,cAAc;YAC/CC,iBAAiBR,WAAWM,KAAK,CAACE,eAAe;QACnD;QACA,IAAI,CAACN,eACH,MAAM5B,4BAA4B0B,WAAWS,MAAM,EAAE,oBAAoB,CAAC;QAE5E,MAAMC,OAAO,MAAMhB,2BAA2B;YAC5CiB,QAAQX,WAAWM,KAAK,CAACK,MAAM;YAC/BJ,gBAAgBP,WAAWM,KAAK,CAACC,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