@salesforce/graphiti 10.10.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/AGENT_GUIDE.md +424 -0
- package/CHANGELOG.md +448 -0
- package/LICENSE.txt +82 -0
- package/README.md +204 -0
- package/TASK.md +249 -0
- package/dist/cli.d.ts +7 -0
- package/dist/cli.js +683 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/args.d.ts +13 -0
- package/dist/commands/args.js +207 -0
- package/dist/commands/args.js.map +1 -0
- package/dist/commands/build.d.ts +11 -0
- package/dist/commands/build.js +209 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/connect.d.ts +8 -0
- package/dist/commands/connect.js +55 -0
- package/dist/commands/connect.js.map +1 -0
- package/dist/commands/describe.d.ts +6 -0
- package/dist/commands/describe.js +229 -0
- package/dist/commands/describe.js.map +1 -0
- package/dist/commands/meta.d.ts +9 -0
- package/dist/commands/meta.js +140 -0
- package/dist/commands/meta.js.map +1 -0
- package/dist/commands/navigate.d.ts +14 -0
- package/dist/commands/navigate.js +105 -0
- package/dist/commands/navigate.js.map +1 -0
- package/dist/commands/query-helpers.d.ts +80 -0
- package/dist/commands/query-helpers.js +865 -0
- package/dist/commands/query-helpers.js.map +1 -0
- package/dist/commands/query.d.ts +26 -0
- package/dist/commands/query.js +901 -0
- package/dist/commands/query.js.map +1 -0
- package/dist/commands/review.d.ts +18 -0
- package/dist/commands/review.js +533 -0
- package/dist/commands/review.js.map +1 -0
- package/dist/commands/session-mgmt.d.ts +25 -0
- package/dist/commands/session-mgmt.js +206 -0
- package/dist/commands/session-mgmt.js.map +1 -0
- package/dist/commands/type.d.ts +6 -0
- package/dist/commands/type.js +342 -0
- package/dist/commands/type.js.map +1 -0
- package/dist/commands/validate-input.d.ts +6 -0
- package/dist/commands/validate-input.js +32 -0
- package/dist/commands/validate-input.js.map +1 -0
- package/dist/intent/build-aggregate.d.ts +33 -0
- package/dist/intent/build-aggregate.js +134 -0
- package/dist/intent/build-aggregate.js.map +1 -0
- package/dist/intent/build-create.d.ts +14 -0
- package/dist/intent/build-create.js +16 -0
- package/dist/intent/build-create.js.map +1 -0
- package/dist/intent/build-delete.d.ts +30 -0
- package/dist/intent/build-delete.js +53 -0
- package/dist/intent/build-delete.js.map +1 -0
- package/dist/intent/build-detail.d.ts +32 -0
- package/dist/intent/build-detail.js +80 -0
- package/dist/intent/build-detail.js.map +1 -0
- package/dist/intent/build-discover.d.ts +30 -0
- package/dist/intent/build-discover.js +149 -0
- package/dist/intent/build-discover.js.map +1 -0
- package/dist/intent/build-list.d.ts +28 -0
- package/dist/intent/build-list.js +75 -0
- package/dist/intent/build-list.js.map +1 -0
- package/dist/intent/build-mutation.d.ts +23 -0
- package/dist/intent/build-mutation.js +54 -0
- package/dist/intent/build-mutation.js.map +1 -0
- package/dist/intent/build-output.d.ts +27 -0
- package/dist/intent/build-output.js +60 -0
- package/dist/intent/build-output.js.map +1 -0
- package/dist/intent/build-raw.d.ts +23 -0
- package/dist/intent/build-raw.js +54 -0
- package/dist/intent/build-raw.js.map +1 -0
- package/dist/intent/build-update.d.ts +14 -0
- package/dist/intent/build-update.js +16 -0
- package/dist/intent/build-update.js.map +1 -0
- package/dist/intent/get-schema-with-priming.d.ts +26 -0
- package/dist/intent/get-schema-with-priming.js +32 -0
- package/dist/intent/get-schema-with-priming.js.map +1 -0
- package/dist/intent/select-child-relationship.d.ts +19 -0
- package/dist/intent/select-child-relationship.js +38 -0
- package/dist/intent/select-child-relationship.js.map +1 -0
- package/dist/intent/types.d.ts +159 -0
- package/dist/intent/types.js +21 -0
- package/dist/intent/types.js.map +1 -0
- package/dist/lib/apply-command.d.ts +15 -0
- package/dist/lib/apply-command.js +238 -0
- package/dist/lib/apply-command.js.map +1 -0
- package/dist/lib/auth.d.ts +38 -0
- package/dist/lib/auth.js +113 -0
- package/dist/lib/auth.js.map +1 -0
- package/dist/lib/codegen.d.ts +32 -0
- package/dist/lib/codegen.js +700 -0
- package/dist/lib/codegen.js.map +1 -0
- package/dist/lib/command-registry.d.ts +59 -0
- package/dist/lib/command-registry.js +366 -0
- package/dist/lib/command-registry.js.map +1 -0
- package/dist/lib/formatter.d.ts +76 -0
- package/dist/lib/formatter.js +419 -0
- package/dist/lib/formatter.js.map +1 -0
- package/dist/lib/fs-utils.d.ts +23 -0
- package/dist/lib/fs-utils.js +46 -0
- package/dist/lib/fs-utils.js.map +1 -0
- package/dist/lib/graphql-name.d.ts +27 -0
- package/dist/lib/graphql-name.js +32 -0
- package/dist/lib/graphql-name.js.map +1 -0
- package/dist/lib/interactive.d.ts +6 -0
- package/dist/lib/interactive.js +562 -0
- package/dist/lib/interactive.js.map +1 -0
- package/dist/lib/introspect.d.ts +40 -0
- package/dist/lib/introspect.js +280 -0
- package/dist/lib/introspect.js.map +1 -0
- package/dist/lib/object-info.d.ts +79 -0
- package/dist/lib/object-info.js +313 -0
- package/dist/lib/object-info.js.map +1 -0
- package/dist/lib/path-selection.d.ts +50 -0
- package/dist/lib/path-selection.js +146 -0
- package/dist/lib/path-selection.js.map +1 -0
- package/dist/lib/prime-schema.d.ts +59 -0
- package/dist/lib/prime-schema.js +158 -0
- package/dist/lib/prime-schema.js.map +1 -0
- package/dist/lib/query-builder.d.ts +10 -0
- package/dist/lib/query-builder.js +168 -0
- package/dist/lib/query-builder.js.map +1 -0
- package/dist/lib/query-commands.d.ts +19 -0
- package/dist/lib/query-commands.js +262 -0
- package/dist/lib/query-commands.js.map +1 -0
- package/dist/lib/session.d.ts +205 -0
- package/dist/lib/session.js +1075 -0
- package/dist/lib/session.js.map +1 -0
- package/dist/lib/tokenize.d.ts +12 -0
- package/dist/lib/tokenize.js +48 -0
- package/dist/lib/tokenize.js.map +1 -0
- package/dist/lib/uiapi.d.ts +109 -0
- package/dist/lib/uiapi.js +159 -0
- package/dist/lib/uiapi.js.map +1 -0
- package/dist/lib/validator.d.ts +27 -0
- package/dist/lib/validator.js +100 -0
- package/dist/lib/validator.js.map +1 -0
- package/dist/lib/variable-promotion.d.ts +69 -0
- package/dist/lib/variable-promotion.js +95 -0
- package/dist/lib/variable-promotion.js.map +1 -0
- package/dist/lib/walker.d.ts +147 -0
- package/dist/lib/walker.js +723 -0
- package/dist/lib/walker.js.map +1 -0
- package/dist/mcp/server.d.ts +7 -0
- package/dist/mcp/server.js +34 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/stdio.d.ts +7 -0
- package/dist/mcp/stdio.js +25 -0
- package/dist/mcp/stdio.js.map +1 -0
- package/dist/mcp/tools/echo.d.ts +7 -0
- package/dist/mcp/tools/echo.js +17 -0
- package/dist/mcp/tools/echo.js.map +1 -0
- package/dist/mcp/tools/sf-gql-aggregate.d.ts +11 -0
- package/dist/mcp/tools/sf-gql-aggregate.js +75 -0
- package/dist/mcp/tools/sf-gql-aggregate.js.map +1 -0
- package/dist/mcp/tools/sf-gql-create.d.ts +11 -0
- package/dist/mcp/tools/sf-gql-create.js +35 -0
- package/dist/mcp/tools/sf-gql-create.js.map +1 -0
- package/dist/mcp/tools/sf-gql-delete.d.ts +11 -0
- package/dist/mcp/tools/sf-gql-delete.js +31 -0
- package/dist/mcp/tools/sf-gql-delete.js.map +1 -0
- package/dist/mcp/tools/sf-gql-detail.d.ts +11 -0
- package/dist/mcp/tools/sf-gql-detail.js +58 -0
- package/dist/mcp/tools/sf-gql-detail.js.map +1 -0
- package/dist/mcp/tools/sf-gql-discover.d.ts +9 -0
- package/dist/mcp/tools/sf-gql-discover.js +51 -0
- package/dist/mcp/tools/sf-gql-discover.js.map +1 -0
- package/dist/mcp/tools/sf-gql-list.d.ts +11 -0
- package/dist/mcp/tools/sf-gql-list.js +53 -0
- package/dist/mcp/tools/sf-gql-list.js.map +1 -0
- package/dist/mcp/tools/sf-gql-raw.d.ts +11 -0
- package/dist/mcp/tools/sf-gql-raw.js +39 -0
- package/dist/mcp/tools/sf-gql-raw.js.map +1 -0
- package/dist/mcp/tools/sf-gql-update.d.ts +11 -0
- package/dist/mcp/tools/sf-gql-update.js +35 -0
- package/dist/mcp/tools/sf-gql-update.js.map +1 -0
- package/dist/mcp/tools/shared/zod-schemas.d.ts +49 -0
- package/dist/mcp/tools/shared/zod-schemas.js +46 -0
- package/dist/mcp/tools/shared/zod-schemas.js.map +1 -0
- package/package.json +36 -0
- package/ralph-loop.sh +120 -0
- package/scripts/smoke-orderby.sh +190 -0
- package/src/__tests__/helpers/prime-deps.ts +46 -0
- package/src/__tests__/helpers/schema.ts +73 -0
- package/src/__tests__/helpers/stdout.ts +33 -0
- package/src/__tests__/setup.ts +19 -0
- package/src/cli.ts +764 -0
- package/src/commands/__tests__/query.spec.ts +137 -0
- package/src/commands/args.ts +306 -0
- package/src/commands/build.ts +288 -0
- package/src/commands/connect.ts +60 -0
- package/src/commands/describe.ts +246 -0
- package/src/commands/meta.ts +171 -0
- package/src/commands/navigate.ts +134 -0
- package/src/commands/query-helpers.ts +1202 -0
- package/src/commands/query.ts +1085 -0
- package/src/commands/review.ts +670 -0
- package/src/commands/session-mgmt.ts +256 -0
- package/src/commands/type.ts +437 -0
- package/src/commands/validate-input.ts +38 -0
- package/src/intent/__tests__/build-aggregate.spec.ts +931 -0
- package/src/intent/__tests__/build-create-validation.spec.ts +135 -0
- package/src/intent/__tests__/build-delete.spec.ts +121 -0
- package/src/intent/__tests__/build-detail.spec.ts +333 -0
- package/src/intent/__tests__/build-discover.spec.ts +432 -0
- package/src/intent/__tests__/build-list.spec.ts +284 -0
- package/src/intent/__tests__/build-mutation.spec.ts +108 -0
- package/src/intent/__tests__/build-output.spec.ts +55 -0
- package/src/intent/__tests__/build-raw.spec.ts +153 -0
- package/src/intent/__tests__/build-update-validation.spec.ts +134 -0
- package/src/intent/build-aggregate.ts +182 -0
- package/src/intent/build-create.ts +19 -0
- package/src/intent/build-delete.ts +62 -0
- package/src/intent/build-detail.ts +95 -0
- package/src/intent/build-discover.ts +199 -0
- package/src/intent/build-list.ts +91 -0
- package/src/intent/build-mutation.ts +75 -0
- package/src/intent/build-output.ts +72 -0
- package/src/intent/build-raw.ts +61 -0
- package/src/intent/build-update.ts +19 -0
- package/src/intent/get-schema-with-priming.ts +43 -0
- package/src/intent/select-child-relationship.ts +48 -0
- package/src/intent/types.ts +181 -0
- package/src/lib/__tests__/apply-command.parity.spec.ts +97 -0
- package/src/lib/__tests__/apply-command.spec.ts +171 -0
- package/src/lib/__tests__/auth.spec.ts +292 -0
- package/src/lib/__tests__/formatter.spec.ts +86 -0
- package/src/lib/__tests__/graphql-name.spec.ts +64 -0
- package/src/lib/__tests__/introspect.spec.ts +399 -0
- package/src/lib/__tests__/object-info.spec.ts +124 -0
- package/src/lib/__tests__/path-selection.spec.ts +219 -0
- package/src/lib/__tests__/prime-schema.spec.ts +269 -0
- package/src/lib/__tests__/query-builder.spec.ts +95 -0
- package/src/lib/__tests__/query-commands.spec.ts +74 -0
- package/src/lib/__tests__/session.spec.ts +292 -0
- package/src/lib/__tests__/tokenize.spec.ts +33 -0
- package/src/lib/__tests__/uiapi.spec.ts +192 -0
- package/src/lib/__tests__/variable-promotion.spec.ts +211 -0
- package/src/lib/__tests__/walker.spec.ts +250 -0
- package/src/lib/apply-command.ts +286 -0
- package/src/lib/auth.ts +157 -0
- package/src/lib/codegen.ts +899 -0
- package/src/lib/command-registry.ts +434 -0
- package/src/lib/formatter.ts +587 -0
- package/src/lib/fs-utils.ts +46 -0
- package/src/lib/graphql-name.ts +35 -0
- package/src/lib/interactive.ts +634 -0
- package/src/lib/introspect.ts +320 -0
- package/src/lib/object-info.ts +409 -0
- package/src/lib/path-selection.ts +162 -0
- package/src/lib/prime-schema.ts +195 -0
- package/src/lib/query-builder.ts +193 -0
- package/src/lib/query-commands.ts +290 -0
- package/src/lib/session.ts +1304 -0
- package/src/lib/tokenize.ts +43 -0
- package/src/lib/uiapi.ts +176 -0
- package/src/lib/validator.ts +143 -0
- package/src/lib/variable-promotion.ts +145 -0
- package/src/lib/walker.ts +975 -0
- package/src/mcp/__tests__/server.spec.ts +155 -0
- package/src/mcp/server.ts +38 -0
- package/src/mcp/stdio.ts +29 -0
- package/src/mcp/tools/__tests__/sf-gql-aggregate.spec.ts +173 -0
- package/src/mcp/tools/__tests__/sf-gql-create.spec.ts +235 -0
- package/src/mcp/tools/__tests__/sf-gql-delete.spec.ts +194 -0
- package/src/mcp/tools/__tests__/sf-gql-detail.spec.ts +246 -0
- package/src/mcp/tools/__tests__/sf-gql-discover.spec.ts +320 -0
- package/src/mcp/tools/__tests__/sf-gql-list.spec.ts +128 -0
- package/src/mcp/tools/__tests__/sf-gql-raw.spec.ts +141 -0
- package/src/mcp/tools/__tests__/sf-gql-update.spec.ts +207 -0
- package/src/mcp/tools/echo.ts +24 -0
- package/src/mcp/tools/sf-gql-aggregate.ts +102 -0
- package/src/mcp/tools/sf-gql-create.ts +55 -0
- package/src/mcp/tools/sf-gql-delete.ts +49 -0
- package/src/mcp/tools/sf-gql-detail.ts +85 -0
- package/src/mcp/tools/sf-gql-discover.ts +67 -0
- package/src/mcp/tools/sf-gql-list.ts +73 -0
- package/src/mcp/tools/sf-gql-raw.ts +56 -0
- package/src/mcp/tools/sf-gql-update.ts +55 -0
- package/src/mcp/tools/shared/zod-schemas.ts +55 -0
- package/tsconfig.json +18 -0
- package/vitest.config.ts +14 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
import { getSchemaWithPriming } from "./get-schema-with-priming.js";
|
|
7
|
+
import { getOrgAuth as realGetOrgAuth } from "../lib/auth.js";
|
|
8
|
+
import { getObjectInfo as realGetObjectInfo, getRequiredCreateFields, } from "../lib/object-info.js";
|
|
9
|
+
import { resolvePath } from "../lib/walker.js";
|
|
10
|
+
/**
|
|
11
|
+
* Build the `sf_gql_discover` payload. Three modes:
|
|
12
|
+
*
|
|
13
|
+
* - `list_objects`: enumerate queryable SObjects from the schema's
|
|
14
|
+
* `uiapi.query` selection. Optional `search` substring-filters names.
|
|
15
|
+
* - `describe_object`: fetch ObjectInfo for `spec.object` and project it
|
|
16
|
+
* onto the spec-defined `ObjectDescription` shape.
|
|
17
|
+
* - `describe_field`: same as `describe_object`, narrowed to one field.
|
|
18
|
+
*
|
|
19
|
+
* Schema priming follows FR-13.3 — first call against an unprimed org
|
|
20
|
+
* triggers introspection and surfaces a `Note: Primed schema cache ...`
|
|
21
|
+
* warning. ObjectInfo carries its own per-object cache inside
|
|
22
|
+
* `lib/object-info.ts` (1-hour TTL), so describe_* modes do not
|
|
23
|
+
* re-introspect on every call.
|
|
24
|
+
*/
|
|
25
|
+
export async function buildDiscover(spec, deps = {}) {
|
|
26
|
+
const { schema, primingNote } = await getSchemaWithPriming(spec.org, deps.primeDeps);
|
|
27
|
+
const warnings = primingNote ? [primingNote] : [];
|
|
28
|
+
if (spec.mode === "list_objects") {
|
|
29
|
+
const objects = listQueryableObjects(schema, spec.search);
|
|
30
|
+
return { mode: "list_objects", objects, ...(warnings.length ? { warnings } : {}) };
|
|
31
|
+
}
|
|
32
|
+
if (!spec.object) {
|
|
33
|
+
throw new Error(`sf_gql_discover mode "${spec.mode}" requires "object".`);
|
|
34
|
+
}
|
|
35
|
+
const getAuth = deps.getOrgAuth ?? realGetOrgAuth;
|
|
36
|
+
const fetchObjectInfo = deps.getObjectInfo ?? realGetObjectInfo;
|
|
37
|
+
const auth = await getAuth(spec.org);
|
|
38
|
+
// ObjectInfo failures (auth expired, network blip, object missing) propagate
|
|
39
|
+
// to the caller. Earlier work tried a schema-only fallback that returned
|
|
40
|
+
// field names from the cached GraphQL schema, but that response cannot
|
|
41
|
+
// satisfy ObjectDescription (no picklists, no filterable/sortable flags,
|
|
42
|
+
// no requiredOnCreate) and silently invites consumers to treat absent
|
|
43
|
+
// metadata as authoritative absence. A loud error forces the right
|
|
44
|
+
// recovery (refresh auth, prime schema, retry).
|
|
45
|
+
const info = await fetchObjectInfo(auth, spec.org, spec.object);
|
|
46
|
+
if (spec.mode === "describe_field") {
|
|
47
|
+
if (!spec.field) {
|
|
48
|
+
throw new Error('sf_gql_discover mode "describe_field" requires "field".');
|
|
49
|
+
}
|
|
50
|
+
const field = info.fields.find((f) => f.apiName === spec.field);
|
|
51
|
+
if (!field) {
|
|
52
|
+
throw new Error(`Field "${spec.field}" not found on "${spec.object}". Use mode "describe_object" to list fields.`);
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
mode: "describe_field",
|
|
56
|
+
field: toFieldDescription(field, info),
|
|
57
|
+
...(warnings.length ? { warnings } : {}),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (spec.mode === "describe_object") {
|
|
61
|
+
return {
|
|
62
|
+
mode: "describe_object",
|
|
63
|
+
object: toObjectDescription(spec.object, info),
|
|
64
|
+
...(warnings.length ? { warnings } : {}),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
// Exhaustiveness guard: any new DiscoverMode added to types.ts must
|
|
68
|
+
// surface as a TS error here instead of silently falling through to
|
|
69
|
+
// describe_object.
|
|
70
|
+
throw new Error(`Unhandled discover mode: ${exhaustive(spec.mode)}`);
|
|
71
|
+
}
|
|
72
|
+
function exhaustive(value) {
|
|
73
|
+
throw new Error(`Unexpected value: ${String(value)}`);
|
|
74
|
+
}
|
|
75
|
+
function listQueryableObjects(schema, search) {
|
|
76
|
+
let result;
|
|
77
|
+
try {
|
|
78
|
+
const walker = resolvePath(schema, "query", ["uiapi", "query"]);
|
|
79
|
+
// uiapi.query exposes per-SObject Connection fields (Account, Contact, etc.)
|
|
80
|
+
// alongside non-SObject helpers (search, aggregate). Filter to fields whose
|
|
81
|
+
// return type follows the *Connection convention so list_objects matches
|
|
82
|
+
// the spec contract — "queryable SObjects" — instead of leaking helpers.
|
|
83
|
+
result = walker.fields
|
|
84
|
+
.filter((f) => /Connection$/.test(f.typeName.replace(/[![\]]/g, "")))
|
|
85
|
+
.map((f) => ({
|
|
86
|
+
name: f.name,
|
|
87
|
+
...(f.description ? { label: f.description } : {}),
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
if (search && search.trim().length > 0) {
|
|
94
|
+
const needle = search.toLowerCase();
|
|
95
|
+
result = result.filter((o) => o.name.toLowerCase().includes(needle));
|
|
96
|
+
}
|
|
97
|
+
result.sort((a, b) => a.name.localeCompare(b.name));
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
function toFieldDescription(field, info) {
|
|
101
|
+
const picklist = info.picklists.find((p) => p.apiName === field.apiName);
|
|
102
|
+
// `parseObjectInfoResponse` already drops null-valued entries, but the
|
|
103
|
+
// PicklistValue type still allows null — filter narrows to string[].
|
|
104
|
+
const picklistValues = picklist?.values.map((v) => v.value).filter((v) => v !== null) ?? [];
|
|
105
|
+
return {
|
|
106
|
+
name: field.apiName,
|
|
107
|
+
label: field.label ?? field.apiName,
|
|
108
|
+
type: field.dataType ?? "UNKNOWN",
|
|
109
|
+
filterable: field.filterable,
|
|
110
|
+
sortable: field.sortable,
|
|
111
|
+
nameField: field.nameField,
|
|
112
|
+
compound: field.compound,
|
|
113
|
+
defaultedOnCreate: field.defaultedOnCreate,
|
|
114
|
+
...(picklistValues.length > 0 ? { picklistValues } : {}),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function toObjectDescription(name, info) {
|
|
118
|
+
const fields = info.fields.map((f) => toFieldDescription(f, info));
|
|
119
|
+
const childRelationships = info.childRelationships
|
|
120
|
+
.filter((cr) => cr.relationshipName !== null)
|
|
121
|
+
.map((cr) => ({
|
|
122
|
+
relationshipName: cr.relationshipName,
|
|
123
|
+
childObject: cr.childObjectApiName,
|
|
124
|
+
}));
|
|
125
|
+
const parentReferences = info.fields
|
|
126
|
+
.filter((f) => f.reference && f.referenceToInfos.length > 0)
|
|
127
|
+
.map((f) => ({
|
|
128
|
+
field: f.apiName,
|
|
129
|
+
targetObjects: f.referenceToInfos.map((r) => r.apiName),
|
|
130
|
+
}));
|
|
131
|
+
const filterableFields = info.fields
|
|
132
|
+
.filter((f) => f.filterable && !f.compound)
|
|
133
|
+
.map((f) => f.apiName);
|
|
134
|
+
const sortable = info.fields.find((f) => f.sortable && !f.compound);
|
|
135
|
+
const orderByExample = sortable
|
|
136
|
+
? { [sortable.apiName]: { order: "DESC" } }
|
|
137
|
+
: {};
|
|
138
|
+
const requiredOnCreate = getRequiredCreateFields(info).map((f) => f.apiName);
|
|
139
|
+
return {
|
|
140
|
+
name,
|
|
141
|
+
fields,
|
|
142
|
+
childRelationships,
|
|
143
|
+
parentReferences,
|
|
144
|
+
filterableFields,
|
|
145
|
+
orderByExample,
|
|
146
|
+
requiredOnCreate,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=build-discover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-discover.js","sourceRoot":"","sources":["../../src/intent/build-discover.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAOpE,OAAO,EAAE,UAAU,IAAI,cAAc,EAAgB,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAEN,aAAa,IAAI,iBAAiB,EAClC,uBAAuB,GAEvB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAY/C;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAClC,IAAkB,EAClB,OAAqB,EAAE;IAEvB,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,oBAAoB,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACrF,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE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AAC;QACZ,KAAK,EAAE,CAAC,CAAC,OAAO;QAChB,aAAa,EAAE,CAAC,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;KACvD,CAAC,CAAC,CAAC;IAEL,MAAM,gBAAgB,GAAG,IAAI,CAAC,MAAM;SAClC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC;SAC1C,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAExB,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IACpE,MAAM,cAAc,GAA4B,QAAQ;QACvD,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;QAC3C,CAAC,CAAC,EAAE,CAAC;IAEN,MAAM,gBAAgB,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAE7E,OAAO;QACN,IAAI;QACJ,MAAM;QACN,kBAAkB;QAClB,gBAAgB;QAChB,gBAAgB;QAChB,cAAc;QACd,gBAAgB;KAChB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
import { type ListSpec, type ToolOutput } from "./types.js";
|
|
7
|
+
import { type PrimeDeps } from "../lib/prime-schema.js";
|
|
8
|
+
/**
|
|
9
|
+
* Build a UIAPI list query against a Salesforce org. Implements `sf_gql_list`
|
|
10
|
+
* intent for the graphiti MCP server.
|
|
11
|
+
*
|
|
12
|
+
* Implicit behaviors not visible in the signature:
|
|
13
|
+
* - Scalar fields are auto-wrapped with `{ value }` per UIAPI; `Id` is selected bare.
|
|
14
|
+
* - Dotted paths in `fields` / `parentFields` expand polymorphic unions into
|
|
15
|
+
* per-member inline fragments; members lacking the field are silently skipped.
|
|
16
|
+
* - `childRelationships` render as `<rel> { edges { node { ... } } }` connections.
|
|
17
|
+
* - `$varName` leaves anywhere in `filter` / `orderBy` / `scope` promote to typed
|
|
18
|
+
* query variables (inferred from the schema; nullable; `String` on inference miss).
|
|
19
|
+
* - `orderBy` arrays are collapsed to the first element (UIAPI expects a singleton).
|
|
20
|
+
* - Cursor pagination is always on: declares `$after: String`, selects
|
|
21
|
+
* `pageInfo { hasNextPage endCursor }`, defaults `first: 10`.
|
|
22
|
+
* - Operation name defaults to `<Object>List`.
|
|
23
|
+
*
|
|
24
|
+
* Throws on invalid `object` or `operationName` (must be valid GraphQL Names),
|
|
25
|
+
* auth-missing, or introspection failure (via `getSchemaWithPriming`); never
|
|
26
|
+
* throws on validation or codegen failure (those surface as `warnings[]`).
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildList(spec: ListSpec, deps?: PrimeDeps): Promise<ToolOutput>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
import { buildOutput } from "./build-output.js";
|
|
7
|
+
import { getSchemaWithPriming } from "./get-schema-with-priming.js";
|
|
8
|
+
import { selectChildRelationship } from "./select-child-relationship.js";
|
|
9
|
+
import { assertGraphqlName } from "../lib/graphql-name.js";
|
|
10
|
+
import { selectDottedFieldPath } from "../lib/path-selection.js";
|
|
11
|
+
import { addVariable, createSession, deepSetArg, selectLeaf } from "../lib/session.js";
|
|
12
|
+
import { normalizeOrderBy, promoteVariables } from "../lib/variable-promotion.js";
|
|
13
|
+
/**
|
|
14
|
+
* Build a UIAPI list query against a Salesforce org. Implements `sf_gql_list`
|
|
15
|
+
* intent for the graphiti MCP server.
|
|
16
|
+
*
|
|
17
|
+
* Implicit behaviors not visible in the signature:
|
|
18
|
+
* - Scalar fields are auto-wrapped with `{ value }` per UIAPI; `Id` is selected bare.
|
|
19
|
+
* - Dotted paths in `fields` / `parentFields` expand polymorphic unions into
|
|
20
|
+
* per-member inline fragments; members lacking the field are silently skipped.
|
|
21
|
+
* - `childRelationships` render as `<rel> { edges { node { ... } } }` connections.
|
|
22
|
+
* - `$varName` leaves anywhere in `filter` / `orderBy` / `scope` promote to typed
|
|
23
|
+
* query variables (inferred from the schema; nullable; `String` on inference miss).
|
|
24
|
+
* - `orderBy` arrays are collapsed to the first element (UIAPI expects a singleton).
|
|
25
|
+
* - Cursor pagination is always on: declares `$after: String`, selects
|
|
26
|
+
* `pageInfo { hasNextPage endCursor }`, defaults `first: 10`.
|
|
27
|
+
* - Operation name defaults to `<Object>List`.
|
|
28
|
+
*
|
|
29
|
+
* Throws on invalid `object` or `operationName` (must be valid GraphQL Names),
|
|
30
|
+
* auth-missing, or introspection failure (via `getSchemaWithPriming`); never
|
|
31
|
+
* throws on validation or codegen failure (those surface as `warnings[]`).
|
|
32
|
+
*/
|
|
33
|
+
export async function buildList(spec, deps) {
|
|
34
|
+
assertGraphqlName(spec.object, "buildList", "object");
|
|
35
|
+
const { schema, primingNote, instanceUrl } = await getSchemaWithPriming(spec.org, deps);
|
|
36
|
+
const session = createSession(spec.org, "query", instanceUrl);
|
|
37
|
+
session.operationName = spec.operationName ?? `${spec.object}List`;
|
|
38
|
+
assertGraphqlName(session.operationName, "buildList", "operationName");
|
|
39
|
+
const connectionPath = ["uiapi", "query", spec.object];
|
|
40
|
+
const nodePath = [...connectionPath, "edges", "node"];
|
|
41
|
+
for (const field of spec.fields) {
|
|
42
|
+
selectDottedFieldPath(session, schema, nodePath, field);
|
|
43
|
+
}
|
|
44
|
+
if (spec.parentFields) {
|
|
45
|
+
for (const pf of spec.parentFields) {
|
|
46
|
+
selectDottedFieldPath(session, schema, nodePath, pf);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (spec.childRelationships) {
|
|
50
|
+
for (const child of spec.childRelationships) {
|
|
51
|
+
selectChildRelationship(session, schema, nodePath, child);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const first = spec.first ?? 10;
|
|
55
|
+
deepSetArg(session, connectionPath, "first", [], String(first));
|
|
56
|
+
addVariable(session, "after", "String");
|
|
57
|
+
deepSetArg(session, connectionPath, "after", [], "$after");
|
|
58
|
+
selectLeaf(session, [...connectionPath, "pageInfo", "hasNextPage"]);
|
|
59
|
+
selectLeaf(session, [...connectionPath, "pageInfo", "endCursor"]);
|
|
60
|
+
if (spec.filter) {
|
|
61
|
+
promoteVariables(session, schema, connectionPath, "where", spec.filter);
|
|
62
|
+
deepSetArg(session, connectionPath, "where", [], JSON.stringify(spec.filter));
|
|
63
|
+
}
|
|
64
|
+
const orderBy = normalizeOrderBy(spec.orderBy);
|
|
65
|
+
if (orderBy) {
|
|
66
|
+
promoteVariables(session, schema, connectionPath, "orderBy", orderBy);
|
|
67
|
+
deepSetArg(session, connectionPath, "orderBy", [], JSON.stringify(orderBy));
|
|
68
|
+
}
|
|
69
|
+
if (spec.scope) {
|
|
70
|
+
promoteVariables(session, schema, connectionPath, "scope", spec.scope);
|
|
71
|
+
deepSetArg(session, connectionPath, "scope", [], spec.scope);
|
|
72
|
+
}
|
|
73
|
+
return buildOutput(session, schema, primingNote);
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=build-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-list.js","sourceRoot":"","sources":["../../src/intent/build-list.ts"],"names":[],"mappings":"AAAA;;;;GA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CAAC;IAED,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/C,IAAI,OAAO,EAAE,CAAC;QACb,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QACtE,UAAU,CAAC,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7E,CAAC;IAED,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;QAChB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACvE,UAAU,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
import { type CreateSpec, type ToolOutput, type UpdateSpec } from "./types.js";
|
|
7
|
+
import { type PrimeDeps } from "../lib/prime-schema.js";
|
|
8
|
+
export type MutationOp = "Create" | "Update";
|
|
9
|
+
/**
|
|
10
|
+
* Build a UIAPI Create/Update mutation against a Salesforce org. Shared
|
|
11
|
+
* implementation for `sf_gql_create` and `sf_gql_update` (FR-5.6).
|
|
12
|
+
*
|
|
13
|
+
* Implicit behaviors:
|
|
14
|
+
* - `returnFields` defaults to `["Id"]`.
|
|
15
|
+
* - `inputVariable` defaults to `"input"`; a leading `$` is stripped.
|
|
16
|
+
* - Operation name defaults to `<Op><Object>` (e.g. `CreateAccount`, `UpdateAccount`).
|
|
17
|
+
* - The `input` argument on the mutation field is bound to the declared variable.
|
|
18
|
+
*
|
|
19
|
+
* Throws on invalid `object`/`inputVariable`/`operationName` GraphQL Names, empty
|
|
20
|
+
* `returnFields`, auth-missing, or introspection failure. Never throws on
|
|
21
|
+
* validation/codegen failure (those surface as `warnings[]`).
|
|
22
|
+
*/
|
|
23
|
+
export declare function buildMutation(spec: CreateSpec | UpdateSpec, op: MutationOp, deps?: PrimeDeps): Promise<ToolOutput>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
import { buildOutput } from "./build-output.js";
|
|
7
|
+
import { getSchemaWithPriming } from "./get-schema-with-priming.js";
|
|
8
|
+
import { assertGraphqlName } from "../lib/graphql-name.js";
|
|
9
|
+
import { selectDottedFieldPath } from "../lib/path-selection.js";
|
|
10
|
+
import { addVariable, createSession, deepSetArg } from "../lib/session.js";
|
|
11
|
+
import { createInputTypeName, mutationFieldPath, mutationRecordPath, updateInputTypeName, } from "../lib/uiapi.js";
|
|
12
|
+
/**
|
|
13
|
+
* Build a UIAPI Create/Update mutation against a Salesforce org. Shared
|
|
14
|
+
* implementation for `sf_gql_create` and `sf_gql_update` (FR-5.6).
|
|
15
|
+
*
|
|
16
|
+
* Implicit behaviors:
|
|
17
|
+
* - `returnFields` defaults to `["Id"]`.
|
|
18
|
+
* - `inputVariable` defaults to `"input"`; a leading `$` is stripped.
|
|
19
|
+
* - Operation name defaults to `<Op><Object>` (e.g. `CreateAccount`, `UpdateAccount`).
|
|
20
|
+
* - The `input` argument on the mutation field is bound to the declared variable.
|
|
21
|
+
*
|
|
22
|
+
* Throws on invalid `object`/`inputVariable`/`operationName` GraphQL Names, empty
|
|
23
|
+
* `returnFields`, auth-missing, or introspection failure. Never throws on
|
|
24
|
+
* validation/codegen failure (those surface as `warnings[]`).
|
|
25
|
+
*/
|
|
26
|
+
export async function buildMutation(spec, op, deps) {
|
|
27
|
+
assertGraphqlName(spec.object, "buildMutation", "object");
|
|
28
|
+
const inputVar = (spec.inputVariable ?? "input").replace(/^\$/, "");
|
|
29
|
+
assertGraphqlName(inputVar, "buildMutation", "inputVariable");
|
|
30
|
+
if (spec.returnFields !== undefined && spec.returnFields.length === 0) {
|
|
31
|
+
throw new Error("buildMutation: returnFields must contain at least one field");
|
|
32
|
+
}
|
|
33
|
+
const { schema, primingNote, instanceUrl } = await getSchemaWithPriming(spec.org, deps);
|
|
34
|
+
const session = createSession(spec.org, "mutation", instanceUrl);
|
|
35
|
+
session.operationName = spec.operationName ?? op + spec.object;
|
|
36
|
+
assertGraphqlName(session.operationName, "buildMutation", "operationName");
|
|
37
|
+
const fieldPath = mutationFieldPath(spec.object, op);
|
|
38
|
+
const recordPath = mutationRecordPath(spec.object, op);
|
|
39
|
+
const inputTypeName = op === "Create" ? createInputTypeName(spec.object) : updateInputTypeName(spec.object);
|
|
40
|
+
addVariable(session, inputVar, inputTypeName + "!");
|
|
41
|
+
deepSetArg(session, fieldPath, "input", [], "$" + inputVar);
|
|
42
|
+
const extraWarnings = [];
|
|
43
|
+
for (const field of spec.returnFields ?? ["Id"]) {
|
|
44
|
+
try {
|
|
45
|
+
selectDottedFieldPath(session, schema, recordPath, field);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
49
|
+
extraWarnings.push(`returnFields: ${msg}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return buildOutput(session, schema, primingNote, extraWarnings);
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=build-mutation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-mutation.js","sourceRoot":"","sources":["../../src/intent/build-mutation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,E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.txt file
|
|
5
|
+
*/
|
|
6
|
+
import { type GraphQLSchema } from "graphql";
|
|
7
|
+
import { type ToolOutput } from "./types.js";
|
|
8
|
+
import { type QuerySession } from "../lib/session.js";
|
|
9
|
+
/**
|
|
10
|
+
* Render → validate → codegen → assemble. Shared finalizer for every typed
|
|
11
|
+
* intent function (`buildList`, `buildDetail`, …).
|
|
12
|
+
*
|
|
13
|
+
* Never throws. Failure modes surface as entries in `warnings[]`:
|
|
14
|
+
* - `Validation: <msg>` — non-schema-level errors from `graphql-js validate()`.
|
|
15
|
+
* - `Validation: schema check skipped (<msg>)` — `validate()` itself crashed.
|
|
16
|
+
* - `Codegen: <msg>` — `generateTypes()` threw; `types` becomes `// Type generation failed: <msg>`.
|
|
17
|
+
*
|
|
18
|
+
* Schema-level errors (e.g. "Input Object type X must define one or more fields"
|
|
19
|
+
* raised by malformed UIAPI schemas, not by the user's query) are filtered out
|
|
20
|
+
* per FR-9.2.
|
|
21
|
+
*
|
|
22
|
+
* `primingNote` (if provided) is prepended to `warnings[]` so callers can surface
|
|
23
|
+
* the FR-13.3 lazy-prime notification without a separate channel. `extraWarnings`
|
|
24
|
+
* are appended after schema-validation warnings — used by intent builders to
|
|
25
|
+
* surface non-validator findings (e.g. malformed `$var` placeholders).
|
|
26
|
+
*/
|
|
27
|
+
export declare function buildOutput(session: QuerySession, schema: GraphQLSchema, primingNote?: string, extraWarnings?: string[]): ToolOutput;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
import { generateTypes } from "../lib/codegen.js";
|
|
7
|
+
import { renderQuery } from "../lib/query-builder.js";
|
|
8
|
+
import { validateQuery } from "../lib/validator.js";
|
|
9
|
+
const SCHEMA_LEVEL_ERROR_MARKERS = ["must define one or more fields"];
|
|
10
|
+
/**
|
|
11
|
+
* Render → validate → codegen → assemble. Shared finalizer for every typed
|
|
12
|
+
* intent function (`buildList`, `buildDetail`, …).
|
|
13
|
+
*
|
|
14
|
+
* Never throws. Failure modes surface as entries in `warnings[]`:
|
|
15
|
+
* - `Validation: <msg>` — non-schema-level errors from `graphql-js validate()`.
|
|
16
|
+
* - `Validation: schema check skipped (<msg>)` — `validate()` itself crashed.
|
|
17
|
+
* - `Codegen: <msg>` — `generateTypes()` threw; `types` becomes `// Type generation failed: <msg>`.
|
|
18
|
+
*
|
|
19
|
+
* Schema-level errors (e.g. "Input Object type X must define one or more fields"
|
|
20
|
+
* raised by malformed UIAPI schemas, not by the user's query) are filtered out
|
|
21
|
+
* per FR-9.2.
|
|
22
|
+
*
|
|
23
|
+
* `primingNote` (if provided) is prepended to `warnings[]` so callers can surface
|
|
24
|
+
* the FR-13.3 lazy-prime notification without a separate channel. `extraWarnings`
|
|
25
|
+
* are appended after schema-validation warnings — used by intent builders to
|
|
26
|
+
* surface non-validator findings (e.g. malformed `$var` placeholders).
|
|
27
|
+
*/
|
|
28
|
+
export function buildOutput(session, schema, primingNote, extraWarnings = []) {
|
|
29
|
+
const query = renderQuery(session);
|
|
30
|
+
const warnings = primingNote ? [primingNote] : [];
|
|
31
|
+
try {
|
|
32
|
+
const errors = validateQuery(schema, query);
|
|
33
|
+
for (const err of errors) {
|
|
34
|
+
if (SCHEMA_LEVEL_ERROR_MARKERS.some((m) => err.message.includes(m)))
|
|
35
|
+
continue;
|
|
36
|
+
warnings.push(`Validation: ${err.message}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
41
|
+
warnings.push(`Validation: schema check skipped (${message})`);
|
|
42
|
+
}
|
|
43
|
+
let types;
|
|
44
|
+
try {
|
|
45
|
+
types = generateTypes(session, schema);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
49
|
+
types = `// Type generation failed: ${message}`;
|
|
50
|
+
warnings.push(`Codegen: ${message}`);
|
|
51
|
+
}
|
|
52
|
+
const variables = session.variables.map((v) => ({
|
|
53
|
+
name: v.name,
|
|
54
|
+
type: v.type,
|
|
55
|
+
required: v.type.endsWith("!"),
|
|
56
|
+
}));
|
|
57
|
+
warnings.push(...extraWarnings);
|
|
58
|
+
return { query, variables, types, warnings };
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=build-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-output.js","sourceRoot":"","sources":["../../src/intent/build-output.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,0BAA0B,GAAG,CAAC,gCAAgC,CAAC,CAAC;AAEtE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,WAAW,CAC1B,OAAqB,EACrB,MAAqB,EACrB,WAAoB,EACpB,gBAA0B,EAAE;IAE5B,MAAM,KAAK,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IACnC,MAAM,QAAQ,GAAa,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAE5D,IAAI,CAAC;QACJ,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAC5C,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;YAC1B,IAAI,0BAA0B,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;gBAAE,SAAS;YAC9E,QAAQ,CAAC,IAAI,CAAC,eAAe,GAAG,CAAC,OAAO,EAA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
import { type RawSpec, type ToolOutput } from "./types.js";
|
|
7
|
+
import { type PrimeDeps } from "../lib/prime-schema.js";
|
|
8
|
+
/**
|
|
9
|
+
* Build an arbitrary UIAPI operation from CLI-style commands. Implements
|
|
10
|
+
* `sf_gql_raw` — the low-level escape hatch (FR-12) for operations the typed
|
|
11
|
+
* tools do not model (cross-union selections, custom mutations).
|
|
12
|
+
*
|
|
13
|
+
* `operation` selects the session root (query/mutation/aggregate); the agent
|
|
14
|
+
* hand-drives every selection. No typed-tool sugar (no aggregations[] handling,
|
|
15
|
+
* no auto-pagination, no Id defaulting).
|
|
16
|
+
*
|
|
17
|
+
* Fails fast: the first command that cannot be applied throws
|
|
18
|
+
* `command <i> (<cmd>): <why>`. Throws on an invalid `typeName` (must be a valid
|
|
19
|
+
* GraphQL Name), auth-missing / introspection failure (via getSchemaWithPriming)
|
|
20
|
+
* and on empty `commands`. Never throws on validation or codegen failure (those
|
|
21
|
+
* surface as warnings[]).
|
|
22
|
+
*/
|
|
23
|
+
export declare function buildRaw(spec: RawSpec, deps?: PrimeDeps): Promise<ToolOutput>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
import { buildOutput } from "./build-output.js";
|
|
7
|
+
import { getSchemaWithPriming } from "./get-schema-with-priming.js";
|
|
8
|
+
import { applyCommand } from "../lib/apply-command.js";
|
|
9
|
+
import { assertGraphqlName } from "../lib/graphql-name.js";
|
|
10
|
+
import { createSession } from "../lib/session.js";
|
|
11
|
+
const DEFAULT_OP_NAME = {
|
|
12
|
+
query: "RawQuery",
|
|
13
|
+
mutation: "RawMutation",
|
|
14
|
+
aggregate: "RawAggregate",
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Build an arbitrary UIAPI operation from CLI-style commands. Implements
|
|
18
|
+
* `sf_gql_raw` — the low-level escape hatch (FR-12) for operations the typed
|
|
19
|
+
* tools do not model (cross-union selections, custom mutations).
|
|
20
|
+
*
|
|
21
|
+
* `operation` selects the session root (query/mutation/aggregate); the agent
|
|
22
|
+
* hand-drives every selection. No typed-tool sugar (no aggregations[] handling,
|
|
23
|
+
* no auto-pagination, no Id defaulting).
|
|
24
|
+
*
|
|
25
|
+
* Fails fast: the first command that cannot be applied throws
|
|
26
|
+
* `command <i> (<cmd>): <why>`. Throws on an invalid `typeName` (must be a valid
|
|
27
|
+
* GraphQL Name), auth-missing / introspection failure (via getSchemaWithPriming)
|
|
28
|
+
* and on empty `commands`. Never throws on validation or codegen failure (those
|
|
29
|
+
* surface as warnings[]).
|
|
30
|
+
*/
|
|
31
|
+
export async function buildRaw(spec, deps) {
|
|
32
|
+
if (!spec.commands || spec.commands.length === 0) {
|
|
33
|
+
throw new Error("buildRaw: commands must contain at least one command");
|
|
34
|
+
}
|
|
35
|
+
const operation = spec.operation ?? "query";
|
|
36
|
+
const { schema, primingNote, instanceUrl } = await getSchemaWithPriming(spec.org, deps);
|
|
37
|
+
const session = createSession(spec.org, operation, instanceUrl);
|
|
38
|
+
// `typeName` lands only in the rendered operation-name position (buildOutput
|
|
39
|
+
// runs codegen without a typeName option), so it carries the GraphQL Name
|
|
40
|
+
// constraint just like the typed builders' `operationName`.
|
|
41
|
+
session.operationName = spec.typeName ?? DEFAULT_OP_NAME[operation];
|
|
42
|
+
assertGraphqlName(session.operationName, "buildRaw", "typeName");
|
|
43
|
+
spec.commands.forEach((cmd, i) => {
|
|
44
|
+
try {
|
|
45
|
+
applyCommand(session, schema, cmd);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
49
|
+
throw new Error(`command ${i} (${cmd}): ${msg}`);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return buildOutput(session, schema, primingNote);
|
|
53
|
+
}
|
|
54
|
+
//# sourceM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C,CAAC;IAEjE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE;QAChC,IAAI,CAAC;YACJ,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QACpC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC7D,MAAM,IAAI,KAAK,CAAC,WAAW,CAAC,KAAK,GAAG,MAAM,GAAG,EAAE,CAAC,CAAC;QAClD,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
import { type ToolOutput, type UpdateSpec } from "./types.js";
|
|
7
|
+
import { type PrimeDeps } from "../lib/prime-schema.js";
|
|
8
|
+
/**
|
|
9
|
+
* Build a UIAPI update mutation against a Salesforce org. Implements
|
|
10
|
+
* `sf_gql_update` intent for the graphiti MCP server (FR-5.6). Thin
|
|
11
|
+
* wrapper around `buildMutation` with `op = "Update"`; see that helper
|
|
12
|
+
* for behavior details.
|
|
13
|
+
*/
|
|
14
|
+
export declare function buildUpdate(spec: UpdateSpec, deps?: PrimeDeps): Promise<ToolOutput>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
import { buildMutation } from "./build-mutation.js";
|
|
7
|
+
/**
|
|
8
|
+
* Build a UIAPI update mutation against a Salesforce org. Implements
|
|
9
|
+
* `sf_gql_update` intent for the graphiti MCP server (FR-5.6). Thin
|
|
10
|
+
* wrapper around `buildMutation` with `op = "Update"`; see that helper
|
|
11
|
+
* for behavior details.
|
|
12
|
+
*/
|
|
13
|
+
export async function buildUpdate(spec, deps) {
|
|
14
|
+
return buildMutation(spec, "Update", deps);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=build-update.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-update.js","sourceRoot":"","sources":["../../src/intent/build-update.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIpD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAgB,EAAE,IAAgB;IACnE,OAAO,aAAa,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
import { type GraphQLSchema } from "graphql";
|
|
7
|
+
import { type PrimeDeps } from "../lib/prime-schema.js";
|
|
8
|
+
export interface SchemaWithPriming {
|
|
9
|
+
schema: GraphQLSchema;
|
|
10
|
+
instanceUrl: string;
|
|
11
|
+
primingNote?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Resolve the schema for `orgAlias`, lazily priming the on-disk cache on miss.
|
|
15
|
+
*
|
|
16
|
+
* - Cache hit → `{ schema, instanceUrl }` only.
|
|
17
|
+
* - Cache miss + auth resolves → introspects, writes cache, returns
|
|
18
|
+
* `{ schema, instanceUrl, primingNote: 'Note: Primed schema cache for "<org>" (took Nms)' }`.
|
|
19
|
+
* Callers thread the note into their `ToolOutput.warnings[]` per FR-13.3.
|
|
20
|
+
* - Auth missing or introspection failure → throws (FR-13.5 / FR-13.6).
|
|
21
|
+
*
|
|
22
|
+
* The returned schema is loaded by instance URL (auth-free fast path), so the
|
|
23
|
+
* cost of `getSchema(prime.instanceUrl)` is just a Map lookup after the first
|
|
24
|
+
* call per process.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getSchemaWithPriming(orgAlias: string, deps?: PrimeDeps): Promise<SchemaWithPriming>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
import { primeSchemaWithLock } from "../lib/prime-schema.js";
|
|
7
|
+
import { getSchema } from "../lib/walker.js";
|
|
8
|
+
/**
|
|
9
|
+
* Resolve the schema for `orgAlias`, lazily priming the on-disk cache on miss.
|
|
10
|
+
*
|
|
11
|
+
* - Cache hit → `{ schema, instanceUrl }` only.
|
|
12
|
+
* - Cache miss + auth resolves → introspects, writes cache, returns
|
|
13
|
+
* `{ schema, instanceUrl, primingNote: 'Note: Primed schema cache for "<org>" (took Nms)' }`.
|
|
14
|
+
* Callers thread the note into their `ToolOutput.warnings[]` per FR-13.3.
|
|
15
|
+
* - Auth missing or introspection failure → throws (FR-13.5 / FR-13.6).
|
|
16
|
+
*
|
|
17
|
+
* The returned schema is loaded by instance URL (auth-free fast path), so the
|
|
18
|
+
* cost of `getSchema(prime.instanceUrl)` is just a Map lookup after the first
|
|
19
|
+
* call per process.
|
|
20
|
+
*/
|
|
21
|
+
export async function getSchemaWithPriming(orgAlias, deps) {
|
|
22
|
+
const prime = await primeSchemaWithLock(orgAlias, deps);
|
|
23
|
+
const schema = getSchema(prime.instanceUrl);
|
|
24
|
+
const base = { schema, instanceUrl: prime.instanceUrl };
|
|
25
|
+
return prime.cached
|
|
26
|
+
? base
|
|
27
|
+
: {
|
|
28
|
+
...base,
|
|
29
|
+
primingNote: `Note: Primed schema cache for "${orgAlias}" (took ${prime.durationMs}ms)`,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=get-schema-with-priming.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-schema-with-priming.js","sourceRoot":"","sources":["../../src/intent/get-schema-with-priming.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,mBAAmB,EAAkB,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAQ7C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACzC,QAAgB,EAChB,IAAgB;IAEhB,MAAM,KAAK,GAAG,MAAM,mBAAmB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACxD,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC5C,MAAM,IAAI,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC;IACxD,OAAO,KAAK,CAAC,MAAM;QAClB,CAAC,CAAC,IAAI;QACN,CAAC,CAAC;YACA,GAAG,IAAI;YACP,WAAW,EAAE,kCAAkC,QAAQ,WAAW,KAAK,CAAC,UAAU,KAAK;SACvF,CAAC;AACL,CAAC"}
|