content-agent 0.7.6 → 0.8.1

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.
@@ -0,0 +1,980 @@
1
+ import { LanguageModelV3 } from "@ai-sdk/provider";
2
+ /**
3
+ * This file was auto-generated by openapi-typescript.
4
+ * Do not make direct changes to the file.
5
+ */
6
+ type paths = {
7
+ '/{organizationId}/threads/{threadId}': {
8
+ parameters: {
9
+ query?: never;
10
+ header?: never;
11
+ path?: never;
12
+ cookie?: never;
13
+ };
14
+ get?: never;
15
+ put?: never;
16
+ /**
17
+ * Send a chat message
18
+ * @description Send a message to the agent and receive a streaming response.
19
+ * This endpoint manages conversation threads and persists message history.
20
+ */
21
+ post: operations['chat'];
22
+ delete?: never;
23
+ options?: never;
24
+ head?: never;
25
+ patch?: never;
26
+ trace?: never;
27
+ };
28
+ '/prompt': {
29
+ parameters: {
30
+ query?: never;
31
+ header?: never;
32
+ path?: never;
33
+ cookie?: never;
34
+ };
35
+ get?: never;
36
+ put?: never;
37
+ /**
38
+ * Send a one-shot prompt
39
+ * @description Stateless one-shot prompt endpoint. No thread management or message persistence.
40
+ * Ideal for simple, single-turn interactions.
41
+ */
42
+ post: operations['prompt'];
43
+ delete?: never;
44
+ options?: never;
45
+ head?: never;
46
+ patch?: never;
47
+ trace?: never;
48
+ };
49
+ };
50
+ type components = {
51
+ schemas: {
52
+ ChatRequest: {
53
+ /** @description Array of message objects */messages: components['schemas']['Message'][];
54
+ application?: components['schemas']['Application'];
55
+ config?: components['schemas']['Config'];
56
+ /**
57
+ * @description Enable or disable streaming responses
58
+ * @default true
59
+ */
60
+ stream: boolean;
61
+ /**
62
+ * @description Controls how directives in the response are formatted.
63
+ * - markdown (default): Directives are resolved server-side into standard markdown (e.g., links with titles).
64
+ * - directives: Raw directive syntax is preserved (e.g., `::document{id="doc-id"}`), useful for clients that render custom UI components.
65
+ * @default markdown
66
+ * @enum {string}
67
+ */
68
+ format: 'markdown' | 'directives';
69
+ };
70
+ PromptRequest: {
71
+ /**
72
+ * @description Your Sanity organization ID
73
+ * @example abc123
74
+ */
75
+ organizationId: string;
76
+ /**
77
+ * @description The prompt message
78
+ * @example Summarize my latest blog posts
79
+ */
80
+ message: string;
81
+ config?: components['schemas']['Config'];
82
+ /**
83
+ * @description Custom instructions for the agent
84
+ * @example Be concise and use bullet points
85
+ */
86
+ instructions?: string;
87
+ /**
88
+ * @description Controls how directives in the response are formatted.
89
+ * - markdown (default): Directives are resolved server-side into standard markdown.
90
+ * - directives: Raw directive syntax is preserved for clients that render custom UI.
91
+ * @default markdown
92
+ * @enum {string}
93
+ */
94
+ format: 'markdown' | 'directives';
95
+ };
96
+ Message: {
97
+ /**
98
+ * @description The role of the message sender
99
+ * @enum {string}
100
+ */
101
+ role: 'user' | 'assistant' | 'system'; /** @description The message content */
102
+ content: string; /** @description Optional unique identifier for the message */
103
+ id?: string; /** @description Optional name for the message sender */
104
+ name?: string;
105
+ }; /** @description Target Sanity application configuration */
106
+ Application: {
107
+ /**
108
+ * @description Application key in format "projectId.datasetName"
109
+ * @example abc123.production
110
+ */
111
+ key?: string;
112
+ resource?: {
113
+ /**
114
+ * @description Resource ID in format "projectId.datasetName"
115
+ * @example abc123.production
116
+ */
117
+ id?: string;
118
+ /**
119
+ * @description Resource type
120
+ * @enum {string}
121
+ */
122
+ type?: 'dataset';
123
+ };
124
+ /**
125
+ * Format: uri
126
+ * @description Base URL for the Sanity Studio
127
+ * @example https://your-studio.sanity.studio
128
+ */
129
+ intentBaseUrl?: string; /** @description Bundle version */
130
+ bundleVersion?: string; /** @description Application name */
131
+ name?: string; /** @description Application title */
132
+ title?: string; /** @description Schema descriptor ID */
133
+ schemaDescriptorId?: string;
134
+ }; /** @description Agent configuration. Controls behavior, capabilities, and document access. */
135
+ Config: {
136
+ /**
137
+ * @description Custom instruction string to include in the system prompt
138
+ * @example You are a helpful content assistant.
139
+ */
140
+ instruction?: string;
141
+ /**
142
+ * @description Key-value pairs appended to each user message as XML tags.
143
+ * Each key becomes an XML tag with the value as content.
144
+ * Example: { "slack-channel": "#marketing" } renders as <slack-channel>#marketing</slack-channel>
145
+ * @example {
146
+ * "slack-channel": "#marketing",
147
+ * "user-role": "editor"
148
+ * }
149
+ */
150
+ userMessageContext?: {
151
+ [key: string]: string;
152
+ };
153
+ capabilities?: components['schemas']['Capabilities'];
154
+ filter?: components['schemas']['Filter'];
155
+ perspectives?: components['schemas']['Perspectives'];
156
+ };
157
+ /**
158
+ * @description Agent capabilities that control what operations are allowed.
159
+ * Each capability can be a boolean or an object with a preset.
160
+ * @example {
161
+ * "read": true,
162
+ * "write": false
163
+ * }
164
+ */
165
+ Capabilities: {
166
+ read?: components['schemas']['Capability'];
167
+ write?: components['schemas']['Capability'];
168
+ features?: components['schemas']['FeatureOverrides'];
169
+ };
170
+ /**
171
+ * @description Explicit feature overrides applied on top of capability-derived defaults.
172
+ * When not specified, features use values derived from read/write capability presets.
173
+ */
174
+ FeatureOverrides: {
175
+ /**
176
+ * @description Override web search availability.
177
+ * By default, web search is enabled when read capability is 'standard'.
178
+ */
179
+ webSearch?: boolean;
180
+ };
181
+ /**
182
+ * @description A capability can be:
183
+ * - true: Full access (standard preset)
184
+ * - false: No access
185
+ * - { preset: 'minimal' | 'standard' }: Explicit preset selection
186
+ */
187
+ Capability: boolean | components['schemas']['CapabilityPreset'];
188
+ CapabilityPreset: {
189
+ /**
190
+ * @description For read capability:
191
+ * - minimal: Basic queries only (no bulk document analysis)
192
+ * - standard: All read tools including bulk analysis
193
+ *
194
+ * For write capability:
195
+ * - minimal: Basic mutations only (no bulk mutations)
196
+ * - standard: All write tools including bulk mutations
197
+ * @enum {string}
198
+ */
199
+ preset: 'minimal' | 'standard';
200
+ }; /** @description GROQ filter expressions for document access control */
201
+ Filter: {
202
+ /**
203
+ * @description GROQ boolean expression for document visibility.
204
+ * Documents matching this filter are visible to the agent.
205
+ * @example _type in ['post', 'author']
206
+ */
207
+ read?: string;
208
+ /**
209
+ * @description GROQ boolean expression for mutation permissions.
210
+ * Documents matching this filter can be mutated.
211
+ * @example _type == 'post'
212
+ */
213
+ write?: string;
214
+ };
215
+ /**
216
+ * @description Perspective locking configuration.
217
+ * Controls which document perspectives the agent can read from and write to.
218
+ * Values are Sanity perspective IDs: 'drafts', 'published', 'raw', or release/bundle IDs.
219
+ */
220
+ Perspectives: {
221
+ /**
222
+ * @description Allowed read perspectives. When set, query tools can only use these perspectives.
223
+ * If the agent tries to use a disallowed perspective, the request is rejected with an error.
224
+ * @example [
225
+ * "drafts",
226
+ * "published"
227
+ * ]
228
+ */
229
+ read?: string[];
230
+ /**
231
+ * @description The write perspective. When set, new documents are created in this perspective
232
+ * and mutations are restricted to documents whose ID matches it.
233
+ * @example drafts
234
+ */
235
+ write?: string;
236
+ }; /** @description JSON response when streaming is disabled */
237
+ ChatResponse: {
238
+ /** @description The agent's response text */text?: string; /** @description The application key used for this conversation */
239
+ applicationKey?: string;
240
+ };
241
+ ErrorResponse: {
242
+ /**
243
+ * @description Error type
244
+ * @example Invalid request
245
+ */
246
+ error: string;
247
+ /**
248
+ * @description Human-readable error description
249
+ * @example Request body validation failed
250
+ */
251
+ details?: string; /** @description Validation issues (when applicable) */
252
+ issues?: components['schemas']['ValidationIssue'][];
253
+ };
254
+ ValidationIssue: {
255
+ /**
256
+ * @description Error code
257
+ * @example invalid_type
258
+ */
259
+ code?: string;
260
+ /**
261
+ * @description Path to the invalid field
262
+ * @example [
263
+ * "messages"
264
+ * ]
265
+ */
266
+ path?: string[];
267
+ /**
268
+ * @description Error message
269
+ * @example Required
270
+ */
271
+ message?: string;
272
+ };
273
+ };
274
+ responses: {
275
+ /** @description Bad Request - Request validation failed */BadRequest: {
276
+ headers: {
277
+ [name: string]: unknown;
278
+ };
279
+ content: {
280
+ /**
281
+ * @example {
282
+ * "error": "Invalid request",
283
+ * "details": "Request body validation failed",
284
+ * "issues": [
285
+ * {
286
+ * "code": "invalid_type",
287
+ * "path": [
288
+ * "messages"
289
+ * ],
290
+ * "message": "Required"
291
+ * }
292
+ * ]
293
+ * }
294
+ */
295
+ 'application/json': components['schemas']['ErrorResponse'];
296
+ };
297
+ }; /** @description Unauthorized - Missing or invalid authentication token */
298
+ Unauthorized: {
299
+ headers: {
300
+ [name: string]: unknown;
301
+ };
302
+ content: {
303
+ /**
304
+ * @example {
305
+ * "error": "Unauthorized",
306
+ * "details": "Missing authorization token"
307
+ * }
308
+ */
309
+ 'application/json': components['schemas']['ErrorResponse'];
310
+ };
311
+ }; /** @description Internal Server Error */
312
+ InternalServerError: {
313
+ headers: {
314
+ [name: string]: unknown;
315
+ };
316
+ content: {
317
+ /**
318
+ * @example {
319
+ * "error": "Internal Server Error",
320
+ * "details": "An unexpected error occurred"
321
+ * }
322
+ */
323
+ 'application/json': components['schemas']['ErrorResponse'];
324
+ };
325
+ };
326
+ };
327
+ parameters: never;
328
+ requestBodies: never;
329
+ headers: never;
330
+ pathItems: never;
331
+ };
332
+ interface operations {
333
+ chat: {
334
+ parameters: {
335
+ query?: never;
336
+ header?: never;
337
+ path: {
338
+ /**
339
+ * @description Your Sanity organization ID
340
+ * @example abc123
341
+ */
342
+ organizationId: string;
343
+ /**
344
+ * @description Unique identifier for the conversation thread
345
+ * @example my-conversation-thread
346
+ */
347
+ threadId: string;
348
+ };
349
+ cookie?: never;
350
+ };
351
+ requestBody: {
352
+ content: {
353
+ 'application/json': components['schemas']['ChatRequest'];
354
+ };
355
+ };
356
+ responses: {
357
+ /** @description Streaming response */200: {
358
+ headers: {
359
+ 'Content-Type'?: string;
360
+ 'X-Vercel-AI-Data-Stream'?: string;
361
+ [name: string]: unknown;
362
+ };
363
+ content: {
364
+ 'text/event-stream': string; /** @description JSON response when stream is false */
365
+ 'application/json': components['schemas']['ChatResponse'];
366
+ };
367
+ };
368
+ 400: components['responses']['BadRequest'];
369
+ 401: components['responses']['Unauthorized'];
370
+ 500: components['responses']['InternalServerError'];
371
+ };
372
+ };
373
+ prompt: {
374
+ parameters: {
375
+ query?: never;
376
+ header?: never;
377
+ path?: never;
378
+ cookie?: never;
379
+ };
380
+ requestBody: {
381
+ content: {
382
+ 'application/json': components['schemas']['PromptRequest'];
383
+ };
384
+ };
385
+ responses: {
386
+ /** @description Streaming response */200: {
387
+ headers: {
388
+ 'Content-Type'?: string;
389
+ 'X-Vercel-AI-Data-Stream'?: string;
390
+ [name: string]: unknown;
391
+ };
392
+ content: {
393
+ 'text/event-stream': string;
394
+ };
395
+ };
396
+ 400: components['responses']['BadRequest'];
397
+ 401: components['responses']['Unauthorized'];
398
+ 500: components['responses']['InternalServerError'];
399
+ };
400
+ };
401
+ }
402
+ /**
403
+ * Request body for the conversation thread endpoint (`POST /{organizationId}/threads/{threadId}`).
404
+ * @category API Types
405
+ */
406
+ type ChatRequest = components['schemas']['ChatRequest'];
407
+ /**
408
+ * Request body for the one-shot prompt endpoint (`POST /prompt`).
409
+ * @category API Types
410
+ */
411
+ type GenerateRequest = components['schemas']['PromptRequest'];
412
+ /**
413
+ * Controls how directives in the response are formatted (`'markdown'` or `'directives'`).
414
+ * @category Configuration
415
+ */
416
+ type OutputFormat = ChatRequest['format'];
417
+ /**
418
+ * Response from the conversation thread endpoint when `stream: false`.
419
+ * @category API Types
420
+ */
421
+ type ChatResponse = components['schemas']['ChatResponse'];
422
+ /**
423
+ * Error response body returned by the API on failure.
424
+ * @category API Types
425
+ */
426
+ type ErrorResponse = components['schemas']['ErrorResponse'];
427
+ /**
428
+ * Individual validation issue within an {@link ErrorResponse}.
429
+ * @category API Types
430
+ */
431
+ type ValidationIssue = components['schemas']['ValidationIssue'];
432
+ /**
433
+ * A message in a conversation (user, assistant, or system).
434
+ * @category API Types
435
+ */
436
+ type Message = components['schemas']['Message'];
437
+ /**
438
+ * The role of a {@link Message}: `'user'`, `'assistant'`, or `'system'`.
439
+ * @category API Types
440
+ */
441
+ type MessageRole = Message['role'];
442
+ /**
443
+ * Specifies which Sanity project and dataset the agent should work with.
444
+ *
445
+ * @category Configuration
446
+ *
447
+ * @example
448
+ * ```ts
449
+ * const application = {
450
+ * key: 'project-id.dataset-name',
451
+ * }
452
+ * ```
453
+ */
454
+ type Application = components['schemas']['Application'];
455
+ /**
456
+ * Resource within an {@link Application}.
457
+ * @category Configuration
458
+ */
459
+ type ApplicationResource = NonNullable<Application['resource']>;
460
+ /**
461
+ * Agent configuration for controlling behavior, capabilities, and document access.
462
+ *
463
+ * @category Configuration
464
+ *
465
+ * @example Read-only with custom instruction and user message context
466
+ * ```ts
467
+ * const config = {
468
+ * instruction: 'You are a Slack bot helping users manage content.',
469
+ * userMessageContext: {
470
+ * 'slack-channel': '#content-team',
471
+ * 'slack-user': '@john.doe',
472
+ * },
473
+ * capabilities: {
474
+ * read: true,
475
+ * write: false,
476
+ * },
477
+ * }
478
+ * ```
479
+ *
480
+ * @example Read-only document explorer with type filtering
481
+ * ```ts
482
+ * const config = {
483
+ * capabilities: {
484
+ * read: { preset: 'standard' },
485
+ * write: false,
486
+ * },
487
+ * filter: {
488
+ * read: '_type in ["post", "author", "page"]',
489
+ * },
490
+ * }
491
+ * ```
492
+ */
493
+ type Config = components['schemas']['Config'] & {
494
+ /** Controls how the agent delivers responses. 'tool' enables the final_answer tool with structured message + suggestions. Omit or use 'stream' for normal streaming. */responseMode?: 'stream' | 'tool'; /** When true and responseMode is 'tool', the final_answer tool includes a suggestions field for follow-up reply buttons. */
495
+ enableReplySuggestions?: boolean;
496
+ };
497
+ /**
498
+ * Controls what operations the agent can perform.
499
+ *
500
+ * Each capability (`read`, `write`) can be:
501
+ * - `true` — Full access (standard preset)
502
+ * - `false` — No access
503
+ * - `{ preset: 'minimal' }` — Basic tools only
504
+ * - `{ preset: 'standard' }` — All tools available
505
+ *
506
+ * Use `features` to override individual feature toggles independently of presets.
507
+ *
508
+ * @example Read-only access
509
+ * ```ts
510
+ * const capabilities = { read: true, write: false }
511
+ * ```
512
+ *
513
+ * @example Full read, minimal write
514
+ * ```ts
515
+ * const capabilities = {
516
+ * read: true,
517
+ * write: { preset: 'minimal' },
518
+ * }
519
+ * ```
520
+ *
521
+ * @example Standard read with web search disabled
522
+ * ```ts
523
+ * const capabilities = {
524
+ * read: true,
525
+ * write: false,
526
+ * features: { webSearch: false },
527
+ * }
528
+ * ```
529
+ *
530
+ * @category Configuration
531
+ */
532
+ type Capabilities = components['schemas']['Capabilities'];
533
+ /**
534
+ * A single capability value: `true`, `false`, or a {@link CapabilityPreset}.
535
+ * @category Configuration
536
+ */
537
+ type Capability = components['schemas']['Capability'];
538
+ /**
539
+ * A capability preset object, e.g. `{ preset: 'minimal' }` or `{ preset: 'standard' }`.
540
+ * @category Configuration
541
+ */
542
+ type CapabilityPreset = components['schemas']['CapabilityPreset'];
543
+ /**
544
+ * The preset level string: `'minimal'` or `'standard'`.
545
+ * @category Configuration
546
+ */
547
+ type CapabilityPresetValue = CapabilityPreset['preset'];
548
+ /**
549
+ * GROQ boolean expressions to control document visibility and mutation permissions.
550
+ *
551
+ * @category Configuration
552
+ *
553
+ * @example
554
+ * ```ts
555
+ * const filter = {
556
+ * read: '_type in ["post", "author", "category"]',
557
+ * write: '_type == "post"',
558
+ * }
559
+ * ```
560
+ */
561
+ type Filter = components['schemas']['Filter'];
562
+ /**
563
+ * Key-value pairs appended to each user message as XML tags.
564
+ *
565
+ * @category Configuration
566
+ *
567
+ * @example
568
+ * ```ts
569
+ * const userMessageContext = {
570
+ * 'slack-channel': '#marketing',
571
+ * 'user-role': 'editor',
572
+ * }
573
+ * // Renders in the user message as:
574
+ * // <slack-channel>#marketing</slack-channel>
575
+ * // <user-role>editor</user-role>
576
+ * ```
577
+ */
578
+ type UserMessageContext = NonNullable<Config['userMessageContext']>;
579
+ /**
580
+ * Settings for creating a Content Agent provider instance via {@link createContentAgent}.
581
+ *
582
+ * @category Provider
583
+ *
584
+ * @example
585
+ * ```ts
586
+ * import { createContentAgent } from 'content-agent'
587
+ *
588
+ * const contentAgent = createContentAgent({
589
+ * organizationId: 'your-org-id',
590
+ * token: 'your-sanity-token',
591
+ * // Optional overrides:
592
+ * // baseURL: 'https://api.sanity.io',
593
+ * // apiVersion: 'v2026-01-01',
594
+ * })
595
+ * ```
596
+ */
597
+ interface ContentAgentProviderSettings {
598
+ /**
599
+ * Your Sanity organization ID.
600
+ *
601
+ * When using {@link createStudioAgent}, this is fetched automatically
602
+ * from the project metadata.
603
+ */
604
+ organizationId: string;
605
+ /**
606
+ * Default application for all agent and prompt calls.
607
+ *
608
+ * When set, this application is used unless overridden per-call via
609
+ * {@link AgentSettings.application} or {@link GenerateSettings.application}.
610
+ *
611
+ * Typically set automatically by {@link createStudioAgent}.
612
+ */
613
+ application?: Application;
614
+ /**
615
+ * Base URL for the Sanity API.
616
+ * @default 'https://api.sanity.io'
617
+ */
618
+ baseURL?: string;
619
+ /**
620
+ * API version to use for requests.
621
+ * Should be in format 'vYYYY-MM-DD' (e.g., 'v2026-01-01').
622
+ * @default 'v2026-01-01'
623
+ */
624
+ apiVersion?: string;
625
+ /**
626
+ * Authentication token for the Sanity API.
627
+ * If not provided, requests will be made without authentication
628
+ * (useful for browser contexts where auth may come from cookies).
629
+ */
630
+ token?: string;
631
+ /**
632
+ * Custom headers to include in requests.
633
+ */
634
+ headers?: Record<string, string>;
635
+ /**
636
+ * Custom fetch implementation.
637
+ * Useful for testing or adding middleware.
638
+ */
639
+ fetch?: typeof globalThis.fetch;
640
+ }
641
+ /**
642
+ * Base settings shared between agent and generate requests.
643
+ *
644
+ * @example Read-only agent with document type filtering
645
+ * ```ts
646
+ * const settings = {
647
+ * application: { key: 'projectId.datasetName' },
648
+ * config: {
649
+ * instruction: 'You are a helpful content assistant for our blog.',
650
+ * capabilities: {
651
+ * read: true,
652
+ * write: false,
653
+ * },
654
+ * filter: {
655
+ * read: '_type in ["post", "author", "category"]',
656
+ * },
657
+ * },
658
+ * }
659
+ * ```
660
+ *
661
+ * @example Read/write agent with perspective locking
662
+ * ```ts
663
+ * const settings = {
664
+ * application: { key: 'projectId.datasetName' },
665
+ * config: {
666
+ * capabilities: {
667
+ * read: true,
668
+ * write: { preset: 'minimal' },
669
+ * },
670
+ * filter: {
671
+ * read: '_type in ["post", "author", "category"]',
672
+ * write: '_type == "post"',
673
+ * },
674
+ * perspectives: {
675
+ * read: ['drafts', 'published'],
676
+ * write: 'drafts',
677
+ * },
678
+ * },
679
+ * }
680
+ * ```
681
+ */
682
+ interface BaseAgentSettings {
683
+ /**
684
+ * Target Sanity application configuration.
685
+ */
686
+ application?: Application;
687
+ /**
688
+ * Agent configuration for controlling behavior, capabilities, and document access.
689
+ */
690
+ config?: Config;
691
+ /**
692
+ * Controls how directives in the response are formatted.
693
+ * - `markdown` (default): Directives are resolved server-side into standard markdown.
694
+ * - `directives`: Raw directive syntax is preserved for clients that render custom UI.
695
+ * @default 'markdown'
696
+ */
697
+ format?: OutputFormat;
698
+ }
699
+ /**
700
+ * Settings for creating an agent instance (per-thread).
701
+ *
702
+ * Passed as the second argument to {@link ContentAgentProvider.agent | contentAgent.agent(threadId, settings)}.
703
+ *
704
+ * @example
705
+ * ```ts
706
+ * const model = contentAgent.agent('my-thread-id', {
707
+ * application: { key: 'projectId.datasetName' },
708
+ * config: {
709
+ * capabilities: { read: true, write: false },
710
+ * },
711
+ * })
712
+ * ```
713
+ *
714
+ * @category Configuration
715
+ */
716
+ interface AgentSettings extends BaseAgentSettings {
717
+ /**
718
+ * Identifies the client that created the thread (e.g. `'slack'`, `'linear'`, `'dashboard'`).
719
+ *
720
+ * Stored in thread metadata and used by the dashboard to filter its thread list.
721
+ * When omitted, the server assigns a default value.
722
+ */
723
+ clientId?: string;
724
+ /**
725
+ * Called when a custom `data-*` SSE part arrives during streaming.
726
+ *
727
+ * @param type - The data part type with the `data-` prefix stripped (e.g. `'agent-status'`).
728
+ * @param data - The parsed payload.
729
+ */
730
+ onStreamData?: (type: string, data: unknown) => void;
731
+ }
732
+ /**
733
+ * Settings for one-shot generation requests via {@link ContentAgentProvider.prompt | contentAgent.prompt()}.
734
+ *
735
+ * Extends {@link BaseAgentSettings} with an additional `instructions` field
736
+ * for providing custom system-level instructions.
737
+ *
738
+ * @example
739
+ * ```ts
740
+ * const { text } = await contentAgent.prompt(
741
+ * {
742
+ * application: { key: 'projectId.datasetName' },
743
+ * config: { capabilities: { read: true, write: false } },
744
+ * instructions: 'Be concise',
745
+ * },
746
+ * { message: 'List my 5 most recent posts' },
747
+ * )
748
+ * ```
749
+ *
750
+ * @category Configuration
751
+ */
752
+ interface GenerateSettings extends BaseAgentSettings {
753
+ /**
754
+ * Custom instructions for the agent.
755
+ */
756
+ instructions?: string;
757
+ }
758
+ /**
759
+ * Options for a one-shot generation request via {@link ContentAgentProvider.prompt | contentAgent.prompt()}.
760
+ *
761
+ * @category Configuration
762
+ *
763
+ * @example
764
+ * ```ts
765
+ * const { text } = await contentAgent.prompt(
766
+ * { instructions: 'Be concise' },
767
+ * { message: 'List all authors in my dataset' },
768
+ * )
769
+ * ```
770
+ */
771
+ interface GenerateOptions {
772
+ /**
773
+ * The prompt message to send.
774
+ */
775
+ message: string;
776
+ /**
777
+ * Enable streaming response.
778
+ * @default false
779
+ */
780
+ stream?: boolean;
781
+ /**
782
+ * Signal to abort the request.
783
+ */
784
+ abortSignal?: AbortSignal;
785
+ }
786
+ /**
787
+ * Result from a one-shot generation request via {@link ContentAgentProvider.prompt | contentAgent.prompt()}.
788
+ *
789
+ * @category Configuration
790
+ */
791
+ interface GenerateResult {
792
+ /**
793
+ * The generated text response.
794
+ */
795
+ text: string;
796
+ }
797
+ /**
798
+ * Narrow client interface — only needs `config()`.
799
+ * Used by {@link resolveApplication} which doesn't need URL generation.
800
+ */
801
+ type SanityClientConfig = {
802
+ config(): {
803
+ projectId?: string;
804
+ dataset?: string;
805
+ apiHost?: string;
806
+ };
807
+ };
808
+ /**
809
+ * Client interface with URL generation support.
810
+ * Any `@sanity/client` instance satisfies this.
811
+ */
812
+ type SanityClientLike = SanityClientConfig & {
813
+ getUrl(uri: string): string;
814
+ };
815
+ /** Extracts the project-scoped API origin from a Sanity client. */
816
+ declare function getBaseUrl(client: SanityClientLike): string;
817
+ type ClientDerivedConfig = {
818
+ baseURL: string;
819
+ application: Application;
820
+ };
821
+ /**
822
+ * Derives Content Agent configuration from a Sanity client and workspace name.
823
+ * Builds a CORS-compatible `baseURL` and an `application` targeting the workspace.
824
+ *
825
+ * @param client - A Sanity client instance. Any `@sanity/client` instance works.
826
+ * @param workspace - The active workspace name (e.g. `'default'`).
827
+ */
828
+ declare function fromClient(client: SanityClientLike, workspace: string): ClientDerivedConfig;
829
+ /**
830
+ * A Content Agent provider instance returned by {@link createContentAgent}.
831
+ *
832
+ * Provides two modes of interaction:
833
+ * - **Conversation threads** via {@link ContentAgentProvider.agent | .agent()} — stateful, multi-turn conversations with server-side message history.
834
+ * - **One-shot prompts** via {@link ContentAgentProvider.prompt | .prompt()} — stateless, single-turn interactions.
835
+ *
836
+ * @category Provider
837
+ */
838
+ interface ContentAgentProvider {
839
+ /**
840
+ * Creates a Vercel AI SDK {@link https://sdk.vercel.ai/docs/ai-sdk-core | LanguageModelV1} for a conversation thread.
841
+ *
842
+ * The thread ID identifies the conversation and maintains message history server-side.
843
+ * If a thread with that ID already exists, the conversation continues. If not, a new
844
+ * thread is automatically created.
845
+ *
846
+ * Use the returned model with `generateText` or `streamText` from the `ai` package.
847
+ *
848
+ * @example
849
+ * ```ts
850
+ * import { generateText, streamText } from 'ai'
851
+ *
852
+ * const model = contentAgent.agent('my-thread-id', {
853
+ * application: { key: 'projectId.datasetName' },
854
+ * config: {
855
+ * capabilities: { read: true, write: false },
856
+ * },
857
+ * })
858
+ *
859
+ * // Non-streaming
860
+ * const { text } = await generateText({ model, prompt: 'What blog posts do I have?' })
861
+ *
862
+ * // Streaming
863
+ * const { textStream } = await streamText({ model, prompt: 'Summarize my content' })
864
+ * for await (const chunk of textStream) {
865
+ * process.stdout.write(chunk)
866
+ * }
867
+ * ```
868
+ *
869
+ * @param threadId - Unique identifier for the conversation thread.
870
+ * @param settings - Optional agent settings (application, capabilities, filters, etc.).
871
+ */
872
+ agent(threadId: string, settings?: AgentSettings): LanguageModelV3;
873
+ /**
874
+ * Lists available applications for the organization.
875
+ *
876
+ * Returns all Sanity Studio applications the authenticated user has access to.
877
+ * Use the `key` from a returned application to target it when creating an agent.
878
+ *
879
+ * @example
880
+ * ```ts
881
+ * const apps = await contentAgent.applications()
882
+ * const app = apps.find((app) => app.title === "My Studio")
883
+ *
884
+ * const model = contentAgent.agent("my-thread", {
885
+ * application: { key: app.key },
886
+ * })
887
+ * ```
888
+ */
889
+ applications(): Promise<Application[]>;
890
+ /**
891
+ * Matches a Sanity client's `projectId` and `dataset` against the org's application list.
892
+ * Throws if no match is found. Prefer {@link createStudioAgent} which calls this automatically.
893
+ */
894
+ resolveApplication(client: SanityClientConfig, workspace: string): Promise<Application>;
895
+ /**
896
+ * Sends a one-shot prompt to the Content Agent (stateless).
897
+ *
898
+ * Unlike {@link ContentAgentProvider.agent | .agent()}, this does not create or use a conversation thread.
899
+ * Each call is independent with no message history or persistence.
900
+ * Ideal for simple, single-turn interactions.
901
+ *
902
+ * @example
903
+ * ```ts
904
+ * const { text } = await contentAgent.prompt(
905
+ * {
906
+ * application: { key: 'projectId.datasetName' },
907
+ * config: { capabilities: { read: true, write: false } },
908
+ * instructions: 'Be concise',
909
+ * },
910
+ * { message: 'List my 5 most recent posts' },
911
+ * )
912
+ * ```
913
+ *
914
+ * @param settings - Generation settings (application, capabilities, instructions, etc.).
915
+ * @param options - The prompt message and request options.
916
+ */
917
+ prompt(settings: GenerateSettings, options: GenerateOptions): Promise<GenerateResult>;
918
+ }
919
+ /**
920
+ * Creates a Content Agent provider instance.
921
+ *
922
+ * The provider is the main entry point for interacting with the Sanity Content Agent API.
923
+ * It returns an object with methods for conversation threads and one-shot prompts.
924
+ *
925
+ * @category Provider
926
+ *
927
+ * @example Basic setup
928
+ * ```ts
929
+ * import { createContentAgent } from 'content-agent'
930
+ *
931
+ * const contentAgent = createContentAgent({
932
+ * organizationId: 'your-org-id',
933
+ * token: 'your-sanity-token',
934
+ * })
935
+ * ```
936
+ *
937
+ * @example Using with Vercel AI SDK for conversation threads
938
+ * ```ts
939
+ * import { createContentAgent } from 'content-agent'
940
+ * import { generateText, streamText } from 'ai'
941
+ *
942
+ * const contentAgent = createContentAgent({
943
+ * organizationId: 'your-org-id',
944
+ * token: 'your-sanity-token',
945
+ * })
946
+ *
947
+ * const model = contentAgent.agent('my-thread-id', {
948
+ * application: { key: 'projectId.datasetName' },
949
+ * config: {
950
+ * capabilities: { read: true, write: false },
951
+ * },
952
+ * })
953
+ *
954
+ * // Non-streaming
955
+ * const { text } = await generateText({ model, prompt: 'What blog posts do I have?' })
956
+ *
957
+ * // Streaming
958
+ * const { textStream } = await streamText({ model, prompt: 'Summarize my content' })
959
+ * for await (const chunk of textStream) {
960
+ * process.stdout.write(chunk)
961
+ * }
962
+ * ```
963
+ *
964
+ * @example One-shot generation (stateless, no thread)
965
+ * ```ts
966
+ * const { text } = await contentAgent.prompt(
967
+ * {
968
+ * application: { key: 'projectId.datasetName' },
969
+ * config: { capabilities: { read: true, write: false } },
970
+ * instructions: 'Be concise',
971
+ * },
972
+ * { message: 'List my 5 most recent posts' },
973
+ * )
974
+ * ```
975
+ *
976
+ * @param options - Provider configuration including organization ID, token, and optional overrides.
977
+ */
978
+ declare function createContentAgent(options: ContentAgentProviderSettings): ContentAgentProvider;
979
+ export { components as A, GenerateResult as C, OutputFormat as D, MessageRole as E, paths as M, UserMessageContext as O, GenerateRequest as S, Message as T, Config as _, SanityClientLike as a, Filter as b, AgentSettings as c, Capabilities as d, Capability as f, ChatResponse as g, ChatRequest as h, SanityClientConfig as i, operations as j, ValidationIssue as k, Application as l, CapabilityPresetValue as m, createContentAgent as n, fromClient as o, CapabilityPreset as p, ClientDerivedConfig as r, getBaseUrl as s, ContentAgentProvider as t, ApplicationResource as u, ContentAgentProviderSettings as v, GenerateSettings as w, GenerateOptions as x, ErrorResponse as y };
980
+ //# sourceMappingURL=sanity-agent-provider.d.ts.map