@openapi-flow/langchain 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +152 -2
- package/THIRD_PARTY_NOTICES.md +3 -0
- 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.d.ts +3 -0
- package/dist/arguments/generate-api-arguments.js +60 -0
- package/dist/arguments/select-api-request-media-type.d.ts +2 -0
- package/dist/arguments/select-api-request-media-type.js +10 -0
- package/dist/bindings/plan-api-bindings.d.ts +3 -0
- package/dist/bindings/plan-api-bindings.js +50 -0
- 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/legacy/planning/operation-plan-inputs.d.ts +3 -0
- package/dist/legacy/planning/operation-plan-inputs.js +17 -0
- package/dist/legacy/planning/parse-structured-output.d.ts +2 -0
- package/dist/legacy/planning/parse-structured-output.js +9 -0
- package/dist/legacy/planning/propose-catalog-scenario.d.ts +3 -0
- package/dist/legacy/planning/propose-catalog-scenario.js +136 -0
- package/dist/legacy/planning/select-operation.d.ts +4 -0
- package/dist/legacy/planning/select-operation.js +43 -0
- package/dist/legacy/schemas/catalog-selection-schema.d.ts +19 -0
- package/dist/legacy/schemas/catalog-selection-schema.js +39 -0
- package/dist/legacy/schemas/catalog-step-schema.d.ts +16 -0
- package/dist/legacy/schemas/catalog-step-schema.js +39 -0
- package/dist/legacy/schemas/operation-selection-schema.d.ts +6 -0
- package/dist/legacy/schemas/operation-selection-schema.js +14 -0
- package/dist/legacy-api.d.ts +9 -0
- package/dist/legacy-api.js +7 -0
- package/dist/prompts/api-arguments-prompt.d.ts +1 -0
- package/dist/prompts/api-arguments-prompt.js +1 -0
- package/dist/prompts/api-bindings-prompt.d.ts +1 -0
- package/dist/prompts/api-bindings-prompt.js +13 -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 -0
- package/dist/prompts/api-request-media-type-prompt.js +1 -0
- 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 -0
- package/dist/prompts/native-node-planning-prompt.js +22 -0
- package/dist/prompts/operation-selection-prompt.d.ts +1 -0
- package/dist/prompts/operation-selection-prompt.js +1 -0
- package/dist/prompts/reviewable-workflow-graph-prompt.d.ts +1 -0
- package/dist/prompts/reviewable-workflow-graph-prompt.js +7 -0
- package/dist/prompts/workflow-connections-prompt.d.ts +1 -0
- package/dist/prompts/workflow-connections-prompt.js +11 -0
- 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 -0
- package/dist/prompts/workflow-graph-prompt.js +15 -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 +67 -0
- package/dist/public-api.js +46 -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 +8 -0
- package/dist/schemas/api-binding-plan-schema.js +59 -0
- 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 +6 -0
- package/dist/schemas/api-request-media-type-schema.js +23 -0
- 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 +25 -0
- package/dist/schemas/api-selection-schema.js +31 -0
- 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 +6 -0
- package/dist/schemas/reviewable-workflow-graph-schema.js +75 -0
- 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 +4 -0
- package/dist/schemas/workflow-graph-proposal-schema.js +45 -0
- 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 +3 -0
- package/dist/selection/select-api-operations.js +84 -0
- 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 +13 -0
- package/dist/types/argument-generation.js +1 -0
- package/dist/types/binding-planning.d.ts +10 -0
- package/dist/types/binding-planning.js +1 -0
- package/dist/types/legacy/catalog-planning.d.ts +16 -0
- package/dist/types/legacy/catalog-planning.js +1 -0
- package/dist/types/legacy/planning.d.ts +5 -0
- package/dist/types/legacy/planning.js +1 -0
- package/dist/types/native-node-planning.d.ts +76 -0
- package/dist/types/native-node-planning.js +1 -0
- package/dist/types/operation-selection.d.ts +14 -0
- package/dist/types/operation-selection.js +1 -0
- package/dist/types/request-media-selection.d.ts +15 -0
- package/dist/types/request-media-selection.js +1 -0
- package/dist/types/reviewable-workflow-planning.d.ts +28 -0
- package/dist/types/reviewable-workflow-planning.js +1 -0
- 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 +21 -0
- package/dist/types/workflow-orchestration.js +1 -0
- package/dist/types/workflow-planning.d.ts +35 -0
- package/dist/types/workflow-planning.js +1 -0
- package/dist/types/workflow-review-suggestions.d.ts +12 -0
- package/dist/types/workflow-review-suggestions.js +1 -0
- package/dist/workflow/complete-reviewable-workflow-graph-proposal.d.ts +4 -0
- package/dist/workflow/complete-reviewable-workflow-graph-proposal.js +13 -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/native-node-planning-error.d.ts +5 -0
- package/dist/workflow/native-node-planning-error.js +10 -0
- package/dist/workflow/orchestrate-workflow.d.ts +4 -0
- package/dist/workflow/orchestrate-workflow.js +31 -0
- 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.d.ts +2 -0
- package/dist/workflow/plan-native-nodes.js +96 -0
- package/dist/workflow/plan-reviewable-workflow-graph.d.ts +3 -0
- package/dist/workflow/plan-reviewable-workflow-graph.js +70 -0
- package/dist/workflow/plan-workflow-connections.d.ts +3 -0
- package/dist/workflow/plan-workflow-connections.js +67 -0
- package/dist/workflow/plan-workflow-graph.d.ts +3 -0
- package/dist/workflow/plan-workflow-graph.js +80 -0
- 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/reviewable-workflow-graph-planning-error.d.ts +5 -0
- package/dist/workflow/reviewable-workflow-graph-planning-error.js +8 -0
- package/dist/workflow/select-native-node-instances.d.ts +4 -0
- package/dist/workflow/select-native-node-instances.js +57 -0
- package/dist/workflow/workflow-graph-planning-error.d.ts +5 -0
- package/dist/workflow/workflow-graph-planning-error.js +10 -0
- package/package.json +47 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
|
+
import type { WorkflowDraftNativeReferenceRepairInput } from '@openapi-flow/core';
|
|
3
|
+
export interface PlanWorkflowDraftNativeReferenceRepairInput extends WorkflowDraftNativeReferenceRepairInput {
|
|
4
|
+
model: BaseChatModel;
|
|
5
|
+
}
|
|
6
|
+
export interface WorkflowDraftNativeReferenceRepairPlanningFailure {
|
|
7
|
+
stage: 'proposal-schema' | 'proposal-validation';
|
|
8
|
+
output: unknown;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { WorkflowMessageEvidence } from '@openapi-flow/core';
|
|
2
|
+
/** Model input contains identities; the parsed result contains code-owned exact source text. */
|
|
3
|
+
export type WorkflowMessageEvidenceSelection = Pick<WorkflowMessageEvidence, 'kind' | 'messageId'>;
|
|
4
|
+
export type WorkflowMessageSelectionOutput<Output> = Output extends WorkflowMessageEvidence ? WorkflowMessageEvidenceSelection : Output extends Array<infer Item> ? WorkflowMessageSelectionOutput<Item>[] : Output extends object ? {
|
|
5
|
+
[Key in keyof Output]: WorkflowMessageSelectionOutput<Output[Key]>;
|
|
6
|
+
} : Output;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
|
+
import type { PlannedNativeNode, WorkflowConnectionPlanningInput, WorkflowConnectionDecision, WorkflowConnectionProposal, ExplainedWorkflowBlockedCall, ExplainedWorkflowConnection } from '@openapi-flow/core';
|
|
3
|
+
import type { ReviewableWorkflowGraphOutput } from './reviewable-workflow-planning.js';
|
|
4
|
+
export interface PlanWorkflowConnectionsInput extends WorkflowConnectionPlanningInput {
|
|
5
|
+
model: BaseChatModel;
|
|
6
|
+
includeExplanations?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface OrchestrateWorkflowInput extends Omit<PlanWorkflowConnectionsInput, 'nativeNodes'> {
|
|
9
|
+
workflowId: string;
|
|
10
|
+
preparedNativeNodes?: PlannedNativeNode[];
|
|
11
|
+
}
|
|
12
|
+
export interface WorkflowConnectionModelDecision extends ReviewableWorkflowGraphOutput {
|
|
13
|
+
reason: string;
|
|
14
|
+
edges: ExplainedWorkflowConnection[];
|
|
15
|
+
blockedCalls?: ExplainedWorkflowBlockedCall[];
|
|
16
|
+
}
|
|
17
|
+
export type WorkflowConnectionPlanningOutput = ReviewableWorkflowGraphOutput | WorkflowConnectionModelDecision;
|
|
18
|
+
export interface ResolvedWorkflowConnectionOutput {
|
|
19
|
+
proposal: WorkflowConnectionProposal;
|
|
20
|
+
decision?: WorkflowConnectionDecision;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
|
+
import type { WorkflowApiMaterial, WorkflowCapability, WorkflowGraphProposal, PlannedNativeNode, ExplainedWorkflowConnection, WorkflowGraphPlanningProposal, WorkflowGraphPlanningAssessment } from '@openapi-flow/core';
|
|
3
|
+
export interface PlanWorkflowGraphInput {
|
|
4
|
+
scenario: string;
|
|
5
|
+
model: BaseChatModel;
|
|
6
|
+
materials: WorkflowApiMaterial[];
|
|
7
|
+
capabilities: WorkflowCapability[];
|
|
8
|
+
preparedNativeNodes?: PlannedNativeNode[];
|
|
9
|
+
includeExplanations?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export type { PreparedNativeNodeMaterial } from '@openapi-flow/core';
|
|
12
|
+
export type WorkflowGraphOutput = Omit<WorkflowGraphProposal, 'nativeNodes'> & {
|
|
13
|
+
additionalNativeNodes?: PlannedNativeNode[];
|
|
14
|
+
};
|
|
15
|
+
export interface ExplainedGraphNativeNode extends PlannedNativeNode {
|
|
16
|
+
reason: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ExplainedWorkflowGraphOutput extends WorkflowGraphOutput {
|
|
19
|
+
reason: string;
|
|
20
|
+
additionalNativeNodes?: ExplainedGraphNativeNode[];
|
|
21
|
+
edges: ExplainedWorkflowConnection[];
|
|
22
|
+
}
|
|
23
|
+
export type WorkflowGraphModelOutput = WorkflowGraphOutput | ExplainedWorkflowGraphOutput;
|
|
24
|
+
export interface ResolvedWorkflowGraphOutput {
|
|
25
|
+
proposal: WorkflowGraphPlanningProposal;
|
|
26
|
+
assessment?: WorkflowGraphPlanningAssessment;
|
|
27
|
+
}
|
|
28
|
+
export type WorkflowGraphExplanationMode = 'none' | 'connections' | 'graph';
|
|
29
|
+
export type WorkflowGraphPlanningFailure = {
|
|
30
|
+
stage: 'proposal-schema';
|
|
31
|
+
output: unknown;
|
|
32
|
+
} | {
|
|
33
|
+
stage: 'graph-validation';
|
|
34
|
+
output: WorkflowGraphModelOutput;
|
|
35
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
|
+
import type { WorkflowReviewSuggestionsInput, WorkflowReviewSuggestionsProposal, WorkflowReviewQuestionEvidence } from '@openapi-flow/core';
|
|
3
|
+
import type { ProposedWorkflowPlanningEvidence } from './workflow-clarification.js';
|
|
4
|
+
export interface SuggestWorkflowReviewFollowUpsInput extends WorkflowReviewSuggestionsInput {
|
|
5
|
+
model: BaseChatModel;
|
|
6
|
+
}
|
|
7
|
+
export type ProposedWorkflowReviewSuggestionEvidence = ProposedWorkflowPlanningEvidence | WorkflowReviewQuestionEvidence;
|
|
8
|
+
export type WorkflowReviewSuggestionsModelOutput = WorkflowReviewSuggestionsProposal<ProposedWorkflowReviewSuggestionEvidence>;
|
|
9
|
+
export interface WorkflowReviewSuggestionPlanningFailure {
|
|
10
|
+
stage: 'proposal-schema' | 'source-validation';
|
|
11
|
+
output: unknown;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ReviewableWorkflowGraphProposal } from '@openapi-flow/core';
|
|
2
|
+
import type { ReviewableWorkflowGraphOutput } from '../types/reviewable-workflow-planning.js';
|
|
3
|
+
/** Complete only fields fixed by the supplied planning context, not model errors. */
|
|
4
|
+
export declare function completeReviewableWorkflowGraphProposal(output: ReviewableWorkflowGraphOutput, capabilityCount: number, readyCallCount: number): ReviewableWorkflowGraphProposal;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Complete only fields fixed by the supplied planning context, not model errors. */
|
|
2
|
+
export function completeReviewableWorkflowGraphProposal(output, capabilityCount, readyCallCount) {
|
|
3
|
+
if (capabilityCount > 0 && output.additionalNativeNodes === undefined)
|
|
4
|
+
throw new Error('model reviewable workflow graph.additionalNativeNodes is required');
|
|
5
|
+
if (readyCallCount > 0 && output.blockedCalls === undefined)
|
|
6
|
+
throw new Error('model reviewable workflow graph.blockedCalls is required');
|
|
7
|
+
const { additionalNativeNodes, ...proposal } = output;
|
|
8
|
+
return {
|
|
9
|
+
...proposal,
|
|
10
|
+
nativeNodes: capabilityCount === 0 ? [] : additionalNativeNodes,
|
|
11
|
+
blockedCalls: readyCallCount === 0 ? [] : output.blockedCalls,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { NativeNodeParameterResult } from '@openapi-flow/core';
|
|
2
|
+
import type { GenerateNativeNodeParametersInput } from '../types/native-node-planning.js';
|
|
3
|
+
/** Zero or one value call for one selected instance; no hidden ownership or connection planning. */
|
|
4
|
+
export declare function generateNativeNodeParameters(input: GenerateNativeNodeParametersInput): Promise<NativeNodeParameterResult>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
2
|
+
import { createNativeNodeParametersSchema, describeNativeNodeConfiguration, resolveNativeNodeParameters, } from '@openapi-flow/core';
|
|
3
|
+
import { serializeStructuredOutputSchema } from '../schemas/serialize-structured-output-schema.js';
|
|
4
|
+
import { nativeNodeParametersPrompt } from '../prompts/native-node-planning-prompt.js';
|
|
5
|
+
import { NativeNodePlanningError } from './native-node-planning-error.js';
|
|
6
|
+
/** Zero or one value call for one selected instance; no hidden ownership or connection planning. */
|
|
7
|
+
export async function generateNativeNodeParameters(input) {
|
|
8
|
+
if (input.model !== undefined &&
|
|
9
|
+
(!input.model || typeof input.model.withStructuredOutput !== 'function'))
|
|
10
|
+
throw new Error('generateNativeNodeParameters.model must support structured output when supplied');
|
|
11
|
+
const description = describeNativeNodeConfiguration(input);
|
|
12
|
+
if (!description.instance.hasLiteralParameters)
|
|
13
|
+
return resolveNativeNodeParameters({
|
|
14
|
+
...input,
|
|
15
|
+
fingerprint: description.fingerprint,
|
|
16
|
+
proposal: {
|
|
17
|
+
decision: {
|
|
18
|
+
status: 'provided',
|
|
19
|
+
parameters: {},
|
|
20
|
+
...(input.includeExplanations
|
|
21
|
+
? {
|
|
22
|
+
reason: 'The validated ownership contract leaves no literal parameter choice.',
|
|
23
|
+
}
|
|
24
|
+
: {}),
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
if (!input.model || typeof input.model.withStructuredOutput !== 'function')
|
|
29
|
+
throw new Error('generateNativeNodeParameters.model must support structured output for remaining values');
|
|
30
|
+
const schema = createNativeNodeParametersSchema(input);
|
|
31
|
+
const capability = description.context.capabilities.find((entry) => entry.name === description.instance.capability);
|
|
32
|
+
if (!capability)
|
|
33
|
+
throw new Error('Native parameter generation has no selected capability material');
|
|
34
|
+
const output = await input.model
|
|
35
|
+
.withStructuredOutput(serializeStructuredOutputSchema(schema, 'draft-2020-12'), {
|
|
36
|
+
name: 'generate_native_node_parameters',
|
|
37
|
+
method: 'jsonSchema',
|
|
38
|
+
strict: true,
|
|
39
|
+
})
|
|
40
|
+
.invoke([
|
|
41
|
+
new SystemMessage(nativeNodeParametersPrompt),
|
|
42
|
+
new HumanMessage(JSON.stringify({
|
|
43
|
+
scenario: description.context.scenario,
|
|
44
|
+
purpose: description.instance.purpose,
|
|
45
|
+
target: {
|
|
46
|
+
id: description.instance.id,
|
|
47
|
+
capability: {
|
|
48
|
+
name: capability.name,
|
|
49
|
+
description: capability.description,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
parametersSchema: description.instance.literalParametersSchema,
|
|
53
|
+
runtimeParameters: description.instance.runtimeParameters,
|
|
54
|
+
apiMaterials: description.context.apiMaterials,
|
|
55
|
+
preparedNativeNodes: description.context.preparedNativeNodes,
|
|
56
|
+
configuredNodes: description.configuredNodes,
|
|
57
|
+
outputs: description.outputs,
|
|
58
|
+
...(description.sourceDependencies === undefined
|
|
59
|
+
? {}
|
|
60
|
+
: { sourceDependencies: description.sourceDependencies }),
|
|
61
|
+
...(description.replies === undefined
|
|
62
|
+
? {}
|
|
63
|
+
: { replies: description.replies }),
|
|
64
|
+
})),
|
|
65
|
+
]);
|
|
66
|
+
try {
|
|
67
|
+
// Validate output separately so callers can distinguish a malformed reply from stale source material.
|
|
68
|
+
schema.parse(output);
|
|
69
|
+
}
|
|
70
|
+
catch (cause) {
|
|
71
|
+
if (!(cause instanceof Error))
|
|
72
|
+
throw cause;
|
|
73
|
+
throw new NativeNodePlanningError({ stage: 'parameter-schema', output }, cause);
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
return resolveNativeNodeParameters({
|
|
77
|
+
...input,
|
|
78
|
+
fingerprint: description.fingerprint,
|
|
79
|
+
proposal: output,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
catch (cause) {
|
|
83
|
+
if (!(cause instanceof Error))
|
|
84
|
+
throw cause;
|
|
85
|
+
throw new NativeNodePlanningError({ stage: 'parameter-validation', output }, cause);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export class NativeNodePlanningError extends Error {
|
|
2
|
+
failure;
|
|
3
|
+
constructor(failure, cause) {
|
|
4
|
+
super(`Native node planning failed at ${failure.stage}: ${cause.message}`, {
|
|
5
|
+
cause,
|
|
6
|
+
});
|
|
7
|
+
this.name = 'NativeNodePlanningError';
|
|
8
|
+
this.failure = failure;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ReviewableWorkflowGraphPlan } from '@openapi-flow/core';
|
|
2
|
+
import type { OrchestrateWorkflowInput } from '../types/workflow-orchestration.js';
|
|
3
|
+
/** Optional material groups mean absence, never an implicit capability registry. */
|
|
4
|
+
export declare function orchestrateWorkflow(input: OrchestrateWorkflowInput): Promise<ReviewableWorkflowGraphPlan>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { planNativeNodes } from './plan-native-nodes.js';
|
|
2
|
+
import { planWorkflowConnections } from './plan-workflow-connections.js';
|
|
3
|
+
import { assembleNativeNodeMaterials } from '@openapi-flow/core';
|
|
4
|
+
import { prepareWorkflowConnectionMaterials } from '@openapi-flow/core';
|
|
5
|
+
/** Optional material groups mean absence, never an implicit capability registry. */
|
|
6
|
+
export async function orchestrateWorkflow(input) {
|
|
7
|
+
if (!input.workflowId?.trim())
|
|
8
|
+
throw new Error('orchestrateWorkflow.workflowId is required');
|
|
9
|
+
prepareWorkflowConnectionMaterials({
|
|
10
|
+
...input,
|
|
11
|
+
nativeNodes: input.preparedNativeNodes,
|
|
12
|
+
});
|
|
13
|
+
const nativePlan = await planNativeNodes({
|
|
14
|
+
planId: `${input.workflowId}-native`,
|
|
15
|
+
scenario: input.scenario,
|
|
16
|
+
model: input.model,
|
|
17
|
+
capabilities: input.capabilities,
|
|
18
|
+
preparedNativeNodes: input.preparedNativeNodes,
|
|
19
|
+
apiMaterials: input.materials?.map((material) => ({
|
|
20
|
+
callId: material.status === 'ready'
|
|
21
|
+
? material.arguments.callId
|
|
22
|
+
: material.callId,
|
|
23
|
+
operation: material.operation,
|
|
24
|
+
})),
|
|
25
|
+
});
|
|
26
|
+
return planWorkflowConnections({
|
|
27
|
+
...input,
|
|
28
|
+
nativeNodes: assembleNativeNodeMaterials(input.preparedNativeNodes ?? [], nativePlan.nativeNodes),
|
|
29
|
+
gaps: [...(input.gaps ?? []), ...nativePlan.gaps],
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { NativeInstanceDependencyPlan } from '@openapi-flow/core';
|
|
2
|
+
import type { PlanNativeInstanceDependenciesInput } from '../types/native-node-planning.js';
|
|
3
|
+
/** Zero or one producer-choice call; no parameters, output contracts or runtime DAG edges. */
|
|
4
|
+
export declare function planNativeInstanceDependencies(input: PlanNativeInstanceDependenciesInput): Promise<NativeInstanceDependencyPlan>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
2
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
3
|
+
import { describeNativeInstanceDependencies, createNativeInstanceDependenciesSchema, resolveNativeInstanceDependencies, } from '@openapi-flow/core';
|
|
4
|
+
import { nativeInstanceDependenciesPrompt } from '../prompts/native-instance-dependencies-prompt.js';
|
|
5
|
+
import { serializeStructuredOutputSchema } from '../schemas/serialize-structured-output-schema.js';
|
|
6
|
+
import { NativeNodePlanningError } from './native-node-planning-error.js';
|
|
7
|
+
/** Zero or one producer-choice call; no parameters, output contracts or runtime DAG edges. */
|
|
8
|
+
export async function planNativeInstanceDependencies(input) {
|
|
9
|
+
if (input.model !== undefined &&
|
|
10
|
+
(!input.model || typeof input.model.withStructuredOutput !== 'function'))
|
|
11
|
+
throw new Error('planNativeInstanceDependencies.model must support structured output when supplied');
|
|
12
|
+
const context = describeNativeInstanceDependencies(input);
|
|
13
|
+
const explanations = input.includeExplanations;
|
|
14
|
+
if (Object.values(context.sourceCandidatesByNodeId).every((ids) => ids.length === 0))
|
|
15
|
+
return resolveNativeInstanceDependencies({
|
|
16
|
+
...input,
|
|
17
|
+
proposal: {
|
|
18
|
+
sourcesByNodeId: Object.fromEntries(context.instances.map((node) => [node.id, { sourceNodeIds: [] }])),
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
if (!input.model || typeof input.model.withStructuredOutput !== 'function')
|
|
22
|
+
throw new Error('planNativeInstanceDependencies.model must support structured output for producer choices');
|
|
23
|
+
const schema = createNativeInstanceDependenciesSchema(input);
|
|
24
|
+
const output = await input.model
|
|
25
|
+
.withStructuredOutput(serializeStructuredOutputSchema(schema, 'draft-2020-12'), {
|
|
26
|
+
name: 'plan_native_instance_dependencies',
|
|
27
|
+
method: 'jsonSchema',
|
|
28
|
+
strict: true,
|
|
29
|
+
})
|
|
30
|
+
.invoke([
|
|
31
|
+
new SystemMessage(nativeInstanceDependenciesPrompt),
|
|
32
|
+
new HumanMessage(JSON.stringify(context)),
|
|
33
|
+
]);
|
|
34
|
+
try {
|
|
35
|
+
if (!isDeepStrictEqual(describeNativeInstanceDependencies(input), context) ||
|
|
36
|
+
explanations !== input.includeExplanations)
|
|
37
|
+
throw new Error('Native dependency source contracts changed during planning; no automatic rebase');
|
|
38
|
+
return resolveNativeInstanceDependencies({ ...input, proposal: output });
|
|
39
|
+
}
|
|
40
|
+
catch (cause) {
|
|
41
|
+
if (!(cause instanceof Error))
|
|
42
|
+
throw cause;
|
|
43
|
+
throw new NativeNodePlanningError({ stage: 'dependency-plan', output }, cause);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
2
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
3
|
+
import { describeNativeNodePlanning, createNativeNodePlan, createNativeNodePlanningRecord, } from '@openapi-flow/core';
|
|
4
|
+
import { createNativeNodePlanningContract } from '../schemas/native-node-planning-contract.js';
|
|
5
|
+
import { nativeNodeExplanationOptionsSchema } from '../schemas/native-node-explanation-schema.js';
|
|
6
|
+
import { nativeNodePlanningPrompt } from '../prompts/native-node-planning-prompt.js';
|
|
7
|
+
import { assertSelectionInput } from '../legacy/planning/select-operation.js';
|
|
8
|
+
import { parseStructuredOutput } from '../legacy/planning/parse-structured-output.js';
|
|
9
|
+
import { resolveNativeNodePlanningOutput } from './resolve-native-node-planning-output.js';
|
|
10
|
+
import { serializeStructuredOutputSchema } from '../schemas/serialize-structured-output-schema.js';
|
|
11
|
+
import { NativeNodePlanningError } from './native-node-planning-error.js';
|
|
12
|
+
export async function planNativeNodes(input) {
|
|
13
|
+
if (!input.planId?.trim())
|
|
14
|
+
throw new Error('planNativeNodes.planId is required');
|
|
15
|
+
if (input.model !== undefined &&
|
|
16
|
+
(!input.model || typeof input.model.withStructuredOutput !== 'function'))
|
|
17
|
+
throw new Error('planNativeNodes.model must support structured output when supplied');
|
|
18
|
+
const options = nativeNodeExplanationOptionsSchema.parse({
|
|
19
|
+
includeExplanations: input.includeExplanations,
|
|
20
|
+
});
|
|
21
|
+
const { input: snapshot, context, planningCapabilities, } = describeNativeNodePlanning(input);
|
|
22
|
+
// No registered choice means no native-selection model call, not an inferred registry.
|
|
23
|
+
if (!snapshot.capabilities.length) {
|
|
24
|
+
const plan = createNativeNodePlan({
|
|
25
|
+
...snapshot,
|
|
26
|
+
proposal: { nativeNodes: [], gaps: [] },
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
...plan,
|
|
30
|
+
...(options.includeExplanations === true
|
|
31
|
+
? {
|
|
32
|
+
nativePlanning: createNativeNodePlanningRecord({
|
|
33
|
+
...snapshot,
|
|
34
|
+
plan,
|
|
35
|
+
}),
|
|
36
|
+
}
|
|
37
|
+
: {}),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const model = input.model;
|
|
41
|
+
if (!model)
|
|
42
|
+
throw new Error('planNativeNodes.model is required when supplied capabilities need a planning decision');
|
|
43
|
+
assertSelectionInput(snapshot.scenario, model);
|
|
44
|
+
const contract = createNativeNodePlanningContract(planningCapabilities, snapshot.allowRuntimeParameters === true, options.includeExplanations === true);
|
|
45
|
+
if (!isDeepStrictEqual(contract.capabilities, context.capabilities))
|
|
46
|
+
throw new Error('native planning schema differs from its supplied capability material');
|
|
47
|
+
const { schema } = contract;
|
|
48
|
+
const output = await model
|
|
49
|
+
.withStructuredOutput(serializeStructuredOutputSchema(schema, 'draft-2020-12'), {
|
|
50
|
+
name: 'plan_native_nodes',
|
|
51
|
+
method: 'functionCalling',
|
|
52
|
+
strict: true,
|
|
53
|
+
})
|
|
54
|
+
.invoke([
|
|
55
|
+
new SystemMessage(nativeNodePlanningPrompt),
|
|
56
|
+
new HumanMessage(JSON.stringify(context)),
|
|
57
|
+
]);
|
|
58
|
+
let parsed;
|
|
59
|
+
try {
|
|
60
|
+
parsed = parseStructuredOutput(schema, output, 'model native node plan');
|
|
61
|
+
if (!isDeepStrictEqual(parsed, output))
|
|
62
|
+
throw new Error('native model schema must validate without defaults, coercion or transformation');
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
if (!(error instanceof Error))
|
|
66
|
+
throw error;
|
|
67
|
+
throw new NativeNodePlanningError({ stage: 'proposal-schema', output }, error);
|
|
68
|
+
}
|
|
69
|
+
const { proposal, assessment } = resolveNativeNodePlanningOutput(parsed);
|
|
70
|
+
try {
|
|
71
|
+
if (!isDeepStrictEqual(describeNativeNodePlanning(snapshot).context, context))
|
|
72
|
+
throw new Error('native planning source contracts changed during the model invocation');
|
|
73
|
+
const plan = createNativeNodePlan({ ...snapshot, proposal });
|
|
74
|
+
return {
|
|
75
|
+
...plan,
|
|
76
|
+
...(options.includeExplanations === true
|
|
77
|
+
? {
|
|
78
|
+
nativePlanning: createNativeNodePlanningRecord({
|
|
79
|
+
...snapshot,
|
|
80
|
+
plan,
|
|
81
|
+
assessment,
|
|
82
|
+
}),
|
|
83
|
+
}
|
|
84
|
+
: {}),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (!(error instanceof Error))
|
|
89
|
+
throw error;
|
|
90
|
+
throw new NativeNodePlanningError({
|
|
91
|
+
stage: 'node-validation',
|
|
92
|
+
output: proposal,
|
|
93
|
+
sourceOutput: parsed,
|
|
94
|
+
}, error);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ReviewableWorkflowGraphPlan } from '@openapi-flow/core';
|
|
2
|
+
import type { PlanReviewableWorkflowGraphInput } from '../types/reviewable-workflow-planning.js';
|
|
3
|
+
export declare function planReviewableWorkflowGraph(input: PlanReviewableWorkflowGraphInput): Promise<ReviewableWorkflowGraphPlan>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
2
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
3
|
+
import { describeWorkflowGraphPlanning, createWorkflowGraphPlanningResult, createWorkflowGraphPlanningRecord, } from '@openapi-flow/core';
|
|
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';
|
|
8
|
+
import { reviewableWorkflowGraphPrompt } from '../prompts/reviewable-workflow-graph-prompt.js';
|
|
9
|
+
import { assertSelectionInput } from '../legacy/planning/select-operation.js';
|
|
10
|
+
import { parseStructuredOutput } from '../legacy/planning/parse-structured-output.js';
|
|
11
|
+
import { ReviewableWorkflowGraphPlanningError } from './reviewable-workflow-graph-planning-error.js';
|
|
12
|
+
export async function planReviewableWorkflowGraph(input) {
|
|
13
|
+
assertSelectionInput(input.scenario, input.model);
|
|
14
|
+
const options = workflowGraphExplanationOptionsSchema.parse({
|
|
15
|
+
includeExplanations: input.includeExplanations,
|
|
16
|
+
});
|
|
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');
|
|
20
|
+
const output = await input.model
|
|
21
|
+
.withStructuredOutput(serializeStructuredOutputSchema(schema, 'draft-2020-12'), {
|
|
22
|
+
name: 'plan_reviewable_workflow_graph',
|
|
23
|
+
method: 'functionCalling',
|
|
24
|
+
strict: true,
|
|
25
|
+
})
|
|
26
|
+
.invoke([
|
|
27
|
+
new SystemMessage(reviewableWorkflowGraphPrompt),
|
|
28
|
+
new HumanMessage(JSON.stringify(context)),
|
|
29
|
+
]);
|
|
30
|
+
let resolved;
|
|
31
|
+
try {
|
|
32
|
+
const parsed = parseStructuredOutput(schema, output, 'model reviewable workflow graph');
|
|
33
|
+
if (!isDeepStrictEqual(parsed, output))
|
|
34
|
+
throw new Error('native model schema must validate without defaults, coercion or transformation');
|
|
35
|
+
resolved = resolveReviewableWorkflowGraphOutput(parsed, snapshot.capabilities.length, readyIds.length);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (!(error instanceof Error))
|
|
39
|
+
throw error;
|
|
40
|
+
throw new ReviewableWorkflowGraphPlanningError({ stage: 'proposal-schema', output }, error);
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
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,
|
|
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;
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (!(error instanceof Error))
|
|
67
|
+
throw error;
|
|
68
|
+
throw new ReviewableWorkflowGraphPlanningError({ stage: 'graph-validation', output }, error);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ReviewableWorkflowGraphPlan } from '@openapi-flow/core';
|
|
2
|
+
import type { PlanWorkflowConnectionsInput } from '../types/workflow-orchestration.js';
|
|
3
|
+
export declare function planWorkflowConnections(input: PlanWorkflowConnectionsInput): Promise<ReviewableWorkflowGraphPlan>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
2
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
3
|
+
import { describeWorkflowConnectionPlanning, createWorkflowConnectionPlan, createWorkflowConnectionPlanningRecord, } from '@openapi-flow/core';
|
|
4
|
+
import { createReviewableWorkflowGraphSchema } from '../schemas/reviewable-workflow-graph-schema.js';
|
|
5
|
+
import { resolveWorkflowConnectionOutput } from './resolve-workflow-connection-output.js';
|
|
6
|
+
import { workflowConnectionsPrompt } from '../prompts/workflow-connections-prompt.js';
|
|
7
|
+
import { assertSelectionInput } from '../legacy/planning/select-operation.js';
|
|
8
|
+
import { parseStructuredOutput } from '../legacy/planning/parse-structured-output.js';
|
|
9
|
+
import { ReviewableWorkflowGraphPlanningError } from './reviewable-workflow-graph-planning-error.js';
|
|
10
|
+
import { workflowConnectionExplanationOptionsSchema } from '../schemas/workflow-connection-explanation-schema.js';
|
|
11
|
+
import { serializeStructuredOutputSchema } from '../schemas/serialize-structured-output-schema.js';
|
|
12
|
+
export async function planWorkflowConnections(input) {
|
|
13
|
+
assertSelectionInput(input.scenario, input.model);
|
|
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');
|
|
20
|
+
const output = await input.model
|
|
21
|
+
.withStructuredOutput(serializeStructuredOutputSchema(schema, 'draft-2020-12'), {
|
|
22
|
+
name: 'plan_workflow_connections',
|
|
23
|
+
method: 'functionCalling',
|
|
24
|
+
strict: true,
|
|
25
|
+
})
|
|
26
|
+
.invoke([
|
|
27
|
+
new SystemMessage(workflowConnectionsPrompt),
|
|
28
|
+
new HumanMessage(JSON.stringify(context)),
|
|
29
|
+
]);
|
|
30
|
+
let resolved;
|
|
31
|
+
try {
|
|
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);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (!(error instanceof Error))
|
|
39
|
+
throw error;
|
|
40
|
+
throw new ReviewableWorkflowGraphPlanningError({ stage: 'proposal-schema', output }, error);
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
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,
|
|
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;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (!(error instanceof Error))
|
|
64
|
+
throw error;
|
|
65
|
+
throw new ReviewableWorkflowGraphPlanningError({ stage: 'graph-validation', output }, error);
|
|
66
|
+
}
|
|
67
|
+
}
|