@openapi-flow/langchain 0.4.1 → 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.
- package/README.md +44 -0
- package/dist/arguments/analyze-api-request-media-type.js +3 -2
- package/dist/arguments/generate-api-arguments.js +10 -5
- package/dist/bindings/plan-api-call-bindings.js +3 -2
- package/dist/bindings/select-api-binding-sources.js +3 -2
- package/dist/prompts/native-instance-selection-review-prompt.d.ts +1 -1
- package/dist/prompts/native-instance-selection-review-prompt.js +6 -3
- package/dist/prompts/native-node-planning-prompt.d.ts +2 -2
- package/dist/prompts/native-node-planning-prompt.js +5 -0
- package/dist/prompts/workflow-connection-goal-review-prompt.d.ts +1 -1
- package/dist/prompts/workflow-connection-goal-review-prompt.js +2 -2
- package/dist/prompts/workflow-connections-prompt.d.ts +1 -1
- package/dist/prompts/workflow-connections-prompt.js +1 -0
- package/dist/prompts/workflow-intent-prompt.d.ts +1 -0
- package/dist/prompts/workflow-intent-prompt.js +8 -0
- package/dist/public-api.d.ts +2 -0
- package/dist/public-api.js +1 -0
- package/dist/schemas/api-call-binding-plan-schema.d.ts +2 -2
- package/dist/schemas/api-call-binding-plan-schema.js +7 -3
- package/dist/schemas/api-literal-generation-output-schema.d.ts +5 -3
- package/dist/schemas/api-literal-generation-output-schema.js +12 -6
- package/dist/schemas/api-request-media-type-schema.d.ts +1 -1
- package/dist/schemas/api-request-media-type-schema.js +6 -1
- package/dist/schemas/api-selection-analysis-schema.d.ts +36 -1
- package/dist/schemas/api-selection-analysis-schema.js +4 -4
- package/dist/schemas/api-selection-schema.d.ts +14 -1
- package/dist/schemas/api-selection-schema.js +3 -3
- package/dist/schemas/reviewable-workflow-graph-schema.d.ts +14 -3
- package/dist/schemas/with-api-selection-explanation.d.ts +11 -3
- package/dist/schemas/with-api-selection-explanation.js +21 -8
- package/dist/schemas/workflow-connection-execution-schema.d.ts +5 -0
- package/dist/schemas/workflow-connection-execution-schema.js +22 -0
- package/dist/schemas/workflow-connection-goal-review-schema.d.ts +1 -1
- package/dist/schemas/workflow-connection-goal-review-schema.js +8 -10
- package/dist/schemas/workflow-connection-selection-schema.d.ts +33 -0
- package/dist/schemas/workflow-connection-selection-schema.js +34 -0
- package/dist/selection/analyze-api-selection.js +6 -5
- package/dist/selection/select-api-operations.js +5 -4
- package/dist/types/argument-generation.d.ts +1 -1
- package/dist/types/incremental-connection-planning.d.ts +2 -0
- package/dist/types/native-instance-selection-review.d.ts +2 -2
- package/dist/types/reviewable-workflow-planning.d.ts +2 -1
- package/dist/types/workflow-connection-selection.d.ts +19 -0
- package/dist/types/workflow-connection-selection.js +1 -0
- package/dist/types/workflow-intent.d.ts +6 -0
- package/dist/types/workflow-intent.js +1 -0
- package/dist/types/workflow-orchestration.d.ts +2 -1
- package/dist/workflow/connections/invoke-connection-planning-model.js +4 -1
- package/dist/workflow/connections/review-workflow-connection-goals.js +1 -0
- package/dist/workflow/generate-native-node-parameters.js +6 -2
- package/dist/workflow/native-selection/review-native-instance-selection.js +2 -2
- package/dist/workflow/plan-workflow-connections.js +9 -8
- package/dist/workflow/plan-workflow-intent.d.ts +4 -0
- package/dist/workflow/plan-workflow-intent.js +49 -0
- package/dist/workflow/resolve-workflow-connection-output.d.ts +3 -2
- package/dist/workflow/resolve-workflow-connection-output.js +30 -18
- package/dist/workflow/resolve-workflow-connection-selection.d.ts +4 -0
- package/dist/workflow/resolve-workflow-connection-selection.js +24 -0
- package/package.json +2 -2
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export declare function createApiSelectionAnalysisSchema(candidateIds: string[], includeExplanations?: boolean): z.ZodObject<{
|
|
2
|
+
export declare function createApiSelectionAnalysisSchema(candidateIds: string[], includeExplanations?: boolean, requireExplanations?: boolean): z.ZodObject<{
|
|
3
3
|
operations: z.ZodArray<z.ZodObject<{
|
|
4
4
|
candidateId: z.ZodEnum<{
|
|
5
5
|
[x: string]: string;
|
|
6
6
|
}>;
|
|
7
7
|
purpose: z.ZodString;
|
|
8
|
+
}, z.core.$strict> | z.ZodObject<{
|
|
9
|
+
candidateId: z.ZodEnum<{
|
|
10
|
+
[x: string]: string;
|
|
11
|
+
}>;
|
|
12
|
+
purpose: z.ZodString;
|
|
13
|
+
explanation: z.ZodOptional<z.ZodPipe<z.ZodUnknown, z.ZodTransform<{
|
|
14
|
+
reason: string;
|
|
15
|
+
} | undefined, unknown>>>;
|
|
8
16
|
}, z.core.$strict> | z.ZodObject<{
|
|
9
17
|
candidateId: z.ZodEnum<{
|
|
10
18
|
[x: string]: string;
|
|
@@ -16,6 +24,11 @@ export declare function createApiSelectionAnalysisSchema(candidateIds: string[],
|
|
|
16
24
|
}, z.core.$strict>>;
|
|
17
25
|
gaps: z.ZodArray<z.ZodObject<{
|
|
18
26
|
description: z.ZodString;
|
|
27
|
+
}, z.core.$strict> | z.ZodObject<{
|
|
28
|
+
description: z.ZodString;
|
|
29
|
+
explanation: z.ZodOptional<z.ZodPipe<z.ZodUnknown, z.ZodTransform<{
|
|
30
|
+
reason: string;
|
|
31
|
+
} | undefined, unknown>>>;
|
|
19
32
|
}, z.core.$strict> | z.ZodObject<{
|
|
20
33
|
description: z.ZodString;
|
|
21
34
|
explanation: z.ZodObject<{
|
|
@@ -29,6 +42,16 @@ export declare function createApiSelectionAnalysisSchema(candidateIds: string[],
|
|
|
29
42
|
candidateIds: z.ZodArray<z.ZodEnum<{
|
|
30
43
|
[x: string]: string;
|
|
31
44
|
}>>;
|
|
45
|
+
}, z.core.$strict> | z.ZodObject<{
|
|
46
|
+
kind: z.ZodLiteral<"single-choice">;
|
|
47
|
+
message: z.ZodString;
|
|
48
|
+
purpose: z.ZodString;
|
|
49
|
+
candidateIds: z.ZodArray<z.ZodEnum<{
|
|
50
|
+
[x: string]: string;
|
|
51
|
+
}>>;
|
|
52
|
+
explanation: z.ZodOptional<z.ZodPipe<z.ZodUnknown, z.ZodTransform<{
|
|
53
|
+
reason: string;
|
|
54
|
+
} | undefined, unknown>>>;
|
|
32
55
|
}, z.core.$strict> | z.ZodObject<{
|
|
33
56
|
kind: z.ZodLiteral<"single-choice">;
|
|
34
57
|
message: z.ZodString;
|
|
@@ -48,6 +71,18 @@ export declare function createApiSelectionAnalysisSchema(candidateIds: string[],
|
|
|
48
71
|
}>>;
|
|
49
72
|
minSelections: z.ZodNumber;
|
|
50
73
|
maxSelections: z.ZodNumber;
|
|
74
|
+
}, z.core.$strict> | z.ZodObject<{
|
|
75
|
+
message: z.ZodString;
|
|
76
|
+
purpose: z.ZodString;
|
|
77
|
+
kind: z.ZodLiteral<"multiple-choice">;
|
|
78
|
+
candidateIds: z.ZodArray<z.ZodEnum<{
|
|
79
|
+
[x: string]: string;
|
|
80
|
+
}>>;
|
|
81
|
+
minSelections: z.ZodNumber;
|
|
82
|
+
maxSelections: z.ZodNumber;
|
|
83
|
+
explanation: z.ZodOptional<z.ZodPipe<z.ZodUnknown, z.ZodTransform<{
|
|
84
|
+
reason: string;
|
|
85
|
+
} | undefined, unknown>>>;
|
|
51
86
|
}, z.core.$strict> | z.ZodObject<{
|
|
52
87
|
message: z.ZodString;
|
|
53
88
|
purpose: z.ZodString;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { createApiSelectionSchema } from './api-selection-schema.js';
|
|
3
3
|
import { withApiSelectionExplanation } from './with-api-selection-explanation.js';
|
|
4
|
-
export function createApiSelectionAnalysisSchema(candidateIds, includeExplanations = false) {
|
|
4
|
+
export function createApiSelectionAnalysisSchema(candidateIds, includeExplanations = false, requireExplanations = true) {
|
|
5
5
|
const single = z.strictObject({
|
|
6
6
|
kind: z
|
|
7
7
|
.literal('single-choice')
|
|
@@ -40,13 +40,13 @@ export function createApiSelectionAnalysisSchema(candidateIds, includeExplanatio
|
|
|
40
40
|
.safe()
|
|
41
41
|
.describe('Maximum selections allowed by the user and offered candidate count. Must be at least minSelections.'),
|
|
42
42
|
});
|
|
43
|
-
return createApiSelectionSchema(candidateIds, includeExplanations).extend({
|
|
43
|
+
return createApiSelectionSchema(candidateIds, includeExplanations, requireExplanations).extend({
|
|
44
44
|
questions: z
|
|
45
45
|
.array(
|
|
46
46
|
// Literal kinds remain disjoint; z.union emits the provider-supported anyOf.
|
|
47
47
|
z.union([
|
|
48
|
-
withApiSelectionExplanation(single, includeExplanations),
|
|
49
|
-
withApiSelectionExplanation(multiple, includeExplanations),
|
|
48
|
+
withApiSelectionExplanation(single, includeExplanations, requireExplanations),
|
|
49
|
+
withApiSelectionExplanation(multiple, includeExplanations, requireExplanations),
|
|
50
50
|
]))
|
|
51
51
|
.describe('Empty when the requested API scope is clear. Multiple available APIs alone is not ambiguity. Never expand a short request into unrelated actions.'),
|
|
52
52
|
});
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export declare function createApiSelectionSchema(candidateIds: string[], includeExplanations?: boolean): z.ZodObject<{
|
|
2
|
+
export declare function createApiSelectionSchema(candidateIds: string[], includeExplanations?: boolean, requireExplanations?: boolean): z.ZodObject<{
|
|
3
3
|
operations: z.ZodArray<z.ZodObject<{
|
|
4
4
|
candidateId: z.ZodEnum<{
|
|
5
5
|
[x: string]: string;
|
|
6
6
|
}>;
|
|
7
7
|
purpose: z.ZodString;
|
|
8
|
+
}, z.core.$strict> | z.ZodObject<{
|
|
9
|
+
candidateId: z.ZodEnum<{
|
|
10
|
+
[x: string]: string;
|
|
11
|
+
}>;
|
|
12
|
+
purpose: z.ZodString;
|
|
13
|
+
explanation: z.ZodOptional<z.ZodPipe<z.ZodUnknown, z.ZodTransform<{
|
|
14
|
+
reason: string;
|
|
15
|
+
} | undefined, unknown>>>;
|
|
8
16
|
}, z.core.$strict> | z.ZodObject<{
|
|
9
17
|
candidateId: z.ZodEnum<{
|
|
10
18
|
[x: string]: string;
|
|
@@ -16,6 +24,11 @@ export declare function createApiSelectionSchema(candidateIds: string[], include
|
|
|
16
24
|
}, z.core.$strict>>;
|
|
17
25
|
gaps: z.ZodArray<z.ZodObject<{
|
|
18
26
|
description: z.ZodString;
|
|
27
|
+
}, z.core.$strict> | z.ZodObject<{
|
|
28
|
+
description: z.ZodString;
|
|
29
|
+
explanation: z.ZodOptional<z.ZodPipe<z.ZodUnknown, z.ZodTransform<{
|
|
30
|
+
reason: string;
|
|
31
|
+
} | undefined, unknown>>>;
|
|
19
32
|
}, z.core.$strict> | z.ZodObject<{
|
|
20
33
|
description: z.ZodString;
|
|
21
34
|
explanation: z.ZodObject<{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { withApiSelectionExplanation } from './with-api-selection-explanation.js';
|
|
3
|
-
export function createApiSelectionSchema(candidateIds, includeExplanations = false) {
|
|
3
|
+
export function createApiSelectionSchema(candidateIds, includeExplanations = false, requireExplanations = true) {
|
|
4
4
|
if (candidateIds.length === 0)
|
|
5
5
|
throw new Error('operations must contain candidates for model selection');
|
|
6
6
|
return z
|
|
@@ -16,7 +16,7 @@ export function createApiSelectionSchema(candidateIds, includeExplanations = fal
|
|
|
16
16
|
.min(1)
|
|
17
17
|
.describe('The scenario role of this one API call instance. Describe separate required calls separately; this is not an execution order.'),
|
|
18
18
|
})
|
|
19
|
-
.strict(), includeExplanations))
|
|
19
|
+
.strict(), includeExplanations, requireExplanations))
|
|
20
20
|
.describe('One entry per required API call instance, not a deduplicated API catalog. Repeat a candidateId only when the scenario requires separate calls to that API.'),
|
|
21
21
|
gaps: z.array(withApiSelectionExplanation(z
|
|
22
22
|
.object({
|
|
@@ -25,7 +25,7 @@ export function createApiSelectionSchema(candidateIds, includeExplanations = fal
|
|
|
25
25
|
.min(1)
|
|
26
26
|
.describe('Required API capability that no supplied discovery candidate matches. Do not judge missing parameters, response fields or security without a full contract.'),
|
|
27
27
|
})
|
|
28
|
-
.strict(), includeExplanations)),
|
|
28
|
+
.strict(), includeExplanations, requireExplanations)),
|
|
29
29
|
})
|
|
30
30
|
.strict();
|
|
31
31
|
}
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { WorkflowCapability } from '@openapi-flow/core';
|
|
3
|
-
import type { WorkflowConnectionPlanningOutput } from '../types/workflow-orchestration.js';
|
|
4
|
-
import type { ReviewableWorkflowGraphModelOutput } from '../types/reviewable-workflow-planning.js';
|
|
5
3
|
import type { WorkflowGraphExplanationMode } from '../types/workflow-planning.js';
|
|
6
|
-
export declare function createReviewableWorkflowGraphSchema(capabilities: WorkflowCapability[], readyCallIds: string[], explanationMode?: WorkflowGraphExplanationMode): z.
|
|
4
|
+
export declare function createReviewableWorkflowGraphSchema(capabilities: WorkflowCapability[], readyCallIds: string[], explanationMode?: WorkflowGraphExplanationMode): z.ZodObject<{
|
|
5
|
+
edges: z.ZodArray<z.ZodObject<{
|
|
6
|
+
from: z.ZodString;
|
|
7
|
+
output: z.ZodString;
|
|
8
|
+
to: z.ZodString;
|
|
9
|
+
input: z.ZodString;
|
|
10
|
+
reason?: z.ZodString | undefined;
|
|
11
|
+
}, z.core.$strict>>;
|
|
12
|
+
additionalGaps: z.ZodArray<z.ZodObject<{
|
|
13
|
+
id: z.ZodString;
|
|
14
|
+
description: z.ZodString;
|
|
15
|
+
}, z.core.$strict>>;
|
|
16
|
+
reason?: z.ZodString | undefined;
|
|
17
|
+
}, z.core.$strict>;
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export declare function withApiSelectionExplanation<Shape extends z.ZodRawShape>(schema: z.ZodObject<Shape, z.core.$strict>, includeExplanations: boolean): z.ZodObject<Shape, z.core.$strict> | z.ZodObject<(keyof Shape & "explanation" extends never ? Shape & {
|
|
2
|
+
export declare function withApiSelectionExplanation<Shape extends z.ZodRawShape>(schema: z.ZodObject<Shape, z.core.$strict>, includeExplanations: boolean, requireExplanations?: boolean): z.ZodObject<Shape, z.core.$strict> | z.ZodObject<(keyof Shape & "explanation" extends never ? Shape & {
|
|
3
|
+
explanation: z.ZodOptional<z.ZodPipe<z.ZodUnknown, z.ZodTransform<{
|
|
4
|
+
reason: string;
|
|
5
|
+
} | undefined, unknown>>>;
|
|
6
|
+
} : { [K in keyof Shape as K extends "explanation" ? never : K]: Shape[K]; } & {
|
|
7
|
+
explanation: z.ZodOptional<z.ZodPipe<z.ZodUnknown, z.ZodTransform<{
|
|
8
|
+
reason: string;
|
|
9
|
+
} | undefined, unknown>>>;
|
|
10
|
+
}) extends infer T ? { [k in keyof T]: T[k]; } : never, z.core.$strict> | z.ZodObject<(keyof Shape & "explanation" extends never ? Shape & {
|
|
3
11
|
explanation: z.ZodObject<{
|
|
4
12
|
reason: z.ZodString;
|
|
5
13
|
}, z.core.$strict>;
|
|
6
|
-
} : { [
|
|
14
|
+
} : { [K_1 in keyof Shape as K_1 extends "explanation" ? never : K_1]: Shape[K_1]; } & {
|
|
7
15
|
explanation: z.ZodObject<{
|
|
8
16
|
reason: z.ZodString;
|
|
9
17
|
}, z.core.$strict>;
|
|
10
|
-
}) extends infer
|
|
18
|
+
}) extends infer T_1 ? { [k_1 in keyof T_1]: T_1[k_1]; } : never, z.core.$strict>;
|
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
|
|
2
|
+
const apiSelectionExplanationSchema = z.strictObject({
|
|
3
|
+
reason: z
|
|
4
|
+
.string()
|
|
5
|
+
.min(1)
|
|
6
|
+
.refine((value) => value.trim().length > 0)
|
|
7
|
+
.describe('Short user-facing reason in the scenario language for this selection, missing capability or consequential API choice. Use only the supplied scenario and discovery metadata; code attaches those unchanged sources. Do not claim request, response or security contract validation, or expose private chain-of-thought.'),
|
|
8
|
+
});
|
|
9
|
+
export function withApiSelectionExplanation(schema, includeExplanations, requireExplanations = true) {
|
|
3
10
|
z.boolean().parse(includeExplanations);
|
|
11
|
+
if (!requireExplanations)
|
|
12
|
+
return schema.extend({
|
|
13
|
+
explanation: z
|
|
14
|
+
.unknown()
|
|
15
|
+
.transform((value) => {
|
|
16
|
+
const explanation = apiSelectionExplanationSchema.safeParse(value);
|
|
17
|
+
return includeExplanations && explanation.success
|
|
18
|
+
? explanation.data
|
|
19
|
+
: undefined;
|
|
20
|
+
})
|
|
21
|
+
.optional(),
|
|
22
|
+
});
|
|
4
23
|
return includeExplanations
|
|
5
24
|
? schema.extend({
|
|
6
|
-
explanation:
|
|
7
|
-
reason: z
|
|
8
|
-
.string()
|
|
9
|
-
.min(1)
|
|
10
|
-
.refine((value) => value.trim().length > 0)
|
|
11
|
-
.describe('Short user-facing reason in the scenario language for this selection, missing capability or consequential API choice. Use only the supplied scenario and discovery metadata; code attaches those unchanged sources. Do not claim request, response or security contract validation, or expose private chain-of-thought.'),
|
|
12
|
-
}),
|
|
25
|
+
explanation: apiSelectionExplanationSchema,
|
|
13
26
|
})
|
|
14
27
|
: schema;
|
|
15
28
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { WorkflowConnectionPlanningContext } from '@openapi-flow/core';
|
|
3
|
+
import type { WorkflowConnectionExecutionOutput } from '../types/workflow-connection-selection.js';
|
|
4
|
+
/** Validate executable fields independently of optional model-authored display text. */
|
|
5
|
+
export declare function createWorkflowConnectionExecutionSchema(context: WorkflowConnectionPlanningContext, includeExplanations: boolean): z.ZodType<WorkflowConnectionExecutionOutput>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { workflowConnectionProposalSchema } from '@openapi-flow/core';
|
|
3
|
+
import { createWorkflowConnectionSelectionSchema } from './workflow-connection-selection-schema.js';
|
|
4
|
+
/** Validate executable fields independently of optional model-authored display text. */
|
|
5
|
+
export function createWorkflowConnectionExecutionSchema(context, includeExplanations) {
|
|
6
|
+
const execution = createWorkflowConnectionSelectionSchema(context, false);
|
|
7
|
+
if (!includeExplanations)
|
|
8
|
+
return execution;
|
|
9
|
+
const display = { reason: z.unknown().optional() };
|
|
10
|
+
const base = execution.extend({
|
|
11
|
+
...display,
|
|
12
|
+
edges: z.array(execution.shape.edges.element.extend(display)),
|
|
13
|
+
});
|
|
14
|
+
if (context.readyCallIds.length)
|
|
15
|
+
return base.extend({
|
|
16
|
+
blockedCalls: z.array(workflowConnectionProposalSchema.shape.blockedCalls.element.extend({
|
|
17
|
+
callId: z.enum(context.readyCallIds),
|
|
18
|
+
...display,
|
|
19
|
+
})),
|
|
20
|
+
});
|
|
21
|
+
return base;
|
|
22
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { WorkflowConnectionGoalReviewDescription } from '@openapi-flow/core';
|
|
3
3
|
import type { WorkflowConnectionGoalReviewModelOutput } from '../types/workflow-connection-goal-review.js';
|
|
4
|
-
export declare function createWorkflowConnectionGoalReviewSchema(description: WorkflowConnectionGoalReviewDescription): z.ZodType<WorkflowConnectionGoalReviewModelOutput>;
|
|
4
|
+
export declare function createWorkflowConnectionGoalReviewSchema(description: WorkflowConnectionGoalReviewDescription, validatePresentation?: boolean): z.ZodType<WorkflowConnectionGoalReviewModelOutput>;
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { workflowConnectionGoalAssessmentSchema } from '@openapi-flow/core';
|
|
3
|
-
export function createWorkflowConnectionGoalReviewSchema(description) {
|
|
3
|
+
export function createWorkflowConnectionGoalReviewSchema(description, validatePresentation = true) {
|
|
4
4
|
const assessment = workflowConnectionGoalAssessmentSchema
|
|
5
|
-
.omit({ factId: true })
|
|
5
|
+
.omit({ factId: true, sourceQuotes: true, explanationStatus: true })
|
|
6
6
|
.extend({
|
|
7
7
|
policyIds: workflowConnectionGoalAssessmentSchema.shape.policyIds.describe('Select only supplied code-enforced policy IDs for clauses actually covered by that policy. A protected-edge policy does not prove data semantics or implementation of new connections.'),
|
|
8
8
|
goalIds: z
|
|
9
9
|
.array(z.enum(description.goals.map((goal) => goal.id)))
|
|
10
10
|
.describe('Select only actual candidate goals. An omitted requirement may have no matching goal.'),
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
.
|
|
17
|
-
.min(1)
|
|
18
|
-
.describe('Brief evidence-based explanation comparing the entire original requirement with goals and actual mappings. Not private reasoning.'),
|
|
11
|
+
reason: validatePresentation
|
|
12
|
+
? z
|
|
13
|
+
.string()
|
|
14
|
+
.min(1)
|
|
15
|
+
.describe('Brief evidence-based explanation comparing the entire original requirement with goals and actual mappings. Not private reasoning.')
|
|
16
|
+
: z.unknown().optional(),
|
|
19
17
|
});
|
|
20
18
|
return z.strictObject({
|
|
21
19
|
assessments: z.strictObject(Object.fromEntries(description.requirements.map((fact) => [
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { WorkflowConnectionPlanningContext } from '@openapi-flow/core';
|
|
3
|
+
/** Existing identities are supplied choices. Only new gap identities belong to the model. */
|
|
4
|
+
export declare function createWorkflowConnectionSelectionSchema(context: WorkflowConnectionPlanningContext, includeExplanations: boolean): z.ZodObject<{
|
|
5
|
+
additionalGaps: z.ZodArray<z.ZodObject<{
|
|
6
|
+
id: z.ZodString;
|
|
7
|
+
description: z.ZodString;
|
|
8
|
+
}, z.core.$strict>>;
|
|
9
|
+
reason?: z.ZodString | undefined;
|
|
10
|
+
edges: z.ZodArray<z.ZodObject<{
|
|
11
|
+
from: z.ZodObject<{
|
|
12
|
+
gapId: z.ZodString;
|
|
13
|
+
}, z.core.$strict> | z.ZodUnion<readonly [z.ZodEnum<{
|
|
14
|
+
[x: string]: string;
|
|
15
|
+
}>, z.ZodObject<{
|
|
16
|
+
gapId: z.ZodString;
|
|
17
|
+
}, z.core.$strict>]>;
|
|
18
|
+
output: z.ZodEnum<{
|
|
19
|
+
[x: string]: string;
|
|
20
|
+
}>;
|
|
21
|
+
to: z.ZodObject<{
|
|
22
|
+
gapId: z.ZodString;
|
|
23
|
+
}, z.core.$strict> | z.ZodUnion<readonly [z.ZodEnum<{
|
|
24
|
+
[x: string]: string;
|
|
25
|
+
}>, z.ZodObject<{
|
|
26
|
+
gapId: z.ZodString;
|
|
27
|
+
}, z.core.$strict>]>;
|
|
28
|
+
input: z.ZodEnum<{
|
|
29
|
+
[x: string]: string;
|
|
30
|
+
}>;
|
|
31
|
+
reason?: z.ZodString | undefined;
|
|
32
|
+
}, z.core.$strict>>;
|
|
33
|
+
}, z.core.$strict>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createReviewableWorkflowGraphSchema } from './reviewable-workflow-graph-schema.js';
|
|
3
|
+
import { workflowConnectionReasonSchema } from './workflow-connection-explanation-schema.js';
|
|
4
|
+
/** Existing identities are supplied choices. Only new gap identities belong to the model. */
|
|
5
|
+
export function createWorkflowConnectionSelectionSchema(context, includeExplanations) {
|
|
6
|
+
const nodeIds = context.nodes.map((node) => node.id);
|
|
7
|
+
const additionalGap = z.strictObject({
|
|
8
|
+
gapId: z
|
|
9
|
+
.string()
|
|
10
|
+
.min(1)
|
|
11
|
+
.describe('ID of a NEW gap declared in additionalGaps, not an existing node.'),
|
|
12
|
+
});
|
|
13
|
+
const endpoint = nodeIds.length
|
|
14
|
+
? z.union([z.enum(nodeIds), additionalGap])
|
|
15
|
+
: additionalGap;
|
|
16
|
+
const outputs = [
|
|
17
|
+
...new Set(['main', ...context.nodes.flatMap((node) => node.outputs)]),
|
|
18
|
+
];
|
|
19
|
+
const inputs = [
|
|
20
|
+
...new Set(['main', ...context.nodes.flatMap((node) => node.inputs)]),
|
|
21
|
+
];
|
|
22
|
+
const base = createReviewableWorkflowGraphSchema([], context.readyCallIds, includeExplanations ? 'connections' : 'none');
|
|
23
|
+
return base.extend({
|
|
24
|
+
edges: z.array(z.strictObject({
|
|
25
|
+
...(includeExplanations
|
|
26
|
+
? { reason: workflowConnectionReasonSchema }
|
|
27
|
+
: {}),
|
|
28
|
+
from: endpoint.describe('Choose an exact supplied source ID, or explicitly reference a new gap.'),
|
|
29
|
+
output: z.enum(outputs),
|
|
30
|
+
to: endpoint.describe('Choose an exact supplied target ID, or explicitly reference a new gap.'),
|
|
31
|
+
input: z.enum(inputs),
|
|
32
|
+
})),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
@@ -8,6 +8,7 @@ import { assertSelectionInput } from '../legacy/planning/select-operation.js';
|
|
|
8
8
|
import { selectApiOperations } from './select-api-operations.js';
|
|
9
9
|
import { resolveApiSelectionOptions } from './resolve-api-selection-options.js';
|
|
10
10
|
import { apiSelectionExplanationPrompt } from '../prompts/api-selection-explanation-prompt.js';
|
|
11
|
+
import { serializeStructuredOutputSchema } from '../schemas/serialize-structured-output-schema.js';
|
|
11
12
|
/** Additive clarification boundary; the existing selector keeps its output contract. */
|
|
12
13
|
export async function analyzeApiSelection(input) {
|
|
13
14
|
assertSelectionInput(input.scenario, input.model);
|
|
@@ -28,7 +29,7 @@ export async function analyzeApiSelection(input) {
|
|
|
28
29
|
}));
|
|
29
30
|
const schema = createApiSelectionAnalysisSchema(candidates.map((item) => item.candidateId), includeExplanations);
|
|
30
31
|
const proposed = await input.model
|
|
31
|
-
.withStructuredOutput(schema, {
|
|
32
|
+
.withStructuredOutput(serializeStructuredOutputSchema(schema, 'draft-2020-12'), {
|
|
32
33
|
name: 'analyze_api_selection',
|
|
33
34
|
method: 'jsonSchema',
|
|
34
35
|
strict: true,
|
|
@@ -37,7 +38,7 @@ export async function analyzeApiSelection(input) {
|
|
|
37
38
|
new SystemMessage(`${apiSelectionAnalysisPrompt}\n${apiSelectionExplanationPrompt}`),
|
|
38
39
|
new HumanMessage(JSON.stringify({ scenario: context.scenario, candidates })),
|
|
39
40
|
]);
|
|
40
|
-
const parsed = parseStructuredOutput(
|
|
41
|
+
const parsed = parseStructuredOutput(createApiSelectionAnalysisSchema(candidates.map((candidate) => candidate.candidateId), includeExplanations, false), proposed, 'model API selection analysis');
|
|
41
42
|
const byId = new Map(candidates.map((item) => [item.candidateId, item]));
|
|
42
43
|
const selected = parsed.operations.map((item) => {
|
|
43
44
|
const candidate = byId.get(item.candidateId);
|
|
@@ -46,7 +47,7 @@ export async function analyzeApiSelection(input) {
|
|
|
46
47
|
return {
|
|
47
48
|
key: structuredClone(candidate.key),
|
|
48
49
|
purpose: item.purpose,
|
|
49
|
-
...('explanation' in item
|
|
50
|
+
...('explanation' in item && item.explanation !== undefined
|
|
50
51
|
? {
|
|
51
52
|
explanation: createApiSelectionExplanation({
|
|
52
53
|
context,
|
|
@@ -85,7 +86,7 @@ export async function analyzeApiSelection(input) {
|
|
|
85
86
|
message: question.message,
|
|
86
87
|
purpose: question.purpose,
|
|
87
88
|
candidates: alternatives,
|
|
88
|
-
...('explanation' in question
|
|
89
|
+
...('explanation' in question && question.explanation !== undefined
|
|
89
90
|
? {
|
|
90
91
|
explanation: createApiSelectionExplanation({
|
|
91
92
|
context,
|
|
@@ -117,7 +118,7 @@ export async function analyzeApiSelection(input) {
|
|
|
117
118
|
gaps: parsed.gaps.map((gap) => ({
|
|
118
119
|
kind: 'missing_operation',
|
|
119
120
|
description: gap.description,
|
|
120
|
-
...('explanation' in gap
|
|
121
|
+
...('explanation' in gap && gap.explanation !== undefined
|
|
121
122
|
? {
|
|
122
123
|
explanation: createApiSelectionExplanation({
|
|
123
124
|
context,
|
|
@@ -7,6 +7,7 @@ import { parseStructuredOutput } from '../legacy/planning/parse-structured-outpu
|
|
|
7
7
|
import { resolveApiSelectionOptions } from './resolve-api-selection-options.js';
|
|
8
8
|
import { apiSelectionExplanationPrompt } from '../prompts/api-selection-explanation-prompt.js';
|
|
9
9
|
import { invokeStructuredModel } from '../model/invoke-structured-model.js';
|
|
10
|
+
import { serializeStructuredOutputSchema } from '../schemas/serialize-structured-output-schema.js';
|
|
10
11
|
export async function selectApiOperations(input) {
|
|
11
12
|
const { scenario, model } = input;
|
|
12
13
|
const { includeExplanations, context } = runOpenApiFlowOperation({
|
|
@@ -46,7 +47,7 @@ export async function selectApiOperations(input) {
|
|
|
46
47
|
const schema = createApiSelectionSchema(candidates.map((candidate) => candidate.candidateId), includeExplanations);
|
|
47
48
|
const proposed = await invokeStructuredModel({
|
|
48
49
|
model,
|
|
49
|
-
schema,
|
|
50
|
+
schema: serializeStructuredOutputSchema(schema, 'draft-2020-12'),
|
|
50
51
|
operation: 'selectApiOperations',
|
|
51
52
|
name: 'select_api_operations',
|
|
52
53
|
method: 'jsonSchema',
|
|
@@ -62,7 +63,7 @@ export async function selectApiOperations(input) {
|
|
|
62
63
|
stage: 'contract-validation',
|
|
63
64
|
code: 'API_SELECTION_INVALID',
|
|
64
65
|
}, () => {
|
|
65
|
-
const selection = parseStructuredOutput(
|
|
66
|
+
const selection = parseStructuredOutput(createApiSelectionSchema(candidates.map((candidate) => candidate.candidateId), includeExplanations, false), proposed, 'model API selection');
|
|
66
67
|
if (selection.operations.length === 0 && selection.gaps.length === 0)
|
|
67
68
|
throw new Error('model API selection must contain operations or gaps');
|
|
68
69
|
const byId = new Map(candidates.map((candidate) => [candidate.candidateId, candidate]));
|
|
@@ -74,7 +75,7 @@ export async function selectApiOperations(input) {
|
|
|
74
75
|
return {
|
|
75
76
|
key: { ...candidate.key },
|
|
76
77
|
purpose: item.purpose,
|
|
77
|
-
...('explanation' in item
|
|
78
|
+
...('explanation' in item && item.explanation !== undefined
|
|
78
79
|
? {
|
|
79
80
|
explanation: createApiSelectionExplanation({
|
|
80
81
|
context,
|
|
@@ -88,7 +89,7 @@ export async function selectApiOperations(input) {
|
|
|
88
89
|
gaps: selection.gaps.map((gap) => ({
|
|
89
90
|
kind: 'missing_operation',
|
|
90
91
|
description: gap.description,
|
|
91
|
-
...('explanation' in gap
|
|
92
|
+
...('explanation' in gap && gap.explanation !== undefined
|
|
92
93
|
? {
|
|
93
94
|
explanation: createApiSelectionExplanation({
|
|
94
95
|
context,
|
|
@@ -40,7 +40,7 @@ export type ApiLiteralProvidedDecision = z.infer<ReturnType<typeof createApiLite
|
|
|
40
40
|
export type ApiLiteralAvailabilityDecision = z.infer<typeof apiLiteralNotProvidedSchema> | ApiLiteralProvidedDecision;
|
|
41
41
|
export type ApiTrackedLiteralGenerationOutput = z.infer<ReturnType<typeof createApiTrackedLiteralGenerationSchema>> | z.infer<ReturnType<typeof createApiExplainedTrackedLiteralGenerationSchema>>;
|
|
42
42
|
export interface ApiExplainedLiteralGenerationOutput extends ApiArgumentProposal {
|
|
43
|
-
explanation
|
|
43
|
+
explanation?: z.infer<typeof apiLiteralGenerationReasonSchema>;
|
|
44
44
|
}
|
|
45
45
|
export type ApiLiteralGenerationOutput = ApiArgumentProposal | ApiExplainedLiteralGenerationOutput | ApiTrackedLiteralGenerationOutput;
|
|
46
46
|
export type ApiLiteralGenerationOutputSchema = z.ZodType<ApiLiteralGenerationOutput>;
|
|
@@ -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,7 +1,7 @@
|
|
|
1
1
|
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
|
-
import type { NativeSelectedPlanningInput } from '@openapi-flow/core';
|
|
2
|
+
import type { NativeSelectedPlanningInput, NativeInstanceSelectionReviewOptions } from '@openapi-flow/core';
|
|
3
3
|
import type { NativePlanningRejectedProposal } from './native-planning-rejection.js';
|
|
4
|
-
export interface ReviewNativeInstanceSelectionInput extends NativeSelectedPlanningInput {
|
|
4
|
+
export interface ReviewNativeInstanceSelectionInput extends NativeSelectedPlanningInput, NativeInstanceSelectionReviewOptions {
|
|
5
5
|
model?: BaseChatModel;
|
|
6
6
|
signal?: AbortSignal;
|
|
7
7
|
rejectedProposals?: NativePlanningRejectedProposal[];
|
|
@@ -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,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
|
}
|
|
@@ -33,7 +33,10 @@ export async function invokeConnectionPlanningModel(input) {
|
|
|
33
33
|
? {}
|
|
34
34
|
: { requestFingerprint: input.requestFingerprint }),
|
|
35
35
|
}, () => {
|
|
36
|
-
const
|
|
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;
|
|
@@ -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),
|
|
@@ -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
|
-
|
|
74
|
+
validationSchema.parse(output);
|
|
71
75
|
}
|
|
72
76
|
catch (cause) {
|
|
73
77
|
if (!(cause instanceof Error))
|