@openapi-flow/langchain 0.3.17 → 0.4.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 +29 -0
- package/dist/arguments/analyze-api-input-answers.js +3 -0
- package/dist/arguments/api-argument-planning-error.d.ts +11 -0
- package/dist/arguments/api-argument-planning-error.js +32 -0
- package/dist/arguments/create-api-argument-rejection.d.ts +3 -0
- package/dist/arguments/create-api-argument-rejection.js +31 -0
- package/dist/arguments/fingerprint-api-argument-source.d.ts +4 -0
- package/dist/arguments/fingerprint-api-argument-source.js +12 -0
- package/dist/arguments/generate-api-arguments.js +78 -32
- package/dist/arguments/interpret-api-argument-enums.js +1 -0
- package/dist/arguments/resolve-api-literal-generation-output.d.ts +3 -0
- package/dist/arguments/resolve-api-literal-generation-output.js +14 -0
- package/dist/bindings/create-api-binding-source-proposal.d.ts +4 -0
- package/dist/bindings/create-api-binding-source-proposal.js +19 -0
- package/dist/bindings/plan-api-bindings-by-call.js +12 -3
- package/dist/bindings/select-api-binding-sources.js +4 -3
- package/dist/model/invoke-structured-model.js +32 -6
- package/dist/prompts/api-arguments-prompt.d.ts +2 -1
- package/dist/prompts/api-arguments-prompt.js +2 -1
- package/dist/prompts/api-call-bindings-prompt.d.ts +1 -1
- package/dist/prompts/api-call-bindings-prompt.js +3 -2
- package/dist/prompts/incremental-workflow-connections-prompt.d.ts +2 -2
- package/dist/prompts/incremental-workflow-connections-prompt.js +5 -4
- package/dist/prompts/native-instance-selection-review-prompt.d.ts +1 -0
- package/dist/prompts/native-instance-selection-review-prompt.js +8 -0
- package/dist/prompts/native-node-planning-prompt.d.ts +1 -1
- package/dist/prompts/native-node-planning-prompt.js +1 -0
- package/dist/prompts/workflow-connection-goal-recovery-prompt.d.ts +1 -0
- package/dist/prompts/workflow-connection-goal-recovery-prompt.js +8 -0
- package/dist/prompts/workflow-connection-goal-review-prompt.d.ts +1 -0
- package/dist/prompts/workflow-connection-goal-review-prompt.js +7 -0
- package/dist/prompts/workflow-connection-outline-prompt.d.ts +1 -0
- package/dist/prompts/workflow-connection-outline-prompt.js +6 -0
- package/dist/prompts/workflow-connection-revision-prompt.d.ts +1 -0
- package/dist/prompts/workflow-connection-revision-prompt.js +10 -0
- package/dist/public-api.d.ts +20 -0
- package/dist/public-api.js +15 -0
- package/dist/schemas/api-argument-rejection-schema.d.ts +28 -0
- package/dist/schemas/api-argument-rejection-schema.js +20 -0
- package/dist/schemas/api-call-binding-plan-schema.d.ts +26 -2
- package/dist/schemas/api-call-binding-plan-schema.js +30 -5
- package/dist/schemas/api-literal-generation-output-schema.d.ts +53 -1
- package/dist/schemas/api-literal-generation-output-schema.js +37 -12
- package/dist/schemas/create-connection-material-repair-choice-schema.d.ts +4 -0
- package/dist/schemas/create-connection-material-repair-choice-schema.js +21 -0
- package/dist/schemas/model-signal-schema.d.ts +3 -0
- package/dist/schemas/model-signal-schema.js +3 -0
- package/dist/schemas/native-node-parameter-contract.js +2 -0
- package/dist/schemas/native-node-planning-contract.js +30 -23
- package/dist/schemas/workflow-connection-goal-recovery-schema.d.ts +4 -0
- package/dist/schemas/workflow-connection-goal-recovery-schema.js +16 -0
- package/dist/schemas/workflow-connection-goal-rejection-schema.d.ts +76 -0
- package/dist/schemas/workflow-connection-goal-rejection-schema.js +2 -1
- package/dist/schemas/workflow-connection-goal-review-schema.d.ts +4 -0
- package/dist/schemas/workflow-connection-goal-review-schema.js +26 -0
- package/dist/schemas/workflow-connection-goals-schema.d.ts +4 -2
- package/dist/schemas/workflow-connection-outline-rejection-schema.d.ts +25 -0
- package/dist/schemas/workflow-connection-outline-rejection-schema.js +21 -0
- package/dist/schemas/workflow-connection-outline-schema.d.ts +3 -0
- package/dist/schemas/workflow-connection-outline-schema.js +25 -0
- package/dist/schemas/workflow-connection-revision-rejection-schema.d.ts +113 -0
- package/dist/schemas/workflow-connection-revision-rejection-schema.js +23 -0
- package/dist/schemas/workflow-connection-revision-schema.d.ts +4 -0
- package/dist/schemas/workflow-connection-revision-schema.js +23 -0
- package/dist/schemas/workflow-connection-step-schema.d.ts +5 -3
- package/dist/schemas/workflow-connection-step-schema.js +62 -31
- package/dist/types/api-call-binding-planning.d.ts +4 -1
- package/dist/types/api-input-answers.d.ts +1 -0
- package/dist/types/argument-generation.d.ts +31 -11
- package/dist/types/incremental-connection-planning.d.ts +10 -3
- package/dist/types/native-instance-selection-review.d.ts +9 -0
- package/dist/types/native-instance-selection-review.js +1 -0
- package/dist/types/native-node-planning.d.ts +6 -2
- package/dist/types/workflow-connection-goal-recovery.d.ts +22 -0
- package/dist/types/workflow-connection-goal-recovery.js +1 -0
- package/dist/types/workflow-connection-goal-review.d.ts +13 -0
- package/dist/types/workflow-connection-goal-review.js +1 -0
- package/dist/types/workflow-connection-outline.d.ts +22 -0
- package/dist/types/workflow-connection-outline.js +1 -0
- package/dist/types/workflow-connection-revision.d.ts +34 -0
- package/dist/types/workflow-connection-revision.js +1 -0
- package/dist/workflow/connections/create-workflow-connection-goal-rejection.js +8 -2
- package/dist/workflow/connections/create-workflow-connection-outline-rejection.d.ts +3 -0
- package/dist/workflow/connections/create-workflow-connection-outline-rejection.js +28 -0
- package/dist/workflow/connections/create-workflow-connection-revision-rejection.d.ts +3 -0
- package/dist/workflow/connections/create-workflow-connection-revision-rejection.js +32 -0
- package/dist/workflow/connections/describe-workflow-connection-outline-request.d.ts +3 -0
- package/dist/workflow/connections/describe-workflow-connection-outline-request.js +30 -0
- package/dist/workflow/connections/invoke-connection-planning-model.js +3 -0
- package/dist/workflow/connections/plan-workflow-connection-goal-recovery.d.ts +3 -0
- package/dist/workflow/connections/plan-workflow-connection-goal-recovery.js +111 -0
- package/dist/workflow/connections/plan-workflow-connection-goals.js +35 -16
- package/dist/workflow/connections/plan-workflow-connection-outline.d.ts +4 -0
- package/dist/workflow/connections/plan-workflow-connection-outline.js +93 -0
- package/dist/workflow/connections/plan-workflow-connection-revision.d.ts +3 -0
- package/dist/workflow/connections/plan-workflow-connection-revision.js +163 -0
- package/dist/workflow/connections/plan-workflow-connection-step.js +75 -29
- package/dist/workflow/connections/resolve-connection-selections.d.ts +6 -0
- package/dist/workflow/connections/resolve-connection-selections.js +28 -0
- package/dist/workflow/connections/review-workflow-connection-goals.d.ts +4 -0
- package/dist/workflow/connections/review-workflow-connection-goals.js +64 -0
- package/dist/workflow/connections/validate-workflow-goal-review-feedback.d.ts +4 -0
- package/dist/workflow/connections/validate-workflow-goal-review-feedback.js +22 -0
- package/dist/workflow/connections/workflow-connection-planning-error.d.ts +1 -0
- package/dist/workflow/connections/workflow-connection-planning-error.js +2 -0
- package/dist/workflow/native-selection/native-instance-selection-review-error.d.ts +6 -0
- package/dist/workflow/native-selection/native-instance-selection-review-error.js +18 -0
- package/dist/workflow/native-selection/review-native-instance-selection.d.ts +4 -0
- package/dist/workflow/native-selection/review-native-instance-selection.js +81 -0
- package/dist/workflow/resolve-native-node-planning-output.js +3 -1
- package/dist/workflow/select-native-node-instances.js +11 -2
- package/package.json +2 -2
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
+
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
3
|
+
import { describeNativeInstanceSelectionReview, createNativeInstanceSelectionReview, createNativeInstanceSelectionReviewSchema, runOpenApiFlowOperation, } from '@openapi-flow/core';
|
|
4
|
+
import { invokeStructuredModel } from '../../model/invoke-structured-model.js';
|
|
5
|
+
import { serializeStructuredOutputSchema } from '../../schemas/serialize-structured-output-schema.js';
|
|
6
|
+
import { modelSignalSchema } from '../../schemas/model-signal-schema.js';
|
|
7
|
+
import { nativeInstanceSelectionReviewPrompt } from '../../prompts/native-instance-selection-review-prompt.js';
|
|
8
|
+
import { NativeInstanceSelectionReviewError } from './native-instance-selection-review-error.js';
|
|
9
|
+
/** One review call only. The host owns replanning, user questions, budgets and persistence. */
|
|
10
|
+
export async function reviewNativeInstanceSelection(input) {
|
|
11
|
+
const operation = 'reviewNativeInstanceSelection';
|
|
12
|
+
const description = runOpenApiFlowOperation({
|
|
13
|
+
owner: 'langchain',
|
|
14
|
+
operation,
|
|
15
|
+
stage: 'input-validation',
|
|
16
|
+
code: 'PLANNING_INPUT_INVALID',
|
|
17
|
+
}, () => {
|
|
18
|
+
modelSignalSchema.parse(input.signal);
|
|
19
|
+
return describeNativeInstanceSelectionReview(input);
|
|
20
|
+
});
|
|
21
|
+
input.signal?.throwIfAborted();
|
|
22
|
+
if (!description.gaps.length)
|
|
23
|
+
return createNativeInstanceSelectionReview({
|
|
24
|
+
...input,
|
|
25
|
+
proposal: { assessments: {} },
|
|
26
|
+
});
|
|
27
|
+
const model = runOpenApiFlowOperation({
|
|
28
|
+
owner: 'langchain',
|
|
29
|
+
operation,
|
|
30
|
+
stage: 'model-configuration',
|
|
31
|
+
code: 'MODEL_CONFIGURATION_FAILED',
|
|
32
|
+
}, () => {
|
|
33
|
+
if (!input.model ||
|
|
34
|
+
typeof input.model.withStructuredOutput !== 'function')
|
|
35
|
+
throw new Error('reviewNativeInstanceSelection.model must support structured output for reported gaps');
|
|
36
|
+
return input.model;
|
|
37
|
+
});
|
|
38
|
+
const checkCurrent = (originalFailure) => {
|
|
39
|
+
runOpenApiFlowOperation({
|
|
40
|
+
owner: 'langchain',
|
|
41
|
+
operation,
|
|
42
|
+
stage: 'input-validation',
|
|
43
|
+
code: 'PLANNING_INPUT_INVALID',
|
|
44
|
+
}, () => {
|
|
45
|
+
try {
|
|
46
|
+
if (!isDeepStrictEqual(description, describeNativeInstanceSelectionReview(input)))
|
|
47
|
+
throw new Error('Native selection review source changed during model invocation');
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
if (originalFailure !== undefined)
|
|
51
|
+
throw new AggregateError([originalFailure, error], 'Native review input changed while a failed model call was received', { cause: error });
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
const output = await invokeStructuredModel({
|
|
57
|
+
operation,
|
|
58
|
+
model,
|
|
59
|
+
schema: serializeStructuredOutputSchema(createNativeInstanceSelectionReviewSchema(description), 'draft-2020-12'),
|
|
60
|
+
name: 'review_native_instance_selection',
|
|
61
|
+
method: 'jsonSchema',
|
|
62
|
+
strict: true,
|
|
63
|
+
messages: [
|
|
64
|
+
new SystemMessage(nativeInstanceSelectionReviewPrompt),
|
|
65
|
+
new HumanMessage(JSON.stringify(description)),
|
|
66
|
+
],
|
|
67
|
+
...(input.signal === undefined ? {} : { signal: input.signal }),
|
|
68
|
+
}).catch((error) => {
|
|
69
|
+
checkCurrent(error);
|
|
70
|
+
throw error;
|
|
71
|
+
});
|
|
72
|
+
checkCurrent();
|
|
73
|
+
try {
|
|
74
|
+
return createNativeInstanceSelectionReview({ ...input, proposal: output });
|
|
75
|
+
}
|
|
76
|
+
catch (cause) {
|
|
77
|
+
if (!(cause instanceof Error))
|
|
78
|
+
throw cause;
|
|
79
|
+
throw new NativeInstanceSelectionReviewError({ output }, cause);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { resolveNativeNodeParameterSource } from './resolve-native-node-parameter-source.js';
|
|
2
2
|
/** Structural projection only: no values, identities or unmet requirements are repaired. */
|
|
3
3
|
export function resolveNativeNodePlanningOutput(output) {
|
|
4
|
-
if (
|
|
4
|
+
if ('nativeNodes' in output)
|
|
5
5
|
return {
|
|
6
6
|
proposal: {
|
|
7
7
|
nativeNodes: output.nativeNodes.map(resolveNativeNodeParameterSource),
|
|
8
8
|
gaps: output.gaps,
|
|
9
9
|
},
|
|
10
10
|
};
|
|
11
|
+
if ('gaps' in output)
|
|
12
|
+
return { proposal: { nativeNodes: [], gaps: output.gaps } };
|
|
11
13
|
const { decision } = output;
|
|
12
14
|
if ('additions' in decision)
|
|
13
15
|
return {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
2
2
|
import { isDeepStrictEqual } from 'node:util';
|
|
3
|
-
import { createNativeInstanceSelectionSchema, describeNativeInstanceSelection, resolveNativeInstanceSelection, } from '@openapi-flow/core';
|
|
3
|
+
import { createNativeInstanceSelectionSchema, describeNativeInstanceSelection, resolveNativeInstanceSelection, describeNativeInstanceSelectionFeedback, } from '@openapi-flow/core';
|
|
4
4
|
import { serializeStructuredOutputSchema } from '../schemas/serialize-structured-output-schema.js';
|
|
5
5
|
import { nativeInstanceSelectionPrompt } from '../prompts/native-node-planning-prompt.js';
|
|
6
6
|
import { NativeNodePlanningError } from './native-node-planning-error.js';
|
|
@@ -11,6 +11,9 @@ export async function selectNativeNodeInstances(input) {
|
|
|
11
11
|
(!input.model || typeof input.model.withStructuredOutput !== 'function'))
|
|
12
12
|
throw new Error('selectNativeNodeInstances.model must support structured output when supplied');
|
|
13
13
|
const { context } = describeNativeInstanceSelection(input);
|
|
14
|
+
const feedback = input.feedback === undefined
|
|
15
|
+
? undefined
|
|
16
|
+
: describeNativeInstanceSelectionFeedback(input, input.feedback);
|
|
14
17
|
const originalOptions = JSON.stringify([
|
|
15
18
|
input.planId,
|
|
16
19
|
input.allowRuntimeParameters,
|
|
@@ -38,11 +41,17 @@ export async function selectNativeNodeInstances(input) {
|
|
|
38
41
|
})
|
|
39
42
|
.invoke([
|
|
40
43
|
new SystemMessage(nativeInstanceSelectionPrompt),
|
|
41
|
-
new HumanMessage(JSON.stringify(
|
|
44
|
+
new HumanMessage(JSON.stringify({
|
|
45
|
+
...context,
|
|
46
|
+
...(feedback === undefined ? {} : { selectionFeedback: feedback }),
|
|
47
|
+
})),
|
|
42
48
|
], input.signal === undefined ? undefined : { signal: input.signal });
|
|
43
49
|
input.signal?.throwIfAborted();
|
|
44
50
|
try {
|
|
45
51
|
if (!isDeepStrictEqual(describeNativeInstanceSelection(input).context, context) ||
|
|
52
|
+
!isDeepStrictEqual(feedback, input.feedback === undefined
|
|
53
|
+
? undefined
|
|
54
|
+
: describeNativeInstanceSelectionFeedback(input, input.feedback)) ||
|
|
46
55
|
JSON.stringify([
|
|
47
56
|
input.planId,
|
|
48
57
|
input.allowRuntimeParameters,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openapi-flow/langchain",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Composable LangChain planning for OpenAPI workflows",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@openapi-flow/core": "0.
|
|
31
|
+
"@openapi-flow/core": "0.4.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@langchain/core": "^1.0.0",
|