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