@sanity/client 6.29.0-generate.0 → 6.29.0-generate.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/dist/index.browser.cjs +44 -0
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +354 -277
- package/dist/index.browser.d.ts +354 -277
- package/dist/index.browser.js +44 -0
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +45 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +354 -266
- package/dist/index.d.ts +354 -266
- package/dist/index.js +45 -1
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +351 -263
- package/dist/stega.browser.d.ts +351 -263
- package/dist/stega.d.cts +351 -263
- package/dist/stega.d.ts +351 -263
- package/package.json +1 -1
- package/src/agent/actions/AgentActionsClient.ts +86 -9
- package/src/agent/actions/{types.ts → commonTypes.ts} +36 -156
- package/src/agent/actions/generate.ts +152 -1
- package/src/agent/actions/transform.ts +107 -0
- package/src/agent/actions/translate.ts +120 -0
- package/src/types.ts +26 -8
- package/umd/sanityClient.js +44 -0
- package/umd/sanityClient.min.js +2 -2
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AgentActionAsync,
|
|
3
|
+
AgentActionPathSegment,
|
|
4
|
+
AgentActionRequestBase,
|
|
5
|
+
AgentActionSync,
|
|
6
|
+
AgentActionTarget,
|
|
7
|
+
AgentActionTargetInclude,
|
|
8
|
+
} from '@sanity/client/agent/actions/commonTypes'
|
|
9
|
+
import {type Observable} from 'rxjs'
|
|
10
|
+
|
|
11
|
+
import {_request} from '../../data/dataMethods'
|
|
12
|
+
import type {ObservableSanityClient, SanityClient} from '../../SanityClient'
|
|
13
|
+
import type {AgentActionParams, Any, HttpRequest, IdentifiedSanityDocumentStub} from '../../types'
|
|
14
|
+
import {hasDataset} from '../../validators'
|
|
15
|
+
|
|
16
|
+
/** @beta */
|
|
17
|
+
export interface TransformRequestBase extends AgentActionRequestBase {
|
|
18
|
+
/** schemaId as reported by sanity deploy / sanity schema store */
|
|
19
|
+
schemaId: string
|
|
20
|
+
|
|
21
|
+
documentId: string
|
|
22
|
+
targetDocument?: TransformTargetDocument
|
|
23
|
+
|
|
24
|
+
/** string template using $variable */
|
|
25
|
+
transformation: string
|
|
26
|
+
/** param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable" */
|
|
27
|
+
transformationParams?: AgentActionParams
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Target defines which parts of the document will be affected by the instruction.
|
|
31
|
+
* It can be an array, so multiple parts of the document can be separately configured in detail.
|
|
32
|
+
*
|
|
33
|
+
* Omitting target implies that the document itself is the root.
|
|
34
|
+
*
|
|
35
|
+
* Notes:
|
|
36
|
+
* - instruction can only affect fields up to `maxPathDepth`
|
|
37
|
+
* - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
|
|
38
|
+
* It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
|
|
39
|
+
*
|
|
40
|
+
* @see AgentActionRequestBase#conditionalPaths
|
|
41
|
+
*/
|
|
42
|
+
target?: TransformTarget | TransformTarget[]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** @beta */
|
|
46
|
+
export type TransformTargetDocument =
|
|
47
|
+
| {operation: 'get'; _id: string}
|
|
48
|
+
| {operation: 'create'; _id?: string}
|
|
49
|
+
| {operation: 'createIfNotExists'; _id: string}
|
|
50
|
+
| {operation: 'createOrReplace'; _id: string}
|
|
51
|
+
|
|
52
|
+
/** @beta */
|
|
53
|
+
export interface TransformTargetInclude extends AgentActionTargetInclude {
|
|
54
|
+
/** string template using $variable from instructionParams */
|
|
55
|
+
transformation?: string
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* By default, all children up to `target.maxPathDepth` are included.
|
|
59
|
+
*
|
|
60
|
+
* When `include` is specified, only segments explicitly listed will be included.
|
|
61
|
+
*
|
|
62
|
+
* Fields or array items not on the include list, are implicitly excluded.
|
|
63
|
+
*/
|
|
64
|
+
include?: (AgentActionPathSegment | TransformTargetInclude)[]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** @beta */
|
|
68
|
+
export interface TransformTarget extends AgentActionTarget {
|
|
69
|
+
/** string template using $variable from instructionParams */
|
|
70
|
+
transformation?: string
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* By default, all children up to `target.maxPathDepth` are included.
|
|
74
|
+
*
|
|
75
|
+
* When `include` is specified, only segments explicitly listed will be included.
|
|
76
|
+
*
|
|
77
|
+
* Fields or array items not on the include list, are implicitly excluded.
|
|
78
|
+
*/
|
|
79
|
+
include?: (AgentActionPathSegment | TransformTargetInclude)[]
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** @beta */
|
|
83
|
+
export type TransformDocumentSync = TransformRequestBase & AgentActionSync
|
|
84
|
+
|
|
85
|
+
/** @beta */
|
|
86
|
+
export type TransformDocumentAsync = TransformRequestBase & AgentActionAsync
|
|
87
|
+
|
|
88
|
+
/** @beta */
|
|
89
|
+
export type TransformDocument = TransformDocumentSync | TransformDocumentAsync
|
|
90
|
+
|
|
91
|
+
export function _transform<
|
|
92
|
+
DocumentShape extends Record<string, Any>,
|
|
93
|
+
Req extends TransformDocument,
|
|
94
|
+
>(
|
|
95
|
+
client: SanityClient | ObservableSanityClient,
|
|
96
|
+
httpRequest: HttpRequest,
|
|
97
|
+
request: Req,
|
|
98
|
+
): Observable<
|
|
99
|
+
Req['async'] extends true ? {_id: string} : IdentifiedSanityDocumentStub & DocumentShape
|
|
100
|
+
> {
|
|
101
|
+
const dataset = hasDataset(client.config())
|
|
102
|
+
return _request(client, httpRequest, {
|
|
103
|
+
method: 'POST',
|
|
104
|
+
uri: `/agent/action/transform/${dataset}`,
|
|
105
|
+
body: request,
|
|
106
|
+
})
|
|
107
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AgentActionAsync,
|
|
3
|
+
AgentActionPath,
|
|
4
|
+
AgentActionRequestBase,
|
|
5
|
+
AgentActionSync,
|
|
6
|
+
AgentActionTargetInclude,
|
|
7
|
+
} from '@sanity/client/agent/actions/commonTypes'
|
|
8
|
+
import {type Observable} from 'rxjs'
|
|
9
|
+
|
|
10
|
+
import {_request} from '../../data/dataMethods'
|
|
11
|
+
import type {ObservableSanityClient, SanityClient} from '../../SanityClient'
|
|
12
|
+
import type {
|
|
13
|
+
AgentActionParams,
|
|
14
|
+
AgentActionPathSegment,
|
|
15
|
+
AgentActionTarget,
|
|
16
|
+
Any,
|
|
17
|
+
HttpRequest,
|
|
18
|
+
IdentifiedSanityDocumentStub,
|
|
19
|
+
} from '../../types'
|
|
20
|
+
import {hasDataset} from '../../validators'
|
|
21
|
+
import type {TransformTargetDocument} from './transform'
|
|
22
|
+
|
|
23
|
+
/** @beta */
|
|
24
|
+
export interface TranslateRequestBase extends AgentActionRequestBase {
|
|
25
|
+
/** schemaId as reported by sanity deploy / sanity schema store */
|
|
26
|
+
schemaId: string
|
|
27
|
+
|
|
28
|
+
documentId: string
|
|
29
|
+
targetDocument?: TransformTargetDocument
|
|
30
|
+
|
|
31
|
+
fromLanguage?: TranslateLanguage
|
|
32
|
+
toLanguage: TranslateLanguage
|
|
33
|
+
|
|
34
|
+
/** string template using $variable */
|
|
35
|
+
styleGuide?: string
|
|
36
|
+
/** param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable" */
|
|
37
|
+
styleGuideParams?: AgentActionParams
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Target defines which parts of the document will be affected by the instruction.
|
|
41
|
+
* It can be an array, so multiple parts of the document can be separately configured in detail.
|
|
42
|
+
*
|
|
43
|
+
* Omitting target implies that the document itself is the root.
|
|
44
|
+
*
|
|
45
|
+
* Notes:
|
|
46
|
+
* - instruction can only affect fields up to `maxPathDepth`
|
|
47
|
+
* - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
|
|
48
|
+
* It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
|
|
49
|
+
*
|
|
50
|
+
* @see AgentActionRequestBase#conditionalPaths
|
|
51
|
+
*/
|
|
52
|
+
target?: TranslateTarget | TranslateTarget[]
|
|
53
|
+
|
|
54
|
+
languageFieldPath?: AgentActionPathSegment | AgentActionPath
|
|
55
|
+
|
|
56
|
+
protectedPhrases?: string[]
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** @beta */
|
|
60
|
+
export interface TranslateLanguage {
|
|
61
|
+
id: string
|
|
62
|
+
title?: string
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** @beta */
|
|
66
|
+
export interface TranslateTargetInclude extends AgentActionTargetInclude {
|
|
67
|
+
/** string template using $variable from instructionParams */
|
|
68
|
+
styleGuide?: string
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* By default, all children up to `target.maxPathDepth` are included.
|
|
72
|
+
*
|
|
73
|
+
* When `include` is specified, only segments explicitly listed will be included.
|
|
74
|
+
*
|
|
75
|
+
* Fields or array items not on the include list, are implicitly excluded.
|
|
76
|
+
*/
|
|
77
|
+
include?: (AgentActionPathSegment | TranslateTargetInclude)[]
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** @beta */
|
|
81
|
+
export interface TranslateTarget extends AgentActionTarget {
|
|
82
|
+
/** string template using $variable from instructionParams */
|
|
83
|
+
styleGuide?: string
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* By default, all children up to `target.maxPathDepth` are included.
|
|
87
|
+
*
|
|
88
|
+
* When `include` is specified, only segments explicitly listed will be included.
|
|
89
|
+
*
|
|
90
|
+
* Fields or array items not on the include list, are implicitly excluded.
|
|
91
|
+
*/
|
|
92
|
+
include?: (AgentActionPathSegment | TranslateTargetInclude)[]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** @beta */
|
|
96
|
+
export type TranslateDocumentSync = TranslateRequestBase & AgentActionSync
|
|
97
|
+
|
|
98
|
+
/** @beta */
|
|
99
|
+
export type TranslateDocumentAsync = TranslateRequestBase & AgentActionAsync
|
|
100
|
+
|
|
101
|
+
/** @beta */
|
|
102
|
+
export type TranslateDocument = TranslateDocumentSync | TranslateDocumentAsync
|
|
103
|
+
|
|
104
|
+
export function _translate<
|
|
105
|
+
DocumentShape extends Record<string, Any>,
|
|
106
|
+
Req extends TranslateDocument,
|
|
107
|
+
>(
|
|
108
|
+
client: SanityClient | ObservableSanityClient,
|
|
109
|
+
httpRequest: HttpRequest,
|
|
110
|
+
request: Req,
|
|
111
|
+
): Observable<
|
|
112
|
+
Req['async'] extends true ? {_id: string} : IdentifiedSanityDocumentStub & DocumentShape
|
|
113
|
+
> {
|
|
114
|
+
const dataset = hasDataset(client.config())
|
|
115
|
+
return _request(client, httpRequest, {
|
|
116
|
+
method: 'POST',
|
|
117
|
+
uri: `/agent/action/translate/${dataset}`,
|
|
118
|
+
body: request,
|
|
119
|
+
})
|
|
120
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1373,15 +1373,33 @@ export type ClientReturn<
|
|
|
1373
1373
|
> = GroqString extends keyof SanityQueries ? SanityQueries[GroqString] : Fallback
|
|
1374
1374
|
|
|
1375
1375
|
export type {
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1376
|
+
AgentActionParam,
|
|
1377
|
+
AgentActionParams,
|
|
1378
|
+
AgentActionPath,
|
|
1379
|
+
AgentActionPathSegment,
|
|
1380
|
+
AgentActionTarget,
|
|
1381
|
+
ConstantAgentActionParam,
|
|
1382
|
+
DocumentAgentActionParam,
|
|
1383
|
+
FieldAgentActionParam,
|
|
1384
|
+
GroqAgentActionParam,
|
|
1385
|
+
} from './agent/actions/commonTypes'
|
|
1386
|
+
export type {
|
|
1380
1387
|
GenerateInstruction,
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
} from './agent/actions/
|
|
1388
|
+
GenerateOperation,
|
|
1389
|
+
GenerateTarget,
|
|
1390
|
+
GenerateTargetInclude,
|
|
1391
|
+
} from './agent/actions/generate'
|
|
1392
|
+
export type {
|
|
1393
|
+
TransformDocument,
|
|
1394
|
+
TransformTarget,
|
|
1395
|
+
TransformTargetDocument,
|
|
1396
|
+
TransformTargetInclude,
|
|
1397
|
+
} from './agent/actions/transform'
|
|
1398
|
+
export type {
|
|
1399
|
+
TranslateDocument,
|
|
1400
|
+
TranslateTarget,
|
|
1401
|
+
TranslateTargetInclude,
|
|
1402
|
+
} from './agent/actions/translate'
|
|
1385
1403
|
export type {
|
|
1386
1404
|
ContentSourceMapParsedPath,
|
|
1387
1405
|
ContentSourceMapParsedPathKeyedSegment,
|
package/umd/sanityClient.js
CHANGED
|
@@ -2879,6 +2879,22 @@ ${selectionOpts}`);
|
|
|
2879
2879
|
body: request
|
|
2880
2880
|
});
|
|
2881
2881
|
}
|
|
2882
|
+
function _transform(client, httpRequest, request) {
|
|
2883
|
+
const dataset2 = hasDataset(client.config());
|
|
2884
|
+
return _request(client, httpRequest, {
|
|
2885
|
+
method: "POST",
|
|
2886
|
+
uri: `/agent/action/transform/${dataset2}`,
|
|
2887
|
+
body: request
|
|
2888
|
+
});
|
|
2889
|
+
}
|
|
2890
|
+
function _translate(client, httpRequest, request) {
|
|
2891
|
+
const dataset2 = hasDataset(client.config());
|
|
2892
|
+
return _request(client, httpRequest, {
|
|
2893
|
+
method: "POST",
|
|
2894
|
+
uri: `/agent/action/translate/${dataset2}`,
|
|
2895
|
+
body: request
|
|
2896
|
+
});
|
|
2897
|
+
}
|
|
2882
2898
|
class ObservableAgentsActionClient {
|
|
2883
2899
|
#client;
|
|
2884
2900
|
#httpRequest;
|
|
@@ -2892,6 +2908,20 @@ ${selectionOpts}`);
|
|
|
2892
2908
|
generate(request) {
|
|
2893
2909
|
return _generate(this.#client, this.#httpRequest, request);
|
|
2894
2910
|
}
|
|
2911
|
+
/**
|
|
2912
|
+
* Transform a target document based on a source.
|
|
2913
|
+
* @param request translation request
|
|
2914
|
+
*/
|
|
2915
|
+
transform(request) {
|
|
2916
|
+
return _transform(this.#client, this.#httpRequest, request);
|
|
2917
|
+
}
|
|
2918
|
+
/**
|
|
2919
|
+
* Translate a target document based on a source.
|
|
2920
|
+
* @param request translation request
|
|
2921
|
+
*/
|
|
2922
|
+
translate(request) {
|
|
2923
|
+
return _translate(this.#client, this.#httpRequest, request);
|
|
2924
|
+
}
|
|
2895
2925
|
}
|
|
2896
2926
|
class AgentActionsClient {
|
|
2897
2927
|
#client;
|
|
@@ -2906,6 +2936,20 @@ ${selectionOpts}`);
|
|
|
2906
2936
|
generate(request) {
|
|
2907
2937
|
return lastValueFrom(_generate(this.#client, this.#httpRequest, request));
|
|
2908
2938
|
}
|
|
2939
|
+
/**
|
|
2940
|
+
* Transform a target document based on a source.
|
|
2941
|
+
* @param request translation request
|
|
2942
|
+
*/
|
|
2943
|
+
transform(request) {
|
|
2944
|
+
return lastValueFrom(_transform(this.#client, this.#httpRequest, request));
|
|
2945
|
+
}
|
|
2946
|
+
/**
|
|
2947
|
+
* Translate a target document based on a source.
|
|
2948
|
+
* @param request translation request
|
|
2949
|
+
*/
|
|
2950
|
+
translate(request) {
|
|
2951
|
+
return lastValueFrom(_translate(this.#client, this.#httpRequest, request));
|
|
2952
|
+
}
|
|
2909
2953
|
}
|
|
2910
2954
|
class ObservableAssetsClient {
|
|
2911
2955
|
#client;
|