@sanity/client 7.2.1-agent-actions.2 → 7.2.1-agent-actions.3

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 CHANGED
@@ -119,6 +119,8 @@ export async function updateDocumentTitle(_id, title) {
119
119
  - [Example: Field-based transformation](#example-field-based-transformation)
120
120
  - [Translating Documents](#translating-documents)
121
121
  - [Example: Storing language in a field](#example-storing-language-in-a-field)
122
+ - [Prompt the LLM](#prompt-the-llm)
123
+ - [Patch with a schema-aware API](#patch-with-a-schema-aware-api)
122
124
  - [Version actions](#version-actions)
123
125
  - [Create Version Action](#create-version)
124
126
  - [Discard Version Action](#discard-version)
@@ -1975,10 +1977,11 @@ Agent Actions allow you to:
1975
1977
  - **Transform** a document based on instructions, optionally copying from a source document.
1976
1978
  - **Translate** a document or fields from one language to another, with support for style guides and protected phrases.
1977
1979
  - **Prompt** the LLM using the same instruction template format as the other actions, but returns text or json instead of acting on a document.
1980
+ - **Patch** documents using a schema-aware API; validates that provided paths and values are schema compliant and handles `setIfMissing` semantics for deep value operations
1978
1981
 
1979
1982
  All methods are available in both Promise and Observable forms:
1980
1983
 
1981
- - `client.agent.action.generate`, `client.agent.action.transform`, `client.agent.action.translate`, `client.agent.action.prompt` (Promise-based)
1984
+ - `client.agent.action.generate`, `client.agent.action.transform`, `client.agent.action.translate`, `client.agent.action.prompt`, `client.agent.action.patch` (Promise-based)
1982
1985
  - `client.observable.agent.action.generate`, etc. (Observable-based, for streaming or RxJS use)
1983
1986
 
1984
1987
  ---
@@ -2003,6 +2006,9 @@ const result = await client.agent.action.generate({
2003
2006
  - **instructionParams**: Values for variables in the instruction. Supports constants, fields, documents, or GROQ queries.
2004
2007
  - **target**: (Optional) Specifies which fields or paths to generate content for.
2005
2008
  - **temperature**: (Optional) Controls variance, 0-1 – defaults to 0.3
2009
+ - **async**: (Optional) when true, the request will respond with the document id; the LLM request and mutations will continue on the server.
2010
+ - **noWrite**: (Optional) when true, the document will not be changed. The response will contain the document value with the changes.
2011
+ - **conditionalPaths**: (Optional) control how conditionally readOnly and hidden fields and types will be treated
2006
2012
 
2007
2013
  ##### Example: Using GROQ in instructionParams
2008
2014
 
@@ -2060,6 +2066,9 @@ const result = await client.agent.action.transform({
2060
2066
  - **targetDocument**: (Optional) Specify a different document to write the result to, or create a new one.
2061
2067
  - **target**: (Optional) Specifies which fields or paths to transform.
2062
2068
  - **temperature**: (Optional) Controls variance, 0-1 – defaults to 0
2069
+ - **async**: (Optional) when true, the request will respond with the document id; the LLM request and mutations will continue on the server.
2070
+ - **noWrite**: (Optional) when true, the document will not be changed. The response will contain the document value with the changes.
2071
+ - **conditionalPaths**: (Optional) control how conditionally readOnly and hidden fields and types will be treated
2063
2072
 
2064
2073
  ##### Example: Field-based transformation
2065
2074
 
@@ -2083,6 +2092,7 @@ await client.agent.action.transform({
2083
2092
  const result = await client.agent.action.translate({
2084
2093
  schemaId: 'your-schema-id',
2085
2094
  documentId: 'source-document-id',
2095
+ targetDocument: {operation: 'create'},
2086
2096
  fromLanguage: {id: 'en', title: 'English'},
2087
2097
  toLanguage: {id: 'es', title: 'Spanish'},
2088
2098
  styleGuide: 'Use a friendly tone.',
@@ -2093,12 +2103,16 @@ const result = await client.agent.action.translate({
2093
2103
 
2094
2104
  - **schemaId**: The schema identifier for the document type.
2095
2105
  - **documentId**: The source document ID.
2106
+ - **targetDocument**: (Optional) Specify a different document to write the result to, or create a new one.
2096
2107
  - **fromLanguage**: (Optional) The source language code and title.
2097
2108
  - **toLanguage**: The target language code and title.
2098
2109
  - **styleGuide**: (Optional) Instructions for translation style.
2099
2110
  - **protectedPhrases**: (Optional) Array of phrases to leave untranslated.
2100
2111
  - **target**: (Optional) Specifies which fields or paths to translate.
2101
2112
  - **temperature**: (Optional) Controls variance, 0-1 – defaults to 0
2113
+ - **async**: (Optional) when true, the request will respond with the document id; the LLM request and mutations will continue on the server.
2114
+ - **noWrite**: (Optional) when true, the document will not be changed. The response will contain the document value with the changes.
2115
+ - **conditionalPaths**: (Optional) control how conditionally readOnly and hidden fields and types will be treated
2102
2116
 
2103
2117
  ##### Example: Storing language in a field
2104
2118
 
@@ -2130,6 +2144,50 @@ const result = await client.agent.action.prompt({
2130
2144
  - **format**: (Optional) 'text' or 'json'. Defaults to 'text'. Note that when specifying 'json', the instruction MUST include the word "json" (ignoring case) in some form.
2131
2145
  - **temperature**: (Optional) Controls variance, 0-1 – defaults to 0
2132
2146
 
2147
+ #### Patch with a schema-aware API
2148
+
2149
+ The `client.patch` and `client.transaction` API are not schema aware. This allows patching documents any way you want, but the operations will not fail if they deviate from the document schema.
2150
+
2151
+ To ensure schema-compliant operation, `client.agent.action.patch` is available. It will ensure that provided paths and values adhere to the document schema,
2152
+ ensure no duplicate keys are inserted, and merge object values so `set` operations dont accidentally remove existing values.
2153
+
2154
+ ```ts
2155
+ const result = await client.agent.action.prompt({
2156
+ schemaId,
2157
+ documentId,
2158
+ target: [
2159
+ {path: 'title', operation: 'set', value: 'New title'},
2160
+ {path: ['wrapper', 'array'], operation: 'append', value: [{_type: 'item', title: 'Item title'}]},
2161
+ ]
2162
+ })
2163
+ ```
2164
+
2165
+ - **schemaId**: The schema identifier for the document type.
2166
+ - **documentId**: The source document ID OR use `targetDocument`
2167
+ - **targetDocument**: (Optional) Specify a different document to write the result to, or create a new one. Incompatible with `documentId`
2168
+ - **target**: Specify patch operations and values for paths in the document.
2169
+ - **async**: (Optional) when true, the request will respond with the document id; the LLM request and mutations will continue on the server.
2170
+ - **noWrite**: (Optional) when true, the document will not be changed. The response will contain the document value with the changes.
2171
+ - **conditionalPaths**: (Optional) control how conditionally readOnly and hidden fields and types will be treated
2172
+
2173
+ #### Appending into array after a key
2174
+
2175
+ When appending to arrays, providing a `_key` is optional.
2176
+ When a path targets a key in an array, the values provided will be appended after that key'ed item in the array.
2177
+ Note that when appending to arrays, `value` must be an array itself, even when only a single item should be appended.
2178
+
2179
+ ```ts
2180
+ const result = await client.agent.action.prompt({
2181
+ schemaId,
2182
+ documentId,
2183
+ target: {
2184
+ path: ['array', {_key: 'existingKey'}],
2185
+ operation: 'append',
2186
+ value: [{_type: 'item', title: 'Item title', _key: 'isOptionalAndWillBeGeneratedIfMissing'}]
2187
+ },
2188
+ })
2189
+ ```
2190
+
2133
2191
  ## License
2134
2192
 
2135
2193
  MIT © [Sanity.io](https://www.sanity.io/)