@openapi-flow/langchain 0.2.0 → 0.3.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/README.md +121 -1
- package/dist/arguments/analyze-api-input-answers.d.ts +3 -0
- package/dist/arguments/analyze-api-input-answers.js +87 -0
- package/dist/arguments/analyze-api-request-media-type.d.ts +4 -0
- package/dist/arguments/analyze-api-request-media-type.js +50 -0
- package/dist/arguments/extract-api-input-answers.d.ts +3 -0
- package/dist/arguments/extract-api-input-answers.js +4 -0
- package/dist/arguments/generate-api-arguments.js +43 -28
- package/dist/arguments/select-api-request-media-type.js +8 -37
- package/dist/bindings/plan-api-bindings.js +30 -23
- package/dist/draft/analyze-workflow-draft-edit.d.ts +4 -0
- package/dist/draft/analyze-workflow-draft-edit.js +84 -0
- package/dist/draft/generate-workflow-draft-api-call-arguments.d.ts +3 -0
- package/dist/draft/generate-workflow-draft-api-call-arguments.js +88 -0
- package/dist/draft/generate-workflow-draft-api-input-edits.d.ts +4 -0
- package/dist/draft/generate-workflow-draft-api-input-edits.js +58 -0
- package/dist/draft/generate-workflow-draft-native-node-addition.d.ts +4 -0
- package/dist/draft/generate-workflow-draft-native-node-addition.js +137 -0
- package/dist/draft/generate-workflow-draft-native-parameter-edits.d.ts +3 -0
- package/dist/draft/generate-workflow-draft-native-parameter-edits.js +71 -0
- package/dist/draft/plan-workflow-draft-api-binding-edit.d.ts +4 -0
- package/dist/draft/plan-workflow-draft-api-binding-edit.js +103 -0
- package/dist/draft/plan-workflow-draft-api-call-bindings.d.ts +3 -0
- package/dist/draft/plan-workflow-draft-api-call-bindings.js +114 -0
- package/dist/draft/plan-workflow-draft-clarification-scopes.d.ts +4 -0
- package/dist/draft/plan-workflow-draft-clarification-scopes.js +77 -0
- package/dist/draft/plan-workflow-draft-connection-edit.d.ts +4 -0
- package/dist/draft/plan-workflow-draft-connection-edit.js +79 -0
- package/dist/draft/plan-workflow-draft-native-dependencies.d.ts +4 -0
- package/dist/draft/plan-workflow-draft-native-dependencies.js +45 -0
- package/dist/draft/plan-workflow-draft-native-reference-repair.d.ts +4 -0
- package/dist/draft/plan-workflow-draft-native-reference-repair.js +68 -0
- package/dist/draft/resolve-workflow-draft-edit-proposal.d.ts +3 -0
- package/dist/draft/resolve-workflow-draft-edit-proposal.js +39 -0
- package/dist/draft/select-workflow-draft-api-binding-inputs.d.ts +4 -0
- package/dist/draft/select-workflow-draft-api-binding-inputs.js +83 -0
- package/dist/draft/select-workflow-draft-api-input-edit-targets.d.ts +4 -0
- package/dist/draft/select-workflow-draft-api-input-edit-targets.js +55 -0
- package/dist/draft/select-workflow-draft-native-node-parameter-ownership.d.ts +4 -0
- package/dist/draft/select-workflow-draft-native-node-parameter-ownership.js +81 -0
- package/dist/draft/select-workflow-draft-native-parameter-edit-targets.d.ts +3 -0
- package/dist/draft/select-workflow-draft-native-parameter-edit-targets.js +51 -0
- package/dist/draft/workflow-draft-api-binding-edit-planning-error.d.ts +5 -0
- package/dist/draft/workflow-draft-api-binding-edit-planning-error.js +10 -0
- package/dist/draft/workflow-draft-api-call-planning-error.d.ts +5 -0
- package/dist/draft/workflow-draft-api-call-planning-error.js +10 -0
- package/dist/draft/workflow-draft-api-input-edit-planning-error.d.ts +5 -0
- package/dist/draft/workflow-draft-api-input-edit-planning-error.js +10 -0
- package/dist/draft/workflow-draft-clarification-scope-planning-error.d.ts +5 -0
- package/dist/draft/workflow-draft-clarification-scope-planning-error.js +8 -0
- package/dist/draft/workflow-draft-connection-edit-planning-error.d.ts +5 -0
- package/dist/draft/workflow-draft-connection-edit-planning-error.js +10 -0
- package/dist/draft/workflow-draft-edit-planning-error.d.ts +5 -0
- package/dist/draft/workflow-draft-edit-planning-error.js +8 -0
- package/dist/draft/workflow-draft-native-node-addition-planning-error.d.ts +5 -0
- package/dist/draft/workflow-draft-native-node-addition-planning-error.js +10 -0
- package/dist/draft/workflow-draft-native-parameter-edit-planning-error.d.ts +5 -0
- package/dist/draft/workflow-draft-native-parameter-edit-planning-error.js +8 -0
- package/dist/draft/workflow-draft-native-reference-repair-planning-error.d.ts +5 -0
- package/dist/draft/workflow-draft-native-reference-repair-planning-error.js +8 -0
- package/dist/prompts/api-arguments-prompt.d.ts +1 -1
- package/dist/prompts/api-arguments-prompt.js +1 -1
- package/dist/prompts/api-bindings-prompt.d.ts +1 -1
- package/dist/prompts/api-bindings-prompt.js +1 -0
- package/dist/prompts/api-input-answers-prompt.d.ts +1 -0
- package/dist/prompts/api-input-answers-prompt.js +7 -0
- package/dist/prompts/api-request-media-type-prompt.d.ts +1 -1
- package/dist/prompts/api-request-media-type-prompt.js +1 -1
- package/dist/prompts/api-selection-analysis-prompt.d.ts +1 -0
- package/dist/prompts/api-selection-analysis-prompt.js +5 -0
- package/dist/prompts/api-selection-explanation-prompt.d.ts +1 -0
- package/dist/prompts/api-selection-explanation-prompt.js +1 -0
- package/dist/prompts/native-instance-dependencies-prompt.d.ts +1 -0
- package/dist/prompts/native-instance-dependencies-prompt.js +8 -0
- package/dist/prompts/native-node-planning-prompt.d.ts +3 -1
- package/dist/prompts/native-node-planning-prompt.js +14 -1
- package/dist/prompts/reviewable-workflow-graph-prompt.d.ts +1 -1
- package/dist/prompts/workflow-connections-prompt.d.ts +1 -1
- package/dist/prompts/workflow-connections-prompt.js +3 -1
- package/dist/prompts/workflow-draft-api-binding-edit-prompt.d.ts +1 -0
- package/dist/prompts/workflow-draft-api-binding-edit-prompt.js +9 -0
- package/dist/prompts/workflow-draft-api-call-planning-prompt.d.ts +3 -0
- package/dist/prompts/workflow-draft-api-call-planning-prompt.js +39 -0
- package/dist/prompts/workflow-draft-api-input-edit-prompt.d.ts +2 -0
- package/dist/prompts/workflow-draft-api-input-edit-prompt.js +14 -0
- package/dist/prompts/workflow-draft-clarification-scope-prompt.d.ts +1 -0
- package/dist/prompts/workflow-draft-clarification-scope-prompt.js +10 -0
- package/dist/prompts/workflow-draft-connection-edit-prompt.d.ts +1 -0
- package/dist/prompts/workflow-draft-connection-edit-prompt.js +7 -0
- package/dist/prompts/workflow-draft-edit-prompt.d.ts +1 -0
- package/dist/prompts/workflow-draft-edit-prompt.js +15 -0
- package/dist/prompts/workflow-draft-native-dependencies-prompt.d.ts +1 -0
- package/dist/prompts/workflow-draft-native-dependencies-prompt.js +5 -0
- package/dist/prompts/workflow-draft-native-node-addition-prompt.d.ts +2 -0
- package/dist/prompts/workflow-draft-native-node-addition-prompt.js +6 -0
- package/dist/prompts/workflow-draft-native-parameter-edit-prompt.d.ts +2 -0
- package/dist/prompts/workflow-draft-native-parameter-edit-prompt.js +2 -0
- package/dist/prompts/workflow-draft-native-reference-repair-prompt.d.ts +1 -0
- package/dist/prompts/workflow-draft-native-reference-repair-prompt.js +7 -0
- package/dist/prompts/workflow-graph-prompt.d.ts +1 -1
- package/dist/prompts/workflow-graph-prompt.js +2 -0
- package/dist/prompts/workflow-requirements-prompt.d.ts +1 -0
- package/dist/prompts/workflow-requirements-prompt.js +14 -0
- package/dist/prompts/workflow-review-suggestions-prompt.d.ts +1 -0
- package/dist/prompts/workflow-review-suggestions-prompt.js +4 -0
- package/dist/prompts/workflow-user-action-evidence-prompt.d.ts +1 -0
- package/dist/prompts/workflow-user-action-evidence-prompt.js +1 -0
- package/dist/public-api.d.ts +47 -0
- package/dist/public-api.js +34 -0
- package/dist/requirements/clarify-workflow-requirements.d.ts +4 -0
- package/dist/requirements/clarify-workflow-requirements.js +53 -0
- package/dist/requirements/resolve-workflow-requirements-evidence.d.ts +4 -0
- package/dist/requirements/resolve-workflow-requirements-evidence.js +58 -0
- package/dist/review/suggest-workflow-review-follow-ups.d.ts +4 -0
- package/dist/review/suggest-workflow-review-follow-ups.js +87 -0
- package/dist/review/workflow-review-suggestion-planning-error.d.ts +5 -0
- package/dist/review/workflow-review-suggestion-planning-error.js +8 -0
- package/dist/schemas/api-binding-plan-schema.d.ts +7 -2
- package/dist/schemas/api-binding-plan-schema.js +11 -1
- package/dist/schemas/api-input-answer-source-schema.d.ts +16 -0
- package/dist/schemas/api-input-answer-source-schema.js +28 -0
- package/dist/schemas/api-literal-generation-output-schema.d.ts +11 -0
- package/dist/schemas/api-literal-generation-output-schema.js +20 -0
- package/dist/schemas/api-request-media-type-schema.d.ts +5 -2
- package/dist/schemas/api-request-media-type-schema.js +14 -2
- package/dist/schemas/api-selection-analysis-schema.d.ts +41 -0
- package/dist/schemas/api-selection-analysis-schema.js +23 -0
- package/dist/schemas/api-selection-options-schema.d.ts +4 -0
- package/dist/schemas/api-selection-options-schema.js +4 -0
- package/dist/schemas/api-selection-schema.d.ts +14 -1
- package/dist/schemas/api-selection-schema.js +6 -5
- package/dist/schemas/create-workflow-message-evidence-selection-schema.d.ts +16 -0
- package/dist/schemas/create-workflow-message-evidence-selection-schema.js +22 -0
- package/dist/schemas/native-node-explanation-schema.d.ts +5 -0
- package/dist/schemas/native-node-explanation-schema.js +9 -0
- package/dist/schemas/native-node-parameter-contract.d.ts +3 -0
- package/dist/schemas/native-node-parameter-contract.js +30 -0
- package/dist/schemas/native-node-planning-contract.d.ts +3 -0
- package/dist/schemas/native-node-planning-contract.js +44 -0
- package/dist/schemas/request-media-selection-options-schema.d.ts +4 -0
- package/dist/schemas/request-media-selection-options-schema.js +4 -0
- package/dist/schemas/reviewable-workflow-graph-schema.d.ts +4 -2
- package/dist/schemas/reviewable-workflow-graph-schema.js +13 -1
- package/dist/schemas/serialize-structured-output-schema.d.ts +5 -0
- package/dist/schemas/serialize-structured-output-schema.js +10 -0
- package/dist/schemas/serialize-workflow-requirements-schema.d.ts +4 -0
- package/dist/schemas/serialize-workflow-requirements-schema.js +5 -0
- package/dist/schemas/with-api-selection-explanation.d.ts +10 -0
- package/dist/schemas/with-api-selection-explanation.js +15 -0
- package/dist/schemas/workflow-connection-explanation-schema.d.ts +5 -0
- package/dist/schemas/workflow-connection-explanation-schema.js +9 -0
- package/dist/schemas/workflow-draft-edit-schema.d.ts +3 -0
- package/dist/schemas/workflow-draft-edit-schema.js +17 -0
- package/dist/schemas/workflow-graph-explanation-schema.d.ts +5 -0
- package/dist/schemas/workflow-graph-explanation-schema.js +9 -0
- package/dist/schemas/workflow-graph-proposal-schema.d.ts +2 -2
- package/dist/schemas/workflow-graph-proposal-schema.js +14 -7
- package/dist/schemas/workflow-planning-evidence-schemas.d.ts +20 -0
- package/dist/schemas/workflow-planning-evidence-schemas.js +44 -0
- package/dist/schemas/workflow-requirements-schema.d.ts +3 -0
- package/dist/schemas/workflow-requirements-schema.js +6 -0
- package/dist/schemas/workflow-review-suggestions-schema.d.ts +4 -0
- package/dist/schemas/workflow-review-suggestions-schema.js +18 -0
- package/dist/selection/analyze-api-selection.d.ts +4 -0
- package/dist/selection/analyze-api-selection.js +117 -0
- package/dist/selection/resolve-api-selection-options.d.ts +3 -0
- package/dist/selection/resolve-api-selection-options.js +6 -0
- package/dist/selection/select-api-operations.d.ts +1 -1
- package/dist/selection/select-api-operations.js +39 -6
- package/dist/types/api-input-answers.d.ts +16 -0
- package/dist/types/api-input-answers.js +1 -0
- package/dist/types/api-selection-analysis.d.ts +3 -0
- package/dist/types/api-selection-analysis.js +1 -0
- package/dist/types/argument-generation.d.ts +11 -5
- package/dist/types/binding-planning.d.ts +7 -5
- package/dist/types/native-node-planning.d.ts +67 -16
- package/dist/types/operation-selection.d.ts +5 -1
- package/dist/types/request-media-selection.d.ts +7 -2
- package/dist/types/reviewable-workflow-planning.d.ts +11 -2
- package/dist/types/structured-output-schema.d.ts +3 -0
- package/dist/types/structured-output-schema.js +1 -0
- package/dist/types/workflow-clarification.d.ts +23 -0
- package/dist/types/workflow-clarification.js +1 -0
- package/dist/types/workflow-draft-api-binding-edit.d.ts +9 -0
- package/dist/types/workflow-draft-api-binding-edit.js +1 -0
- package/dist/types/workflow-draft-api-call-planning.d.ts +15 -0
- package/dist/types/workflow-draft-api-call-planning.js +1 -0
- package/dist/types/workflow-draft-api-input-edit.d.ts +13 -0
- package/dist/types/workflow-draft-api-input-edit.js +1 -0
- package/dist/types/workflow-draft-clarification.d.ts +9 -0
- package/dist/types/workflow-draft-clarification.js +1 -0
- package/dist/types/workflow-draft-connection-edit.d.ts +9 -0
- package/dist/types/workflow-draft-connection-edit.js +1 -0
- package/dist/types/workflow-draft-edit.d.ts +16 -0
- package/dist/types/workflow-draft-edit.js +1 -0
- package/dist/types/workflow-draft-native-node-addition.d.ts +18 -0
- package/dist/types/workflow-draft-native-node-addition.js +1 -0
- package/dist/types/workflow-draft-native-parameter-edit.d.ts +13 -0
- package/dist/types/workflow-draft-native-parameter-edit.js +1 -0
- package/dist/types/workflow-draft-native-reference-repair.d.ts +9 -0
- package/dist/types/workflow-draft-native-reference-repair.js +1 -0
- package/dist/types/workflow-message-evidence-selection.d.ts +6 -0
- package/dist/types/workflow-message-evidence-selection.js +1 -0
- package/dist/types/workflow-orchestration.d.ts +13 -15
- package/dist/types/workflow-planning.d.ts +19 -7
- package/dist/types/workflow-review-suggestions.d.ts +12 -0
- package/dist/types/workflow-review-suggestions.js +1 -0
- package/dist/workflow/generate-native-node-parameters.d.ts +4 -0
- package/dist/workflow/generate-native-node-parameters.js +87 -0
- package/dist/workflow/orchestrate-workflow.js +2 -2
- package/dist/workflow/plan-native-instance-dependencies.d.ts +4 -0
- package/dist/workflow/plan-native-instance-dependencies.js +45 -0
- package/dist/workflow/plan-native-nodes.js +63 -66
- package/dist/workflow/plan-reviewable-workflow-graph.js +33 -64
- package/dist/workflow/plan-workflow-connections.js +35 -30
- package/dist/workflow/plan-workflow-graph.js +45 -64
- package/dist/workflow/resolve-native-node-parameter-source.d.ts +4 -0
- package/dist/workflow/resolve-native-node-parameter-source.js +7 -0
- package/dist/workflow/resolve-native-node-planning-output.d.ts +3 -0
- package/dist/workflow/resolve-native-node-planning-output.js +33 -0
- package/dist/workflow/resolve-workflow-connection-output.d.ts +3 -0
- package/dist/workflow/resolve-workflow-connection-output.js +22 -0
- package/dist/workflow/resolve-workflow-graph-output.d.ts +5 -0
- package/dist/workflow/resolve-workflow-graph-output.js +69 -0
- package/dist/workflow/select-native-node-instances.d.ts +4 -0
- package/dist/workflow/select-native-node-instances.js +57 -0
- package/package.json +7 -4
- package/dist/schemas/native-node-plan-schema.d.ts +0 -4
- package/dist/schemas/native-node-plan-schema.js +0 -26
- package/dist/workflow/assemble-native-node-materials.d.ts +0 -3
- package/dist/workflow/assemble-native-node-materials.js +0 -8
- package/dist/workflow/create-prepared-native-node-materials.d.ts +0 -4
- package/dist/workflow/create-prepared-native-node-materials.js +0 -15
- package/dist/workflow/prepare-workflow-connection-materials.d.ts +0 -3
- package/dist/workflow/prepare-workflow-connection-materials.js +0 -66
|
@@ -1,83 +1,38 @@
|
|
|
1
1
|
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
2
2
|
import { isDeepStrictEqual } from 'node:util';
|
|
3
|
-
import {
|
|
4
|
-
import { createReviewableWorkflowGraphPlan, createNativeOutputContracts, createWorkflowPlanningCapabilities, validateNativeApiResponseReferences, } from '@openapi-flow/core';
|
|
5
|
-
import { completeReviewableWorkflowGraphProposal } from './complete-reviewable-workflow-graph-proposal.js';
|
|
3
|
+
import { describeWorkflowGraphPlanning, createWorkflowGraphPlanningResult, createWorkflowGraphPlanningRecord, } from '@openapi-flow/core';
|
|
6
4
|
import { createReviewableWorkflowGraphSchema } from '../schemas/reviewable-workflow-graph-schema.js';
|
|
5
|
+
import { workflowGraphExplanationOptionsSchema } from '../schemas/workflow-graph-explanation-schema.js';
|
|
6
|
+
import { serializeStructuredOutputSchema } from '../schemas/serialize-structured-output-schema.js';
|
|
7
|
+
import { resolveReviewableWorkflowGraphOutput } from './resolve-workflow-graph-output.js';
|
|
7
8
|
import { reviewableWorkflowGraphPrompt } from '../prompts/reviewable-workflow-graph-prompt.js';
|
|
8
9
|
import { assertSelectionInput } from '../legacy/planning/select-operation.js';
|
|
9
10
|
import { parseStructuredOutput } from '../legacy/planning/parse-structured-output.js';
|
|
10
11
|
import { ReviewableWorkflowGraphPlanningError } from './reviewable-workflow-graph-planning-error.js';
|
|
11
|
-
import { createPreparedNativeNodeMaterials } from './create-prepared-native-node-materials.js';
|
|
12
|
-
import { assembleNativeNodeMaterials } from './assemble-native-node-materials.js';
|
|
13
12
|
export async function planReviewableWorkflowGraph(input) {
|
|
14
13
|
assertSelectionInput(input.scenario, input.model);
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const planningCapabilities = createWorkflowPlanningCapabilities({
|
|
18
|
-
capabilities: input.capabilities,
|
|
19
|
-
apiCallIds,
|
|
14
|
+
const options = workflowGraphExplanationOptionsSchema.parse({
|
|
15
|
+
includeExplanations: input.includeExplanations,
|
|
20
16
|
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
apiCallIds,
|
|
25
|
-
});
|
|
26
|
-
const nativeOutputs = createNativeOutputContracts({
|
|
27
|
-
nativeNodes: preparedNativeNodes,
|
|
28
|
-
capabilities: input.capabilities,
|
|
29
|
-
});
|
|
30
|
-
const readyIds = input.materials
|
|
31
|
-
.filter((item) => item.status === 'ready')
|
|
32
|
-
.map((item) => item.arguments.callId);
|
|
33
|
-
const schema = createReviewableWorkflowGraphSchema(planningCapabilities, readyIds);
|
|
17
|
+
const { input: snapshot, context, sources, planningCapabilities, } = describeWorkflowGraphPlanning({ ...input, mode: 'reviewable' });
|
|
18
|
+
const readyIds = snapshot.materials.flatMap((material) => material.status === 'ready' ? [material.arguments.callId] : []);
|
|
19
|
+
const schema = createReviewableWorkflowGraphSchema(planningCapabilities, readyIds, options.includeExplanations === true ? 'graph' : 'none');
|
|
34
20
|
const output = await input.model
|
|
35
|
-
.withStructuredOutput(schema, {
|
|
21
|
+
.withStructuredOutput(serializeStructuredOutputSchema(schema, 'draft-2020-12'), {
|
|
36
22
|
name: 'plan_reviewable_workflow_graph',
|
|
37
23
|
method: 'functionCalling',
|
|
38
24
|
strict: true,
|
|
39
25
|
})
|
|
40
26
|
.invoke([
|
|
41
27
|
new SystemMessage(reviewableWorkflowGraphPrompt),
|
|
42
|
-
new HumanMessage(JSON.stringify(
|
|
43
|
-
scenario: input.scenario,
|
|
44
|
-
preparedNativeNodes: createPreparedNativeNodeMaterials(preparedNativeNodes, input.capabilities),
|
|
45
|
-
nativeOutputs,
|
|
46
|
-
materials: input.materials.map(({ operation, ...material }) => ({
|
|
47
|
-
...material,
|
|
48
|
-
operation: {
|
|
49
|
-
key: operation.key,
|
|
50
|
-
method: operation.method,
|
|
51
|
-
path: operation.path,
|
|
52
|
-
operation: {
|
|
53
|
-
summary: operation.operation.summary,
|
|
54
|
-
description: operation.operation.description,
|
|
55
|
-
responses: operation.operation.responses,
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
inputPorts: ['main'],
|
|
59
|
-
outputPorts: ['main'],
|
|
60
|
-
})),
|
|
61
|
-
gaps: input.gaps.map((gap) => ({
|
|
62
|
-
...gap,
|
|
63
|
-
inputPorts: ['main'],
|
|
64
|
-
outputPorts: ['main'],
|
|
65
|
-
})),
|
|
66
|
-
capabilities: planningCapabilities.map((capability) => ({
|
|
67
|
-
name: capability.name,
|
|
68
|
-
description: capability.description,
|
|
69
|
-
parametersSchema: z.toJSONSchema(capability.parametersSchema),
|
|
70
|
-
waitsForAllInputs: capability.waitsForAllInputs,
|
|
71
|
-
exclusiveOutputPorts: capability.exclusiveOutputPorts,
|
|
72
|
-
})),
|
|
73
|
-
})),
|
|
28
|
+
new HumanMessage(JSON.stringify(context)),
|
|
74
29
|
]);
|
|
75
|
-
let
|
|
30
|
+
let resolved;
|
|
76
31
|
try {
|
|
77
32
|
const parsed = parseStructuredOutput(schema, output, 'model reviewable workflow graph');
|
|
78
33
|
if (!isDeepStrictEqual(parsed, output))
|
|
79
34
|
throw new Error('native model schema must validate without defaults, coercion or transformation');
|
|
80
|
-
|
|
35
|
+
resolved = resolveReviewableWorkflowGraphOutput(parsed, snapshot.capabilities.length, readyIds.length);
|
|
81
36
|
}
|
|
82
37
|
catch (error) {
|
|
83
38
|
if (!(error instanceof Error))
|
|
@@ -85,13 +40,27 @@ export async function planReviewableWorkflowGraph(input) {
|
|
|
85
40
|
throw new ReviewableWorkflowGraphPlanningError({ stage: 'proposal-schema', output }, error);
|
|
86
41
|
}
|
|
87
42
|
try {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
43
|
+
const current = describeWorkflowGraphPlanning(snapshot);
|
|
44
|
+
if (!isDeepStrictEqual(current.context, context) ||
|
|
45
|
+
!isDeepStrictEqual(current.sources, sources))
|
|
46
|
+
throw new Error('reviewable workflow graph source contracts changed during the model invocation');
|
|
47
|
+
const plan = createWorkflowGraphPlanningResult({
|
|
48
|
+
...snapshot,
|
|
49
|
+
proposal: resolved.proposal,
|
|
94
50
|
});
|
|
51
|
+
if (!('blockedCalls' in plan))
|
|
52
|
+
throw new Error('reviewable graph result is missing blockedCalls');
|
|
53
|
+
if (options.includeExplanations === true) {
|
|
54
|
+
if (!resolved.assessment)
|
|
55
|
+
throw new Error('model reviewable workflow graph is missing its explanation assessment');
|
|
56
|
+
plan.graphPlanning = createWorkflowGraphPlanningRecord({
|
|
57
|
+
...snapshot,
|
|
58
|
+
proposal: resolved.proposal,
|
|
59
|
+
plan,
|
|
60
|
+
assessment: resolved.assessment,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return plan;
|
|
95
64
|
}
|
|
96
65
|
catch (error) {
|
|
97
66
|
if (!(error instanceof Error))
|
|
@@ -1,43 +1,38 @@
|
|
|
1
1
|
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
2
|
-
import {
|
|
2
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
3
|
+
import { describeWorkflowConnectionPlanning, createWorkflowConnectionPlan, createWorkflowConnectionPlanningRecord, } from '@openapi-flow/core';
|
|
3
4
|
import { createReviewableWorkflowGraphSchema } from '../schemas/reviewable-workflow-graph-schema.js';
|
|
4
|
-
import {
|
|
5
|
+
import { resolveWorkflowConnectionOutput } from './resolve-workflow-connection-output.js';
|
|
5
6
|
import { workflowConnectionsPrompt } from '../prompts/workflow-connections-prompt.js';
|
|
6
7
|
import { assertSelectionInput } from '../legacy/planning/select-operation.js';
|
|
7
8
|
import { parseStructuredOutput } from '../legacy/planning/parse-structured-output.js';
|
|
8
9
|
import { ReviewableWorkflowGraphPlanningError } from './reviewable-workflow-graph-planning-error.js';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
10
|
+
import { workflowConnectionExplanationOptionsSchema } from '../schemas/workflow-connection-explanation-schema.js';
|
|
11
|
+
import { serializeStructuredOutputSchema } from '../schemas/serialize-structured-output-schema.js';
|
|
11
12
|
export async function planWorkflowConnections(input) {
|
|
12
13
|
assertSelectionInput(input.scenario, input.model);
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
14
|
+
const options = workflowConnectionExplanationOptionsSchema.parse({
|
|
15
|
+
includeExplanations: input.includeExplanations,
|
|
16
|
+
});
|
|
17
|
+
const { input: snapshot, context, sources, } = describeWorkflowConnectionPlanning(input);
|
|
18
|
+
const readyIds = context.readyCallIds;
|
|
19
|
+
const schema = createReviewableWorkflowGraphSchema([], readyIds, options.includeExplanations === true ? 'connections' : 'none');
|
|
17
20
|
const output = await input.model
|
|
18
|
-
.withStructuredOutput(schema, {
|
|
21
|
+
.withStructuredOutput(serializeStructuredOutputSchema(schema, 'draft-2020-12'), {
|
|
19
22
|
name: 'plan_workflow_connections',
|
|
20
23
|
method: 'functionCalling',
|
|
21
24
|
strict: true,
|
|
22
25
|
})
|
|
23
26
|
.invoke([
|
|
24
27
|
new SystemMessage(workflowConnectionsPrompt),
|
|
25
|
-
new HumanMessage(JSON.stringify(
|
|
26
|
-
scenario: input.scenario,
|
|
27
|
-
nodes: contracts,
|
|
28
|
-
...(nativeNodes.length
|
|
29
|
-
? {
|
|
30
|
-
nativeNodes: createPreparedNativeNodeMaterials(nativeNodes, capabilities),
|
|
31
|
-
}
|
|
32
|
-
: {}),
|
|
33
|
-
edges,
|
|
34
|
-
gaps,
|
|
35
|
-
readyCallIds: readyIds,
|
|
36
|
-
})),
|
|
28
|
+
new HumanMessage(JSON.stringify(context)),
|
|
37
29
|
]);
|
|
38
|
-
let
|
|
30
|
+
let resolved;
|
|
39
31
|
try {
|
|
40
|
-
|
|
32
|
+
const parsed = parseStructuredOutput(schema, output, 'model workflow connections');
|
|
33
|
+
if (!isDeepStrictEqual(parsed, output))
|
|
34
|
+
throw new Error('connection model schema must validate without defaults, coercion or transformation');
|
|
35
|
+
resolved = resolveWorkflowConnectionOutput(parsed, readyIds.length);
|
|
41
36
|
}
|
|
42
37
|
catch (error) {
|
|
43
38
|
if (!(error instanceof Error))
|
|
@@ -45,14 +40,24 @@ export async function planWorkflowConnections(input) {
|
|
|
45
40
|
throw new ReviewableWorkflowGraphPlanningError({ stage: 'proposal-schema', output }, error);
|
|
46
41
|
}
|
|
47
42
|
try {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
const current = describeWorkflowConnectionPlanning(snapshot);
|
|
44
|
+
if (!isDeepStrictEqual(current.context, context) ||
|
|
45
|
+
!isDeepStrictEqual(current.sources, sources))
|
|
46
|
+
throw new Error('connection planning source contracts changed during the model invocation');
|
|
47
|
+
const plan = createWorkflowConnectionPlan({
|
|
48
|
+
...snapshot,
|
|
49
|
+
proposal: resolved.proposal,
|
|
55
50
|
});
|
|
51
|
+
if (options.includeExplanations === true) {
|
|
52
|
+
if (!resolved.decision)
|
|
53
|
+
throw new Error('model workflow connections are missing the explanation decision');
|
|
54
|
+
plan.connectionPlanning = createWorkflowConnectionPlanningRecord({
|
|
55
|
+
...snapshot,
|
|
56
|
+
plan,
|
|
57
|
+
decision: resolved.decision,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return plan;
|
|
56
61
|
}
|
|
57
62
|
catch (error) {
|
|
58
63
|
if (!(error instanceof Error))
|
|
@@ -1,80 +1,50 @@
|
|
|
1
1
|
import { SystemMessage, HumanMessage } from '@langchain/core/messages';
|
|
2
2
|
import { isDeepStrictEqual } from 'node:util';
|
|
3
|
-
import {
|
|
4
|
-
import { z } from 'zod';
|
|
3
|
+
import { describeWorkflowGraphPlanning, createWorkflowGraphPlanningResult, createWorkflowGraphPlanningRecord, } from '@openapi-flow/core';
|
|
5
4
|
import { createWorkflowGraphProposalSchema } from '../schemas/workflow-graph-proposal-schema.js';
|
|
5
|
+
import { workflowGraphExplanationOptionsSchema } from '../schemas/workflow-graph-explanation-schema.js';
|
|
6
|
+
import { serializeStructuredOutputSchema } from '../schemas/serialize-structured-output-schema.js';
|
|
7
|
+
import { resolveExecutableWorkflowGraphOutput } from './resolve-workflow-graph-output.js';
|
|
6
8
|
import { WorkflowGraphPlanningError } from './workflow-graph-planning-error.js';
|
|
7
9
|
import { workflowGraphPrompt } from '../prompts/workflow-graph-prompt.js';
|
|
8
10
|
import { assertSelectionInput } from '../legacy/planning/select-operation.js';
|
|
9
11
|
import { parseStructuredOutput } from '../legacy/planning/parse-structured-output.js';
|
|
10
|
-
import { createPreparedNativeNodeMaterials } from './create-prepared-native-node-materials.js';
|
|
11
|
-
import { assembleNativeNodeMaterials } from './assemble-native-node-materials.js';
|
|
12
12
|
export async function planWorkflowGraph(input) {
|
|
13
13
|
assertSelectionInput(input.scenario, input.model);
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
const planningCapabilities = createWorkflowPlanningCapabilities({
|
|
17
|
-
capabilities: input.capabilities,
|
|
18
|
-
apiCallIds,
|
|
19
|
-
});
|
|
20
|
-
const schema = createWorkflowGraphProposalSchema(planningCapabilities);
|
|
21
|
-
validateNativeApiResponseReferences({
|
|
22
|
-
nativeNodes: preparedNativeNodes,
|
|
23
|
-
capabilities: input.capabilities,
|
|
24
|
-
apiCallIds,
|
|
14
|
+
const options = workflowGraphExplanationOptionsSchema.parse({
|
|
15
|
+
includeExplanations: input.includeExplanations,
|
|
25
16
|
});
|
|
26
|
-
|
|
27
|
-
|
|
17
|
+
if (!Array.isArray(input.materials))
|
|
18
|
+
throw new Error('planWorkflowGraph.materials must be an array');
|
|
19
|
+
const source = {
|
|
20
|
+
mode: 'executable',
|
|
21
|
+
scenario: input.scenario,
|
|
22
|
+
materials: input.materials.map((material) => ({
|
|
23
|
+
...material,
|
|
24
|
+
status: 'ready',
|
|
25
|
+
})),
|
|
28
26
|
capabilities: input.capabilities,
|
|
29
|
-
|
|
27
|
+
preparedNativeNodes: input.preparedNativeNodes,
|
|
28
|
+
gaps: [],
|
|
29
|
+
};
|
|
30
|
+
const { input: snapshot, context, sources, planningCapabilities, } = describeWorkflowGraphPlanning(source);
|
|
31
|
+
const schema = createWorkflowGraphProposalSchema(planningCapabilities, options.includeExplanations === true);
|
|
30
32
|
const output = await input.model
|
|
31
|
-
.withStructuredOutput(schema, {
|
|
33
|
+
.withStructuredOutput(serializeStructuredOutputSchema(schema, 'draft-2020-12'), {
|
|
32
34
|
name: 'plan_workflow_graph',
|
|
33
35
|
method: 'functionCalling',
|
|
34
36
|
strict: true,
|
|
35
37
|
})
|
|
36
38
|
.invoke([
|
|
37
39
|
new SystemMessage(workflowGraphPrompt),
|
|
38
|
-
new HumanMessage(JSON.stringify(
|
|
39
|
-
scenario: input.scenario,
|
|
40
|
-
preparedNativeNodes: createPreparedNativeNodeMaterials(preparedNativeNodes, input.capabilities),
|
|
41
|
-
nativeOutputs,
|
|
42
|
-
// Request values are already generated. Avoid duplicating the resolved
|
|
43
|
-
// response schemas through both operation and pathItem in this stage.
|
|
44
|
-
materials: input.materials.map(({ operation, arguments: args }) => ({
|
|
45
|
-
operation: {
|
|
46
|
-
key: operation.key,
|
|
47
|
-
method: operation.method,
|
|
48
|
-
path: operation.path,
|
|
49
|
-
operation: {
|
|
50
|
-
summary: operation.operation.summary,
|
|
51
|
-
description: operation.operation.description,
|
|
52
|
-
tags: operation.operation.tags,
|
|
53
|
-
responses: operation.operation.responses,
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
arguments: {
|
|
57
|
-
callId: args.callId,
|
|
58
|
-
values: args.values,
|
|
59
|
-
bindings: args.bindings,
|
|
60
|
-
},
|
|
61
|
-
inputPorts: ['main'],
|
|
62
|
-
outputPorts: ['main'],
|
|
63
|
-
})),
|
|
64
|
-
capabilities: planningCapabilities.map((capability) => ({
|
|
65
|
-
name: capability.name,
|
|
66
|
-
description: capability.description,
|
|
67
|
-
parametersSchema: z.toJSONSchema(capability.parametersSchema),
|
|
68
|
-
waitsForAllInputs: capability.waitsForAllInputs,
|
|
69
|
-
exclusiveOutputPorts: capability.exclusiveOutputPorts,
|
|
70
|
-
})),
|
|
71
|
-
})),
|
|
40
|
+
new HumanMessage(JSON.stringify(context)),
|
|
72
41
|
]);
|
|
73
|
-
let
|
|
42
|
+
let resolved;
|
|
74
43
|
try {
|
|
75
|
-
|
|
76
|
-
if (!isDeepStrictEqual(
|
|
44
|
+
const parsed = parseStructuredOutput(schema, output, 'model workflow graph');
|
|
45
|
+
if (!isDeepStrictEqual(parsed, output))
|
|
77
46
|
throw new Error('native model schema must validate without defaults, coercion or transformation');
|
|
47
|
+
resolved = resolveExecutableWorkflowGraphOutput(parsed, snapshot.capabilities.length);
|
|
78
48
|
}
|
|
79
49
|
catch (error) {
|
|
80
50
|
if (!(error instanceof Error))
|
|
@@ -82,18 +52,29 @@ export async function planWorkflowGraph(input) {
|
|
|
82
52
|
throw new WorkflowGraphPlanningError({ stage: 'proposal-schema', output }, error);
|
|
83
53
|
}
|
|
84
54
|
try {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
55
|
+
const current = describeWorkflowGraphPlanning(snapshot);
|
|
56
|
+
if (!isDeepStrictEqual(current.context, context) ||
|
|
57
|
+
!isDeepStrictEqual(current.sources, sources))
|
|
58
|
+
throw new Error('workflow graph source contracts changed during the model invocation');
|
|
59
|
+
const plan = createWorkflowGraphPlanningResult({
|
|
60
|
+
...snapshot,
|
|
61
|
+
proposal: resolved.proposal,
|
|
92
62
|
});
|
|
63
|
+
if (options.includeExplanations === true) {
|
|
64
|
+
if (!resolved.assessment)
|
|
65
|
+
throw new Error('model workflow graph is missing its explanation assessment');
|
|
66
|
+
plan.graphPlanning = createWorkflowGraphPlanningRecord({
|
|
67
|
+
...snapshot,
|
|
68
|
+
proposal: resolved.proposal,
|
|
69
|
+
plan,
|
|
70
|
+
assessment: resolved.assessment,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return plan;
|
|
93
74
|
}
|
|
94
75
|
catch (error) {
|
|
95
76
|
if (!(error instanceof Error))
|
|
96
77
|
throw error;
|
|
97
|
-
throw new WorkflowGraphPlanningError({ stage: 'graph-validation', output
|
|
78
|
+
throw new WorkflowGraphPlanningError({ stage: 'graph-validation', output }, error);
|
|
98
79
|
}
|
|
99
80
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { PlannedNativeNode } from '@openapi-flow/core';
|
|
2
|
+
import type { NativeNodeModelInstance } from '../types/native-node-planning.js';
|
|
3
|
+
/** Runtime flags and empty execution parameters are code-owned, never inferred from placeholder text. */
|
|
4
|
+
export declare function resolveNativeNodeParameterSource(node: NativeNodeModelInstance): PlannedNativeNode;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Runtime flags and empty execution parameters are code-owned, never inferred from placeholder text. */
|
|
2
|
+
export function resolveNativeNodeParameterSource(node) {
|
|
3
|
+
const identity = { id: node.id, capability: node.capability };
|
|
4
|
+
if ('parameterSource' in node && node.parameterSource === 'workflow-input')
|
|
5
|
+
return { ...identity, parameters: {}, runtimeParameters: true };
|
|
6
|
+
return { ...identity, parameters: node.parameters };
|
|
7
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { NativeNodePlanningOutput, ResolvedNativeNodePlanningOutput } from '../types/native-node-planning.js';
|
|
2
|
+
/** Structural projection only: no values, identities or unmet requirements are repaired. */
|
|
3
|
+
export declare function resolveNativeNodePlanningOutput(output: NativeNodePlanningOutput): ResolvedNativeNodePlanningOutput;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { resolveNativeNodeParameterSource } from './resolve-native-node-parameter-source.js';
|
|
2
|
+
/** Structural projection only: no values, identities or unmet requirements are repaired. */
|
|
3
|
+
export function resolveNativeNodePlanningOutput(output) {
|
|
4
|
+
if (!('decision' in output))
|
|
5
|
+
return {
|
|
6
|
+
proposal: {
|
|
7
|
+
nativeNodes: output.nativeNodes.map(resolveNativeNodeParameterSource),
|
|
8
|
+
gaps: output.gaps,
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
const { decision } = output;
|
|
12
|
+
if ('additions' in decision)
|
|
13
|
+
return {
|
|
14
|
+
proposal: {
|
|
15
|
+
nativeNodes: decision.additions.map((item) => resolveNativeNodeParameterSource(item.node)),
|
|
16
|
+
gaps: decision.gaps,
|
|
17
|
+
},
|
|
18
|
+
assessment: {
|
|
19
|
+
kind: 'additions',
|
|
20
|
+
nodes: decision.additions.map(({ node, reason }) => ({
|
|
21
|
+
nodeId: node.id,
|
|
22
|
+
reason,
|
|
23
|
+
})),
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
proposal: { nativeNodes: [], gaps: decision.gaps },
|
|
28
|
+
assessment: {
|
|
29
|
+
kind: 'no-additions',
|
|
30
|
+
reason: decision.noAdditionalNodesReason,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ResolvedWorkflowConnectionOutput, WorkflowConnectionPlanningOutput } from '../types/workflow-orchestration.js';
|
|
2
|
+
/** Fill only context-fixed omissions, then separate reasons from executable edges. */
|
|
3
|
+
export declare function resolveWorkflowConnectionOutput(output: WorkflowConnectionPlanningOutput, readyCallCount: number): ResolvedWorkflowConnectionOutput;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { projectWorkflowConnectionDecision } from '@openapi-flow/core';
|
|
2
|
+
import { completeReviewableWorkflowGraphProposal } from './complete-reviewable-workflow-graph-proposal.js';
|
|
3
|
+
/** Fill only context-fixed omissions, then separate reasons from executable edges. */
|
|
4
|
+
export function resolveWorkflowConnectionOutput(output, readyCallCount) {
|
|
5
|
+
const completed = completeReviewableWorkflowGraphProposal(output, 0, readyCallCount);
|
|
6
|
+
if ('reason' in output) {
|
|
7
|
+
const decision = {
|
|
8
|
+
reason: output.reason,
|
|
9
|
+
edges: output.edges,
|
|
10
|
+
additionalGaps: output.additionalGaps,
|
|
11
|
+
blockedCalls: output.blockedCalls === undefined ? [] : output.blockedCalls,
|
|
12
|
+
};
|
|
13
|
+
return { proposal: projectWorkflowConnectionDecision(decision), decision };
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
proposal: {
|
|
17
|
+
edges: structuredClone(completed.edges),
|
|
18
|
+
additionalGaps: structuredClone(completed.additionalGaps),
|
|
19
|
+
blockedCalls: structuredClone(completed.blockedCalls),
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { WorkflowGraphModelOutput, ResolvedWorkflowGraphOutput } from '../types/workflow-planning.js';
|
|
2
|
+
import type { ReviewableWorkflowGraphModelOutput } from '../types/reviewable-workflow-planning.js';
|
|
3
|
+
/** Context-fixed empty choices are code-owned, never fallback for a missing required model field. */
|
|
4
|
+
export declare function resolveExecutableWorkflowGraphOutput(output: WorkflowGraphModelOutput, capabilityCount: number): ResolvedWorkflowGraphOutput;
|
|
5
|
+
export declare function resolveReviewableWorkflowGraphOutput(output: ReviewableWorkflowGraphModelOutput, capabilityCount: number, readyCallCount: number): ResolvedWorkflowGraphOutput;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
function assessment(output) {
|
|
2
|
+
return {
|
|
3
|
+
reason: output.reason,
|
|
4
|
+
nodes: output.additionalNativeNodes === undefined
|
|
5
|
+
? []
|
|
6
|
+
: output.additionalNativeNodes.map((node) => ({
|
|
7
|
+
nodeId: node.id,
|
|
8
|
+
reason: node.reason,
|
|
9
|
+
})),
|
|
10
|
+
edges: structuredClone(output.edges),
|
|
11
|
+
blockedCalls: 'blockedCalls' in output && output.blockedCalls !== undefined
|
|
12
|
+
? structuredClone(output.blockedCalls)
|
|
13
|
+
: [],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** Context-fixed empty choices are code-owned, never fallback for a missing required model field. */
|
|
17
|
+
export function resolveExecutableWorkflowGraphOutput(output, capabilityCount) {
|
|
18
|
+
if (capabilityCount > 0 && output.additionalNativeNodes === undefined)
|
|
19
|
+
throw new Error('model workflow graph.additionalNativeNodes is required');
|
|
20
|
+
const nodes = capabilityCount === 0 ? [] : output.additionalNativeNodes;
|
|
21
|
+
return {
|
|
22
|
+
proposal: {
|
|
23
|
+
mode: 'executable',
|
|
24
|
+
additionalNativeNodes: nodes.map(({ id, capability, parameters }) => ({
|
|
25
|
+
id,
|
|
26
|
+
capability,
|
|
27
|
+
parameters,
|
|
28
|
+
})),
|
|
29
|
+
edges: output.edges.map(({ from, output, to, input }) => ({
|
|
30
|
+
from,
|
|
31
|
+
output,
|
|
32
|
+
to,
|
|
33
|
+
input,
|
|
34
|
+
})),
|
|
35
|
+
gaps: structuredClone(output.gaps),
|
|
36
|
+
},
|
|
37
|
+
...('reason' in output ? { assessment: assessment(output) } : {}),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export function resolveReviewableWorkflowGraphOutput(output, capabilityCount, readyCallCount) {
|
|
41
|
+
if (capabilityCount > 0 && output.additionalNativeNodes === undefined)
|
|
42
|
+
throw new Error('model reviewable workflow graph.additionalNativeNodes is required');
|
|
43
|
+
if (readyCallCount > 0 && output.blockedCalls === undefined)
|
|
44
|
+
throw new Error('model reviewable workflow graph.blockedCalls is required');
|
|
45
|
+
const nodes = capabilityCount === 0 ? [] : output.additionalNativeNodes;
|
|
46
|
+
const blocked = readyCallCount === 0 ? [] : output.blockedCalls;
|
|
47
|
+
return {
|
|
48
|
+
proposal: {
|
|
49
|
+
mode: 'reviewable',
|
|
50
|
+
additionalNativeNodes: nodes.map(({ id, capability, parameters }) => ({
|
|
51
|
+
id,
|
|
52
|
+
capability,
|
|
53
|
+
parameters,
|
|
54
|
+
})),
|
|
55
|
+
edges: output.edges.map(({ from, output, to, input }) => ({
|
|
56
|
+
from,
|
|
57
|
+
output,
|
|
58
|
+
to,
|
|
59
|
+
input,
|
|
60
|
+
})),
|
|
61
|
+
additionalGaps: structuredClone(output.additionalGaps),
|
|
62
|
+
blockedCalls: blocked.map(({ callId, gapIds }) => ({
|
|
63
|
+
callId,
|
|
64
|
+
gapIds: structuredClone(gapIds),
|
|
65
|
+
})),
|
|
66
|
+
},
|
|
67
|
+
...('reason' in output ? { assessment: assessment(output) } : {}),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { NativeInstanceSelection } from '@openapi-flow/core';
|
|
2
|
+
import type { SelectNativeNodeInstancesInput } from '../types/native-node-planning.js';
|
|
3
|
+
/** One checkpointable role/ownership selection; parameter values are a separate public stage. */
|
|
4
|
+
export declare function selectNativeNodeInstances(input: SelectNativeNodeInstancesInput): Promise<NativeInstanceSelection>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
2
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
3
|
+
import { createNativeInstanceSelectionSchema, describeNativeInstanceSelection, resolveNativeInstanceSelection, } from '@openapi-flow/core';
|
|
4
|
+
import { serializeStructuredOutputSchema } from '../schemas/serialize-structured-output-schema.js';
|
|
5
|
+
import { nativeInstanceSelectionPrompt } from '../prompts/native-node-planning-prompt.js';
|
|
6
|
+
import { NativeNodePlanningError } from './native-node-planning-error.js';
|
|
7
|
+
/** One checkpointable role/ownership selection; parameter values are a separate public stage. */
|
|
8
|
+
export async function selectNativeNodeInstances(input) {
|
|
9
|
+
if (input.model !== undefined &&
|
|
10
|
+
(!input.model || typeof input.model.withStructuredOutput !== 'function'))
|
|
11
|
+
throw new Error('selectNativeNodeInstances.model must support structured output when supplied');
|
|
12
|
+
const { context } = describeNativeInstanceSelection(input);
|
|
13
|
+
const originalOptions = JSON.stringify([
|
|
14
|
+
input.planId,
|
|
15
|
+
input.allowRuntimeParameters,
|
|
16
|
+
input.includeExplanations,
|
|
17
|
+
]);
|
|
18
|
+
const schema = createNativeInstanceSelectionSchema(input);
|
|
19
|
+
if (!context.capabilities.length)
|
|
20
|
+
return resolveNativeInstanceSelection({
|
|
21
|
+
...input,
|
|
22
|
+
proposal: {
|
|
23
|
+
instances: [],
|
|
24
|
+
gaps: [],
|
|
25
|
+
...(input.includeExplanations
|
|
26
|
+
? { reason: 'No native capabilities were supplied.' }
|
|
27
|
+
: {}),
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
if (!input.model || typeof input.model.withStructuredOutput !== 'function')
|
|
31
|
+
throw new Error('selectNativeNodeInstances.model must support structured output for native choices');
|
|
32
|
+
const output = await input.model
|
|
33
|
+
.withStructuredOutput(serializeStructuredOutputSchema(schema, 'draft-2020-12'), {
|
|
34
|
+
name: 'select_native_node_instances',
|
|
35
|
+
method: 'jsonSchema',
|
|
36
|
+
strict: true,
|
|
37
|
+
})
|
|
38
|
+
.invoke([
|
|
39
|
+
new SystemMessage(nativeInstanceSelectionPrompt),
|
|
40
|
+
new HumanMessage(JSON.stringify(context)),
|
|
41
|
+
]);
|
|
42
|
+
try {
|
|
43
|
+
if (!isDeepStrictEqual(describeNativeInstanceSelection(input).context, context) ||
|
|
44
|
+
JSON.stringify([
|
|
45
|
+
input.planId,
|
|
46
|
+
input.allowRuntimeParameters,
|
|
47
|
+
input.includeExplanations,
|
|
48
|
+
]) !== originalOptions)
|
|
49
|
+
throw new Error('Native instance source contracts changed during selection; no automatic rebase');
|
|
50
|
+
return resolveNativeInstanceSelection({ ...input, proposal: output });
|
|
51
|
+
}
|
|
52
|
+
catch (cause) {
|
|
53
|
+
if (!(cause instanceof Error))
|
|
54
|
+
throw cause;
|
|
55
|
+
throw new NativeNodePlanningError({ stage: 'instance-selection', output }, cause);
|
|
56
|
+
}
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openapi-flow/langchain",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Composable LangChain planning for OpenAPI workflows",
|
|
@@ -28,11 +28,14 @@
|
|
|
28
28
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@openapi-flow/core": "0.
|
|
32
|
-
"zod": "4.6.5"
|
|
31
|
+
"@openapi-flow/core": "0.3.0"
|
|
33
32
|
},
|
|
34
33
|
"peerDependencies": {
|
|
35
|
-
"@langchain/core": "^1.0.0"
|
|
34
|
+
"@langchain/core": "^1.0.0",
|
|
35
|
+
"zod": "^4.6.5"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"zod": "4.6.5"
|
|
36
39
|
},
|
|
37
40
|
"publishConfig": {
|
|
38
41
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import type { WorkflowCapability } from '@openapi-flow/core';
|
|
3
|
-
import type { NativeNodeProposal } from '../types/native-node-planning.js';
|
|
4
|
-
export declare function createNativeNodePlanSchema(capabilities: WorkflowCapability[]): z.ZodType<NativeNodeProposal>;
|