@sanity/client 7.2.0 → 7.2.1-agent-actions.0

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.d.cts CHANGED
@@ -55,15 +55,27 @@ declare interface AgentActionAsync {
55
55
  }
56
56
 
57
57
  /** @beta */
58
- export declare type AgentActionParam =
58
+ export declare type AgentActionParam<
59
+ TParamConfig extends {
60
+ docIdRequired: boolean
61
+ } = {
62
+ docIdRequired: false
63
+ },
64
+ > =
59
65
  | string
60
66
  | ConstantAgentActionParam
61
- | FieldAgentActionParam
62
- | DocumentAgentActionParam
67
+ | FieldAgentActionParam<TParamConfig>
68
+ | DocumentAgentActionParam<TParamConfig>
63
69
  | GroqAgentActionParam
64
70
 
65
71
  /** @beta */
66
- export declare type AgentActionParams = Record<string, AgentActionParam>
72
+ export declare type AgentActionParams<
73
+ TParamConfig extends {
74
+ docIdRequired: boolean
75
+ } = {
76
+ docIdRequired: false
77
+ },
78
+ > = Record<string, AgentActionParam<TParamConfig>>
67
79
 
68
80
  /** @beta */
69
81
  export declare type AgentActionPath = AgentActionPathSegment[]
@@ -192,6 +204,13 @@ declare class AgentActionsClient {
192
204
  }
193
205
  : IdentifiedSanityDocumentStub & DocumentShape
194
206
  >
207
+ /**
208
+ * Run a raw instruction and return the result either as text or json
209
+ * @param request - prompt request
210
+ */
211
+ prompt<DocumentShape extends Record<string, Any>>(
212
+ request: PromptRequest<DocumentShape>,
213
+ ): Promise<(typeof request)['json'] extends true ? DocumentShape : string>
195
214
  }
196
215
 
197
216
  /** @beta */
@@ -1099,6 +1118,23 @@ export declare type DisconnectEvent = {
1099
1118
  reason: string
1100
1119
  }
1101
1120
 
1121
+ declare type DocIdParam<
1122
+ TParamConfig extends {
1123
+ docIdRequired: boolean
1124
+ } = {
1125
+ docIdRequired: false
1126
+ },
1127
+ > = TParamConfig['docIdRequired'] extends true
1128
+ ? {
1129
+ documentId: string
1130
+ }
1131
+ : {
1132
+ /**
1133
+ * If omitted, implicitly uses the documentId of the instruction target
1134
+ */
1135
+ documentId?: string
1136
+ }
1137
+
1102
1138
  /**
1103
1139
  *
1104
1140
  * Includes a LLM-friendly version of the document in the instruction
@@ -1119,13 +1155,15 @@ export declare type DisconnectEvent = {
1119
1155
  *
1120
1156
  * @beta
1121
1157
  * */
1122
- export declare interface DocumentAgentActionParam {
1158
+ export declare type DocumentAgentActionParam<
1159
+ TParamConfig extends {
1160
+ docIdRequired: boolean
1161
+ } = {
1162
+ docIdRequired: false
1163
+ },
1164
+ > = {
1123
1165
  type: 'document'
1124
- /**
1125
- * If omitted, implicitly uses the documentId of the instruction target
1126
- */
1127
- documentId?: string
1128
- }
1166
+ } & DocIdParam<TParamConfig>
1129
1167
 
1130
1168
  /** @internal */
1131
1169
  export declare type EditableReleaseDocument = Omit<
@@ -1212,17 +1250,19 @@ export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSo
1212
1250
  *
1213
1251
  * @beta
1214
1252
  * */
1215
- export declare interface FieldAgentActionParam {
1253
+ export declare type FieldAgentActionParam<
1254
+ TParamConfig extends {
1255
+ docIdRequired: boolean
1256
+ } = {
1257
+ docIdRequired: false
1258
+ },
1259
+ > = {
1216
1260
  type: 'field'
1217
1261
  /**
1218
1262
  * Examples: 'title', ['array', \{_key: 'arrayItemKey'\}, 'field']
1219
1263
  */
1220
1264
  path: AgentActionPathSegment | AgentActionPath
1221
- /**
1222
- * If omitted, implicitly uses the documentId of the instruction target
1223
- */
1224
- documentId?: string
1225
- }
1265
+ } & DocIdParam<TParamConfig>
1226
1266
 
1227
1267
  /** @public */
1228
1268
  export declare type FilterDefault = (props: {
@@ -3433,6 +3473,136 @@ export declare class ProjectsClient {
3433
3473
  getById(projectId: string): Promise<SanityProject>
3434
3474
  }
3435
3475
 
3476
+ /**
3477
+ * @beta
3478
+ */
3479
+ declare interface PromptJsonResponse<T extends Record<string, Any> = Record<string, Any>> {
3480
+ /**
3481
+ *
3482
+ * When true, the response body will be json according to the instruction.
3483
+ * When false, the response is the raw text response to the instruction.
3484
+ *
3485
+ * Note: In addition to setting this to true, `instruction` MUST include the word 'JSON', or 'json' for this to work.
3486
+ */
3487
+ json: true
3488
+ }
3489
+
3490
+ /** @beta */
3491
+ export declare type PromptRequest<T extends Record<string, Any> = Record<string, Any>> = (
3492
+ | PromptTextResponse
3493
+ | PromptJsonResponse<T>
3494
+ ) &
3495
+ PromptRequestBase
3496
+
3497
+ /** @beta */
3498
+ declare interface PromptRequestBase {
3499
+ /**
3500
+ * Instruct the LLM how it should generate content. Be as specific and detailed as needed.
3501
+ *
3502
+ * The LLM only has access to information in the instruction, plus the target schema.
3503
+ *
3504
+ * string template using $variable
3505
+ * */
3506
+ instruction: string
3507
+ /**
3508
+ * param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable"
3509
+ *
3510
+ * ### Examples
3511
+ *
3512
+ * #### Constant
3513
+ *
3514
+ * ##### Shorthand
3515
+ * ```ts
3516
+ * client.agent.action.generate({
3517
+ * schemaId,
3518
+ * documentId,
3519
+ * instruction: 'Give the following topic:\n $topic \n ---\nReturns some facts about it',
3520
+ * instructionParams: {
3521
+ * topic: 'Grapefruit'
3522
+ * },
3523
+ * })
3524
+ * ```
3525
+ * ##### Object-form
3526
+ *
3527
+ * ```ts
3528
+ * client.agent.action.prompt({
3529
+ * instruction: 'Give the following topic:\n $topic \n ---\nReturns some facts about it.',
3530
+ * instructionParams: {
3531
+ * topic: {
3532
+ * type: 'constant',
3533
+ * value: 'Grapefruit'
3534
+ * },
3535
+ * },
3536
+ * })
3537
+ * ```
3538
+ * #### Field
3539
+ * ```ts
3540
+ * client.agent.action.prompt({
3541
+ * instruction: 'Give the following field value:\n $pte \n ---\nGenerate keywords.',
3542
+ * instructionParams: {
3543
+ * pte: {
3544
+ * type: 'field',
3545
+ * path: ['pteField'],
3546
+ * documentId: 'someSanityDocId'
3547
+ * },
3548
+ * },
3549
+ * })
3550
+ * ```
3551
+ * #### Document
3552
+ * ```ts
3553
+ * client.agent.action.prompt({
3554
+ * json: true,
3555
+ * instruction: 'Given the following document:$document\nCreate a JSON string[] array with keywords describing it.',
3556
+ * instructionParams: {
3557
+ * document: {
3558
+ * type: 'document',
3559
+ * documentId: 'someSanityDocId'
3560
+ * },
3561
+ * },
3562
+ * })
3563
+ * ```
3564
+ *
3565
+ * #### GROQ
3566
+ * ```ts
3567
+ * client.agent.action.prompt({
3568
+ * instruction: 'Return the best title amongst these: $titles.',
3569
+ * instructionParams: {
3570
+ * titles: {
3571
+ * type: 'groq',
3572
+ * query: '* [_type==$type].title',
3573
+ * params: {type: 'article'}
3574
+ * },
3575
+ * },
3576
+ * })
3577
+ * ```
3578
+ * */
3579
+ instructionParams?: AgentActionParams<{
3580
+ docIdRequired: true
3581
+ }>
3582
+ /**
3583
+ * Controls how much variance the instructions will run with.
3584
+ *
3585
+ * Value must be in the range [0, 1] (inclusive).
3586
+ *
3587
+ * Defaults:
3588
+ * - generate: 0.3
3589
+ * - translate: 0
3590
+ * - transform: 0
3591
+ */
3592
+ temperature?: number
3593
+ }
3594
+
3595
+ declare interface PromptTextResponse {
3596
+ /**
3597
+ *
3598
+ * When true, the response body will be json according to the instruction.
3599
+ * When false, the response is the raw text response to the instruction.
3600
+ *
3601
+ * Note: In addition to setting this to true, `instruction` MUST include the word 'JSON', or 'json' for this to work.
3602
+ */
3603
+ json?: false
3604
+ }
3605
+
3436
3606
  /**
3437
3607
  * Publishes a draft document.
3438
3608
  * If a published version of the document already exists this is replaced by the current draft document.
package/dist/index.d.ts CHANGED
@@ -55,15 +55,27 @@ declare interface AgentActionAsync {
55
55
  }
56
56
 
57
57
  /** @beta */
58
- export declare type AgentActionParam =
58
+ export declare type AgentActionParam<
59
+ TParamConfig extends {
60
+ docIdRequired: boolean
61
+ } = {
62
+ docIdRequired: false
63
+ },
64
+ > =
59
65
  | string
60
66
  | ConstantAgentActionParam
61
- | FieldAgentActionParam
62
- | DocumentAgentActionParam
67
+ | FieldAgentActionParam<TParamConfig>
68
+ | DocumentAgentActionParam<TParamConfig>
63
69
  | GroqAgentActionParam
64
70
 
65
71
  /** @beta */
66
- export declare type AgentActionParams = Record<string, AgentActionParam>
72
+ export declare type AgentActionParams<
73
+ TParamConfig extends {
74
+ docIdRequired: boolean
75
+ } = {
76
+ docIdRequired: false
77
+ },
78
+ > = Record<string, AgentActionParam<TParamConfig>>
67
79
 
68
80
  /** @beta */
69
81
  export declare type AgentActionPath = AgentActionPathSegment[]
@@ -192,6 +204,13 @@ declare class AgentActionsClient {
192
204
  }
193
205
  : IdentifiedSanityDocumentStub & DocumentShape
194
206
  >
207
+ /**
208
+ * Run a raw instruction and return the result either as text or json
209
+ * @param request - prompt request
210
+ */
211
+ prompt<DocumentShape extends Record<string, Any>>(
212
+ request: PromptRequest<DocumentShape>,
213
+ ): Promise<(typeof request)['json'] extends true ? DocumentShape : string>
195
214
  }
196
215
 
197
216
  /** @beta */
@@ -1099,6 +1118,23 @@ export declare type DisconnectEvent = {
1099
1118
  reason: string
1100
1119
  }
1101
1120
 
1121
+ declare type DocIdParam<
1122
+ TParamConfig extends {
1123
+ docIdRequired: boolean
1124
+ } = {
1125
+ docIdRequired: false
1126
+ },
1127
+ > = TParamConfig['docIdRequired'] extends true
1128
+ ? {
1129
+ documentId: string
1130
+ }
1131
+ : {
1132
+ /**
1133
+ * If omitted, implicitly uses the documentId of the instruction target
1134
+ */
1135
+ documentId?: string
1136
+ }
1137
+
1102
1138
  /**
1103
1139
  *
1104
1140
  * Includes a LLM-friendly version of the document in the instruction
@@ -1119,13 +1155,15 @@ export declare type DisconnectEvent = {
1119
1155
  *
1120
1156
  * @beta
1121
1157
  * */
1122
- export declare interface DocumentAgentActionParam {
1158
+ export declare type DocumentAgentActionParam<
1159
+ TParamConfig extends {
1160
+ docIdRequired: boolean
1161
+ } = {
1162
+ docIdRequired: false
1163
+ },
1164
+ > = {
1123
1165
  type: 'document'
1124
- /**
1125
- * If omitted, implicitly uses the documentId of the instruction target
1126
- */
1127
- documentId?: string
1128
- }
1166
+ } & DocIdParam<TParamConfig>
1129
1167
 
1130
1168
  /** @internal */
1131
1169
  export declare type EditableReleaseDocument = Omit<
@@ -1212,17 +1250,19 @@ export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSo
1212
1250
  *
1213
1251
  * @beta
1214
1252
  * */
1215
- export declare interface FieldAgentActionParam {
1253
+ export declare type FieldAgentActionParam<
1254
+ TParamConfig extends {
1255
+ docIdRequired: boolean
1256
+ } = {
1257
+ docIdRequired: false
1258
+ },
1259
+ > = {
1216
1260
  type: 'field'
1217
1261
  /**
1218
1262
  * Examples: 'title', ['array', \{_key: 'arrayItemKey'\}, 'field']
1219
1263
  */
1220
1264
  path: AgentActionPathSegment | AgentActionPath
1221
- /**
1222
- * If omitted, implicitly uses the documentId of the instruction target
1223
- */
1224
- documentId?: string
1225
- }
1265
+ } & DocIdParam<TParamConfig>
1226
1266
 
1227
1267
  /** @public */
1228
1268
  export declare type FilterDefault = (props: {
@@ -3433,6 +3473,136 @@ export declare class ProjectsClient {
3433
3473
  getById(projectId: string): Promise<SanityProject>
3434
3474
  }
3435
3475
 
3476
+ /**
3477
+ * @beta
3478
+ */
3479
+ declare interface PromptJsonResponse<T extends Record<string, Any> = Record<string, Any>> {
3480
+ /**
3481
+ *
3482
+ * When true, the response body will be json according to the instruction.
3483
+ * When false, the response is the raw text response to the instruction.
3484
+ *
3485
+ * Note: In addition to setting this to true, `instruction` MUST include the word 'JSON', or 'json' for this to work.
3486
+ */
3487
+ json: true
3488
+ }
3489
+
3490
+ /** @beta */
3491
+ export declare type PromptRequest<T extends Record<string, Any> = Record<string, Any>> = (
3492
+ | PromptTextResponse
3493
+ | PromptJsonResponse<T>
3494
+ ) &
3495
+ PromptRequestBase
3496
+
3497
+ /** @beta */
3498
+ declare interface PromptRequestBase {
3499
+ /**
3500
+ * Instruct the LLM how it should generate content. Be as specific and detailed as needed.
3501
+ *
3502
+ * The LLM only has access to information in the instruction, plus the target schema.
3503
+ *
3504
+ * string template using $variable
3505
+ * */
3506
+ instruction: string
3507
+ /**
3508
+ * param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable"
3509
+ *
3510
+ * ### Examples
3511
+ *
3512
+ * #### Constant
3513
+ *
3514
+ * ##### Shorthand
3515
+ * ```ts
3516
+ * client.agent.action.generate({
3517
+ * schemaId,
3518
+ * documentId,
3519
+ * instruction: 'Give the following topic:\n $topic \n ---\nReturns some facts about it',
3520
+ * instructionParams: {
3521
+ * topic: 'Grapefruit'
3522
+ * },
3523
+ * })
3524
+ * ```
3525
+ * ##### Object-form
3526
+ *
3527
+ * ```ts
3528
+ * client.agent.action.prompt({
3529
+ * instruction: 'Give the following topic:\n $topic \n ---\nReturns some facts about it.',
3530
+ * instructionParams: {
3531
+ * topic: {
3532
+ * type: 'constant',
3533
+ * value: 'Grapefruit'
3534
+ * },
3535
+ * },
3536
+ * })
3537
+ * ```
3538
+ * #### Field
3539
+ * ```ts
3540
+ * client.agent.action.prompt({
3541
+ * instruction: 'Give the following field value:\n $pte \n ---\nGenerate keywords.',
3542
+ * instructionParams: {
3543
+ * pte: {
3544
+ * type: 'field',
3545
+ * path: ['pteField'],
3546
+ * documentId: 'someSanityDocId'
3547
+ * },
3548
+ * },
3549
+ * })
3550
+ * ```
3551
+ * #### Document
3552
+ * ```ts
3553
+ * client.agent.action.prompt({
3554
+ * json: true,
3555
+ * instruction: 'Given the following document:$document\nCreate a JSON string[] array with keywords describing it.',
3556
+ * instructionParams: {
3557
+ * document: {
3558
+ * type: 'document',
3559
+ * documentId: 'someSanityDocId'
3560
+ * },
3561
+ * },
3562
+ * })
3563
+ * ```
3564
+ *
3565
+ * #### GROQ
3566
+ * ```ts
3567
+ * client.agent.action.prompt({
3568
+ * instruction: 'Return the best title amongst these: $titles.',
3569
+ * instructionParams: {
3570
+ * titles: {
3571
+ * type: 'groq',
3572
+ * query: '* [_type==$type].title',
3573
+ * params: {type: 'article'}
3574
+ * },
3575
+ * },
3576
+ * })
3577
+ * ```
3578
+ * */
3579
+ instructionParams?: AgentActionParams<{
3580
+ docIdRequired: true
3581
+ }>
3582
+ /**
3583
+ * Controls how much variance the instructions will run with.
3584
+ *
3585
+ * Value must be in the range [0, 1] (inclusive).
3586
+ *
3587
+ * Defaults:
3588
+ * - generate: 0.3
3589
+ * - translate: 0
3590
+ * - transform: 0
3591
+ */
3592
+ temperature?: number
3593
+ }
3594
+
3595
+ declare interface PromptTextResponse {
3596
+ /**
3597
+ *
3598
+ * When true, the response body will be json according to the instruction.
3599
+ * When false, the response is the raw text response to the instruction.
3600
+ *
3601
+ * Note: In addition to setting this to true, `instruction` MUST include the word 'JSON', or 'json' for this to work.
3602
+ */
3603
+ json?: false
3604
+ }
3605
+
3436
3606
  /**
3437
3607
  * Publishes a draft document.
3438
3608
  * If a published version of the document already exists this is replaced by the current draft document.
package/dist/index.js CHANGED
@@ -873,6 +873,14 @@ function _generate(client, httpRequest, request) {
873
873
  body: request
874
874
  });
875
875
  }
876
+ function _prompt(client, httpRequest, request) {
877
+ const dataset2 = hasDataset(client.config());
878
+ return _request(client, httpRequest, {
879
+ method: "POST",
880
+ uri: `/agent/action/prompt/${dataset2}`,
881
+ body: request
882
+ });
883
+ }
876
884
  function _transform(client, httpRequest, request) {
877
885
  const dataset2 = hasDataset(client.config());
878
886
  return _request(client, httpRequest, {
@@ -944,6 +952,13 @@ class AgentActionsClient {
944
952
  translate(request) {
945
953
  return lastValueFrom(_translate(this.#client, this.#httpRequest, request));
946
954
  }
955
+ /**
956
+ * Run a raw instruction and return the result either as text or json
957
+ * @param request - prompt request
958
+ */
959
+ prompt(request) {
960
+ return lastValueFrom(_prompt(this.#client, this.#httpRequest, request));
961
+ }
947
962
  }
948
963
  class ObservableAssetsClient {
949
964
  #client;
@@ -2386,7 +2401,7 @@ function defineDeprecatedCreateClient(createClient2) {
2386
2401
  return printNoDefaultExport(), createClient2(config);
2387
2402
  };
2388
2403
  }
2389
- var name = "@sanity/client", version = "7.2.0";
2404
+ var name = "@sanity/client", version = "7.2.1-agent-actions.0";
2390
2405
  const middleware = [
2391
2406
  debug({ verbose: !0, namespace: "sanity:client" }),
2392
2407
  headers({ "User-Agent": `${name} ${version}` }),