@openapi-flow/langchain 0.4.0 → 0.4.2

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.
Files changed (100) hide show
  1. package/README.md +44 -0
  2. package/dist/arguments/analyze-api-input-answers.js +31 -6
  3. package/dist/arguments/analyze-api-request-media-type.js +3 -2
  4. package/dist/arguments/assert-api-argument-generation-source.d.ts +4 -0
  5. package/dist/arguments/assert-api-argument-generation-source.js +16 -0
  6. package/dist/arguments/attribute-api-literal-generation-sources.d.ts +4 -0
  7. package/dist/arguments/attribute-api-literal-generation-sources.js +16 -0
  8. package/dist/arguments/create-api-argument-rejection.js +9 -2
  9. package/dist/arguments/fingerprint-api-argument-source.d.ts +2 -2
  10. package/dist/arguments/fingerprint-api-argument-source.js +2 -1
  11. package/dist/arguments/generate-api-arguments.js +45 -18
  12. package/dist/bindings/plan-api-call-bindings.js +32 -10
  13. package/dist/bindings/select-api-binding-sources.js +34 -9
  14. package/dist/prompts/api-arguments-prompt.d.ts +2 -2
  15. package/dist/prompts/api-arguments-prompt.js +11 -2
  16. package/dist/prompts/api-input-answers-prompt.d.ts +1 -1
  17. package/dist/prompts/api-input-answers-prompt.js +8 -7
  18. package/dist/prompts/api-material-repair-prompt.d.ts +1 -0
  19. package/dist/prompts/api-material-repair-prompt.js +1 -0
  20. package/dist/prompts/native-instance-selection-review-prompt.d.ts +1 -1
  21. package/dist/prompts/native-instance-selection-review-prompt.js +6 -2
  22. package/dist/prompts/native-node-planning-prompt.d.ts +2 -2
  23. package/dist/prompts/native-node-planning-prompt.js +6 -0
  24. package/dist/prompts/workflow-connection-goal-review-prompt.d.ts +1 -1
  25. package/dist/prompts/workflow-connection-goal-review-prompt.js +2 -2
  26. package/dist/prompts/workflow-connection-native-repair-prompt.d.ts +1 -0
  27. package/dist/prompts/workflow-connection-native-repair-prompt.js +1 -0
  28. package/dist/prompts/workflow-connections-prompt.d.ts +1 -1
  29. package/dist/prompts/workflow-connections-prompt.js +1 -0
  30. package/dist/prompts/workflow-intent-prompt.d.ts +1 -0
  31. package/dist/prompts/workflow-intent-prompt.js +8 -0
  32. package/dist/public-api.d.ts +10 -0
  33. package/dist/public-api.js +7 -0
  34. package/dist/schemas/api-call-binding-plan-schema.d.ts +2 -2
  35. package/dist/schemas/api-call-binding-plan-schema.js +7 -3
  36. package/dist/schemas/api-input-answer-source-schema.d.ts +5 -5
  37. package/dist/schemas/api-input-answer-source-schema.js +14 -6
  38. package/dist/schemas/api-literal-generation-output-schema.d.ts +12 -31
  39. package/dist/schemas/api-literal-generation-output-schema.js +31 -15
  40. package/dist/schemas/api-request-media-type-schema.d.ts +1 -1
  41. package/dist/schemas/api-request-media-type-schema.js +6 -1
  42. package/dist/schemas/api-selection-analysis-schema.d.ts +36 -1
  43. package/dist/schemas/api-selection-analysis-schema.js +4 -4
  44. package/dist/schemas/api-selection-schema.d.ts +14 -1
  45. package/dist/schemas/api-selection-schema.js +3 -3
  46. package/dist/schemas/create-connection-material-repair-choice-schema.js +3 -1
  47. package/dist/schemas/native-planning-rejection-schema.d.ts +11 -0
  48. package/dist/schemas/native-planning-rejection-schema.js +8 -0
  49. package/dist/schemas/reviewable-workflow-graph-schema.d.ts +14 -3
  50. package/dist/schemas/with-api-selection-explanation.d.ts +11 -3
  51. package/dist/schemas/with-api-selection-explanation.js +21 -8
  52. package/dist/schemas/workflow-connection-execution-schema.d.ts +5 -0
  53. package/dist/schemas/workflow-connection-execution-schema.js +22 -0
  54. package/dist/schemas/workflow-connection-goal-review-schema.d.ts +1 -1
  55. package/dist/schemas/workflow-connection-goal-review-schema.js +8 -10
  56. package/dist/schemas/workflow-connection-selection-schema.d.ts +33 -0
  57. package/dist/schemas/workflow-connection-selection-schema.js +34 -0
  58. package/dist/selection/analyze-api-selection.js +6 -5
  59. package/dist/selection/select-api-operations.js +5 -4
  60. package/dist/types/api-call-binding-planning.d.ts +2 -1
  61. package/dist/types/api-input-answers.d.ts +2 -6
  62. package/dist/types/argument-generation.d.ts +9 -4
  63. package/dist/types/incremental-connection-planning.d.ts +2 -0
  64. package/dist/types/native-instance-selection-review.d.ts +5 -2
  65. package/dist/types/native-node-planning.d.ts +4 -0
  66. package/dist/types/native-planning-rejection.d.ts +21 -0
  67. package/dist/types/native-planning-rejection.js +1 -0
  68. package/dist/types/reviewable-workflow-planning.d.ts +2 -1
  69. package/dist/types/workflow-connection-native-repair.d.ts +16 -0
  70. package/dist/types/workflow-connection-native-repair.js +1 -0
  71. package/dist/types/workflow-connection-selection.d.ts +19 -0
  72. package/dist/types/workflow-connection-selection.js +1 -0
  73. package/dist/types/workflow-intent.d.ts +6 -0
  74. package/dist/types/workflow-intent.js +1 -0
  75. package/dist/types/workflow-orchestration.d.ts +2 -1
  76. package/dist/workflow/connections/generate-workflow-connection-native-parameters.d.ts +4 -0
  77. package/dist/workflow/connections/generate-workflow-connection-native-parameters.js +80 -0
  78. package/dist/workflow/connections/invoke-connection-planning-model.js +4 -1
  79. package/dist/workflow/connections/plan-workflow-connection-native-dependencies.d.ts +4 -0
  80. package/dist/workflow/connections/plan-workflow-connection-native-dependencies.js +73 -0
  81. package/dist/workflow/connections/review-workflow-connection-goals.js +1 -0
  82. package/dist/workflow/connections/workflow-connection-native-repair-error.d.ts +6 -0
  83. package/dist/workflow/connections/workflow-connection-native-repair-error.js +18 -0
  84. package/dist/workflow/generate-native-node-parameters.js +6 -2
  85. package/dist/workflow/native-selection/create-native-planning-rejection.d.ts +4 -0
  86. package/dist/workflow/native-selection/create-native-planning-rejection.js +45 -0
  87. package/dist/workflow/native-selection/describe-native-planning-request.d.ts +5 -0
  88. package/dist/workflow/native-selection/describe-native-planning-request.js +26 -0
  89. package/dist/workflow/native-selection/review-native-instance-selection.js +21 -5
  90. package/dist/workflow/native-selection/validate-native-planning-rejections.d.ts +2 -0
  91. package/dist/workflow/native-selection/validate-native-planning-rejections.js +14 -0
  92. package/dist/workflow/plan-workflow-connections.js +9 -8
  93. package/dist/workflow/plan-workflow-intent.d.ts +4 -0
  94. package/dist/workflow/plan-workflow-intent.js +49 -0
  95. package/dist/workflow/resolve-workflow-connection-output.d.ts +3 -2
  96. package/dist/workflow/resolve-workflow-connection-output.js +30 -18
  97. package/dist/workflow/resolve-workflow-connection-selection.d.ts +4 -0
  98. package/dist/workflow/resolve-workflow-connection-selection.js +24 -0
  99. package/dist/workflow/select-native-node-instances.js +40 -22
  100. package/package.json +2 -2
@@ -1,13 +1,9 @@
1
- import type { ApiInputRequirement } from '@openapi-flow/core';
1
+ import type { ApiInputAnswerContext } from '@openapi-flow/core';
2
2
  import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
3
3
  import type { z } from 'zod';
4
4
  import type { createApiInputAnswerSourceSchema } from '../schemas/api-input-answer-source-schema.js';
5
- export interface ExtractApiInputAnswersInput {
6
- requirements: ApiInputRequirement[];
7
- reply: string;
5
+ export interface ExtractApiInputAnswersInput extends ApiInputAnswerContext {
8
6
  model: BaseChatModel;
9
- selectOasEnums?: boolean;
10
- purpose?: string;
11
7
  signal?: AbortSignal;
12
8
  }
13
9
  export interface AnalyzeApiInputAnswersInput extends Omit<ExtractApiInputAnswersInput, 'model'> {
@@ -1,8 +1,7 @@
1
1
  import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
2
- import type { ApiLiteralGenerationInput, ApiCallArguments, ApiArgumentProposal, ApiLiteralProposalSource, OpenApiFlowError } from '@openapi-flow/core';
2
+ import type { ApiLiteralGenerationInput, ApiCallArguments, ApiArgumentProposal, ApiLiteralProposalSource, OpenApiFlowError, WorkflowConnectionApiRepairContext, ApiInputLiteralSource } from '@openapi-flow/core';
3
3
  import type { z } from 'zod';
4
4
  import type { apiLiteralGenerationReasonSchema } from '../schemas/api-literal-generation-output-schema.js';
5
- import type { apiLiteralGenerationSourcesSchema } from '../schemas/api-literal-generation-output-schema.js';
6
5
  import type { apiLiteralNotProvidedSchema } from '../schemas/api-literal-generation-output-schema.js';
7
6
  import type { createApiLiteralProvidedSchema, createApiTrackedLiteralGenerationSchema, createApiExplainedTrackedLiteralGenerationSchema } from '../schemas/api-literal-generation-output-schema.js';
8
7
  import type { apiLiteralGenerationOptionsSchema } from '../schemas/api-literal-generation-output-schema.js';
@@ -15,6 +14,12 @@ export interface GenerateApiArgumentsInput extends ApiLiteralGenerationInput {
15
14
  /** Exact, private rejection feedback for the same source; no library-owned retries. */
16
15
  rejectedProposals?: ApiArgumentRejection[];
17
16
  signal?: AbortSignal;
17
+ materialRepair?: WorkflowConnectionApiRepairContext;
18
+ }
19
+ export interface ApiLiteralGenerationSource extends ApiInputLiteralSource {
20
+ targetPointer: string;
21
+ /** Selected only when more than one original message is supplied. */
22
+ messageId?: string;
18
23
  }
19
24
  export type ApiArgumentRejection = z.infer<typeof apiArgumentRejectionSchema>;
20
25
  export interface CreateApiArgumentRejectionInput extends Omit<GenerateApiArgumentsInput, 'model' | 'rejectedProposals' | 'signal'> {
@@ -35,12 +40,12 @@ export type ApiLiteralProvidedDecision = z.infer<ReturnType<typeof createApiLite
35
40
  export type ApiLiteralAvailabilityDecision = z.infer<typeof apiLiteralNotProvidedSchema> | ApiLiteralProvidedDecision;
36
41
  export type ApiTrackedLiteralGenerationOutput = z.infer<ReturnType<typeof createApiTrackedLiteralGenerationSchema>> | z.infer<ReturnType<typeof createApiExplainedTrackedLiteralGenerationSchema>>;
37
42
  export interface ApiExplainedLiteralGenerationOutput extends ApiArgumentProposal {
38
- explanation: z.infer<typeof apiLiteralGenerationReasonSchema>;
43
+ explanation?: z.infer<typeof apiLiteralGenerationReasonSchema>;
39
44
  }
40
45
  export type ApiLiteralGenerationOutput = ApiArgumentProposal | ApiExplainedLiteralGenerationOutput | ApiTrackedLiteralGenerationOutput;
41
46
  export type ApiLiteralGenerationOutputSchema = z.ZodType<ApiLiteralGenerationOutput>;
42
47
  export interface ResolvedApiLiteralGenerationOutput extends ApiArgumentProposal {
43
48
  requestedInputs?: string[];
44
- literalSources?: z.infer<typeof apiLiteralGenerationSourcesSchema>;
49
+ literalSources?: ApiLiteralGenerationSource[];
45
50
  explanation?: z.infer<typeof apiLiteralGenerationReasonSchema>;
46
51
  }
@@ -61,6 +61,8 @@ export interface InvokeConnectionPlanningModelInput<Output extends object> {
61
61
  operation: string;
62
62
  name: string;
63
63
  schema: ZodType<Output>;
64
+ /** Optional distinct receiver validation when display-only fields must not gate execution. */
65
+ validationSchema?: ZodType<Output>;
64
66
  messages: BaseMessage[];
65
67
  sourceFingerprint?: string;
66
68
  requestFingerprint?: string;
@@ -1,9 +1,12 @@
1
1
  import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
2
- import type { NativeSelectedPlanningInput } from '@openapi-flow/core';
3
- export interface ReviewNativeInstanceSelectionInput extends NativeSelectedPlanningInput {
2
+ import type { NativeSelectedPlanningInput, NativeInstanceSelectionReviewOptions } from '@openapi-flow/core';
3
+ import type { NativePlanningRejectedProposal } from './native-planning-rejection.js';
4
+ export interface ReviewNativeInstanceSelectionInput extends NativeSelectedPlanningInput, NativeInstanceSelectionReviewOptions {
4
5
  model?: BaseChatModel;
5
6
  signal?: AbortSignal;
7
+ rejectedProposals?: NativePlanningRejectedProposal[];
6
8
  }
7
9
  export interface NativeInstanceSelectionReviewFailure {
8
10
  output: unknown;
11
+ requestFingerprint?: string;
9
12
  }
@@ -1,5 +1,6 @@
1
1
  import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
2
2
  import type { z } from 'zod';
3
+ import type { NativePlanningRejectedProposal } from './native-planning-rejection.js';
3
4
  import type { JsonValueObject, NativeNodePlanningInput, NativePlanningProposal, NativePlanningResult, NativePlanningAssessment, NativePlanningCapabilityMaterial, NativeNodePlanningRecord, NativeInstanceSelectionInput, NativeNodeConfigurationInput, NativeSelectedPlanningInput, NativeInstanceSelectionFeedback } from '@openapi-flow/core';
4
5
  export interface PlanNativeNodesInput extends NativeNodePlanningInput {
5
6
  model?: BaseChatModel;
@@ -59,6 +60,7 @@ export interface NativeNodePlan extends NativePlanningResult {
59
60
  export type NativeNodePlanningFailure = {
60
61
  stage: 'instance-selection' | 'dependency-plan' | 'parameter-schema' | 'parameter-validation';
61
62
  output: unknown;
63
+ requestFingerprint?: string;
62
64
  } | {
63
65
  stage: 'proposal-schema';
64
66
  output: unknown;
@@ -72,6 +74,8 @@ export interface SelectNativeNodeInstancesInput extends NativeInstanceSelectionI
72
74
  signal?: AbortSignal;
73
75
  /** Explicit independently reviewed rejection. Never causes a hidden retry. */
74
76
  feedback?: NativeInstanceSelectionFeedback;
77
+ /** Explicit same-source contract rejections. No library-owned retry is performed. */
78
+ rejectedProposals?: NativePlanningRejectedProposal[];
75
79
  }
76
80
  export interface GenerateNativeNodeParametersInput extends NativeNodeConfigurationInput {
77
81
  model?: BaseChatModel;
@@ -0,0 +1,21 @@
1
+ import type { z } from 'zod';
2
+ import type { NativeInstanceSelectionDescription, NativeInstanceSelectionFeedbackDescription } from '@openapi-flow/core';
3
+ import type { nativePlanningRejectionSchema } from '../schemas/native-planning-rejection-schema.js';
4
+ import type { SelectNativeNodeInstancesInput } from './native-node-planning.js';
5
+ import type { ReviewNativeInstanceSelectionInput } from './native-instance-selection-review.js';
6
+ export type NativePlanningRejectedProposal = z.infer<typeof nativePlanningRejectionSchema>;
7
+ export interface NativeSelectionRequestDescription extends Pick<NativeInstanceSelectionDescription, 'context'> {
8
+ requestFingerprint: string;
9
+ feedback?: NativeInstanceSelectionFeedbackDescription;
10
+ }
11
+ export interface NativePlanningRejectionValidationInput {
12
+ stage: NativePlanningRejectedProposal['stage'];
13
+ requestFingerprint: string;
14
+ rejectedProposals?: NativePlanningRejectedProposal[];
15
+ }
16
+ export interface CreateNativeSelectionRejectionInput extends SelectNativeNodeInstancesInput {
17
+ error: unknown;
18
+ }
19
+ export interface CreateNativeSelectionReviewRejectionInput extends ReviewNativeInstanceSelectionInput {
20
+ error: unknown;
21
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,7 @@
1
1
  import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
2
2
  import type { ReviewableWorkflowGraphProposal, ReviewableWorkflowPlanningContext, WorkflowReviewGap, PlannedNativeNode, ExplainedWorkflowConnection, ExplainedWorkflowBlockedCall } from '@openapi-flow/core';
3
3
  import type { ExplainedGraphNativeNode } from './workflow-planning.js';
4
+ import type { WorkflowConnectionSelectionOutput } from './workflow-connection-selection.js';
4
5
  export interface PlanReviewableWorkflowGraphInput extends ReviewableWorkflowPlanningContext {
5
6
  scenario: string;
6
7
  model: BaseChatModel;
@@ -13,7 +14,7 @@ export type ReviewableWorkflowGraphPlanningFailure = {
13
14
  output: unknown;
14
15
  } | {
15
16
  stage: 'graph-validation';
16
- output: ReviewableWorkflowGraphModelOutput;
17
+ output: ReviewableWorkflowGraphModelOutput | WorkflowConnectionSelectionOutput;
17
18
  };
18
19
  export type ReviewableWorkflowGraphOutput = Omit<ReviewableWorkflowGraphProposal, 'nativeNodes' | 'blockedCalls'> & {
19
20
  additionalNativeNodes?: ReviewableWorkflowGraphProposal['nativeNodes'];
@@ -0,0 +1,16 @@
1
+ import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
2
+ import type { WorkflowConnectionNativeRepairInput, WorkflowConnectionNativeParametersInput } from '@openapi-flow/core';
3
+ export interface PlanWorkflowConnectionNativeDependenciesInput extends WorkflowConnectionNativeRepairInput {
4
+ model?: BaseChatModel;
5
+ signal?: AbortSignal;
6
+ }
7
+ export interface GenerateWorkflowConnectionNativeParametersInput extends WorkflowConnectionNativeParametersInput {
8
+ model?: BaseChatModel;
9
+ signal?: AbortSignal;
10
+ }
11
+ export interface WorkflowConnectionNativeRepairFailure {
12
+ operation: 'planWorkflowConnectionNativeDependencies' | 'generateWorkflowConnectionNativeParameters';
13
+ fingerprint: string;
14
+ /** Private original response, including malformed output; never a browser diagnostic or a repaired proposal. */
15
+ output: unknown;
16
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ import type { z } from 'zod';
2
+ import type { createWorkflowConnectionSelectionSchema } from '../schemas/workflow-connection-selection-schema.js';
3
+ import type { WorkflowConnectionProposal, BlockedWorkflowCall, WorkflowPlanEdge } from '@openapi-flow/core';
4
+ export type WorkflowConnectionSelectionOutput = z.infer<ReturnType<typeof createWorkflowConnectionSelectionSchema>>;
5
+ export type WorkflowConnectionExecutionEdge = Omit<WorkflowConnectionSelectionOutput['edges'][number], 'reason'> & {
6
+ reason?: unknown;
7
+ };
8
+ export type WorkflowConnectionExecutionBlockedCall = BlockedWorkflowCall & {
9
+ reason?: unknown;
10
+ };
11
+ export interface WorkflowConnectionExecutionOutput extends Omit<WorkflowConnectionProposal, 'edges' | 'blockedCalls'> {
12
+ reason?: unknown;
13
+ edges: WorkflowConnectionExecutionEdge[];
14
+ blockedCalls?: WorkflowConnectionExecutionBlockedCall[];
15
+ }
16
+ export type ResolvedWorkflowConnectionSelectionEdge = WorkflowPlanEdge & Pick<WorkflowConnectionExecutionEdge, 'reason'>;
17
+ export interface ResolvedWorkflowConnectionSelection extends Omit<WorkflowConnectionExecutionOutput, 'edges'> {
18
+ edges: ResolvedWorkflowConnectionSelectionEdge[];
19
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
2
+ import type { WorkflowIntentInput } from '@openapi-flow/core';
3
+ export interface PlanWorkflowIntentInput extends WorkflowIntentInput {
4
+ model: BaseChatModel;
5
+ signal?: AbortSignal;
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
1
  import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
2
- import type { PlannedNativeNode, WorkflowConnectionPlanningInput, WorkflowConnectionDecision, WorkflowConnectionProposal, ExplainedWorkflowBlockedCall, ExplainedWorkflowConnection } from '@openapi-flow/core';
2
+ import type { PlannedNativeNode, WorkflowConnectionPlanningInput, WorkflowConnectionDecision, WorkflowConnectionProposal, ExplainedWorkflowBlockedCall, ExplainedWorkflowConnection, WorkflowConnectionExplanationIssue } from '@openapi-flow/core';
3
3
  import type { ReviewableWorkflowGraphOutput } from './reviewable-workflow-planning.js';
4
4
  export interface PlanWorkflowConnectionsInput extends WorkflowConnectionPlanningInput {
5
5
  model: BaseChatModel;
@@ -18,4 +18,5 @@ export type WorkflowConnectionPlanningOutput = ReviewableWorkflowGraphOutput | W
18
18
  export interface ResolvedWorkflowConnectionOutput {
19
19
  proposal: WorkflowConnectionProposal;
20
20
  decision?: WorkflowConnectionDecision;
21
+ explanationIssues?: WorkflowConnectionExplanationIssue[];
21
22
  }
@@ -0,0 +1,4 @@
1
+ import type { WorkflowConnectionNativeParameterResult } from '@openapi-flow/core';
2
+ import type { GenerateWorkflowConnectionNativeParametersInput } from '../../types/workflow-connection-native-repair.js';
3
+ /** One existing instance, checked selected producers, and at most one value decision. */
4
+ export declare function generateWorkflowConnectionNativeParameters(input: GenerateWorkflowConnectionNativeParametersInput): Promise<WorkflowConnectionNativeParameterResult>;
@@ -0,0 +1,80 @@
1
+ import { isDeepStrictEqual } from 'node:util';
2
+ import { HumanMessage, SystemMessage } from '@langchain/core/messages';
3
+ import { describeWorkflowConnectionNativeParameters, createWorkflowConnectionNativeParametersSchema, resolveWorkflowConnectionNativeParameters, runOpenApiFlowOperation, } from '@openapi-flow/core';
4
+ import { invokeStructuredModel } from '../../model/invoke-structured-model.js';
5
+ import { workflowConnectionNativeRepairPrompt } from '../../prompts/workflow-connection-native-repair-prompt.js';
6
+ import { modelSignalSchema } from '../../schemas/model-signal-schema.js';
7
+ import { WorkflowConnectionNativeRepairError } from './workflow-connection-native-repair-error.js';
8
+ /** One existing instance, checked selected producers, and at most one value decision. */
9
+ export async function generateWorkflowConnectionNativeParameters(input) {
10
+ const context = runOpenApiFlowOperation({
11
+ owner: 'langchain',
12
+ operation: 'generateWorkflowConnectionNativeParameters',
13
+ stage: 'input-validation',
14
+ code: 'PLANNING_INPUT_INVALID',
15
+ }, () => {
16
+ modelSignalSchema.parse(input.signal);
17
+ if (input.model !== undefined &&
18
+ (!input.model || typeof input.model.withStructuredOutput !== 'function'))
19
+ throw new Error('generateWorkflowConnectionNativeParameters.model must support structured output when supplied');
20
+ return describeWorkflowConnectionNativeParameters(input);
21
+ });
22
+ input.signal?.throwIfAborted();
23
+ if (!context.hasLiteralParameters)
24
+ return resolveWorkflowConnectionNativeParameters({
25
+ ...input,
26
+ fingerprint: context.fingerprint,
27
+ proposal: {
28
+ decision: {
29
+ status: 'provided',
30
+ parameters: {},
31
+ ...(input.includeExplanations === true
32
+ ? {
33
+ reason: 'The original ownership contract leaves no literal setting choice.',
34
+ }
35
+ : {}),
36
+ },
37
+ },
38
+ });
39
+ if (!input.model)
40
+ throw new Error('generateWorkflowConnectionNativeParameters.model is required for remaining settings');
41
+ const output = await invokeStructuredModel({
42
+ model: input.model,
43
+ schema: createWorkflowConnectionNativeParametersSchema(input),
44
+ operation: 'generateWorkflowConnectionNativeParameters',
45
+ name: 'repair_native_parameters',
46
+ method: 'functionCalling',
47
+ strict: true,
48
+ signal: input.signal,
49
+ messages: [
50
+ new SystemMessage(workflowConnectionNativeRepairPrompt),
51
+ new HumanMessage(JSON.stringify(context)),
52
+ ],
53
+ });
54
+ input.signal?.throwIfAborted();
55
+ return runOpenApiFlowOperation({
56
+ owner: 'langchain',
57
+ operation: 'generateWorkflowConnectionNativeParameters',
58
+ stage: 'contract-validation',
59
+ code: 'NATIVE_NODE_PLANNING_FAILED',
60
+ }, () => {
61
+ try {
62
+ if (!isDeepStrictEqual(context, describeWorkflowConnectionNativeParameters(input)))
63
+ throw new Error('Native repair source changed during parameter planning');
64
+ return resolveWorkflowConnectionNativeParameters({
65
+ ...input,
66
+ fingerprint: context.fingerprint,
67
+ proposal: output,
68
+ });
69
+ }
70
+ catch (cause) {
71
+ if (!(cause instanceof Error))
72
+ throw cause;
73
+ throw new WorkflowConnectionNativeRepairError({
74
+ operation: 'generateWorkflowConnectionNativeParameters',
75
+ fingerprint: context.fingerprint,
76
+ output,
77
+ }, cause);
78
+ }
79
+ });
80
+ }
@@ -33,7 +33,10 @@ export async function invokeConnectionPlanningModel(input) {
33
33
  ? {}
34
34
  : { requestFingerprint: input.requestFingerprint }),
35
35
  }, () => {
36
- const parsed = input.schema.parse(output);
36
+ const receiver = input.validationSchema === undefined
37
+ ? input.schema
38
+ : input.validationSchema;
39
+ const parsed = receiver.parse(output);
37
40
  if (!isDeepStrictEqual(parsed, output))
38
41
  throw new Error('Connection output schema must not default, coerce or transform model data');
39
42
  return parsed;
@@ -0,0 +1,4 @@
1
+ import type { WorkflowConnectionNativeDependencies } from '@openapi-flow/core';
2
+ import type { PlanWorkflowConnectionNativeDependenciesInput } from '../../types/workflow-connection-native-repair.js';
3
+ /** Zero or one scoped decision. No retries or mutation of the original source. */
4
+ export declare function planWorkflowConnectionNativeDependencies(input: PlanWorkflowConnectionNativeDependenciesInput): Promise<WorkflowConnectionNativeDependencies>;
@@ -0,0 +1,73 @@
1
+ import { isDeepStrictEqual } from 'node:util';
2
+ import { HumanMessage, SystemMessage } from '@langchain/core/messages';
3
+ import { describeWorkflowConnectionNativeDependencies, createWorkflowConnectionNativeDependenciesSchema, resolveWorkflowConnectionNativeDependencies, runOpenApiFlowOperation, } from '@openapi-flow/core';
4
+ import { invokeStructuredModel } from '../../model/invoke-structured-model.js';
5
+ import { workflowConnectionNativeRepairPrompt } from '../../prompts/workflow-connection-native-repair-prompt.js';
6
+ import { modelSignalSchema } from '../../schemas/model-signal-schema.js';
7
+ import { WorkflowConnectionNativeRepairError } from './workflow-connection-native-repair-error.js';
8
+ /** Zero or one scoped decision. No retries or mutation of the original source. */
9
+ export async function planWorkflowConnectionNativeDependencies(input) {
10
+ const context = runOpenApiFlowOperation({
11
+ owner: 'langchain',
12
+ operation: 'planWorkflowConnectionNativeDependencies',
13
+ stage: 'input-validation',
14
+ code: 'PLANNING_INPUT_INVALID',
15
+ }, () => {
16
+ modelSignalSchema.parse(input.signal);
17
+ if (input.model !== undefined &&
18
+ (!input.model || typeof input.model.withStructuredOutput !== 'function'))
19
+ throw new Error('planWorkflowConnectionNativeDependencies.model must support structured output when supplied');
20
+ return describeWorkflowConnectionNativeDependencies(input);
21
+ });
22
+ input.signal?.throwIfAborted();
23
+ if (context.targets.every((target) => target.sourceNodeIds.length === 0))
24
+ return resolveWorkflowConnectionNativeDependencies({
25
+ ...input,
26
+ proposal: {
27
+ sourcesByNodeId: Object.fromEntries(context.targets.map((target) => [
28
+ target.nodeId,
29
+ { sourceNodeIds: [] },
30
+ ])),
31
+ },
32
+ });
33
+ if (!input.model)
34
+ throw new Error('planWorkflowConnectionNativeDependencies.model is required for producer choices');
35
+ const output = await invokeStructuredModel({
36
+ model: input.model,
37
+ schema: createWorkflowConnectionNativeDependenciesSchema(input),
38
+ operation: 'planWorkflowConnectionNativeDependencies',
39
+ name: 'repair_native_dependencies',
40
+ method: 'functionCalling',
41
+ strict: true,
42
+ signal: input.signal,
43
+ messages: [
44
+ new SystemMessage(workflowConnectionNativeRepairPrompt),
45
+ new HumanMessage(JSON.stringify(context)),
46
+ ],
47
+ });
48
+ input.signal?.throwIfAborted();
49
+ return runOpenApiFlowOperation({
50
+ owner: 'langchain',
51
+ operation: 'planWorkflowConnectionNativeDependencies',
52
+ stage: 'contract-validation',
53
+ code: 'NATIVE_NODE_PLANNING_FAILED',
54
+ }, () => {
55
+ try {
56
+ if (!isDeepStrictEqual(context, describeWorkflowConnectionNativeDependencies(input)))
57
+ throw new Error('Native repair source changed during dependency planning');
58
+ return resolveWorkflowConnectionNativeDependencies({
59
+ ...input,
60
+ proposal: output,
61
+ });
62
+ }
63
+ catch (cause) {
64
+ if (!(cause instanceof Error))
65
+ throw cause;
66
+ throw new WorkflowConnectionNativeRepairError({
67
+ operation: 'planWorkflowConnectionNativeDependencies',
68
+ fingerprint: context.fingerprint,
69
+ output,
70
+ }, cause);
71
+ }
72
+ });
73
+ }
@@ -33,6 +33,7 @@ export async function reviewWorkflowConnectionGoals(input) {
33
33
  operation,
34
34
  name: 'review_workflow_connection_goals',
35
35
  schema: createWorkflowConnectionGoalReviewSchema(description),
36
+ validationSchema: createWorkflowConnectionGoalReviewSchema(description, false),
36
37
  sourceFingerprint: description.sourceFingerprint,
37
38
  messages: [
38
39
  new SystemMessage(workflowConnectionGoalReviewPrompt),
@@ -0,0 +1,6 @@
1
+ import { OpenApiFlowError } from '@openapi-flow/core';
2
+ import type { WorkflowConnectionNativeRepairFailure } from '../../types/workflow-connection-native-repair.js';
3
+ export declare class WorkflowConnectionNativeRepairError extends OpenApiFlowError {
4
+ readonly failure: WorkflowConnectionNativeRepairFailure;
5
+ constructor(failure: WorkflowConnectionNativeRepairFailure, cause: Error);
6
+ }
@@ -0,0 +1,18 @@
1
+ import { OpenApiFlowError } from '@openapi-flow/core';
2
+ export class WorkflowConnectionNativeRepairError extends OpenApiFlowError {
3
+ failure;
4
+ constructor(failure, cause) {
5
+ super({
6
+ message: cause.message,
7
+ diagnostic: {
8
+ owner: 'langchain',
9
+ operation: failure.operation,
10
+ stage: 'contract-validation',
11
+ code: 'NATIVE_NODE_PLANNING_FAILED',
12
+ },
13
+ cause,
14
+ });
15
+ this.name = 'WorkflowConnectionNativeRepairError';
16
+ this.failure = failure;
17
+ }
18
+ }
@@ -1,5 +1,5 @@
1
1
  import { HumanMessage, SystemMessage } from '@langchain/core/messages';
2
- import { createNativeNodeParametersSchema, describeNativeNodeConfiguration, resolveNativeNodeParameters, } from '@openapi-flow/core';
2
+ import { createNativeNodeParametersSchema, describeNativeNodeConfiguration, resolveNativeNodeParameters, resolveNativeProducerParameters, } from '@openapi-flow/core';
3
3
  import { serializeStructuredOutputSchema } from '../schemas/serialize-structured-output-schema.js';
4
4
  import { nativeNodeParametersPrompt } from '../prompts/native-node-planning-prompt.js';
5
5
  import { NativeNodePlanningError } from './native-node-planning-error.js';
@@ -9,6 +9,9 @@ export async function generateNativeNodeParameters(input) {
9
9
  if (input.model !== undefined &&
10
10
  (!input.model || typeof input.model.withStructuredOutput !== 'function'))
11
11
  throw new Error('generateNativeNodeParameters.model must support structured output when supplied');
12
+ const derived = resolveNativeProducerParameters(input);
13
+ if (derived !== undefined)
14
+ return derived;
12
15
  const description = describeNativeNodeConfiguration(input);
13
16
  if (!description.instance.hasLiteralParameters)
14
17
  return resolveNativeNodeParameters({
@@ -29,6 +32,7 @@ export async function generateNativeNodeParameters(input) {
29
32
  if (!input.model || typeof input.model.withStructuredOutput !== 'function')
30
33
  throw new Error('generateNativeNodeParameters.model must support structured output for remaining values');
31
34
  const schema = createNativeNodeParametersSchema(input);
35
+ const validationSchema = createNativeNodeParametersSchema(input, false);
32
36
  const capability = description.context.capabilities.find((entry) => entry.name === description.instance.capability);
33
37
  if (!capability)
34
38
  throw new Error('Native parameter generation has no selected capability material');
@@ -67,7 +71,7 @@ export async function generateNativeNodeParameters(input) {
67
71
  input.signal?.throwIfAborted();
68
72
  try {
69
73
  // Validate output separately so callers can distinguish a malformed reply from stale source material.
70
- schema.parse(output);
74
+ validationSchema.parse(output);
71
75
  }
72
76
  catch (cause) {
73
77
  if (!(cause instanceof Error))
@@ -0,0 +1,4 @@
1
+ import type { CreateNativeSelectionRejectionInput, CreateNativeSelectionReviewRejectionInput, NativePlanningRejectedProposal } from '../../types/native-planning-rejection.js';
2
+ /** Only unchanged, source-bound output failures are eligible; transport/configuration failures are not proposals. */
3
+ export declare function createNativeSelectionRejection(input: CreateNativeSelectionRejectionInput): NativePlanningRejectedProposal | undefined;
4
+ export declare function createNativeSelectionReviewRejection(input: CreateNativeSelectionReviewRejectionInput): NativePlanningRejectedProposal | undefined;
@@ -0,0 +1,45 @@
1
+ import { isDeepStrictEqual } from 'node:util';
2
+ import { nativePlanningRejectionSchema } from '../../schemas/native-planning-rejection-schema.js';
3
+ import { NativeNodePlanningError } from '../native-node-planning-error.js';
4
+ import { NativeInstanceSelectionReviewError } from './native-instance-selection-review-error.js';
5
+ import { describeNativeSelectionRequest, fingerprintNativeSelectionReviewRequest, } from './describe-native-planning-request.js';
6
+ /** Only unchanged, source-bound output failures are eligible; transport/configuration failures are not proposals. */
7
+ export function createNativeSelectionRejection(input) {
8
+ const error = input.error;
9
+ if (!(error instanceof NativeNodePlanningError) ||
10
+ error.failure.stage !== 'instance-selection' ||
11
+ error.failure.requestFingerprint === undefined)
12
+ return undefined;
13
+ const current = describeNativeSelectionRequest(input);
14
+ if (current.requestFingerprint !== error.failure.requestFingerprint)
15
+ return undefined;
16
+ const parsed = nativePlanningRejectionSchema.safeParse({
17
+ stage: 'instance-selection',
18
+ requestFingerprint: current.requestFingerprint,
19
+ output: error.failure.output,
20
+ reason: error.message,
21
+ });
22
+ if (!parsed.success ||
23
+ !isDeepStrictEqual(parsed.data.output, error.failure.output))
24
+ return undefined;
25
+ return structuredClone(parsed.data);
26
+ }
27
+ export function createNativeSelectionReviewRejection(input) {
28
+ const error = input.error;
29
+ if (!(error instanceof NativeInstanceSelectionReviewError) ||
30
+ error.failure.requestFingerprint === undefined)
31
+ return undefined;
32
+ const requestFingerprint = fingerprintNativeSelectionReviewRequest(input);
33
+ if (requestFingerprint !== error.failure.requestFingerprint)
34
+ return undefined;
35
+ const parsed = nativePlanningRejectionSchema.safeParse({
36
+ stage: 'selection-review',
37
+ requestFingerprint,
38
+ output: error.failure.output,
39
+ reason: error.message,
40
+ });
41
+ if (!parsed.success ||
42
+ !isDeepStrictEqual(parsed.data.output, error.failure.output))
43
+ return undefined;
44
+ return structuredClone(parsed.data);
45
+ }
@@ -0,0 +1,5 @@
1
+ import type { SelectNativeNodeInstancesInput } from '../../types/native-node-planning.js';
2
+ import type { ReviewNativeInstanceSelectionInput } from '../../types/native-instance-selection-review.js';
3
+ import type { NativeSelectionRequestDescription } from '../../types/native-planning-rejection.js';
4
+ export declare function describeNativeSelectionRequest(input: SelectNativeNodeInstancesInput): NativeSelectionRequestDescription;
5
+ export declare function fingerprintNativeSelectionReviewRequest(input: ReviewNativeInstanceSelectionInput): string;
@@ -0,0 +1,26 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { describeNativeInstanceSelection, describeNativeInstanceSelectionFeedback, describeNativeInstanceSelectionReview, } from '@openapi-flow/core';
3
+ export function describeNativeSelectionRequest(input) {
4
+ const { context } = describeNativeInstanceSelection(input);
5
+ const feedback = input.feedback === undefined
6
+ ? undefined
7
+ : describeNativeInstanceSelectionFeedback(input, input.feedback);
8
+ return {
9
+ context,
10
+ ...(feedback === undefined ? {} : { feedback }),
11
+ requestFingerprint: createHash('sha256')
12
+ .update(JSON.stringify([
13
+ input.planId,
14
+ input.allowRuntimeParameters,
15
+ input.includeExplanations,
16
+ context,
17
+ feedback,
18
+ ]))
19
+ .digest('hex'),
20
+ };
21
+ }
22
+ export function fingerprintNativeSelectionReviewRequest(input) {
23
+ return createHash('sha256')
24
+ .update(JSON.stringify(describeNativeInstanceSelectionReview(input)))
25
+ .digest('hex');
26
+ }
@@ -6,6 +6,8 @@ import { serializeStructuredOutputSchema } from '../../schemas/serialize-structu
6
6
  import { modelSignalSchema } from '../../schemas/model-signal-schema.js';
7
7
  import { nativeInstanceSelectionReviewPrompt } from '../../prompts/native-instance-selection-review-prompt.js';
8
8
  import { NativeInstanceSelectionReviewError } from './native-instance-selection-review-error.js';
9
+ import { fingerprintNativeSelectionReviewRequest } from './describe-native-planning-request.js';
10
+ import { validateNativePlanningRejections } from './validate-native-planning-rejections.js';
9
11
  /** One review call only. The host owns replanning, user questions, budgets and persistence. */
10
12
  export async function reviewNativeInstanceSelection(input) {
11
13
  const operation = 'reviewNativeInstanceSelection';
@@ -19,7 +21,13 @@ export async function reviewNativeInstanceSelection(input) {
19
21
  return describeNativeInstanceSelectionReview(input);
20
22
  });
21
23
  input.signal?.throwIfAborted();
22
- if (!description.gaps.length)
24
+ const requestFingerprint = fingerprintNativeSelectionReviewRequest(input);
25
+ const rejectedProposals = validateNativePlanningRejections({
26
+ stage: 'selection-review',
27
+ requestFingerprint,
28
+ rejectedProposals: input.rejectedProposals,
29
+ });
30
+ if (!description.gaps.length && description.reviewInstances !== true)
23
31
  return createNativeInstanceSelectionReview({
24
32
  ...input,
25
33
  proposal: { assessments: {} },
@@ -32,7 +40,7 @@ export async function reviewNativeInstanceSelection(input) {
32
40
  }, () => {
33
41
  if (!input.model ||
34
42
  typeof input.model.withStructuredOutput !== 'function')
35
- throw new Error('reviewNativeInstanceSelection.model must support structured output for reported gaps');
43
+ throw new Error('reviewNativeInstanceSelection.model must support structured output for the requested review');
36
44
  return input.model;
37
45
  });
38
46
  const checkCurrent = (originalFailure) => {
@@ -43,7 +51,12 @@ export async function reviewNativeInstanceSelection(input) {
43
51
  code: 'PLANNING_INPUT_INVALID',
44
52
  }, () => {
45
53
  try {
46
- if (!isDeepStrictEqual(description, describeNativeInstanceSelectionReview(input)))
54
+ if (!isDeepStrictEqual(description, describeNativeInstanceSelectionReview(input)) ||
55
+ !isDeepStrictEqual(rejectedProposals, validateNativePlanningRejections({
56
+ stage: 'selection-review',
57
+ requestFingerprint,
58
+ rejectedProposals: input.rejectedProposals,
59
+ })))
47
60
  throw new Error('Native selection review source changed during model invocation');
48
61
  }
49
62
  catch (error) {
@@ -62,7 +75,10 @@ export async function reviewNativeInstanceSelection(input) {
62
75
  strict: true,
63
76
  messages: [
64
77
  new SystemMessage(nativeInstanceSelectionReviewPrompt),
65
- new HumanMessage(JSON.stringify(description)),
78
+ new HumanMessage(JSON.stringify({
79
+ ...description,
80
+ ...(rejectedProposals.length === 0 ? {} : { rejectedProposals }),
81
+ })),
66
82
  ],
67
83
  ...(input.signal === undefined ? {} : { signal: input.signal }),
68
84
  }).catch((error) => {
@@ -76,6 +92,6 @@ export async function reviewNativeInstanceSelection(input) {
76
92
  catch (cause) {
77
93
  if (!(cause instanceof Error))
78
94
  throw cause;
79
- throw new NativeInstanceSelectionReviewError({ output }, cause);
95
+ throw new NativeInstanceSelectionReviewError({ output, requestFingerprint }, cause);
80
96
  }
81
97
  }
@@ -0,0 +1,2 @@
1
+ import type { NativePlanningRejectedProposal, NativePlanningRejectionValidationInput } from '../../types/native-planning-rejection.js';
2
+ export declare function validateNativePlanningRejections(input: NativePlanningRejectionValidationInput): NativePlanningRejectedProposal[];