@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.
- package/README.md +44 -0
- package/dist/arguments/analyze-api-input-answers.js +31 -6
- package/dist/arguments/analyze-api-request-media-type.js +3 -2
- package/dist/arguments/assert-api-argument-generation-source.d.ts +4 -0
- package/dist/arguments/assert-api-argument-generation-source.js +16 -0
- package/dist/arguments/attribute-api-literal-generation-sources.d.ts +4 -0
- package/dist/arguments/attribute-api-literal-generation-sources.js +16 -0
- package/dist/arguments/create-api-argument-rejection.js +9 -2
- package/dist/arguments/fingerprint-api-argument-source.d.ts +2 -2
- package/dist/arguments/fingerprint-api-argument-source.js +2 -1
- package/dist/arguments/generate-api-arguments.js +45 -18
- package/dist/bindings/plan-api-call-bindings.js +32 -10
- package/dist/bindings/select-api-binding-sources.js +34 -9
- package/dist/prompts/api-arguments-prompt.d.ts +2 -2
- package/dist/prompts/api-arguments-prompt.js +11 -2
- package/dist/prompts/api-input-answers-prompt.d.ts +1 -1
- package/dist/prompts/api-input-answers-prompt.js +8 -7
- package/dist/prompts/api-material-repair-prompt.d.ts +1 -0
- package/dist/prompts/api-material-repair-prompt.js +1 -0
- package/dist/prompts/native-instance-selection-review-prompt.d.ts +1 -1
- package/dist/prompts/native-instance-selection-review-prompt.js +6 -2
- package/dist/prompts/native-node-planning-prompt.d.ts +2 -2
- package/dist/prompts/native-node-planning-prompt.js +6 -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-connection-native-repair-prompt.d.ts +1 -0
- package/dist/prompts/workflow-connection-native-repair-prompt.js +1 -0
- 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 +10 -0
- package/dist/public-api.js +7 -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-input-answer-source-schema.d.ts +5 -5
- package/dist/schemas/api-input-answer-source-schema.js +14 -6
- package/dist/schemas/api-literal-generation-output-schema.d.ts +12 -31
- package/dist/schemas/api-literal-generation-output-schema.js +31 -15
- 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/create-connection-material-repair-choice-schema.js +3 -1
- package/dist/schemas/native-planning-rejection-schema.d.ts +11 -0
- package/dist/schemas/native-planning-rejection-schema.js +8 -0
- 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/api-call-binding-planning.d.ts +2 -1
- package/dist/types/api-input-answers.d.ts +2 -6
- package/dist/types/argument-generation.d.ts +9 -4
- package/dist/types/incremental-connection-planning.d.ts +2 -0
- package/dist/types/native-instance-selection-review.d.ts +5 -2
- package/dist/types/native-node-planning.d.ts +4 -0
- package/dist/types/native-planning-rejection.d.ts +21 -0
- package/dist/types/native-planning-rejection.js +1 -0
- package/dist/types/reviewable-workflow-planning.d.ts +2 -1
- package/dist/types/workflow-connection-native-repair.d.ts +16 -0
- package/dist/types/workflow-connection-native-repair.js +1 -0
- 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/generate-workflow-connection-native-parameters.d.ts +4 -0
- package/dist/workflow/connections/generate-workflow-connection-native-parameters.js +80 -0
- package/dist/workflow/connections/invoke-connection-planning-model.js +4 -1
- package/dist/workflow/connections/plan-workflow-connection-native-dependencies.d.ts +4 -0
- package/dist/workflow/connections/plan-workflow-connection-native-dependencies.js +73 -0
- package/dist/workflow/connections/review-workflow-connection-goals.js +1 -0
- package/dist/workflow/connections/workflow-connection-native-repair-error.d.ts +6 -0
- package/dist/workflow/connections/workflow-connection-native-repair-error.js +18 -0
- package/dist/workflow/generate-native-node-parameters.js +6 -2
- package/dist/workflow/native-selection/create-native-planning-rejection.d.ts +4 -0
- package/dist/workflow/native-selection/create-native-planning-rejection.js +45 -0
- package/dist/workflow/native-selection/describe-native-planning-request.d.ts +5 -0
- package/dist/workflow/native-selection/describe-native-planning-request.js +26 -0
- package/dist/workflow/native-selection/review-native-instance-selection.js +21 -5
- package/dist/workflow/native-selection/validate-native-planning-rejections.d.ts +2 -0
- package/dist/workflow/native-selection/validate-native-planning-rejections.js +14 -0
- 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/dist/workflow/select-native-node-instances.js +40 -22
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { createApiRequestInputPointerSchema, apiInputLiteralSourceSchema, } from '@openapi-flow/core';
|
|
2
|
+
import { createApiRequestInputPointerSchema, apiInputLiteralSourceSchema, optionalPlanningExplanationObjectSchema, } from '@openapi-flow/core';
|
|
3
3
|
export const apiLiteralGenerationOptionsSchema = z.strictObject({
|
|
4
4
|
includeExplanations: z.boolean().optional(),
|
|
5
5
|
selectOasEnums: z.boolean().optional(),
|
|
@@ -15,27 +15,37 @@ export const apiLiteralGenerationReasonSchema = z.strictObject({
|
|
|
15
15
|
export const apiLiteralGenerationSourcesSchema = z.array(apiInputLiteralSourceSchema.extend({
|
|
16
16
|
targetPointer: z
|
|
17
17
|
.string()
|
|
18
|
-
.describe('RFC 6901 pointer relative to values, e.g. /query/id, never /values/query/id. Cover each proposed literal leaf or an explicitly quoted whole object/array. Code verifies exact occurrence, JSON type equality and complete coverage.
|
|
18
|
+
.describe('RFC 6901 pointer relative to values, e.g. /query/id, never /values/query/id. Cover each proposed literal leaf or an explicitly quoted whole object/array. Code verifies exact occurrence, JSON type equality and complete coverage. Use literalSourceMessages when supplied; otherwise use the original scenario. Purpose, OAS and feedback are not literal quotations.'),
|
|
19
19
|
}));
|
|
20
|
+
function createLiteralSourcesSchema(messages) {
|
|
21
|
+
if (messages === undefined || messages.length === 1)
|
|
22
|
+
return apiLiteralGenerationSourcesSchema.min(1);
|
|
23
|
+
const ids = messages.map((message) => message.id);
|
|
24
|
+
return z
|
|
25
|
+
.array(apiLiteralGenerationSourcesSchema.element.extend({
|
|
26
|
+
messageId: z
|
|
27
|
+
.enum(ids)
|
|
28
|
+
.describe('Select the supplied original message containing this exact quotation. Never cite scenario context or feedback instead.'),
|
|
29
|
+
}))
|
|
30
|
+
.min(1);
|
|
31
|
+
}
|
|
20
32
|
export const apiLiteralNotProvidedSchema = z.strictObject({
|
|
21
33
|
state: z
|
|
22
34
|
.literal('not-provided')
|
|
23
35
|
.describe('No request literal was supplied by the scenario for this call. Code owns the empty values and source list. Do not supply a placeholder body, values, or literalSources in this decision.'),
|
|
24
36
|
});
|
|
25
|
-
export function createApiLiteralProvidedSchema(contract) {
|
|
37
|
+
export function createApiLiteralProvidedSchema(contract, messages) {
|
|
26
38
|
return z.strictObject({
|
|
27
39
|
state: z.literal('provided'),
|
|
28
40
|
values: contract.valuesSchema.refine((values) => Object.entries(values).some(([group, value]) => group === 'body' ||
|
|
29
41
|
(value !== null &&
|
|
30
42
|
typeof value === 'object' &&
|
|
31
43
|
Object.keys(value).length > 0)), 'Provided literals require an actual request value, not empty parameter-location containers.'),
|
|
32
|
-
literalSources:
|
|
33
|
-
.min(1)
|
|
34
|
-
.describe('Every provided literal, including an empty object, empty array, empty string or null, needs its original exact user source. Never use a source-free placeholder.'),
|
|
44
|
+
literalSources: createLiteralSourcesSchema(messages).describe('Every provided literal, including an empty object, empty array, empty string or null, needs its original exact user source. Never use a source-free placeholder.'),
|
|
35
45
|
});
|
|
36
46
|
}
|
|
37
|
-
export function createApiTrackedLiteralGenerationSchema(contract, requestSchema) {
|
|
38
|
-
const provided = createApiLiteralProvidedSchema(contract);
|
|
47
|
+
export function createApiTrackedLiteralGenerationSchema(contract, requestSchema, messages) {
|
|
48
|
+
const provided = createApiLiteralProvidedSchema(contract, messages);
|
|
39
49
|
const schema = z.strictObject({
|
|
40
50
|
literalInputs: z.union([apiLiteralNotProvidedSchema, provided]),
|
|
41
51
|
requestedInputs: z
|
|
@@ -45,19 +55,25 @@ export function createApiTrackedLiteralGenerationSchema(contract, requestSchema)
|
|
|
45
55
|
});
|
|
46
56
|
return schema;
|
|
47
57
|
}
|
|
48
|
-
export function createApiExplainedTrackedLiteralGenerationSchema(contract, requestSchema) {
|
|
49
|
-
return createApiTrackedLiteralGenerationSchema(contract, requestSchema).extend({
|
|
50
|
-
explanation:
|
|
58
|
+
export function createApiExplainedTrackedLiteralGenerationSchema(contract, requestSchema, messages, requireExplanations = true) {
|
|
59
|
+
return createApiTrackedLiteralGenerationSchema(contract, requestSchema, messages).extend({
|
|
60
|
+
explanation: requireExplanations
|
|
61
|
+
? apiLiteralGenerationReasonSchema
|
|
62
|
+
: optionalPlanningExplanationObjectSchema,
|
|
51
63
|
});
|
|
52
64
|
}
|
|
53
65
|
/** Tracked generation separates absence from literal empty values; the OAS value contract stays unchanged. */
|
|
54
|
-
export function createApiLiteralGenerationOutputSchema(contract, includeExplanations, requestSchema) {
|
|
66
|
+
export function createApiLiteralGenerationOutputSchema(contract, includeExplanations, requestSchema, messages, requireExplanations = true) {
|
|
55
67
|
z.boolean().parse(includeExplanations);
|
|
56
68
|
if (requestSchema !== undefined)
|
|
57
69
|
return includeExplanations && contract.hasLiteralInputs
|
|
58
|
-
? createApiExplainedTrackedLiteralGenerationSchema(contract, requestSchema)
|
|
59
|
-
: createApiTrackedLiteralGenerationSchema(contract, requestSchema);
|
|
70
|
+
? createApiExplainedTrackedLiteralGenerationSchema(contract, requestSchema, messages, requireExplanations)
|
|
71
|
+
: createApiTrackedLiteralGenerationSchema(contract, requestSchema, messages);
|
|
60
72
|
return includeExplanations && contract.hasLiteralInputs
|
|
61
|
-
? contract.schema.extend({
|
|
73
|
+
? contract.schema.extend({
|
|
74
|
+
explanation: requireExplanations
|
|
75
|
+
? apiLiteralGenerationReasonSchema
|
|
76
|
+
: optionalPlanningExplanationObjectSchema,
|
|
77
|
+
})
|
|
62
78
|
: contract.schema;
|
|
63
79
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export declare function createApiRequestMediaTypeSchema(mediaTypes: string[], includeExplanations?: boolean): z.ZodObject<{
|
|
2
|
+
export declare function createApiRequestMediaTypeSchema(mediaTypes: string[], includeExplanations?: boolean, requireExplanations?: boolean): z.ZodObject<{
|
|
3
3
|
requestMediaType: z.ZodNullable<z.ZodEnum<{
|
|
4
4
|
[x: string]: string;
|
|
5
5
|
}>>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
|
|
2
|
+
import { optionalPlanningExplanationObjectSchema } from '@openapi-flow/core';
|
|
3
|
+
export function createApiRequestMediaTypeSchema(mediaTypes, includeExplanations = false, requireExplanations = true) {
|
|
3
4
|
z.boolean().parse(includeExplanations);
|
|
4
5
|
if (mediaTypes.length < 2)
|
|
5
6
|
throw new Error('request media selection requires multiple declared media types');
|
|
@@ -9,6 +10,10 @@ export function createApiRequestMediaTypeSchema(mediaTypes, includeExplanations
|
|
|
9
10
|
.nullable()
|
|
10
11
|
.describe('Exact OAS requestBody.content key matching an explicitly requested format, or null when the scenario leaves the format unspecified or ambiguous so code can apply the documented default. This is the request Content-Type, not the response format.'),
|
|
11
12
|
});
|
|
13
|
+
if (!requireExplanations)
|
|
14
|
+
return schema.extend({
|
|
15
|
+
explanation: optionalPlanningExplanationObjectSchema,
|
|
16
|
+
});
|
|
12
17
|
return includeExplanations
|
|
13
18
|
? schema.extend({
|
|
14
19
|
explanation: z.strictObject({
|
|
@@ -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
|
}
|
|
@@ -8,7 +8,9 @@ export function createConnectionMaterialRepairChoiceSchema(stages, factIds) {
|
|
|
8
8
|
if (!stage.nodeIds.length)
|
|
9
9
|
continue;
|
|
10
10
|
targets.push(workflowConnectionMaterialRepairTargetSchema.extend({
|
|
11
|
-
stage: z
|
|
11
|
+
stage: z
|
|
12
|
+
.literal(stage.stage)
|
|
13
|
+
.describe('Origin-stage ownership: api-bindings changes API producer references; api-arguments changes only API literals/requested inputs and retains bindings; native-dependencies changes native producer IDs and then regenerates its settings; native-parameters changes settings or pointers while retaining the existing producer IDs. Request native-dependencies for a producer substitution, not native-parameters alone.'),
|
|
12
14
|
nodeId: z.enum(stage.nodeIds),
|
|
13
15
|
}));
|
|
14
16
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Private, lossless model-output feedback; not a public progress/error payload. */
|
|
3
|
+
export declare const nativePlanningRejectionSchema: z.ZodObject<{
|
|
4
|
+
stage: z.ZodEnum<{
|
|
5
|
+
"instance-selection": "instance-selection";
|
|
6
|
+
"selection-review": "selection-review";
|
|
7
|
+
}>;
|
|
8
|
+
requestFingerprint: z.ZodString;
|
|
9
|
+
output: z.ZodJSONSchema;
|
|
10
|
+
reason: z.ZodString;
|
|
11
|
+
}, z.core.$strict>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Private, lossless model-output feedback; not a public progress/error payload. */
|
|
3
|
+
export const nativePlanningRejectionSchema = z.strictObject({
|
|
4
|
+
stage: z.enum(['instance-selection', 'selection-review']),
|
|
5
|
+
requestFingerprint: z.string().regex(/^[a-f0-9]{64}$/u),
|
|
6
|
+
output: z.json(),
|
|
7
|
+
reason: z.string().min(1),
|
|
8
|
+
});
|
|
@@ -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,
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
2
|
import type { z } from 'zod';
|
|
3
3
|
import type { createApiBindingSourceDecisionSchema } from '../schemas/api-call-binding-plan-schema.js';
|
|
4
|
-
import type { ApiCallBindingPlanningInput, ApiBindingSourceSelection, ApiCallBindingPlan, ApiBindingSourceProposal } from '@openapi-flow/core';
|
|
4
|
+
import type { ApiCallBindingPlanningInput, ApiBindingSourceSelection, ApiCallBindingPlan, ApiBindingSourceProposal, WorkflowConnectionApiRepairContext } from '@openapi-flow/core';
|
|
5
5
|
import type { PlanApiBindingsInput } from './binding-planning.js';
|
|
6
6
|
export type ApiBindingSourceDecisionOutput = z.infer<ReturnType<typeof createApiBindingSourceDecisionSchema>> & Pick<ApiBindingSourceProposal, 'reason'>;
|
|
7
7
|
export interface SelectApiBindingSourcesInput extends ApiCallBindingPlanningInput {
|
|
8
8
|
model: BaseChatModel;
|
|
9
9
|
signal?: AbortSignal;
|
|
10
|
+
materialRepair?: WorkflowConnectionApiRepairContext;
|
|
10
11
|
}
|
|
11
12
|
export interface PlanApiCallBindingsInput extends SelectApiBindingSourcesInput {
|
|
12
13
|
sources: ApiBindingSourceSelection;
|