@openapi-flow/langchain 0.3.18 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/dist/arguments/analyze-api-input-answers.js +34 -6
- package/dist/arguments/api-argument-planning-error.d.ts +11 -0
- package/dist/arguments/api-argument-planning-error.js +32 -0
- package/dist/arguments/assert-api-argument-generation-source.d.ts +4 -0
- package/dist/arguments/assert-api-argument-generation-source.js +16 -0
- package/dist/arguments/attribute-api-literal-generation-sources.d.ts +4 -0
- package/dist/arguments/attribute-api-literal-generation-sources.js +16 -0
- package/dist/arguments/create-api-argument-rejection.d.ts +3 -0
- package/dist/arguments/create-api-argument-rejection.js +38 -0
- package/dist/arguments/fingerprint-api-argument-source.d.ts +4 -0
- package/dist/arguments/fingerprint-api-argument-source.js +13 -0
- package/dist/arguments/generate-api-arguments.js +108 -40
- package/dist/arguments/interpret-api-argument-enums.js +1 -0
- package/dist/arguments/resolve-api-literal-generation-output.d.ts +3 -0
- package/dist/arguments/resolve-api-literal-generation-output.js +14 -0
- package/dist/bindings/plan-api-bindings-by-call.js +12 -3
- package/dist/bindings/plan-api-call-bindings.js +30 -9
- package/dist/bindings/select-api-binding-sources.js +32 -8
- package/dist/model/invoke-structured-model.js +32 -6
- package/dist/prompts/api-arguments-prompt.d.ts +2 -1
- package/dist/prompts/api-arguments-prompt.js +11 -1
- package/dist/prompts/api-input-answers-prompt.d.ts +1 -1
- package/dist/prompts/api-input-answers-prompt.js +8 -7
- package/dist/prompts/api-material-repair-prompt.d.ts +1 -0
- package/dist/prompts/api-material-repair-prompt.js +1 -0
- package/dist/prompts/incremental-workflow-connections-prompt.d.ts +2 -2
- package/dist/prompts/incremental-workflow-connections-prompt.js +5 -4
- package/dist/prompts/native-instance-selection-review-prompt.d.ts +1 -0
- package/dist/prompts/native-instance-selection-review-prompt.js +9 -0
- package/dist/prompts/native-node-planning-prompt.d.ts +1 -1
- package/dist/prompts/native-node-planning-prompt.js +2 -0
- package/dist/prompts/workflow-connection-goal-recovery-prompt.d.ts +1 -0
- package/dist/prompts/workflow-connection-goal-recovery-prompt.js +8 -0
- package/dist/prompts/workflow-connection-goal-review-prompt.d.ts +1 -0
- package/dist/prompts/workflow-connection-goal-review-prompt.js +7 -0
- package/dist/prompts/workflow-connection-native-repair-prompt.d.ts +1 -0
- package/dist/prompts/workflow-connection-native-repair-prompt.js +1 -0
- package/dist/prompts/workflow-connection-outline-prompt.d.ts +1 -0
- package/dist/prompts/workflow-connection-outline-prompt.js +6 -0
- package/dist/prompts/workflow-connection-revision-prompt.d.ts +1 -0
- package/dist/prompts/workflow-connection-revision-prompt.js +10 -0
- package/dist/public-api.d.ts +28 -0
- package/dist/public-api.js +21 -0
- package/dist/schemas/api-argument-rejection-schema.d.ts +28 -0
- package/dist/schemas/api-argument-rejection-schema.js +20 -0
- package/dist/schemas/api-input-answer-source-schema.d.ts +5 -5
- package/dist/schemas/api-input-answer-source-schema.js +14 -6
- package/dist/schemas/api-literal-generation-output-schema.d.ts +35 -4
- package/dist/schemas/api-literal-generation-output-schema.js +49 -14
- package/dist/schemas/create-connection-material-repair-choice-schema.d.ts +4 -0
- package/dist/schemas/create-connection-material-repair-choice-schema.js +23 -0
- package/dist/schemas/model-signal-schema.d.ts +3 -0
- package/dist/schemas/model-signal-schema.js +3 -0
- package/dist/schemas/native-node-parameter-contract.js +2 -0
- package/dist/schemas/native-node-planning-contract.js +30 -23
- package/dist/schemas/native-planning-rejection-schema.d.ts +11 -0
- package/dist/schemas/native-planning-rejection-schema.js +8 -0
- package/dist/schemas/workflow-connection-goal-recovery-schema.d.ts +4 -0
- package/dist/schemas/workflow-connection-goal-recovery-schema.js +16 -0
- package/dist/schemas/workflow-connection-goal-rejection-schema.d.ts +76 -0
- package/dist/schemas/workflow-connection-goal-rejection-schema.js +2 -1
- package/dist/schemas/workflow-connection-goal-review-schema.d.ts +4 -0
- package/dist/schemas/workflow-connection-goal-review-schema.js +26 -0
- package/dist/schemas/workflow-connection-goals-schema.d.ts +4 -2
- package/dist/schemas/workflow-connection-outline-rejection-schema.d.ts +25 -0
- package/dist/schemas/workflow-connection-outline-rejection-schema.js +21 -0
- package/dist/schemas/workflow-connection-outline-schema.d.ts +3 -0
- package/dist/schemas/workflow-connection-outline-schema.js +25 -0
- package/dist/schemas/workflow-connection-revision-rejection-schema.d.ts +113 -0
- package/dist/schemas/workflow-connection-revision-rejection-schema.js +23 -0
- package/dist/schemas/workflow-connection-revision-schema.d.ts +4 -0
- package/dist/schemas/workflow-connection-revision-schema.js +23 -0
- package/dist/schemas/workflow-connection-step-schema.d.ts +5 -3
- package/dist/schemas/workflow-connection-step-schema.js +62 -31
- package/dist/types/api-call-binding-planning.d.ts +2 -1
- package/dist/types/api-input-answers.d.ts +3 -6
- package/dist/types/argument-generation.d.ts +37 -12
- package/dist/types/incremental-connection-planning.d.ts +10 -3
- package/dist/types/native-instance-selection-review.d.ts +12 -0
- package/dist/types/native-instance-selection-review.js +1 -0
- package/dist/types/native-node-planning.d.ts +10 -2
- package/dist/types/native-planning-rejection.d.ts +21 -0
- package/dist/types/native-planning-rejection.js +1 -0
- package/dist/types/workflow-connection-goal-recovery.d.ts +22 -0
- package/dist/types/workflow-connection-goal-recovery.js +1 -0
- package/dist/types/workflow-connection-goal-review.d.ts +13 -0
- package/dist/types/workflow-connection-goal-review.js +1 -0
- package/dist/types/workflow-connection-native-repair.d.ts +16 -0
- package/dist/types/workflow-connection-native-repair.js +1 -0
- package/dist/types/workflow-connection-outline.d.ts +22 -0
- package/dist/types/workflow-connection-outline.js +1 -0
- package/dist/types/workflow-connection-revision.d.ts +34 -0
- package/dist/types/workflow-connection-revision.js +1 -0
- package/dist/workflow/connections/create-workflow-connection-goal-rejection.js +8 -2
- package/dist/workflow/connections/create-workflow-connection-outline-rejection.d.ts +3 -0
- package/dist/workflow/connections/create-workflow-connection-outline-rejection.js +28 -0
- package/dist/workflow/connections/create-workflow-connection-revision-rejection.d.ts +3 -0
- package/dist/workflow/connections/create-workflow-connection-revision-rejection.js +32 -0
- package/dist/workflow/connections/describe-workflow-connection-outline-request.d.ts +3 -0
- package/dist/workflow/connections/describe-workflow-connection-outline-request.js +30 -0
- package/dist/workflow/connections/generate-workflow-connection-native-parameters.d.ts +4 -0
- package/dist/workflow/connections/generate-workflow-connection-native-parameters.js +80 -0
- package/dist/workflow/connections/invoke-connection-planning-model.js +3 -0
- package/dist/workflow/connections/plan-workflow-connection-goal-recovery.d.ts +3 -0
- package/dist/workflow/connections/plan-workflow-connection-goal-recovery.js +111 -0
- package/dist/workflow/connections/plan-workflow-connection-goals.js +35 -16
- package/dist/workflow/connections/plan-workflow-connection-native-dependencies.d.ts +4 -0
- package/dist/workflow/connections/plan-workflow-connection-native-dependencies.js +73 -0
- package/dist/workflow/connections/plan-workflow-connection-outline.d.ts +4 -0
- package/dist/workflow/connections/plan-workflow-connection-outline.js +93 -0
- package/dist/workflow/connections/plan-workflow-connection-revision.d.ts +3 -0
- package/dist/workflow/connections/plan-workflow-connection-revision.js +163 -0
- package/dist/workflow/connections/plan-workflow-connection-step.js +75 -29
- package/dist/workflow/connections/resolve-connection-selections.d.ts +6 -0
- package/dist/workflow/connections/resolve-connection-selections.js +28 -0
- package/dist/workflow/connections/review-workflow-connection-goals.d.ts +4 -0
- package/dist/workflow/connections/review-workflow-connection-goals.js +64 -0
- package/dist/workflow/connections/validate-workflow-goal-review-feedback.d.ts +4 -0
- package/dist/workflow/connections/validate-workflow-goal-review-feedback.js +22 -0
- package/dist/workflow/connections/workflow-connection-native-repair-error.d.ts +6 -0
- package/dist/workflow/connections/workflow-connection-native-repair-error.js +18 -0
- package/dist/workflow/connections/workflow-connection-planning-error.d.ts +1 -0
- package/dist/workflow/connections/workflow-connection-planning-error.js +2 -0
- package/dist/workflow/native-selection/create-native-planning-rejection.d.ts +4 -0
- package/dist/workflow/native-selection/create-native-planning-rejection.js +45 -0
- package/dist/workflow/native-selection/describe-native-planning-request.d.ts +5 -0
- package/dist/workflow/native-selection/describe-native-planning-request.js +26 -0
- package/dist/workflow/native-selection/native-instance-selection-review-error.d.ts +6 -0
- package/dist/workflow/native-selection/native-instance-selection-review-error.js +18 -0
- package/dist/workflow/native-selection/review-native-instance-selection.d.ts +4 -0
- package/dist/workflow/native-selection/review-native-instance-selection.js +97 -0
- package/dist/workflow/native-selection/validate-native-planning-rejections.d.ts +2 -0
- package/dist/workflow/native-selection/validate-native-planning-rejections.js +14 -0
- package/dist/workflow/resolve-native-node-planning-output.js +3 -1
- package/dist/workflow/select-native-node-instances.js +44 -17
- package/package.json +2 -2
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
import type { workflowConnectionRevisionRejectionSchema } from '../schemas/workflow-connection-revision-rejection-schema.js';
|
|
4
|
+
import type { WorkflowConnectionRevisionInput, WorkflowConnectionRevision, WorkflowConnectionMaterialRepairRequest, WorkflowConnectionMaterialRepairReceipt, WorkflowConnectionRejectedProposal, WorkflowConnectionGoalReview } from '@openapi-flow/core';
|
|
5
|
+
import type { WorkflowConnectionGoalSelection, WorkflowConnectionPatchSelection } from './incremental-connection-planning.js';
|
|
6
|
+
export interface PlanWorkflowConnectionRevisionInput extends WorkflowConnectionRevisionInput {
|
|
7
|
+
model: BaseChatModel;
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
rejectedProposals?: WorkflowConnectionRevisionRejection[];
|
|
10
|
+
rejectedConnections?: WorkflowConnectionRejectedProposal[];
|
|
11
|
+
rejectedGoalReviews?: WorkflowReviewedConnectionRevision[];
|
|
12
|
+
}
|
|
13
|
+
export interface WorkflowReviewedConnectionRevision {
|
|
14
|
+
revision: WorkflowConnectionRevision;
|
|
15
|
+
review: WorkflowConnectionGoalReview;
|
|
16
|
+
}
|
|
17
|
+
export type WorkflowConnectionRevisionRejection = z.infer<typeof workflowConnectionRevisionRejectionSchema>;
|
|
18
|
+
export interface CreateWorkflowConnectionRevisionRejectionInput extends WorkflowConnectionRevisionInput {
|
|
19
|
+
error: unknown;
|
|
20
|
+
}
|
|
21
|
+
export interface WorkflowConnectionRevisionSelection {
|
|
22
|
+
kind: 'revise-connections';
|
|
23
|
+
goals: WorkflowConnectionGoalSelection[];
|
|
24
|
+
graphChange: WorkflowConnectionPatchSelection;
|
|
25
|
+
}
|
|
26
|
+
export type WorkflowConnectionRevisionModelDecision = WorkflowConnectionRevisionSelection | WorkflowConnectionMaterialRepairRequest;
|
|
27
|
+
export interface WorkflowConnectionRevisionModelOutput {
|
|
28
|
+
decision: WorkflowConnectionRevisionModelDecision;
|
|
29
|
+
}
|
|
30
|
+
export interface RevisedWorkflowConnections {
|
|
31
|
+
kind: 'revised-connections';
|
|
32
|
+
revision: WorkflowConnectionRevision;
|
|
33
|
+
}
|
|
34
|
+
export type PlanWorkflowConnectionRevisionResult = RevisedWorkflowConnections | WorkflowConnectionMaterialRepairReceipt;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
-
import { describeWorkflowConnectionGoals } from '@openapi-flow/core';
|
|
2
|
+
import { describeWorkflowConnectionGoals, WorkflowPlanningConstraintError, } from '@openapi-flow/core';
|
|
3
3
|
import { workflowConnectionGoalRejectionSchema } from '../../schemas/workflow-connection-goal-rejection-schema.js';
|
|
4
4
|
import { WorkflowConnectionPlanningError } from './workflow-connection-planning-error.js';
|
|
5
5
|
/** Classify an unchanged-source proposal rejection. Other failures must remain failures. */
|
|
6
6
|
export function createWorkflowConnectionGoalRejection(input) {
|
|
7
7
|
const { error } = input;
|
|
8
8
|
if (!(error instanceof WorkflowConnectionPlanningError) ||
|
|
9
|
-
|
|
9
|
+
![
|
|
10
|
+
'planWorkflowConnectionGoals',
|
|
11
|
+
'planWorkflowConnectionGoalRecovery',
|
|
12
|
+
].includes(error.diagnostic.operation) ||
|
|
10
13
|
!['model-output', 'contract-validation'].includes(error.diagnostic.stage) ||
|
|
11
14
|
error.sourceFingerprint === undefined)
|
|
12
15
|
return undefined;
|
|
@@ -19,6 +22,9 @@ export function createWorkflowConnectionGoalRejection(input) {
|
|
|
19
22
|
code: error.diagnostic.code,
|
|
20
23
|
output: error.output,
|
|
21
24
|
reason: error.message,
|
|
25
|
+
...(error.cause instanceof WorkflowPlanningConstraintError
|
|
26
|
+
? { constraints: error.cause.inspection }
|
|
27
|
+
: {}),
|
|
22
28
|
});
|
|
23
29
|
// Non-JSON results cannot be checkpointed losslessly; never repair them to enable a retry.
|
|
24
30
|
if (!parsed.success || !isDeepStrictEqual(parsed.data.output, error.output))
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { CreateWorkflowConnectionOutlineRejectionInput, WorkflowConnectionOutlineRejection } from '../../types/workflow-connection-outline.js';
|
|
2
|
+
/** Classify only lossless proposal failures from this unchanged outline request. */
|
|
3
|
+
export declare function createWorkflowConnectionOutlineRejection(input: CreateWorkflowConnectionOutlineRejectionInput): WorkflowConnectionOutlineRejection | undefined;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
+
import { workflowConnectionOutlineRejectionSchema } from '../../schemas/workflow-connection-outline-rejection-schema.js';
|
|
3
|
+
import { describeWorkflowConnectionOutlineRequest } from './describe-workflow-connection-outline-request.js';
|
|
4
|
+
import { WorkflowConnectionPlanningError } from './workflow-connection-planning-error.js';
|
|
5
|
+
/** Classify only lossless proposal failures from this unchanged outline request. */
|
|
6
|
+
export function createWorkflowConnectionOutlineRejection(input) {
|
|
7
|
+
const { error } = input;
|
|
8
|
+
if (!(error instanceof WorkflowConnectionPlanningError) ||
|
|
9
|
+
error.diagnostic.operation !== 'planWorkflowConnectionOutline' ||
|
|
10
|
+
!['model-output', 'contract-validation'].includes(error.diagnostic.stage) ||
|
|
11
|
+
error.requestFingerprint === undefined)
|
|
12
|
+
return undefined;
|
|
13
|
+
const current = describeWorkflowConnectionOutlineRequest(input);
|
|
14
|
+
if (error.requestFingerprint !== current.requestFingerprint ||
|
|
15
|
+
error.sourceFingerprint !== current.description.expected.sourceFingerprint)
|
|
16
|
+
return undefined;
|
|
17
|
+
const parsed = workflowConnectionOutlineRejectionSchema.safeParse({
|
|
18
|
+
requestFingerprint: current.requestFingerprint,
|
|
19
|
+
expected: current.description.expected,
|
|
20
|
+
stage: error.diagnostic.stage,
|
|
21
|
+
code: error.diagnostic.code,
|
|
22
|
+
output: error.output,
|
|
23
|
+
reason: error.message,
|
|
24
|
+
});
|
|
25
|
+
if (!parsed.success || !isDeepStrictEqual(parsed.data.output, error.output))
|
|
26
|
+
return undefined;
|
|
27
|
+
return structuredClone(parsed.data);
|
|
28
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { CreateWorkflowConnectionRevisionRejectionInput, WorkflowConnectionRevisionRejection } from '../../types/workflow-connection-revision.js';
|
|
2
|
+
/** Classify a lossless proposal rejection only. Never convert transport, cancellation or changed-source failures into retries. */
|
|
3
|
+
export declare function createWorkflowConnectionRevisionRejection(input: CreateWorkflowConnectionRevisionRejectionInput): WorkflowConnectionRevisionRejection | undefined;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
+
import { describeWorkflowConnectionRevision, WorkflowConnectionRevisionError, WorkflowPlanningConstraintError, } from '@openapi-flow/core';
|
|
3
|
+
import { workflowConnectionRevisionRejectionSchema } from '../../schemas/workflow-connection-revision-rejection-schema.js';
|
|
4
|
+
import { WorkflowConnectionPlanningError } from './workflow-connection-planning-error.js';
|
|
5
|
+
/** Classify a lossless proposal rejection only. Never convert transport, cancellation or changed-source failures into retries. */
|
|
6
|
+
export function createWorkflowConnectionRevisionRejection(input) {
|
|
7
|
+
const { error } = input;
|
|
8
|
+
if (!(error instanceof WorkflowConnectionPlanningError) ||
|
|
9
|
+
error.diagnostic.operation !== 'planWorkflowConnectionRevision' ||
|
|
10
|
+
!['model-output', 'contract-validation'].includes(error.diagnostic.stage))
|
|
11
|
+
return undefined;
|
|
12
|
+
const current = describeWorkflowConnectionRevision(input);
|
|
13
|
+
if (error.sourceFingerprint !== current.sourceFingerprint)
|
|
14
|
+
return undefined;
|
|
15
|
+
const parsed = workflowConnectionRevisionRejectionSchema.safeParse({
|
|
16
|
+
sourceFingerprint: current.sourceFingerprint,
|
|
17
|
+
expected: current.before.expected,
|
|
18
|
+
stage: error.diagnostic.stage,
|
|
19
|
+
code: error.diagnostic.code,
|
|
20
|
+
output: error.output,
|
|
21
|
+
reason: error.message,
|
|
22
|
+
...(error.cause instanceof WorkflowConnectionRevisionError
|
|
23
|
+
? { violations: error.cause.violations }
|
|
24
|
+
: {}),
|
|
25
|
+
...(error.cause instanceof WorkflowPlanningConstraintError
|
|
26
|
+
? { constraints: error.cause.inspection }
|
|
27
|
+
: {}),
|
|
28
|
+
});
|
|
29
|
+
if (!parsed.success || !isDeepStrictEqual(parsed.data.output, error.output))
|
|
30
|
+
return undefined;
|
|
31
|
+
return structuredClone(parsed.data);
|
|
32
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { WorkflowConnectionOutlineRequestInput, WorkflowConnectionOutlineRequestDescription } from '../../types/workflow-connection-outline.js';
|
|
2
|
+
/** Replanning feedback belongs to this exact session revision and grouping hypothesis. */
|
|
3
|
+
export declare function describeWorkflowConnectionOutlineRequest(input: WorkflowConnectionOutlineRequestInput): WorkflowConnectionOutlineRequestDescription;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { describeWorkflowConnectionStep, describeWorkflowConnectionOutline, runOpenApiFlowOperation, } from '@openapi-flow/core';
|
|
3
|
+
/** Replanning feedback belongs to this exact session revision and grouping hypothesis. */
|
|
4
|
+
export function describeWorkflowConnectionOutlineRequest(input) {
|
|
5
|
+
return runOpenApiFlowOperation({
|
|
6
|
+
owner: 'langchain',
|
|
7
|
+
operation: 'describeWorkflowConnectionOutlineRequest',
|
|
8
|
+
stage: 'input-validation',
|
|
9
|
+
code: 'PLANNING_INPUT_INVALID',
|
|
10
|
+
}, () => {
|
|
11
|
+
const description = describeWorkflowConnectionStep(input);
|
|
12
|
+
if (input.previousOutline !== undefined)
|
|
13
|
+
describeWorkflowConnectionOutline({
|
|
14
|
+
...input,
|
|
15
|
+
outline: input.previousOutline,
|
|
16
|
+
});
|
|
17
|
+
const context = {
|
|
18
|
+
description,
|
|
19
|
+
...(input.previousOutline === undefined
|
|
20
|
+
? {}
|
|
21
|
+
: { previousOutline: structuredClone(input.previousOutline) }),
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
...context,
|
|
25
|
+
requestFingerprint: createHash('sha256')
|
|
26
|
+
.update(JSON.stringify(context))
|
|
27
|
+
.digest('hex'),
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { WorkflowConnectionNativeParameterResult } from '@openapi-flow/core';
|
|
2
|
+
import type { GenerateWorkflowConnectionNativeParametersInput } from '../../types/workflow-connection-native-repair.js';
|
|
3
|
+
/** One existing instance, checked selected producers, and at most one value decision. */
|
|
4
|
+
export declare function generateWorkflowConnectionNativeParameters(input: GenerateWorkflowConnectionNativeParametersInput): Promise<WorkflowConnectionNativeParameterResult>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
+
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
3
|
+
import { describeWorkflowConnectionNativeParameters, createWorkflowConnectionNativeParametersSchema, resolveWorkflowConnectionNativeParameters, runOpenApiFlowOperation, } from '@openapi-flow/core';
|
|
4
|
+
import { invokeStructuredModel } from '../../model/invoke-structured-model.js';
|
|
5
|
+
import { workflowConnectionNativeRepairPrompt } from '../../prompts/workflow-connection-native-repair-prompt.js';
|
|
6
|
+
import { modelSignalSchema } from '../../schemas/model-signal-schema.js';
|
|
7
|
+
import { WorkflowConnectionNativeRepairError } from './workflow-connection-native-repair-error.js';
|
|
8
|
+
/** One existing instance, checked selected producers, and at most one value decision. */
|
|
9
|
+
export async function generateWorkflowConnectionNativeParameters(input) {
|
|
10
|
+
const context = runOpenApiFlowOperation({
|
|
11
|
+
owner: 'langchain',
|
|
12
|
+
operation: 'generateWorkflowConnectionNativeParameters',
|
|
13
|
+
stage: 'input-validation',
|
|
14
|
+
code: 'PLANNING_INPUT_INVALID',
|
|
15
|
+
}, () => {
|
|
16
|
+
modelSignalSchema.parse(input.signal);
|
|
17
|
+
if (input.model !== undefined &&
|
|
18
|
+
(!input.model || typeof input.model.withStructuredOutput !== 'function'))
|
|
19
|
+
throw new Error('generateWorkflowConnectionNativeParameters.model must support structured output when supplied');
|
|
20
|
+
return describeWorkflowConnectionNativeParameters(input);
|
|
21
|
+
});
|
|
22
|
+
input.signal?.throwIfAborted();
|
|
23
|
+
if (!context.hasLiteralParameters)
|
|
24
|
+
return resolveWorkflowConnectionNativeParameters({
|
|
25
|
+
...input,
|
|
26
|
+
fingerprint: context.fingerprint,
|
|
27
|
+
proposal: {
|
|
28
|
+
decision: {
|
|
29
|
+
status: 'provided',
|
|
30
|
+
parameters: {},
|
|
31
|
+
...(input.includeExplanations === true
|
|
32
|
+
? {
|
|
33
|
+
reason: 'The original ownership contract leaves no literal setting choice.',
|
|
34
|
+
}
|
|
35
|
+
: {}),
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
if (!input.model)
|
|
40
|
+
throw new Error('generateWorkflowConnectionNativeParameters.model is required for remaining settings');
|
|
41
|
+
const output = await invokeStructuredModel({
|
|
42
|
+
model: input.model,
|
|
43
|
+
schema: createWorkflowConnectionNativeParametersSchema(input),
|
|
44
|
+
operation: 'generateWorkflowConnectionNativeParameters',
|
|
45
|
+
name: 'repair_native_parameters',
|
|
46
|
+
method: 'functionCalling',
|
|
47
|
+
strict: true,
|
|
48
|
+
signal: input.signal,
|
|
49
|
+
messages: [
|
|
50
|
+
new SystemMessage(workflowConnectionNativeRepairPrompt),
|
|
51
|
+
new HumanMessage(JSON.stringify(context)),
|
|
52
|
+
],
|
|
53
|
+
});
|
|
54
|
+
input.signal?.throwIfAborted();
|
|
55
|
+
return runOpenApiFlowOperation({
|
|
56
|
+
owner: 'langchain',
|
|
57
|
+
operation: 'generateWorkflowConnectionNativeParameters',
|
|
58
|
+
stage: 'contract-validation',
|
|
59
|
+
code: 'NATIVE_NODE_PLANNING_FAILED',
|
|
60
|
+
}, () => {
|
|
61
|
+
try {
|
|
62
|
+
if (!isDeepStrictEqual(context, describeWorkflowConnectionNativeParameters(input)))
|
|
63
|
+
throw new Error('Native repair source changed during parameter planning');
|
|
64
|
+
return resolveWorkflowConnectionNativeParameters({
|
|
65
|
+
...input,
|
|
66
|
+
fingerprint: context.fingerprint,
|
|
67
|
+
proposal: output,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
catch (cause) {
|
|
71
|
+
if (!(cause instanceof Error))
|
|
72
|
+
throw cause;
|
|
73
|
+
throw new WorkflowConnectionNativeRepairError({
|
|
74
|
+
operation: 'generateWorkflowConnectionNativeParameters',
|
|
75
|
+
fingerprint: context.fingerprint,
|
|
76
|
+
output,
|
|
77
|
+
}, cause);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
@@ -29,6 +29,9 @@ export async function invokeConnectionPlanningModel(input) {
|
|
|
29
29
|
...(input.sourceFingerprint === undefined
|
|
30
30
|
? {}
|
|
31
31
|
: { sourceFingerprint: input.sourceFingerprint }),
|
|
32
|
+
...(input.requestFingerprint === undefined
|
|
33
|
+
? {}
|
|
34
|
+
: { requestFingerprint: input.requestFingerprint }),
|
|
32
35
|
}, () => {
|
|
33
36
|
const parsed = input.schema.parse(output);
|
|
34
37
|
if (!isDeepStrictEqual(parsed, output))
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { PlanWorkflowConnectionGoalRecoveryInput, PlanWorkflowConnectionGoalRecoveryResult } from '../../types/workflow-connection-goal-recovery.js';
|
|
2
|
+
/** One reconsideration before any accepted session exists. The host owns originating-stage invocation and budgets. */
|
|
3
|
+
export declare function planWorkflowConnectionGoalRecovery(input: PlanWorkflowConnectionGoalRecoveryInput): Promise<PlanWorkflowConnectionGoalRecoveryResult>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
+
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
3
|
+
import { describeWorkflowConnectionGoals, describeWorkflowConnectionConflictMaterials, createWorkflowConnectionSession, validateWorkflowConnectionSourceRepairRequest, runOpenApiFlowOperation, } from '@openapi-flow/core';
|
|
4
|
+
import { modelSignalSchema } from '../../schemas/model-signal-schema.js';
|
|
5
|
+
import { workflowConnectionGoalRejectionSchema } from '../../schemas/workflow-connection-goal-rejection-schema.js';
|
|
6
|
+
import { createWorkflowConnectionGoalRecoverySchema } from '../../schemas/workflow-connection-goal-recovery-schema.js';
|
|
7
|
+
import { workflowConnectionGoalRecoveryPrompt } from '../../prompts/workflow-connection-goal-recovery-prompt.js';
|
|
8
|
+
import { invokeConnectionPlanningModel } from './invoke-connection-planning-model.js';
|
|
9
|
+
import { resolveConnectionGoalSelections } from './resolve-connection-selections.js';
|
|
10
|
+
import { validateWorkflowGoalReviewFeedback } from './validate-workflow-goal-review-feedback.js';
|
|
11
|
+
import { WorkflowConnectionPlanningError, validateConnectionProposal, } from './workflow-connection-planning-error.js';
|
|
12
|
+
function describeRecovery(input) {
|
|
13
|
+
modelSignalSchema.parse(input.signal);
|
|
14
|
+
const description = describeWorkflowConnectionGoals(input);
|
|
15
|
+
const reviews = validateWorkflowGoalReviewFeedback(input);
|
|
16
|
+
if (!Array.isArray(input.rejectedProposals) ||
|
|
17
|
+
(!input.rejectedProposals.length && !reviews.length))
|
|
18
|
+
throw new Error('Goal recovery requires rejectedProposals');
|
|
19
|
+
for (const value of input.rejectedProposals) {
|
|
20
|
+
const checked = workflowConnectionGoalRejectionSchema.parse(value);
|
|
21
|
+
if (!isDeepStrictEqual(value, checked) ||
|
|
22
|
+
value.sourceFingerprint !== description.sourceFingerprint)
|
|
23
|
+
throw new Error('Goal recovery requires unchanged source and lossless rejection evidence');
|
|
24
|
+
}
|
|
25
|
+
const nodes = [
|
|
26
|
+
...new Set(input.rejectedProposals
|
|
27
|
+
.flatMap((rejection) => rejection.stage === 'contract-validation' &&
|
|
28
|
+
rejection.constraints !== undefined
|
|
29
|
+
? rejection.constraints.conflicts.flatMap((conflict) => conflict.nodeIds)
|
|
30
|
+
: [])
|
|
31
|
+
.concat(reviews.length
|
|
32
|
+
? description.context.nodes.map((node) => node.id)
|
|
33
|
+
: [])),
|
|
34
|
+
];
|
|
35
|
+
if (!nodes.length && !reviews.length)
|
|
36
|
+
throw new Error('Goal recovery requires code-owned conflict evidence');
|
|
37
|
+
return {
|
|
38
|
+
...description,
|
|
39
|
+
conflictMaterials: nodes.length === 0
|
|
40
|
+
? { apiCalls: [], nativeNodes: [], apiResponseContracts: [] }
|
|
41
|
+
: describeWorkflowConnectionConflictMaterials({
|
|
42
|
+
source: input,
|
|
43
|
+
nodeIds: nodes,
|
|
44
|
+
}),
|
|
45
|
+
rejectedProposals: structuredClone(input.rejectedProposals),
|
|
46
|
+
...(input.rejectedGoalReviews === undefined
|
|
47
|
+
? {}
|
|
48
|
+
: { rejectedGoalReviews: reviews }),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** One reconsideration before any accepted session exists. The host owns originating-stage invocation and budgets. */
|
|
52
|
+
export async function planWorkflowConnectionGoalRecovery(input) {
|
|
53
|
+
const operation = 'planWorkflowConnectionGoalRecovery';
|
|
54
|
+
const description = runOpenApiFlowOperation({
|
|
55
|
+
owner: 'langchain',
|
|
56
|
+
operation,
|
|
57
|
+
stage: 'input-validation',
|
|
58
|
+
code: 'PLANNING_INPUT_INVALID',
|
|
59
|
+
}, () => describeRecovery(input));
|
|
60
|
+
const checkCurrent = (output) => validateConnectionProposal({
|
|
61
|
+
operation,
|
|
62
|
+
stage: 'input-validation',
|
|
63
|
+
code: 'PLANNING_INPUT_INVALID',
|
|
64
|
+
output,
|
|
65
|
+
sourceFingerprint: description.sourceFingerprint,
|
|
66
|
+
}, () => {
|
|
67
|
+
if (!isDeepStrictEqual(describeRecovery(input), description))
|
|
68
|
+
throw new Error('Goal recovery source or rejection evidence changed during model invocation');
|
|
69
|
+
});
|
|
70
|
+
const output = await invokeConnectionPlanningModel({
|
|
71
|
+
model: input.model,
|
|
72
|
+
operation,
|
|
73
|
+
name: 'plan_workflow_connection_goal_recovery',
|
|
74
|
+
schema: createWorkflowConnectionGoalRecoverySchema(description),
|
|
75
|
+
sourceFingerprint: description.sourceFingerprint,
|
|
76
|
+
messages: [
|
|
77
|
+
new SystemMessage(workflowConnectionGoalRecoveryPrompt),
|
|
78
|
+
new HumanMessage(JSON.stringify(description)),
|
|
79
|
+
],
|
|
80
|
+
...(input.signal === undefined ? {} : { signal: input.signal }),
|
|
81
|
+
}).catch((error) => {
|
|
82
|
+
if (error instanceof WorkflowConnectionPlanningError &&
|
|
83
|
+
error.diagnostic.stage === 'model-output')
|
|
84
|
+
checkCurrent(error.output);
|
|
85
|
+
throw error;
|
|
86
|
+
});
|
|
87
|
+
checkCurrent(output);
|
|
88
|
+
return validateConnectionProposal({
|
|
89
|
+
operation,
|
|
90
|
+
stage: 'contract-validation',
|
|
91
|
+
code: 'WORKFLOW_GRAPH_PLANNING_FAILED',
|
|
92
|
+
output,
|
|
93
|
+
sourceFingerprint: description.sourceFingerprint,
|
|
94
|
+
}, () => {
|
|
95
|
+
if (output.decision.kind === 'goals')
|
|
96
|
+
return {
|
|
97
|
+
kind: 'goals',
|
|
98
|
+
session: createWorkflowConnectionSession({
|
|
99
|
+
...input,
|
|
100
|
+
goals: resolveConnectionGoalSelections(output.decision.goals, description.context.nodes),
|
|
101
|
+
}),
|
|
102
|
+
};
|
|
103
|
+
const request = {
|
|
104
|
+
kind: 'replan-materials',
|
|
105
|
+
sourceFingerprint: description.sourceFingerprint,
|
|
106
|
+
request: output.decision,
|
|
107
|
+
};
|
|
108
|
+
validateWorkflowConnectionSourceRepairRequest({ source: input, request });
|
|
109
|
+
return request;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
2
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
3
|
import { describeWorkflowConnectionGoals, createWorkflowConnectionSession, runOpenApiFlowOperation, } from '@openapi-flow/core';
|
|
3
4
|
import { createWorkflowConnectionGoalsSchema } from '../../schemas/workflow-connection-goals-schema.js';
|
|
4
5
|
import { workflowConnectionGoalRejectionSchema } from '../../schemas/workflow-connection-goal-rejection-schema.js';
|
|
5
6
|
import { workflowConnectionGoalsPrompt } from '../../prompts/incremental-workflow-connections-prompt.js';
|
|
6
7
|
import { invokeConnectionPlanningModel } from './invoke-connection-planning-model.js';
|
|
7
|
-
import {
|
|
8
|
-
import { validateConnectionProposal } from './workflow-connection-planning-error.js';
|
|
8
|
+
import { resolveConnectionGoalSelections } from './resolve-connection-selections.js';
|
|
9
|
+
import { validateConnectionProposal, WorkflowConnectionPlanningError, } from './workflow-connection-planning-error.js';
|
|
10
|
+
import { validateWorkflowGoalReviewFeedback } from './validate-workflow-goal-review-feedback.js';
|
|
9
11
|
/** One semantic interpretation; code validates coverage/identities and creates the initial session. */
|
|
10
12
|
export async function planWorkflowConnectionGoals(input) {
|
|
11
13
|
const operation = 'planWorkflowConnectionGoals';
|
|
12
|
-
const { description, schema } = runOpenApiFlowOperation({
|
|
14
|
+
const { description, schema, rejectedGoalReviews } = runOpenApiFlowOperation({
|
|
13
15
|
owner: 'langchain',
|
|
14
16
|
operation,
|
|
15
17
|
stage: 'input-validation',
|
|
@@ -27,9 +29,29 @@ export async function planWorkflowConnectionGoals(input) {
|
|
|
27
29
|
}
|
|
28
30
|
return {
|
|
29
31
|
description,
|
|
32
|
+
rejectedGoalReviews: validateWorkflowGoalReviewFeedback(input),
|
|
30
33
|
schema: createWorkflowConnectionGoalsSchema(description),
|
|
31
34
|
};
|
|
32
35
|
});
|
|
36
|
+
const checkCurrent = (output, originalFailure) => validateConnectionProposal({
|
|
37
|
+
operation,
|
|
38
|
+
stage: 'input-validation',
|
|
39
|
+
code: 'PLANNING_INPUT_INVALID',
|
|
40
|
+
output,
|
|
41
|
+
sourceFingerprint: description.sourceFingerprint,
|
|
42
|
+
}, () => {
|
|
43
|
+
try {
|
|
44
|
+
if (describeWorkflowConnectionGoals(input).sourceFingerprint !==
|
|
45
|
+
description.sourceFingerprint ||
|
|
46
|
+
!isDeepStrictEqual(validateWorkflowGoalReviewFeedback(input), rejectedGoalReviews))
|
|
47
|
+
throw new Error('Connection goal source or review evidence changed during model invocation');
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
if (originalFailure === undefined)
|
|
51
|
+
throw error;
|
|
52
|
+
throw new AggregateError([originalFailure, error], 'Connection goal source or review evidence changed during malformed model output', { cause: error });
|
|
53
|
+
}
|
|
54
|
+
});
|
|
33
55
|
const output = await invokeConnectionPlanningModel({
|
|
34
56
|
model: input.model,
|
|
35
57
|
operation,
|
|
@@ -43,10 +65,19 @@ export async function planWorkflowConnectionGoals(input) {
|
|
|
43
65
|
...(input.rejectedProposals === undefined
|
|
44
66
|
? {}
|
|
45
67
|
: { rejectedProposals: input.rejectedProposals }),
|
|
68
|
+
...(input.rejectedGoalReviews === undefined
|
|
69
|
+
? {}
|
|
70
|
+
: { rejectedGoalReviews }),
|
|
46
71
|
})),
|
|
47
72
|
],
|
|
48
73
|
...(input.signal === undefined ? {} : { signal: input.signal }),
|
|
74
|
+
}).catch((error) => {
|
|
75
|
+
if (error instanceof WorkflowConnectionPlanningError &&
|
|
76
|
+
error.diagnostic.stage === 'model-output')
|
|
77
|
+
checkCurrent(error.output, error);
|
|
78
|
+
throw error;
|
|
49
79
|
});
|
|
80
|
+
checkCurrent(output);
|
|
50
81
|
return validateConnectionProposal({
|
|
51
82
|
operation,
|
|
52
83
|
stage: 'contract-validation',
|
|
@@ -54,19 +85,7 @@ export async function planWorkflowConnectionGoals(input) {
|
|
|
54
85
|
output,
|
|
55
86
|
sourceFingerprint: description.sourceFingerprint,
|
|
56
87
|
}, () => {
|
|
57
|
-
|
|
58
|
-
description.sourceFingerprint)
|
|
59
|
-
throw new Error('Connection goal source changed during model invocation');
|
|
60
|
-
const goals = output.goals.map((goal) => goal.kind !== 'route'
|
|
61
|
-
? goal
|
|
62
|
-
: {
|
|
63
|
-
kind: goal.kind,
|
|
64
|
-
from: goal.source.nodeId,
|
|
65
|
-
to: goal.to,
|
|
66
|
-
factIds: goal.factIds,
|
|
67
|
-
reason: goal.reason,
|
|
68
|
-
output: resolveConnectionPortSelection(goal.source, description.context.nodes, 'outputs'),
|
|
69
|
-
});
|
|
88
|
+
const goals = resolveConnectionGoalSelections(output.goals, description.context.nodes);
|
|
70
89
|
return createWorkflowConnectionSession({ ...input, goals });
|
|
71
90
|
});
|
|
72
91
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { WorkflowConnectionNativeDependencies } from '@openapi-flow/core';
|
|
2
|
+
import type { PlanWorkflowConnectionNativeDependenciesInput } from '../../types/workflow-connection-native-repair.js';
|
|
3
|
+
/** Zero or one scoped decision. No retries or mutation of the original source. */
|
|
4
|
+
export declare function planWorkflowConnectionNativeDependencies(input: PlanWorkflowConnectionNativeDependenciesInput): Promise<WorkflowConnectionNativeDependencies>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
+
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
3
|
+
import { describeWorkflowConnectionNativeDependencies, createWorkflowConnectionNativeDependenciesSchema, resolveWorkflowConnectionNativeDependencies, runOpenApiFlowOperation, } from '@openapi-flow/core';
|
|
4
|
+
import { invokeStructuredModel } from '../../model/invoke-structured-model.js';
|
|
5
|
+
import { workflowConnectionNativeRepairPrompt } from '../../prompts/workflow-connection-native-repair-prompt.js';
|
|
6
|
+
import { modelSignalSchema } from '../../schemas/model-signal-schema.js';
|
|
7
|
+
import { WorkflowConnectionNativeRepairError } from './workflow-connection-native-repair-error.js';
|
|
8
|
+
/** Zero or one scoped decision. No retries or mutation of the original source. */
|
|
9
|
+
export async function planWorkflowConnectionNativeDependencies(input) {
|
|
10
|
+
const context = runOpenApiFlowOperation({
|
|
11
|
+
owner: 'langchain',
|
|
12
|
+
operation: 'planWorkflowConnectionNativeDependencies',
|
|
13
|
+
stage: 'input-validation',
|
|
14
|
+
code: 'PLANNING_INPUT_INVALID',
|
|
15
|
+
}, () => {
|
|
16
|
+
modelSignalSchema.parse(input.signal);
|
|
17
|
+
if (input.model !== undefined &&
|
|
18
|
+
(!input.model || typeof input.model.withStructuredOutput !== 'function'))
|
|
19
|
+
throw new Error('planWorkflowConnectionNativeDependencies.model must support structured output when supplied');
|
|
20
|
+
return describeWorkflowConnectionNativeDependencies(input);
|
|
21
|
+
});
|
|
22
|
+
input.signal?.throwIfAborted();
|
|
23
|
+
if (context.targets.every((target) => target.sourceNodeIds.length === 0))
|
|
24
|
+
return resolveWorkflowConnectionNativeDependencies({
|
|
25
|
+
...input,
|
|
26
|
+
proposal: {
|
|
27
|
+
sourcesByNodeId: Object.fromEntries(context.targets.map((target) => [
|
|
28
|
+
target.nodeId,
|
|
29
|
+
{ sourceNodeIds: [] },
|
|
30
|
+
])),
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
if (!input.model)
|
|
34
|
+
throw new Error('planWorkflowConnectionNativeDependencies.model is required for producer choices');
|
|
35
|
+
const output = await invokeStructuredModel({
|
|
36
|
+
model: input.model,
|
|
37
|
+
schema: createWorkflowConnectionNativeDependenciesSchema(input),
|
|
38
|
+
operation: 'planWorkflowConnectionNativeDependencies',
|
|
39
|
+
name: 'repair_native_dependencies',
|
|
40
|
+
method: 'functionCalling',
|
|
41
|
+
strict: true,
|
|
42
|
+
signal: input.signal,
|
|
43
|
+
messages: [
|
|
44
|
+
new SystemMessage(workflowConnectionNativeRepairPrompt),
|
|
45
|
+
new HumanMessage(JSON.stringify(context)),
|
|
46
|
+
],
|
|
47
|
+
});
|
|
48
|
+
input.signal?.throwIfAborted();
|
|
49
|
+
return runOpenApiFlowOperation({
|
|
50
|
+
owner: 'langchain',
|
|
51
|
+
operation: 'planWorkflowConnectionNativeDependencies',
|
|
52
|
+
stage: 'contract-validation',
|
|
53
|
+
code: 'NATIVE_NODE_PLANNING_FAILED',
|
|
54
|
+
}, () => {
|
|
55
|
+
try {
|
|
56
|
+
if (!isDeepStrictEqual(context, describeWorkflowConnectionNativeDependencies(input)))
|
|
57
|
+
throw new Error('Native repair source changed during dependency planning');
|
|
58
|
+
return resolveWorkflowConnectionNativeDependencies({
|
|
59
|
+
...input,
|
|
60
|
+
proposal: output,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
catch (cause) {
|
|
64
|
+
if (!(cause instanceof Error))
|
|
65
|
+
throw cause;
|
|
66
|
+
throw new WorkflowConnectionNativeRepairError({
|
|
67
|
+
operation: 'planWorkflowConnectionNativeDependencies',
|
|
68
|
+
fingerprint: context.fingerprint,
|
|
69
|
+
output,
|
|
70
|
+
}, cause);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { WorkflowConnectionOutline } from '@openapi-flow/core';
|
|
2
|
+
import type { PlanWorkflowConnectionOutlineInput } from '../../types/workflow-connection-outline.js';
|
|
3
|
+
/** One outline proposal; the host owns selection, retry, checkpoints and adoption. */
|
|
4
|
+
export declare function planWorkflowConnectionOutline(input: PlanWorkflowConnectionOutlineInput): Promise<WorkflowConnectionOutline>;
|