content-agent 0.4.0 → 0.4.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.
- package/dist/index.d.ts +425 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -400,25 +400,197 @@ interface operations {
|
|
|
400
400
|
};
|
|
401
401
|
};
|
|
402
402
|
}
|
|
403
|
+
/**
|
|
404
|
+
* Request body for the conversation thread endpoint (`POST /{organizationId}/threads/{threadId}`).
|
|
405
|
+
* @category API Types
|
|
406
|
+
*/
|
|
403
407
|
type ChatRequest = components['schemas']['ChatRequest'];
|
|
408
|
+
/**
|
|
409
|
+
* Request body for the one-shot prompt endpoint (`POST /prompt`).
|
|
410
|
+
* @category API Types
|
|
411
|
+
*/
|
|
404
412
|
type GenerateRequest = components['schemas']['PromptRequest'];
|
|
413
|
+
/**
|
|
414
|
+
* Controls how directives in the response are formatted (`'markdown'` or `'directives'`).
|
|
415
|
+
* @category Configuration
|
|
416
|
+
*/
|
|
405
417
|
type OutputFormat = ChatRequest['format'];
|
|
418
|
+
/**
|
|
419
|
+
* Response from the conversation thread endpoint when `stream: false`.
|
|
420
|
+
* @category API Types
|
|
421
|
+
*/
|
|
406
422
|
type ChatResponse = components['schemas']['ChatResponse'];
|
|
423
|
+
/**
|
|
424
|
+
* Error response body returned by the API on failure.
|
|
425
|
+
* @category API Types
|
|
426
|
+
*/
|
|
407
427
|
type ErrorResponse = components['schemas']['ErrorResponse'];
|
|
428
|
+
/**
|
|
429
|
+
* Individual validation issue within an {@link ErrorResponse}.
|
|
430
|
+
* @category API Types
|
|
431
|
+
*/
|
|
408
432
|
type ValidationIssue = components['schemas']['ValidationIssue'];
|
|
433
|
+
/**
|
|
434
|
+
* A message in a conversation (user, assistant, or system).
|
|
435
|
+
* @category API Types
|
|
436
|
+
*/
|
|
409
437
|
type Message = components['schemas']['Message'];
|
|
438
|
+
/**
|
|
439
|
+
* The role of a {@link Message}: `'user'`, `'assistant'`, or `'system'`.
|
|
440
|
+
* @category API Types
|
|
441
|
+
*/
|
|
410
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
|
+
*/
|
|
411
455
|
type Application = components['schemas']['Application'];
|
|
456
|
+
/**
|
|
457
|
+
* Resource within an {@link Application}.
|
|
458
|
+
* @category Configuration
|
|
459
|
+
*/
|
|
412
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
|
+
*/
|
|
413
494
|
type Config = components['schemas']['Config'];
|
|
495
|
+
/**
|
|
496
|
+
* Controls what operations the agent can perform.
|
|
497
|
+
*
|
|
498
|
+
* Each capability (`read`, `write`) can be:
|
|
499
|
+
* - `true` — Full access (standard preset)
|
|
500
|
+
* - `false` — No access
|
|
501
|
+
* - `{ preset: 'minimal' }` — Basic tools only
|
|
502
|
+
* - `{ preset: 'standard' }` — All tools available
|
|
503
|
+
*
|
|
504
|
+
* Use `features` to override individual feature toggles independently of presets.
|
|
505
|
+
*
|
|
506
|
+
* @example Read-only access
|
|
507
|
+
* ```ts
|
|
508
|
+
* const capabilities = { read: true, write: false }
|
|
509
|
+
* ```
|
|
510
|
+
*
|
|
511
|
+
* @example Full read, minimal write
|
|
512
|
+
* ```ts
|
|
513
|
+
* const capabilities = {
|
|
514
|
+
* read: true,
|
|
515
|
+
* write: { preset: 'minimal' },
|
|
516
|
+
* }
|
|
517
|
+
* ```
|
|
518
|
+
*
|
|
519
|
+
* @example Standard read with web search disabled
|
|
520
|
+
* ```ts
|
|
521
|
+
* const capabilities = {
|
|
522
|
+
* read: true,
|
|
523
|
+
* write: false,
|
|
524
|
+
* features: { webSearch: false },
|
|
525
|
+
* }
|
|
526
|
+
* ```
|
|
527
|
+
*
|
|
528
|
+
* @category Configuration
|
|
529
|
+
*/
|
|
414
530
|
type Capabilities = components['schemas']['Capabilities'];
|
|
531
|
+
/**
|
|
532
|
+
* A single capability value: `true`, `false`, or a {@link CapabilityPreset}.
|
|
533
|
+
* @category Configuration
|
|
534
|
+
*/
|
|
415
535
|
type Capability = components['schemas']['Capability'];
|
|
536
|
+
/**
|
|
537
|
+
* A capability preset object, e.g. `{ preset: 'minimal' }` or `{ preset: 'standard' }`.
|
|
538
|
+
* @category Configuration
|
|
539
|
+
*/
|
|
416
540
|
type CapabilityPreset = components['schemas']['CapabilityPreset'];
|
|
541
|
+
/**
|
|
542
|
+
* The preset level string: `'minimal'` or `'standard'`.
|
|
543
|
+
* @category Configuration
|
|
544
|
+
*/
|
|
417
545
|
type CapabilityPresetValue = CapabilityPreset['preset'];
|
|
546
|
+
/**
|
|
547
|
+
* GROQ boolean expressions to control document visibility and mutation permissions.
|
|
548
|
+
*
|
|
549
|
+
* @category Configuration
|
|
550
|
+
*
|
|
551
|
+
* @example
|
|
552
|
+
* ```ts
|
|
553
|
+
* const filter = {
|
|
554
|
+
* read: '_type in ["post", "author", "category"]',
|
|
555
|
+
* write: '_type == "post"',
|
|
556
|
+
* }
|
|
557
|
+
* ```
|
|
558
|
+
*/
|
|
418
559
|
type Filter = components['schemas']['Filter'];
|
|
560
|
+
/**
|
|
561
|
+
* Key-value pairs appended to each user message as XML tags.
|
|
562
|
+
*
|
|
563
|
+
* @category Configuration
|
|
564
|
+
*
|
|
565
|
+
* @example
|
|
566
|
+
* ```ts
|
|
567
|
+
* const userMessageContext = {
|
|
568
|
+
* 'slack-channel': '#marketing',
|
|
569
|
+
* 'user-role': 'editor',
|
|
570
|
+
* }
|
|
571
|
+
* // Renders in the user message as:
|
|
572
|
+
* // <slack-channel>#marketing</slack-channel>
|
|
573
|
+
* // <user-role>editor</user-role>
|
|
574
|
+
* ```
|
|
575
|
+
*/
|
|
419
576
|
type UserMessageContext = NonNullable<Config['userMessageContext']>;
|
|
420
577
|
/**
|
|
421
|
-
* Settings for creating a Content Agent provider instance.
|
|
578
|
+
* Settings for creating a Content Agent provider instance via {@link createContentAgent}.
|
|
579
|
+
*
|
|
580
|
+
* @category Provider
|
|
581
|
+
*
|
|
582
|
+
* @example
|
|
583
|
+
* ```ts
|
|
584
|
+
* import { createContentAgent } from 'content-agent'
|
|
585
|
+
*
|
|
586
|
+
* const contentAgent = createContentAgent({
|
|
587
|
+
* organizationId: 'your-org-id',
|
|
588
|
+
* token: 'your-sanity-token',
|
|
589
|
+
* // Optional overrides:
|
|
590
|
+
* // baseURL: 'https://api.sanity.io',
|
|
591
|
+
* // apiVersion: 'v2026-01-01',
|
|
592
|
+
* })
|
|
593
|
+
* ```
|
|
422
594
|
*/
|
|
423
595
|
interface ContentAgentProviderSettings {
|
|
424
596
|
/**
|
|
@@ -454,6 +626,44 @@ interface ContentAgentProviderSettings {
|
|
|
454
626
|
}
|
|
455
627
|
/**
|
|
456
628
|
* Base settings shared between agent and generate requests.
|
|
629
|
+
*
|
|
630
|
+
* @example Read-only agent with document type filtering
|
|
631
|
+
* ```ts
|
|
632
|
+
* const settings = {
|
|
633
|
+
* application: { key: 'projectId.datasetName' },
|
|
634
|
+
* config: {
|
|
635
|
+
* instruction: 'You are a helpful content assistant for our blog.',
|
|
636
|
+
* capabilities: {
|
|
637
|
+
* read: true,
|
|
638
|
+
* write: false,
|
|
639
|
+
* },
|
|
640
|
+
* filter: {
|
|
641
|
+
* read: '_type in ["post", "author", "category"]',
|
|
642
|
+
* },
|
|
643
|
+
* },
|
|
644
|
+
* }
|
|
645
|
+
* ```
|
|
646
|
+
*
|
|
647
|
+
* @example Read/write agent with perspective locking
|
|
648
|
+
* ```ts
|
|
649
|
+
* const settings = {
|
|
650
|
+
* application: { key: 'projectId.datasetName' },
|
|
651
|
+
* config: {
|
|
652
|
+
* capabilities: {
|
|
653
|
+
* read: true,
|
|
654
|
+
* write: { preset: 'minimal' },
|
|
655
|
+
* },
|
|
656
|
+
* filter: {
|
|
657
|
+
* read: '_type in ["post", "author", "category"]',
|
|
658
|
+
* write: '_type == "post"',
|
|
659
|
+
* },
|
|
660
|
+
* perspectives: {
|
|
661
|
+
* read: ['drafts', 'published'],
|
|
662
|
+
* write: 'drafts',
|
|
663
|
+
* },
|
|
664
|
+
* },
|
|
665
|
+
* }
|
|
666
|
+
* ```
|
|
457
667
|
*/
|
|
458
668
|
interface BaseAgentSettings {
|
|
459
669
|
/**
|
|
@@ -474,10 +684,41 @@ interface BaseAgentSettings {
|
|
|
474
684
|
}
|
|
475
685
|
/**
|
|
476
686
|
* Settings for creating an agent instance (per-thread).
|
|
687
|
+
*
|
|
688
|
+
* Passed as the second argument to {@link ContentAgentProvider.agent | contentAgent.agent(threadId, settings)}.
|
|
689
|
+
*
|
|
690
|
+
* @example
|
|
691
|
+
* ```ts
|
|
692
|
+
* const model = contentAgent.agent('my-thread-id', {
|
|
693
|
+
* application: { key: 'projectId.datasetName' },
|
|
694
|
+
* config: {
|
|
695
|
+
* capabilities: { read: true, write: false },
|
|
696
|
+
* },
|
|
697
|
+
* })
|
|
698
|
+
* ```
|
|
699
|
+
*
|
|
700
|
+
* @category Configuration
|
|
477
701
|
*/
|
|
478
702
|
type AgentSettings = BaseAgentSettings;
|
|
479
703
|
/**
|
|
480
|
-
* Settings for one-shot generation requests.
|
|
704
|
+
* Settings for one-shot generation requests via {@link ContentAgentProvider.prompt | contentAgent.prompt()}.
|
|
705
|
+
*
|
|
706
|
+
* Extends {@link BaseAgentSettings} with an additional `instructions` field
|
|
707
|
+
* for providing custom system-level instructions.
|
|
708
|
+
*
|
|
709
|
+
* @example
|
|
710
|
+
* ```ts
|
|
711
|
+
* const { text } = await contentAgent.prompt(
|
|
712
|
+
* {
|
|
713
|
+
* application: { key: 'projectId.datasetName' },
|
|
714
|
+
* config: { capabilities: { read: true, write: false } },
|
|
715
|
+
* instructions: 'Be concise',
|
|
716
|
+
* },
|
|
717
|
+
* { message: 'List my 5 most recent posts' },
|
|
718
|
+
* )
|
|
719
|
+
* ```
|
|
720
|
+
*
|
|
721
|
+
* @category Configuration
|
|
481
722
|
*/
|
|
482
723
|
interface GenerateSettings extends BaseAgentSettings {
|
|
483
724
|
/**
|
|
@@ -485,6 +726,19 @@ interface GenerateSettings extends BaseAgentSettings {
|
|
|
485
726
|
*/
|
|
486
727
|
instructions?: string;
|
|
487
728
|
}
|
|
729
|
+
/**
|
|
730
|
+
* Options for a one-shot generation request via {@link ContentAgentProvider.prompt | contentAgent.prompt()}.
|
|
731
|
+
*
|
|
732
|
+
* @category Configuration
|
|
733
|
+
*
|
|
734
|
+
* @example
|
|
735
|
+
* ```ts
|
|
736
|
+
* const { text } = await contentAgent.prompt(
|
|
737
|
+
* { instructions: 'Be concise' },
|
|
738
|
+
* { message: 'List all authors in my dataset' },
|
|
739
|
+
* )
|
|
740
|
+
* ```
|
|
741
|
+
*/
|
|
488
742
|
interface GenerateOptions {
|
|
489
743
|
/**
|
|
490
744
|
* The prompt message to send.
|
|
@@ -500,12 +754,20 @@ interface GenerateOptions {
|
|
|
500
754
|
*/
|
|
501
755
|
abortSignal?: AbortSignal;
|
|
502
756
|
}
|
|
757
|
+
/**
|
|
758
|
+
* Result from a one-shot generation request via {@link ContentAgentProvider.prompt | contentAgent.prompt()}.
|
|
759
|
+
*
|
|
760
|
+
* @category Configuration
|
|
761
|
+
*/
|
|
503
762
|
interface GenerateResult {
|
|
504
763
|
/**
|
|
505
764
|
* The generated text response.
|
|
506
765
|
*/
|
|
507
766
|
text: string;
|
|
508
767
|
}
|
|
768
|
+
/**
|
|
769
|
+
* @category Model
|
|
770
|
+
*/
|
|
509
771
|
interface ContentAgentModelConfig {
|
|
510
772
|
provider: string;
|
|
511
773
|
baseURL: string;
|
|
@@ -514,6 +776,38 @@ interface ContentAgentModelConfig {
|
|
|
514
776
|
headers: () => Record<string, string | undefined>;
|
|
515
777
|
fetch?: typeof globalThis.fetch;
|
|
516
778
|
}
|
|
779
|
+
/**
|
|
780
|
+
* Vercel AI SDK `LanguageModelV1` implementation that communicates with the
|
|
781
|
+
* Sanity Content Agent API via a conversation thread.
|
|
782
|
+
*
|
|
783
|
+
* Typically you don't construct this directly — use
|
|
784
|
+
* {@link createContentAgent | createContentAgent().agent(threadId)} instead.
|
|
785
|
+
*
|
|
786
|
+
* @category Model
|
|
787
|
+
*
|
|
788
|
+
* @example
|
|
789
|
+
* ```ts
|
|
790
|
+
* import { createContentAgent } from 'content-agent'
|
|
791
|
+
* import { streamText } from 'ai'
|
|
792
|
+
*
|
|
793
|
+
* const contentAgent = createContentAgent({
|
|
794
|
+
* organizationId: 'your-org-id',
|
|
795
|
+
* token: 'your-sanity-token',
|
|
796
|
+
* })
|
|
797
|
+
*
|
|
798
|
+
* const model = contentAgent.agent('my-thread-id', {
|
|
799
|
+
* application: { key: 'projectId.datasetName' },
|
|
800
|
+
* config: {
|
|
801
|
+
* capabilities: { read: true, write: false },
|
|
802
|
+
* },
|
|
803
|
+
* })
|
|
804
|
+
*
|
|
805
|
+
* const { textStream } = await streamText({ model, prompt: 'Summarize my content' })
|
|
806
|
+
* for await (const chunk of textStream) {
|
|
807
|
+
* process.stdout.write(chunk)
|
|
808
|
+
* }
|
|
809
|
+
* ```
|
|
810
|
+
*/
|
|
517
811
|
declare class ContentAgentModel implements LanguageModelV3 {
|
|
518
812
|
readonly specificationVersion: "v3";
|
|
519
813
|
readonly provider: string;
|
|
@@ -549,9 +843,48 @@ declare class ContentAgentModel implements LanguageModelV3 {
|
|
|
549
843
|
private extractContentFromStream;
|
|
550
844
|
doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
|
|
551
845
|
}
|
|
846
|
+
/**
|
|
847
|
+
* A Content Agent provider instance returned by {@link createContentAgent}.
|
|
848
|
+
*
|
|
849
|
+
* Provides two modes of interaction:
|
|
850
|
+
* - **Conversation threads** via {@link ContentAgentProvider.agent | .agent()} — stateful, multi-turn conversations with server-side message history.
|
|
851
|
+
* - **One-shot prompts** via {@link ContentAgentProvider.prompt | .prompt()} — stateless, single-turn interactions.
|
|
852
|
+
*
|
|
853
|
+
* @category Provider
|
|
854
|
+
*/
|
|
552
855
|
interface ContentAgentProvider {
|
|
553
856
|
/**
|
|
554
|
-
* Creates
|
|
857
|
+
* Creates a Vercel AI SDK {@link https://sdk.vercel.ai/docs/ai-sdk-core | LanguageModelV1} for a conversation thread.
|
|
858
|
+
*
|
|
859
|
+
* The thread ID identifies the conversation and maintains message history server-side.
|
|
860
|
+
* If a thread with that ID already exists, the conversation continues. If not, a new
|
|
861
|
+
* thread is automatically created.
|
|
862
|
+
*
|
|
863
|
+
* Use the returned model with `generateText` or `streamText` from the `ai` package.
|
|
864
|
+
*
|
|
865
|
+
* @example
|
|
866
|
+
* ```ts
|
|
867
|
+
* import { generateText, streamText } from 'ai'
|
|
868
|
+
*
|
|
869
|
+
* const model = contentAgent.agent('my-thread-id', {
|
|
870
|
+
* application: { key: 'projectId.datasetName' },
|
|
871
|
+
* config: {
|
|
872
|
+
* capabilities: { read: true, write: false },
|
|
873
|
+
* },
|
|
874
|
+
* })
|
|
875
|
+
*
|
|
876
|
+
* // Non-streaming
|
|
877
|
+
* const { text } = await generateText({ model, prompt: 'What blog posts do I have?' })
|
|
878
|
+
*
|
|
879
|
+
* // Streaming
|
|
880
|
+
* const { textStream } = await streamText({ model, prompt: 'Summarize my content' })
|
|
881
|
+
* for await (const chunk of textStream) {
|
|
882
|
+
* process.stdout.write(chunk)
|
|
883
|
+
* }
|
|
884
|
+
* ```
|
|
885
|
+
*
|
|
886
|
+
* @param threadId - Unique identifier for the conversation thread.
|
|
887
|
+
* @param settings - Optional agent settings (application, capabilities, filters, etc.).
|
|
555
888
|
*/
|
|
556
889
|
agent(threadId: string, settings?: AgentSettings): LanguageModelV3;
|
|
557
890
|
/**
|
|
@@ -574,37 +907,105 @@ interface ContentAgentProvider {
|
|
|
574
907
|
/**
|
|
575
908
|
* Sends a one-shot prompt to the Content Agent (stateless).
|
|
576
909
|
*
|
|
577
|
-
* Unlike
|
|
910
|
+
* Unlike {@link ContentAgentProvider.agent | .agent()}, this does not create or use a conversation thread.
|
|
578
911
|
* Each call is independent with no message history or persistence.
|
|
579
912
|
* Ideal for simple, single-turn interactions.
|
|
580
913
|
*
|
|
581
914
|
* @example
|
|
582
915
|
* ```ts
|
|
583
|
-
* const
|
|
584
|
-
* {
|
|
585
|
-
*
|
|
916
|
+
* const { text } = await contentAgent.prompt(
|
|
917
|
+
* {
|
|
918
|
+
* application: { key: 'projectId.datasetName' },
|
|
919
|
+
* config: { capabilities: { read: true, write: false } },
|
|
920
|
+
* instructions: 'Be concise',
|
|
921
|
+
* },
|
|
922
|
+
* { message: 'List my 5 most recent posts' },
|
|
586
923
|
* )
|
|
587
|
-
* console.log(result.text)
|
|
588
924
|
* ```
|
|
925
|
+
*
|
|
926
|
+
* @param settings - Generation settings (application, capabilities, instructions, etc.).
|
|
927
|
+
* @param options - The prompt message and request options.
|
|
589
928
|
*/
|
|
590
929
|
prompt(settings: GenerateSettings, options: GenerateOptions): Promise<GenerateResult>;
|
|
591
930
|
}
|
|
592
931
|
/**
|
|
593
932
|
* Creates a Content Agent provider instance.
|
|
933
|
+
*
|
|
934
|
+
* The provider is the main entry point for interacting with the Sanity Content Agent API.
|
|
935
|
+
* It returns an object with methods for conversation threads and one-shot prompts.
|
|
936
|
+
*
|
|
937
|
+
* @category Provider
|
|
938
|
+
*
|
|
939
|
+
* @example Basic setup
|
|
940
|
+
* ```ts
|
|
941
|
+
* import { createContentAgent } from 'content-agent'
|
|
942
|
+
*
|
|
943
|
+
* const contentAgent = createContentAgent({
|
|
944
|
+
* organizationId: 'your-org-id',
|
|
945
|
+
* token: 'your-sanity-token',
|
|
946
|
+
* })
|
|
947
|
+
* ```
|
|
948
|
+
*
|
|
949
|
+
* @example Using with Vercel AI SDK for conversation threads
|
|
950
|
+
* ```ts
|
|
951
|
+
* import { createContentAgent } from 'content-agent'
|
|
952
|
+
* import { generateText, streamText } from 'ai'
|
|
953
|
+
*
|
|
954
|
+
* const contentAgent = createContentAgent({
|
|
955
|
+
* organizationId: 'your-org-id',
|
|
956
|
+
* token: 'your-sanity-token',
|
|
957
|
+
* })
|
|
958
|
+
*
|
|
959
|
+
* const model = contentAgent.agent('my-thread-id', {
|
|
960
|
+
* application: { key: 'projectId.datasetName' },
|
|
961
|
+
* config: {
|
|
962
|
+
* capabilities: { read: true, write: false },
|
|
963
|
+
* },
|
|
964
|
+
* })
|
|
965
|
+
*
|
|
966
|
+
* // Non-streaming
|
|
967
|
+
* const { text } = await generateText({ model, prompt: 'What blog posts do I have?' })
|
|
968
|
+
*
|
|
969
|
+
* // Streaming
|
|
970
|
+
* const { textStream } = await streamText({ model, prompt: 'Summarize my content' })
|
|
971
|
+
* for await (const chunk of textStream) {
|
|
972
|
+
* process.stdout.write(chunk)
|
|
973
|
+
* }
|
|
974
|
+
* ```
|
|
975
|
+
*
|
|
976
|
+
* @example One-shot generation (stateless, no thread)
|
|
977
|
+
* ```ts
|
|
978
|
+
* const { text } = await contentAgent.prompt(
|
|
979
|
+
* {
|
|
980
|
+
* application: { key: 'projectId.datasetName' },
|
|
981
|
+
* config: { capabilities: { read: true, write: false } },
|
|
982
|
+
* instructions: 'Be concise',
|
|
983
|
+
* },
|
|
984
|
+
* { message: 'List my 5 most recent posts' },
|
|
985
|
+
* )
|
|
986
|
+
* ```
|
|
987
|
+
*
|
|
988
|
+
* @param options - Provider configuration including organization ID, token, and optional overrides.
|
|
594
989
|
*/
|
|
595
990
|
declare function createContentAgent(options: ContentAgentProviderSettings): ContentAgentProvider;
|
|
596
991
|
/**
|
|
597
992
|
* Builds headers for API requests, filtering out undefined values.
|
|
993
|
+
*
|
|
994
|
+
* @category Utilities
|
|
598
995
|
*/
|
|
599
996
|
declare function buildHeaders(configHeaders: Record<string, string | undefined>, additionalHeaders?: Record<string, string>): Record<string, string>;
|
|
600
997
|
/**
|
|
601
998
|
* Constructs the full API URL for an endpoint.
|
|
999
|
+
*
|
|
1000
|
+
* @category Utilities
|
|
602
1001
|
*/
|
|
603
1002
|
declare function buildApiUrl(baseURL: string, apiVersion: string, endpoint: string): string;
|
|
604
1003
|
/**
|
|
605
1004
|
* Custom error class for Sanity Agent API errors.
|
|
606
1005
|
* The {@link body} is parsed from the JSON response and follows the
|
|
607
1006
|
* {@link HeadlessErrorResponse} shape defined in `@sanity/agent-types`.
|
|
1007
|
+
*
|
|
1008
|
+
* @category Utilities
|
|
608
1009
|
*/
|
|
609
1010
|
declare class SanityAgentError extends Error {
|
|
610
1011
|
readonly status: number;
|
|
@@ -625,11 +1026,15 @@ type AgentErrorType = {
|
|
|
625
1026
|
* Classifies a caught error from the Content Agent API into a known error type.
|
|
626
1027
|
* Useful for clients that need to take different actions per error (e.g. show
|
|
627
1028
|
* resource-selection buttons). For the user-facing message, use {@link getAgentErrorMessage}.
|
|
1029
|
+
*
|
|
1030
|
+
* @category Utilities
|
|
628
1031
|
*/
|
|
629
1032
|
declare function classifyAgentError(error: unknown): AgentErrorType;
|
|
630
1033
|
/**
|
|
631
1034
|
* Extracts a user-facing error message from an agent API error.
|
|
632
1035
|
* Returns the message sent by the API when available, otherwise a generic fallback.
|
|
1036
|
+
*
|
|
1037
|
+
* @category Utilities
|
|
633
1038
|
*/
|
|
634
1039
|
declare function getAgentErrorMessage(error: unknown): string;
|
|
635
1040
|
interface FetchOptions {
|
|
@@ -642,10 +1047,14 @@ interface FetchOptions {
|
|
|
642
1047
|
/**
|
|
643
1048
|
* Makes a POST request and returns the response.
|
|
644
1049
|
* Throws SanityAgentError if the response is not ok.
|
|
1050
|
+
*
|
|
1051
|
+
* @category Utilities
|
|
645
1052
|
*/
|
|
646
1053
|
declare function fetchApi(options: FetchOptions): Promise<Response>;
|
|
647
1054
|
/**
|
|
648
1055
|
* Extracts text content from message parts (user or assistant).
|
|
1056
|
+
*
|
|
1057
|
+
* @category Utilities
|
|
649
1058
|
*/
|
|
650
1059
|
declare function extractTextFromParts(content: string | Array<{
|
|
651
1060
|
type: string;
|
|
@@ -653,6 +1062,8 @@ declare function extractTextFromParts(content: string | Array<{
|
|
|
653
1062
|
}>): string;
|
|
654
1063
|
/**
|
|
655
1064
|
* Maps API finish reasons to LanguageModelV3FinishReason.
|
|
1065
|
+
*
|
|
1066
|
+
* @category Utilities
|
|
656
1067
|
*/
|
|
657
1068
|
declare function mapFinishReason(reason: string | undefined): LanguageModelV3FinishReason;
|
|
658
1069
|
type ParsedStreamLine = {
|
|
@@ -675,16 +1086,22 @@ type ParsedStreamLine = {
|
|
|
675
1086
|
* e:{finishReason, usage} – finish step
|
|
676
1087
|
*
|
|
677
1088
|
* @see https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol
|
|
1089
|
+
*
|
|
1090
|
+
* @category Utilities
|
|
678
1091
|
*/
|
|
679
1092
|
declare function parseStreamLine(line: string, textContentId: string): ParsedStreamLine | null;
|
|
680
1093
|
/**
|
|
681
1094
|
* Extracts accumulated text from a streaming response body.
|
|
682
1095
|
* Used for simple streaming cases where only the final text is needed.
|
|
1096
|
+
*
|
|
1097
|
+
* @category Utilities
|
|
683
1098
|
*/
|
|
684
1099
|
declare function extractTextFromStream(responseBody: ReadableStream<Uint8Array>): Promise<string>;
|
|
685
1100
|
/**
|
|
686
1101
|
* Creates a ReadableStream that parses SSE data from a response body
|
|
687
1102
|
* and emits LanguageModelV3 stream parts with proper lifecycle events.
|
|
1103
|
+
*
|
|
1104
|
+
* @category Utilities
|
|
688
1105
|
*/
|
|
689
1106
|
declare function createSSEStream(responseBody: ReadableStream<Uint8Array>, warnings: SharedV3Warning[]): ReadableStream<LanguageModelV3StreamPart>;
|
|
690
1107
|
export { type AgentErrorType, type AgentSettings, type Application, type ApplicationResource, type Capabilities, type Capability, type CapabilityPreset, type CapabilityPresetValue, type ChatRequest, type ChatResponse, type ClientToolDefinition, type Config, ContentAgentModel, type ContentAgentModelConfig, type ContentAgentProvider, type ContentAgentProviderSettings, type ErrorResponse, type Filter, GENERIC_ERROR_MESSAGE, type GenerateOptions, type GenerateRequest, type GenerateResult, type GenerateSettings, type Message, type MessageRole, type OutputFormat, type ParsedStreamLine, SanityAgentError, type UserMessageContext, type ValidationIssue, buildApiUrl, buildHeaders, classifyAgentError, type components, createContentAgent, createSSEStream, extractTextFromParts, extractTextFromStream, fetchApi, getAgentErrorMessage, mapFinishReason, type operations, parseStreamLine, type paths };
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/generated/openapi.ts","../src/types.ts","../src/sanity-agent-language-model.ts","../src/sanity-agent-provider.ts","../src/utils.ts"],"mappings":";;;;;AAKA;KAAY,KAAA;EACV,sCAAA;IACE,UAAA;MACE,KAAA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AAO,UAAA;MACP,KAAA,GAAQ,UAAA;MACR,QAAA,GAAW,UAAA;IAAA;IAgMb;;;;IA1LA,gBAAA;MAiME;;;;MA5LA,SAAA;IAAA;IAmMI;;;;;;IA3LN,UAAA,YAAsB,UAAA;IACtB,gBAAA;MAiMO;;;;;;;;;;MAtLL,MAAA;IAAA,GAuMA;IApMF,MAAA;MAsMM;;;;;MAhMJ,IAAA;MAwMK;;;;;MAlML,KAAA;IAAA;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/generated/openapi.ts","../src/types.ts","../src/sanity-agent-language-model.ts","../src/sanity-agent-provider.ts","../src/utils.ts"],"mappings":";;;;;AAKA;KAAY,KAAA;EACV,sCAAA;IACE,UAAA;MACE,KAAA;MACA,MAAA;MACA,IAAA;MACA,MAAA;IAAA;IAEF,GAAA;IACA,GAAA;IAAA;;;;;IAMA,IAAA,EAAM,UAAA;IACN,MAAA;IACA,OAAA;IACA,IAAA;IACA,KAAA;IACA,KAAA;EAAA;EAEF,SAAA;IACE,UAAA;MACE,KAAA;MACA,MAAA;MACA,IAAA;MACA,MAAA;IAAA;IAEF,GAAA;IACA,GAAA;IAUA;;;;AAKJ;IATI,IAAA,EAAM,UAAA;IACN,MAAA;IACA,OAAA;IACA,IAAA;IACA,KAAA;IACA,KAAA;EAAA;AAAA;AAAA,KAIQ,UAAA;EACV,OAAA;IACE,WAAA;MAiJsB,4CA/IpB,QAAA,EAAU,UAAA;MACV,WAAA,GAAc,UAAA;MACd,MAAA,GAAS,UAAA;MA6Ra;;;;MAxRtB,MAAA;MAPA;;;;;;;MAeA,MAAA;IAAA;IAEF,aAAA;MAUE;;;;MALA,cAAA;MAqBF;;;;MAhBE,OAAA;MACA,MAAA,GAAS,UAAA;MAkCT;;;;MA7BA,YAAA;MAiDA;;;;;;;MAzCA,MAAA;IAAA;IAEF,OAAA;MAmEE;;;;MA9DA,IAAA,mCA0EA;MAxEA,OAAA,UAyEA;MAvEA,EAAA,WAwEA;M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AA,IAC5B,OAAA;;;;;;;iBA4Ba,eAAA,CACd,YAAA,EAAc,cAAA,CAAe,UAAA,GAC7B,QAAA,EAAU,eAAA,KACT,cAAA,CAAe,yBAAA"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/utils.ts","../src/sanity-agent-language-model.ts","../src/sanity-agent-provider.ts"],"sourcesContent":["import type {\n LanguageModelV3FinishReason,\n LanguageModelV3StreamPart,\n LanguageModelV3Usage,\n SharedV3Warning,\n} from '@ai-sdk/provider'\nimport { HEADLESS_ERROR_CODES, type HeadlessErrorResponse } from '@sanity/agent-types'\nimport { isString, pickBy } from 'es-toolkit'\n\n/**\n * Builds headers for API requests, filtering out undefined values.\n */\nexport function buildHeaders(\n configHeaders: Record<string, string | undefined>,\n additionalHeaders?: Record<string, string>,\n): Record<string, string> {\n return pickBy(\n {\n 'Content-Type': 'application/json',\n ...additionalHeaders,\n ...configHeaders,\n },\n isString,\n )\n}\n\n/**\n * Constructs the full API URL for an endpoint.\n */\nexport function buildApiUrl(baseURL: string, apiVersion: string, endpoint: string): string {\n return `${baseURL}/${apiVersion}/agent${endpoint}`\n}\n\n/**\n * Custom error class for Sanity Agent API errors.\n * The {@link body} is parsed from the JSON response and follows the\n * {@link HeadlessErrorResponse} shape defined in `@sanity/agent-types`.\n */\nexport class SanityAgentError extends Error {\n readonly status: number\n readonly isRetryable: boolean\n readonly body: Partial<HeadlessErrorResponse>\n\n constructor(status: number, message: string) {\n super(`Sanity Agent API error: ${status} ${message}`)\n this.name = 'SanityAgentError'\n this.status = status\n this.isRetryable = status >= 500\n this.body = SanityAgentError.parseBody(message)\n }\n\n private static parseBody(message: string): Partial<HeadlessErrorResponse> {\n try {\n return JSON.parse(message)\n } catch {\n return {}\n }\n }\n}\n\nexport const GENERIC_ERROR_MESSAGE = 'Sorry, something went wrong. Please try again.'\n\nexport type AgentErrorType =\n | { type: 'no_applications' }\n | { type: 'application_not_found' }\n | { type: 'unknown' }\n\n/**\n * Classifies a caught error from the Content Agent API into a known error type.\n * Useful for clients that need to take different actions per error (e.g. show\n * resource-selection buttons). For the user-facing message, use {@link getAgentErrorMessage}.\n */\nexport function classifyAgentError(error: unknown): AgentErrorType {\n if (!(error instanceof SanityAgentError) || error.status !== 400) {\n return { type: 'unknown' }\n }\n\n switch (error.body.code) {\n case HEADLESS_ERROR_CODES.NO_COMPATIBLE_APPLICATIONS:\n return { type: 'no_applications' }\n case HEADLESS_ERROR_CODES.APPLICATION_NOT_FOUND:\n return { type: 'application_not_found' }\n default:\n return { type: 'unknown' }\n }\n}\n\n/**\n * Extracts a user-facing error message from an agent API error.\n * Returns the message sent by the API when available, otherwise a generic fallback.\n */\nexport function getAgentErrorMessage(error: unknown): string {\n if (error instanceof SanityAgentError && error.body.message) {\n return error.body.message\n }\n return GENERIC_ERROR_MESSAGE\n}\n\nexport interface FetchOptions {\n url: string\n body: unknown\n headers: Record<string, string>\n signal?: AbortSignal\n fetch?: typeof globalThis.fetch\n}\n\n/**\n * Makes a POST request and returns the response.\n * Throws SanityAgentError if the response is not ok.\n */\nexport async function fetchApi(options: FetchOptions): Promise<Response> {\n const fetchFn = options.fetch ?? globalThis.fetch\n\n const response = await fetchFn(options.url, {\n method: 'POST',\n headers: options.headers,\n body: JSON.stringify(options.body),\n signal: options.signal,\n })\n\n if (!response.ok) {\n const errorText = await response.text()\n throw new SanityAgentError(response.status, errorText)\n }\n\n return response\n}\n\n/**\n * Extracts text content from message parts (user or assistant).\n */\nexport function extractTextFromParts(\n content: string | Array<{ type: string; text?: string }>,\n): string {\n if (typeof content === 'string') {\n return content\n }\n\n return content\n .filter(\n (part): part is { type: 'text'; text: string } =>\n part.type === 'text' && typeof part.text === 'string',\n )\n .map((part) => part.text)\n .join('\\n')\n}\n\n/**\n * Creates an empty V3 usage object. Our API does not return token counts.\n */\nexport function createEmptyUsage(): LanguageModelV3Usage {\n return {\n inputTokens: {\n total: 0,\n noCache: undefined,\n cacheRead: undefined,\n cacheWrite: undefined,\n },\n outputTokens: {\n total: 0,\n text: undefined,\n reasoning: undefined,\n },\n }\n}\n\n/**\n * Maps API finish reasons to LanguageModelV3FinishReason.\n */\nexport function mapFinishReason(reason: string | undefined): LanguageModelV3FinishReason {\n const unified = (() => {\n switch (reason) {\n case 'stop':\n case 'length':\n case 'content-filter':\n case 'tool-calls':\n case 'error':\n return reason\n default:\n return 'other' as const\n }\n })()\n\n return { unified, raw: reason }\n}\n\nexport type ParsedStreamLine =\n | { kind: 'part'; part: LanguageModelV3StreamPart }\n | { kind: 'finish'; finishReason: LanguageModelV3FinishReason }\n\n/**\n * Parses a single line from the Vercel AI Data Stream Protocol.\n * Returns null if the line cannot be parsed or should be ignored.\n *\n * Protocol prefixes:\n * 0:\"text\" – text content\n * 2:[data] – data array (ignored)\n * 3:\"error\" – error\n * b:{toolCallId,toolName,args} – client tool call\n * d:{finishReason, usage} – finish message\n * e:{finishReason, usage} – finish step\n *\n * @see https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol\n */\nexport function parseStreamLine(line: string, textContentId: string): ParsedStreamLine | null {\n const trimmed = line.trim()\n if (!trimmed || trimmed.length < 2 || trimmed[1] !== ':') return null\n\n const prefix = trimmed[0]\n const payload = trimmed.slice(2)\n\n switch (prefix) {\n case '0': {\n try {\n const text = JSON.parse(payload) as unknown\n if (typeof text === 'string') {\n return { kind: 'part', part: { type: 'text-delta', id: textContentId, delta: text } }\n }\n } catch {\n // Ignore parse errors\n }\n return null\n }\n\n case '3': {\n try {\n const msg = JSON.parse(payload) as unknown\n return {\n kind: 'part',\n part: {\n type: 'error',\n error: new Error(typeof msg === 'string' ? msg : 'Unknown error'),\n },\n }\n } catch {\n return {\n kind: 'part',\n part: { type: 'error', error: new Error('Unknown streaming error') },\n }\n }\n }\n\n case 'b': {\n try {\n const data = JSON.parse(payload) as {\n toolCallId: string\n toolName: string\n args: unknown\n }\n return {\n kind: 'part',\n part: {\n type: 'tool-call',\n toolCallId: data.toolCallId,\n toolName: data.toolName,\n input: typeof data.args === 'string' ? data.args : JSON.stringify(data.args),\n },\n }\n } catch {\n return null\n }\n }\n\n case 'd':\n case 'e': {\n try {\n const data = JSON.parse(payload) as { finishReason?: string }\n return { kind: 'finish', finishReason: mapFinishReason(data.finishReason) }\n } catch {\n return null\n }\n }\n\n default:\n return null\n }\n}\n\n/**\n * Extracts accumulated text from a streaming response body.\n * Used for simple streaming cases where only the final text is needed.\n */\nexport async function extractTextFromStream(\n responseBody: ReadableStream<Uint8Array>,\n): Promise<string> {\n const reader = responseBody.getReader()\n const decoder = new TextDecoder()\n const textContentId = 'extract'\n let text = ''\n\n while (true) {\n const { done, value } = await reader.read()\n if (done) break\n\n const chunk = decoder.decode(value, { stream: true })\n for (const line of chunk.split('\\n')) {\n const parsed = parseStreamLine(line, textContentId)\n if (parsed?.kind === 'part' && parsed.part.type === 'text-delta') {\n text += parsed.part.delta\n }\n }\n }\n\n return text\n}\n\n/**\n * Creates a ReadableStream that parses SSE data from a response body\n * and emits LanguageModelV3 stream parts with proper lifecycle events.\n */\nexport function createSSEStream(\n responseBody: ReadableStream<Uint8Array>,\n warnings: SharedV3Warning[],\n): ReadableStream<LanguageModelV3StreamPart> {\n let finishReason: LanguageModelV3FinishReason = { unified: 'other', raw: undefined }\n const textContentId = crypto.randomUUID()\n let textStarted = false\n let hasToolCalls = false\n\n return new ReadableStream<LanguageModelV3StreamPart>({\n async start(controller) {\n const reader = responseBody.getReader()\n const decoder = new TextDecoder()\n let buffer = ''\n\n controller.enqueue({ type: 'stream-start', warnings })\n\n try {\n while (true) {\n const { done, value } = await reader.read()\n if (done) break\n\n buffer += decoder.decode(value, { stream: true })\n const lines = buffer.split('\\n')\n buffer = lines.pop() ?? ''\n\n for (const line of lines) {\n const parsed = parseStreamLine(line, textContentId)\n if (parsed?.kind === 'part') {\n if (parsed.part.type === 'text-delta' && !textStarted) {\n controller.enqueue({ type: 'text-start', id: textContentId })\n textStarted = true\n }\n if (parsed.part.type === 'tool-call') {\n // Close any open text block before emitting a tool call\n if (textStarted) {\n controller.enqueue({ type: 'text-end', id: textContentId })\n textStarted = false\n }\n hasToolCalls = true\n }\n controller.enqueue(parsed.part)\n } else if (parsed?.kind === 'finish') {\n finishReason = parsed.finishReason\n }\n }\n }\n\n // Process remaining buffer\n if (buffer.trim()) {\n const parsed = parseStreamLine(buffer, textContentId)\n if (parsed?.kind === 'part') {\n if (parsed.part.type === 'text-delta' && !textStarted) {\n controller.enqueue({ type: 'text-start', id: textContentId })\n textStarted = true\n }\n if (parsed.part.type === 'tool-call') {\n if (textStarted) {\n controller.enqueue({ type: 'text-end', id: textContentId })\n textStarted = false\n }\n hasToolCalls = true\n }\n controller.enqueue(parsed.part)\n } else if (parsed?.kind === 'finish') {\n finishReason = parsed.finishReason\n }\n }\n\n if (textStarted) {\n controller.enqueue({ type: 'text-end', id: textContentId })\n }\n\n // If tool calls were emitted, override finish reason so streamText\n // knows to execute tools and continue with the next step.\n if (hasToolCalls && finishReason.unified !== 'tool-calls') {\n finishReason = { unified: 'tool-calls', raw: finishReason.raw ?? 'tool-calls' }\n }\n\n controller.enqueue({\n type: 'finish',\n finishReason,\n usage: createEmptyUsage(),\n })\n } catch (error) {\n controller.enqueue({\n type: 'error',\n error: error instanceof Error ? error : new Error(String(error)),\n })\n } finally {\n controller.close()\n }\n },\n })\n}\n","import type {\n LanguageModelV3,\n LanguageModelV3CallOptions,\n LanguageModelV3Content,\n LanguageModelV3GenerateResult,\n LanguageModelV3Prompt,\n LanguageModelV3StreamResult,\n SharedV3Warning,\n} from '@ai-sdk/provider'\nimport type { ClientToolDefinition } from '@sanity/agent-types'\nimport { groupBy } from 'es-toolkit'\nimport type { AgentSettings, Message } from './types'\nimport {\n buildApiUrl,\n buildHeaders,\n createEmptyUsage,\n createSSEStream,\n extractTextFromParts,\n fetchApi,\n parseStreamLine,\n} from './utils'\n\nexport interface ContentAgentModelConfig {\n provider: string\n baseURL: string\n apiVersion: string\n organizationId: string\n headers: () => Record<string, string | undefined>\n fetch?: typeof globalThis.fetch\n}\n\n/**\n * Extended message type for the wire format that supports tool calls and tool results\n * in addition to plain text messages.\n */\ntype WireMessage =\n | Message\n | {\n role: 'assistant'\n content: Array<\n | { type: 'text'; text: string }\n | { type: 'tool-call'; toolCallId: string; toolName: string; input: string }\n >\n }\n | {\n role: 'tool'\n content: Array<{\n type: 'tool-result'\n toolCallId: string\n toolName: string\n output: unknown\n }>\n }\n\nconst UNSUPPORTED_SETTINGS = [\n 'maxOutputTokens',\n 'temperature',\n 'topP',\n 'topK',\n 'frequencyPenalty',\n 'presencePenalty',\n 'seed',\n] as const\n\nexport class ContentAgentModel implements LanguageModelV3 {\n readonly specificationVersion = 'v3' as const\n readonly provider: string\n readonly modelId: string\n readonly supportedUrls: Record<string, RegExp[]> = {}\n\n private readonly config: ContentAgentModelConfig\n private readonly threadId: string\n private readonly settings: AgentSettings\n\n constructor(\n threadId: string,\n settings: AgentSettings | undefined,\n config: ContentAgentModelConfig,\n ) {\n this.threadId = threadId\n this.modelId = `content-agent:${threadId}`\n this.provider = config.provider\n this.settings = settings ?? {}\n this.config = config\n }\n\n /**\n * Converts a LanguageModelV3Prompt into wire messages for the agent API.\n *\n * Handles all message roles:\n * - system: plain text system messages\n * - user: extracts text from content parts\n * - assistant: extracts text and/or tool-call parts\n * - tool: converts tool-result parts for the API\n */\n private convertPromptToMessages(prompt: LanguageModelV3Prompt): WireMessage[] {\n const messages: WireMessage[] = []\n\n for (const message of prompt) {\n if (message.role === 'system') {\n if (message.content) {\n messages.push({ role: 'system', content: message.content })\n }\n continue\n }\n\n if (message.role === 'tool') {\n const toolResults = message.content\n .filter((part) => part.type === 'tool-result')\n .map((part) => {\n const p = part as {\n toolCallId: string\n toolName: string\n output: { type: string; value: unknown } | unknown\n }\n return {\n type: 'tool-result' as const,\n toolCallId: p.toolCallId,\n toolName: p.toolName,\n output:\n p.output && typeof p.output === 'object' && 'value' in p.output\n ? (p.output as { value: unknown }).value\n : p.output,\n }\n })\n\n if (toolResults.length > 0) {\n messages.push({ role: 'tool', content: toolResults })\n }\n continue\n }\n\n if (message.role === 'assistant') {\n const content = message.content as Array<{\n type: string\n text?: string\n toolCallId?: string\n toolName?: string\n input?: string\n }>\n\n const grouped = groupBy(content, (p) => p.type)\n const toolCalls = grouped['tool-call'] ?? []\n const textParts = grouped['text'] ?? []\n\n if (toolCalls.length > 0) {\n const parts = [\n ...textParts\n .filter((p) => p.text)\n .map((p) => ({ type: 'text' as const, text: p.text! })),\n ...toolCalls.map((tc) => ({\n type: 'tool-call' as const,\n toolCallId: tc.toolCallId!,\n toolName: tc.toolName!,\n input: tc.input!,\n })),\n ]\n\n if (parts.length > 0) {\n messages.push({ role: 'assistant', content: parts })\n }\n } else {\n const text = extractTextFromParts(content as Array<{ type: string; text?: string }>)\n if (text) {\n messages.push({ role: 'assistant', content: text })\n }\n }\n continue\n }\n\n // user messages\n const text = extractTextFromParts(message.content as Array<{ type: string; text?: string }>)\n if (text) {\n messages.push({ role: message.role, content: text })\n }\n }\n\n return messages\n }\n\n /**\n * Extracts client tool definitions from the model call options.\n * Only the schemas are sent — execute functions stay on the client.\n */\n private extractClientTools(\n options: LanguageModelV3CallOptions,\n ): ClientToolDefinition[] | undefined {\n if (!options.tools?.length) return undefined\n\n const clientTools = options.tools\n .filter((t) => t.type === 'function')\n .map((t) => ({\n type: 'function' as const,\n name: t.name,\n description: t.description,\n inputSchema: t.inputSchema as Record<string, unknown>,\n }))\n\n return clientTools.length > 0 ? clientTools : undefined\n }\n\n private collectWarnings(options: LanguageModelV3CallOptions): SharedV3Warning[] {\n const warnings: SharedV3Warning[] = []\n\n for (const setting of UNSUPPORTED_SETTINGS) {\n if (options[setting] !== undefined) {\n warnings.push({ type: 'unsupported', feature: setting })\n }\n }\n\n if (options.stopSequences?.length) {\n warnings.push({ type: 'unsupported', feature: 'stopSequences' })\n }\n\n if (options.responseFormat && options.responseFormat.type !== 'text') {\n warnings.push({ type: 'unsupported', feature: 'responseFormat' })\n }\n\n return warnings\n }\n\n private buildRequestBody(options: LanguageModelV3CallOptions, stream: boolean) {\n const clientTools = this.extractClientTools(options)\n const toolChoice = options.toolChoice\n\n return {\n messages: this.convertPromptToMessages(options.prompt),\n stream,\n ...(clientTools && { clientTools }),\n ...(toolChoice && { toolChoice }),\n ...(this.settings.application && { application: this.settings.application }),\n ...(this.settings.config && { config: this.settings.config }),\n ...(this.settings.format && { format: this.settings.format }),\n }\n }\n\n private getResponseHeaders(response: Response): Record<string, string> {\n return Object.fromEntries(response.headers.entries())\n }\n\n async doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult> {\n // Always request a stream from the backend and buffer the result.\n // This keeps the HTTP connection alive with incremental data, avoiding\n // 504 gateway timeouts on long-running agent requests.\n const body = this.buildRequestBody(options, true)\n const warnings = this.collectWarnings(options)\n\n const response = await fetchApi({\n url: buildApiUrl(\n this.config.baseURL,\n this.config.apiVersion,\n `/${this.config.organizationId}/threads/${this.threadId}`,\n ),\n body,\n headers: buildHeaders(this.config.headers()),\n signal: options.abortSignal,\n fetch: this.config.fetch,\n })\n\n if (!response.body) {\n throw new Error('No response body for generate request')\n }\n\n const { content, finishReason } = await this.extractContentFromStream(response.body)\n\n return {\n content,\n finishReason,\n usage: createEmptyUsage(),\n request: { body },\n response: { headers: this.getResponseHeaders(response) },\n warnings,\n }\n }\n\n /**\n * Parses a streamed response body into content parts (text and tool calls)\n * and a finish reason. Used by doGenerate to buffer the full response.\n */\n private async extractContentFromStream(responseBody: ReadableStream<Uint8Array>): Promise<{\n content: LanguageModelV3Content[]\n finishReason: LanguageModelV3GenerateResult['finishReason']\n }> {\n const reader = responseBody.getReader()\n const decoder = new TextDecoder()\n const textContentId = 'generate'\n let text = ''\n let hasToolCalls = false\n const content: LanguageModelV3Content[] = []\n\n while (true) {\n const { done, value } = await reader.read()\n if (done) break\n\n const chunk = decoder.decode(value, { stream: true })\n for (const line of chunk.split('\\n')) {\n const parsed = parseStreamLine(line, textContentId)\n if (parsed?.kind === 'part') {\n if (parsed.part.type === 'text-delta') {\n text += parsed.part.delta\n } else if (parsed.part.type === 'tool-call') {\n hasToolCalls = true\n const tc = parsed.part as { toolCallId: string; toolName: string; input: string }\n content.push({\n type: 'tool-call',\n toolCallId: tc.toolCallId,\n toolName: tc.toolName,\n input: tc.input,\n })\n }\n }\n }\n }\n\n if (text) {\n content.unshift({ type: 'text', text })\n }\n\n const finishReason = hasToolCalls\n ? { unified: 'tool-calls' as const, raw: 'tool-calls' }\n : { unified: 'stop' as const, raw: undefined }\n\n return { content, finishReason }\n }\n\n async doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult> {\n const body = this.buildRequestBody(options, true)\n const warnings = this.collectWarnings(options)\n\n const response = await fetchApi({\n url: buildApiUrl(\n this.config.baseURL,\n this.config.apiVersion,\n `/${this.config.organizationId}/threads/${this.threadId}`,\n ),\n body,\n headers: buildHeaders(this.config.headers()),\n signal: options.abortSignal,\n fetch: this.config.fetch,\n })\n\n if (!response.body) {\n throw new Error('No response body for streaming request')\n }\n\n return {\n stream: createSSEStream(response.body, warnings),\n request: { body },\n response: { headers: this.getResponseHeaders(response) },\n }\n }\n}\n","import type { LanguageModelV3 } from '@ai-sdk/provider'\nimport { ContentAgentModel, type ContentAgentModelConfig } from './sanity-agent-language-model'\nimport type {\n AgentSettings,\n Application,\n ContentAgentProviderSettings,\n GenerateOptions,\n GenerateResult,\n GenerateSettings,\n} from './types'\nimport {\n buildApiUrl,\n buildHeaders,\n extractTextFromStream,\n fetchApi,\n SanityAgentError,\n} from './utils'\n\nconst DEFAULT_BASE_URL = 'https://api.sanity.io'\nconst DEFAULT_API_VERSION = 'v2026-01-01'\n\nexport interface ContentAgentProvider {\n /**\n * Creates an agent for a conversation thread.\n */\n agent(threadId: string, settings?: AgentSettings): LanguageModelV3\n\n /**\n * Lists available applications for the organization.\n *\n * Returns all Sanity Studio applications the authenticated user has access to.\n * Use the `key` from a returned application to target it when creating an agent.\n *\n * @example\n * ```ts\n * const apps = await contentAgent.applications()\n * const app = apps.find((app) => app.title === \"My Studio\")\n *\n * const model = contentAgent.agent(\"my-thread\", {\n * application: { key: app.key },\n * })\n * ```\n */\n applications(): Promise<Application[]>\n\n /**\n * Sends a one-shot prompt to the Content Agent (stateless).\n *\n * Unlike `.agent()`, this does not create or use a conversation thread.\n * Each call is independent with no message history or persistence.\n * Ideal for simple, single-turn interactions.\n *\n * @example\n * ```ts\n * const result = await contentAgent.prompt(\n * { instructions: \"Be concise\" },\n * { message: \"List all authors in my dataset\" }\n * )\n * console.log(result.text)\n * ```\n */\n prompt(settings: GenerateSettings, options: GenerateOptions): Promise<GenerateResult>\n}\n\n/**\n * Creates a Content Agent provider instance.\n */\nexport function createContentAgent(options: ContentAgentProviderSettings): ContentAgentProvider {\n const baseURL = options.baseURL?.replace(/\\/$/, '') ?? DEFAULT_BASE_URL\n const apiVersion = options.apiVersion ?? DEFAULT_API_VERSION\n const { organizationId } = options\n\n const getHeaders = (): Record<string, string | undefined> => ({\n ...(options.token && { Authorization: `Bearer ${options.token}` }),\n ...options.headers,\n })\n\n const config: ContentAgentModelConfig = {\n provider: 'content-agent',\n baseURL,\n apiVersion,\n organizationId,\n headers: getHeaders,\n fetch: options.fetch,\n }\n\n const agent = (threadId: string, settings?: AgentSettings): LanguageModelV3 => {\n return new ContentAgentModel(threadId, settings, config)\n }\n\n const applications = async (): Promise<Application[]> => {\n const fetchFn = options.fetch ?? globalThis.fetch\n const url = buildApiUrl(baseURL, apiVersion, `/${organizationId}/applications`)\n const headers = buildHeaders(getHeaders())\n\n const response = await fetchFn(url, { method: 'GET', headers })\n\n if (!response.ok) {\n const errorText = await response.text()\n throw new SanityAgentError(response.status, errorText)\n }\n\n const json = (await response.json()) as { applications?: Application[] }\n return json.applications ?? []\n }\n\n const prompt = async (\n settings: GenerateSettings,\n generateOptions: GenerateOptions,\n ): Promise<GenerateResult> => {\n const body = {\n organizationId,\n message: generateOptions.message,\n stream: generateOptions.stream ?? false,\n ...(settings.application && { application: settings.application }),\n ...(settings.config && { config: settings.config }),\n ...(settings.instructions && { instructions: settings.instructions }),\n ...(settings.format && { format: settings.format }),\n }\n\n const response = await fetchApi({\n url: buildApiUrl(baseURL, apiVersion, '/prompt'),\n body,\n headers: buildHeaders(getHeaders()),\n signal: generateOptions.abortSignal,\n fetch: options.fetch,\n })\n\n if (body.stream) {\n if (!response.body) {\n throw new SanityAgentError(500, 'No response body')\n }\n return { text: await extractTextFromStream(response.body) }\n }\n\n const json = (await response.json()) as { text?: string }\n return { text: json.text ?? '' }\n }\n\n return { agent, applications, prompt }\n}\n"],"names":["text"],"mappings":";;AAYO,SAAS,aACd,eACA,mBACwB;AACxB,SAAO;AAAA,IACL;AAAA,MACE,gBAAgB;AAAA,MAChB,GAAG;AAAA,MACH,GAAG;AAAA,IAAA;AAAA,IAEL;AAAA,EAAA;AAEJ;AAKO,SAAS,YAAY,SAAiB,YAAoB,UAA0B;AACzF,SAAO,GAAG,OAAO,IAAI,UAAU,SAAS,QAAQ;AAClD;AAOO,MAAM,yBAAyB,MAAM;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,QAAgB,SAAiB;AAC3C,UAAM,2BAA2B,MAAM,IAAI,OAAO,EAAE,GACpD,KAAK,OAAO,oBACZ,KAAK,SAAS,QACd,KAAK,cAAc,UAAU,KAC7B,KAAK,OAAO,iBAAiB,UAAU,OAAO;AAAA,EAChD;AAAA,EAEA,OAAe,UAAU,SAAiD;AACxE,QAAI;AACF,aAAO,KAAK,MAAM,OAAO;AAAA,IAC3B,QAAQ;AACN,aAAO,CAAA;AAAA,IACT;AAAA,EACF;AACF;AAEO,MAAM,wBAAwB;AAY9B,SAAS,mBAAmB,OAAgC;AACjE,MAAI,EAAE,iBAAiB,qBAAqB,MAAM,WAAW;AAC3D,WAAO,EAAE,MAAM,UAAA;AAGjB,UAAQ,MAAM,KAAK,MAAA;AAAA,IACjB,KAAK,qBAAqB;AACxB,aA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SAAS,QAAQ,SAAS;AAAA,IACvD;AAGA,YADc,MAAM,SAAS,KAAA,GACjB,gBAAgB,CAAA;AAAA,EAC9B,GAmC8B,QAjCf,OACb,UACA,oBAC4B;AAC5B,UAAM,OAAO;AAAA,MACX;AAAA,MACA,SAAS,gBAAgB;AAAA,MACzB,QAAQ,gBAAgB,UAAU;AAAA,MAClC,GAAI,SAAS,eAAe,EAAE,aAAa,SAAS,YAAA;AAAA,MACpD,GAAI,SAAS,UAAU,EAAE,QAAQ,SAAS,OAAA;AAAA,MAC1C,GAAI,SAAS,gBAAgB,EAAE,cAAc,SAAS,aAAA;AAAA,MACtD,GAAI,SAAS,UAAU,EAAE,QAAQ,SAAS,OAAA;AAAA,IAAO,GAG7C,WAAW,MAAM,SAAS;AAAA,MAC9B,KAAK,YAAY,SAAS,YAAY,SAAS;AAAA,MAC/C;AAAA,MACA,SAAS,aAAa,YAAY;AAAA,MAClC,QAAQ,gBAAgB;AAAA,MACxB,OAAO,QAAQ;AAAA,IAAA,CAChB;AAED,QAAI,KAAK,QAAQ;AACf,UAAI,CAAC,SAAS;AACZ,cAAM,IAAI,iBAAiB,KAAK,kBAAkB;AAEpD,aAAO,EAAE,MAAM,MAAM,sBAAsB,SAAS,IAAI,EAAA;AAAA,IAC1D;AAGA,WAAO,EAAE,OADK,MAAM,SAAS,KAAA,GACT,QAAQ,GAAA;AAAA,EAC9B,EAAA;AAGF;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/utils.ts","../src/sanity-agent-language-model.ts","../src/sanity-agent-provider.ts"],"sourcesContent":["import type {\n LanguageModelV3FinishReason,\n LanguageModelV3StreamPart,\n LanguageModelV3Usage,\n SharedV3Warning,\n} from '@ai-sdk/provider'\nimport { HEADLESS_ERROR_CODES, type HeadlessErrorResponse } from '@sanity/agent-types'\nimport { isString, pickBy } from 'es-toolkit'\n\n/**\n * Builds headers for API requests, filtering out undefined values.\n *\n * @category Utilities\n */\nexport function buildHeaders(\n configHeaders: Record<string, string | undefined>,\n additionalHeaders?: Record<string, string>,\n): Record<string, string> {\n return pickBy(\n {\n 'Content-Type': 'application/json',\n ...additionalHeaders,\n ...configHeaders,\n },\n isString,\n )\n}\n\n/**\n * Constructs the full API URL for an endpoint.\n *\n * @category Utilities\n */\nexport function buildApiUrl(baseURL: string, apiVersion: string, endpoint: string): string {\n return `${baseURL}/${apiVersion}/agent${endpoint}`\n}\n\n/**\n * Custom error class for Sanity Agent API errors.\n * The {@link body} is parsed from the JSON response and follows the\n * {@link HeadlessErrorResponse} shape defined in `@sanity/agent-types`.\n *\n * @category Utilities\n */\nexport class SanityAgentError extends Error {\n readonly status: number\n readonly isRetryable: boolean\n readonly body: Partial<HeadlessErrorResponse>\n\n constructor(status: number, message: string) {\n super(`Sanity Agent API error: ${status} ${message}`)\n this.name = 'SanityAgentError'\n this.status = status\n this.isRetryable = status >= 500\n this.body = SanityAgentError.parseBody(message)\n }\n\n private static parseBody(message: string): Partial<HeadlessErrorResponse> {\n try {\n return JSON.parse(message)\n } catch {\n return {}\n }\n }\n}\n\nexport const GENERIC_ERROR_MESSAGE = 'Sorry, something went wrong. Please try again.'\n\nexport type AgentErrorType =\n | { type: 'no_applications' }\n | { type: 'application_not_found' }\n | { type: 'unknown' }\n\n/**\n * Classifies a caught error from the Content Agent API into a known error type.\n * Useful for clients that need to take different actions per error (e.g. show\n * resource-selection buttons). For the user-facing message, use {@link getAgentErrorMessage}.\n *\n * @category Utilities\n */\nexport function classifyAgentError(error: unknown): AgentErrorType {\n if (!(error instanceof SanityAgentError) || error.status !== 400) {\n return { type: 'unknown' }\n }\n\n switch (error.body.code) {\n case HEADLESS_ERROR_CODES.NO_COMPATIBLE_APPLICATIONS:\n return { type: 'no_applications' }\n case HEADLESS_ERROR_CODES.APPLICATION_NOT_FOUND:\n return { type: 'application_not_found' }\n default:\n return { type: 'unknown' }\n }\n}\n\n/**\n * Extracts a user-facing error message from an agent API error.\n * Returns the message sent by the API when available, otherwise a generic fallback.\n *\n * @category Utilities\n */\nexport function getAgentErrorMessage(error: unknown): string {\n if (error instanceof SanityAgentError && error.body.message) {\n return error.body.message\n }\n return GENERIC_ERROR_MESSAGE\n}\n\nexport interface FetchOptions {\n url: string\n body: unknown\n headers: Record<string, string>\n signal?: AbortSignal\n fetch?: typeof globalThis.fetch\n}\n\n/**\n * Makes a POST request and returns the response.\n * Throws SanityAgentError if the response is not ok.\n *\n * @category Utilities\n */\nexport async function fetchApi(options: FetchOptions): Promise<Response> {\n const fetchFn = options.fetch ?? globalThis.fetch\n\n const response = await fetchFn(options.url, {\n method: 'POST',\n headers: options.headers,\n body: JSON.stringify(options.body),\n signal: options.signal,\n })\n\n if (!response.ok) {\n const errorText = await response.text()\n throw new SanityAgentError(response.status, errorText)\n }\n\n return response\n}\n\n/**\n * Extracts text content from message parts (user or assistant).\n *\n * @category Utilities\n */\nexport function extractTextFromParts(\n content: string | Array<{ type: string; text?: string }>,\n): string {\n if (typeof content === 'string') {\n return content\n }\n\n return content\n .filter(\n (part): part is { type: 'text'; text: string } =>\n part.type === 'text' && typeof part.text === 'string',\n )\n .map((part) => part.text)\n .join('\\n')\n}\n\n/**\n * Creates an empty V3 usage object. Our API does not return token counts.\n *\n * @category Utilities\n */\nexport function createEmptyUsage(): LanguageModelV3Usage {\n return {\n inputTokens: {\n total: 0,\n noCache: undefined,\n cacheRead: undefined,\n cacheWrite: undefined,\n },\n outputTokens: {\n total: 0,\n text: undefined,\n reasoning: undefined,\n },\n }\n}\n\n/**\n * Maps API finish reasons to LanguageModelV3FinishReason.\n *\n * @category Utilities\n */\nexport function mapFinishReason(reason: string | undefined): LanguageModelV3FinishReason {\n const unified = (() => {\n switch (reason) {\n case 'stop':\n case 'length':\n case 'content-filter':\n case 'tool-calls':\n case 'error':\n return reason\n default:\n return 'other' as const\n }\n })()\n\n return { unified, raw: reason }\n}\n\nexport type ParsedStreamLine =\n | { kind: 'part'; part: LanguageModelV3StreamPart }\n | { kind: 'finish'; finishReason: LanguageModelV3FinishReason }\n\n/**\n * Parses a single line from the Vercel AI Data Stream Protocol.\n * Returns null if the line cannot be parsed or should be ignored.\n *\n * Protocol prefixes:\n * 0:\"text\" – text content\n * 2:[data] – data array (ignored)\n * 3:\"error\" – error\n * b:{toolCallId,toolName,args} – client tool call\n * d:{finishReason, usage} – finish message\n * e:{finishReason, usage} – finish step\n *\n * @see https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol\n *\n * @category Utilities\n */\nexport function parseStreamLine(line: string, textContentId: string): ParsedStreamLine | null {\n const trimmed = line.trim()\n if (!trimmed || trimmed.length < 2 || trimmed[1] !== ':') return null\n\n const prefix = trimmed[0]\n const payload = trimmed.slice(2)\n\n switch (prefix) {\n case '0': {\n try {\n const text = JSON.parse(payload) as unknown\n if (typeof text === 'string') {\n return { kind: 'part', part: { type: 'text-delta', id: textContentId, delta: text } }\n }\n } catch {\n // Ignore parse errors\n }\n return null\n }\n\n case '3': {\n try {\n const msg = JSON.parse(payload) as unknown\n return {\n kind: 'part',\n part: {\n type: 'error',\n error: new Error(typeof msg === 'string' ? msg : 'Unknown error'),\n },\n }\n } catch {\n return {\n kind: 'part',\n part: { type: 'error', error: new Error('Unknown streaming error') },\n }\n }\n }\n\n case 'b': {\n try {\n const data = JSON.parse(payload) as {\n toolCallId: string\n toolName: string\n args: unknown\n }\n return {\n kind: 'part',\n part: {\n type: 'tool-call',\n toolCallId: data.toolCallId,\n toolName: data.toolName,\n input: typeof data.args === 'string' ? data.args : JSON.stringify(data.args),\n },\n }\n } catch {\n return null\n }\n }\n\n case 'd':\n case 'e': {\n try {\n const data = JSON.parse(payload) as { finishReason?: string }\n return { kind: 'finish', finishReason: mapFinishReason(data.finishReason) }\n } catch {\n return null\n }\n }\n\n default:\n return null\n }\n}\n\n/**\n * Extracts accumulated text from a streaming response body.\n * Used for simple streaming cases where only the final text is needed.\n *\n * @category Utilities\n */\nexport async function extractTextFromStream(\n responseBody: ReadableStream<Uint8Array>,\n): Promise<string> {\n const reader = responseBody.getReader()\n const decoder = new TextDecoder()\n const textContentId = 'extract'\n let text = ''\n\n while (true) {\n const { done, value } = await reader.read()\n if (done) break\n\n const chunk = decoder.decode(value, { stream: true })\n for (const line of chunk.split('\\n')) {\n const parsed = parseStreamLine(line, textContentId)\n if (parsed?.kind === 'part' && parsed.part.type === 'text-delta') {\n text += parsed.part.delta\n }\n }\n }\n\n return text\n}\n\n/**\n * Creates a ReadableStream that parses SSE data from a response body\n * and emits LanguageModelV3 stream parts with proper lifecycle events.\n *\n * @category Utilities\n */\nexport function createSSEStream(\n responseBody: ReadableStream<Uint8Array>,\n warnings: SharedV3Warning[],\n): ReadableStream<LanguageModelV3StreamPart> {\n let finishReason: LanguageModelV3FinishReason = { unified: 'other', raw: undefined }\n const textContentId = crypto.randomUUID()\n let textStarted = false\n let hasToolCalls = false\n\n return new ReadableStream<LanguageModelV3StreamPart>({\n async start(controller) {\n const reader = responseBody.getReader()\n const decoder = new TextDecoder()\n let buffer = ''\n\n controller.enqueue({ type: 'stream-start', warnings })\n\n try {\n while (true) {\n const { done, value } = await reader.read()\n if (done) break\n\n buffer += decoder.decode(value, { stream: true })\n const lines = buffer.split('\\n')\n buffer = lines.pop() ?? ''\n\n for (const line of lines) {\n const parsed = parseStreamLine(line, textContentId)\n if (parsed?.kind === 'part') {\n if (parsed.part.type === 'text-delta' && !textStarted) {\n controller.enqueue({ type: 'text-start', id: textContentId })\n textStarted = true\n }\n if (parsed.part.type === 'tool-call') {\n // Close any open text block before emitting a tool call\n if (textStarted) {\n controller.enqueue({ type: 'text-end', id: textContentId })\n textStarted = false\n }\n hasToolCalls = true\n }\n controller.enqueue(parsed.part)\n } else if (parsed?.kind === 'finish') {\n finishReason = parsed.finishReason\n }\n }\n }\n\n // Process remaining buffer\n if (buffer.trim()) {\n const parsed = parseStreamLine(buffer, textContentId)\n if (parsed?.kind === 'part') {\n if (parsed.part.type === 'text-delta' && !textStarted) {\n controller.enqueue({ type: 'text-start', id: textContentId })\n textStarted = true\n }\n if (parsed.part.type === 'tool-call') {\n if (textStarted) {\n controller.enqueue({ type: 'text-end', id: textContentId })\n textStarted = false\n }\n hasToolCalls = true\n }\n controller.enqueue(parsed.part)\n } else if (parsed?.kind === 'finish') {\n finishReason = parsed.finishReason\n }\n }\n\n if (textStarted) {\n controller.enqueue({ type: 'text-end', id: textContentId })\n }\n\n // If tool calls were emitted, override finish reason so streamText\n // knows to execute tools and continue with the next step.\n if (hasToolCalls && finishReason.unified !== 'tool-calls') {\n finishReason = { unified: 'tool-calls', raw: finishReason.raw ?? 'tool-calls' }\n }\n\n controller.enqueue({\n type: 'finish',\n finishReason,\n usage: createEmptyUsage(),\n })\n } catch (error) {\n controller.enqueue({\n type: 'error',\n error: error instanceof Error ? error : new Error(String(error)),\n })\n } finally {\n controller.close()\n }\n },\n })\n}\n","import type {\n LanguageModelV3,\n LanguageModelV3CallOptions,\n LanguageModelV3Content,\n LanguageModelV3GenerateResult,\n LanguageModelV3Prompt,\n LanguageModelV3StreamResult,\n SharedV3Warning,\n} from '@ai-sdk/provider'\nimport type { ClientToolDefinition } from '@sanity/agent-types'\nimport { groupBy } from 'es-toolkit'\nimport type { AgentSettings, Message } from './types'\nimport {\n buildApiUrl,\n buildHeaders,\n createEmptyUsage,\n createSSEStream,\n extractTextFromParts,\n fetchApi,\n parseStreamLine,\n} from './utils'\n\n/**\n * @category Model\n */\nexport interface ContentAgentModelConfig {\n provider: string\n baseURL: string\n apiVersion: string\n organizationId: string\n headers: () => Record<string, string | undefined>\n fetch?: typeof globalThis.fetch\n}\n\n/**\n * Extended message type for the wire format that supports tool calls and tool results\n * in addition to plain text messages.\n */\ntype WireMessage =\n | Message\n | {\n role: 'assistant'\n content: Array<\n | { type: 'text'; text: string }\n | { type: 'tool-call'; toolCallId: string; toolName: string; input: string }\n >\n }\n | {\n role: 'tool'\n content: Array<{\n type: 'tool-result'\n toolCallId: string\n toolName: string\n output: unknown\n }>\n }\n\nconst UNSUPPORTED_SETTINGS = [\n 'maxOutputTokens',\n 'temperature',\n 'topP',\n 'topK',\n 'frequencyPenalty',\n 'presencePenalty',\n 'seed',\n] as const\n\n/**\n * Vercel AI SDK `LanguageModelV1` implementation that communicates with the\n * Sanity Content Agent API via a conversation thread.\n *\n * Typically you don't construct this directly — use\n * {@link createContentAgent | createContentAgent().agent(threadId)} instead.\n *\n * @category Model\n *\n * @example\n * ```ts\n * import { createContentAgent } from 'content-agent'\n * import { streamText } from 'ai'\n *\n * const contentAgent = createContentAgent({\n * organizationId: 'your-org-id',\n * token: 'your-sanity-token',\n * })\n *\n * const model = contentAgent.agent('my-thread-id', {\n * application: { key: 'projectId.datasetName' },\n * config: {\n * capabilities: { read: true, write: false },\n * },\n * })\n *\n * const { textStream } = await streamText({ model, prompt: 'Summarize my content' })\n * for await (const chunk of textStream) {\n * process.stdout.write(chunk)\n * }\n * ```\n */\nexport class ContentAgentModel implements LanguageModelV3 {\n readonly specificationVersion = 'v3' as const\n readonly provider: string\n readonly modelId: string\n readonly supportedUrls: Record<string, RegExp[]> = {}\n\n private readonly config: ContentAgentModelConfig\n private readonly threadId: string\n private readonly settings: AgentSettings\n\n constructor(\n threadId: string,\n settings: AgentSettings | undefined,\n config: ContentAgentModelConfig,\n ) {\n this.threadId = threadId\n this.modelId = `content-agent:${threadId}`\n this.provider = config.provider\n this.settings = settings ?? {}\n this.config = config\n }\n\n /**\n * Converts a LanguageModelV3Prompt into wire messages for the agent API.\n *\n * Handles all message roles:\n * - system: plain text system messages\n * - user: extracts text from content parts\n * - assistant: extracts text and/or tool-call parts\n * - tool: converts tool-result parts for the API\n */\n private convertPromptToMessages(prompt: LanguageModelV3Prompt): WireMessage[] {\n const messages: WireMessage[] = []\n\n for (const message of prompt) {\n if (message.role === 'system') {\n if (message.content) {\n messages.push({ role: 'system', content: message.content })\n }\n continue\n }\n\n if (message.role === 'tool') {\n const toolResults = message.content\n .filter((part) => part.type === 'tool-result')\n .map((part) => {\n const p = part as {\n toolCallId: string\n toolName: string\n output: { type: string; value: unknown } | unknown\n }\n return {\n type: 'tool-result' as const,\n toolCallId: p.toolCallId,\n toolName: p.toolName,\n output:\n p.output && typeof p.output === 'object' && 'value' in p.output\n ? (p.output as { value: unknown }).value\n : p.output,\n }\n })\n\n if (toolResults.length > 0) {\n messages.push({ role: 'tool', content: toolResults })\n }\n continue\n }\n\n if (message.role === 'assistant') {\n const content = message.content as Array<{\n type: string\n text?: string\n toolCallId?: string\n toolName?: string\n input?: string\n }>\n\n const grouped = groupBy(content, (p) => p.type)\n const toolCalls = grouped['tool-call'] ?? []\n const textParts = grouped['text'] ?? []\n\n if (toolCalls.length > 0) {\n const parts = [\n ...textParts\n .filter((p) => p.text)\n .map((p) => ({ type: 'text' as const, text: p.text! })),\n ...toolCalls.map((tc) => ({\n type: 'tool-call' as const,\n toolCallId: tc.toolCallId!,\n toolName: tc.toolName!,\n input: tc.input!,\n })),\n ]\n\n if (parts.length > 0) {\n messages.push({ role: 'assistant', content: parts })\n }\n } else {\n const text = extractTextFromParts(content as Array<{ type: string; text?: string }>)\n if (text) {\n messages.push({ role: 'assistant', content: text })\n }\n }\n continue\n }\n\n // user messages\n const text = extractTextFromParts(message.content as Array<{ type: string; text?: string }>)\n if (text) {\n messages.push({ role: message.role, content: text })\n }\n }\n\n return messages\n }\n\n /**\n * Extracts client tool definitions from the model call options.\n * Only the schemas are sent — execute functions stay on the client.\n */\n private extractClientTools(\n options: LanguageModelV3CallOptions,\n ): ClientToolDefinition[] | undefined {\n if (!options.tools?.length) return undefined\n\n const clientTools = options.tools\n .filter((t) => t.type === 'function')\n .map((t) => ({\n type: 'function' as const,\n name: t.name,\n description: t.description,\n inputSchema: t.inputSchema as Record<string, unknown>,\n }))\n\n return clientTools.length > 0 ? clientTools : undefined\n }\n\n private collectWarnings(options: LanguageModelV3CallOptions): SharedV3Warning[] {\n const warnings: SharedV3Warning[] = []\n\n for (const setting of UNSUPPORTED_SETTINGS) {\n if (options[setting] !== undefined) {\n warnings.push({ type: 'unsupported', feature: setting })\n }\n }\n\n if (options.stopSequences?.length) {\n warnings.push({ type: 'unsupported', feature: 'stopSequences' })\n }\n\n if (options.responseFormat && options.responseFormat.type !== 'text') {\n warnings.push({ type: 'unsupported', feature: 'responseFormat' })\n }\n\n return warnings\n }\n\n private buildRequestBody(options: LanguageModelV3CallOptions, stream: boolean) {\n const clientTools = this.extractClientTools(options)\n const toolChoice = options.toolChoice\n\n return {\n messages: this.convertPromptToMessages(options.prompt),\n stream,\n ...(clientTools && { clientTools }),\n ...(toolChoice && { toolChoice }),\n ...(this.settings.application && { application: this.settings.application }),\n ...(this.settings.config && { config: this.settings.config }),\n ...(this.settings.format && { format: this.settings.format }),\n }\n }\n\n private getResponseHeaders(response: Response): Record<string, string> {\n return Object.fromEntries(response.headers.entries())\n }\n\n async doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult> {\n // Always request a stream from the backend and buffer the result.\n // This keeps the HTTP connection alive with incremental data, avoiding\n // 504 gateway timeouts on long-running agent requests.\n const body = this.buildRequestBody(options, true)\n const warnings = this.collectWarnings(options)\n\n const response = await fetchApi({\n url: buildApiUrl(\n this.config.baseURL,\n this.config.apiVersion,\n `/${this.config.organizationId}/threads/${this.threadId}`,\n ),\n body,\n headers: buildHeaders(this.config.headers()),\n signal: options.abortSignal,\n fetch: this.config.fetch,\n })\n\n if (!response.body) {\n throw new Error('No response body for generate request')\n }\n\n const { content, finishReason } = await this.extractContentFromStream(response.body)\n\n return {\n content,\n finishReason,\n usage: createEmptyUsage(),\n request: { body },\n response: { headers: this.getResponseHeaders(response) },\n warnings,\n }\n }\n\n /**\n * Parses a streamed response body into content parts (text and tool calls)\n * and a finish reason. Used by doGenerate to buffer the full response.\n */\n private async extractContentFromStream(responseBody: ReadableStream<Uint8Array>): Promise<{\n content: LanguageModelV3Content[]\n finishReason: LanguageModelV3GenerateResult['finishReason']\n }> {\n const reader = responseBody.getReader()\n const decoder = new TextDecoder()\n const textContentId = 'generate'\n let text = ''\n let hasToolCalls = false\n const content: LanguageModelV3Content[] = []\n\n while (true) {\n const { done, value } = await reader.read()\n if (done) break\n\n const chunk = decoder.decode(value, { stream: true })\n for (const line of chunk.split('\\n')) {\n const parsed = parseStreamLine(line, textContentId)\n if (parsed?.kind === 'part') {\n if (parsed.part.type === 'text-delta') {\n text += parsed.part.delta\n } else if (parsed.part.type === 'tool-call') {\n hasToolCalls = true\n const tc = parsed.part as { toolCallId: string; toolName: string; input: string }\n content.push({\n type: 'tool-call',\n toolCallId: tc.toolCallId,\n toolName: tc.toolName,\n input: tc.input,\n })\n }\n }\n }\n }\n\n if (text) {\n content.unshift({ type: 'text', text })\n }\n\n const finishReason = hasToolCalls\n ? { unified: 'tool-calls' as const, raw: 'tool-calls' }\n : { unified: 'stop' as const, raw: undefined }\n\n return { content, finishReason }\n }\n\n async doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult> {\n const body = this.buildRequestBody(options, true)\n const warnings = this.collectWarnings(options)\n\n const response = await fetchApi({\n url: buildApiUrl(\n this.config.baseURL,\n this.config.apiVersion,\n `/${this.config.organizationId}/threads/${this.threadId}`,\n ),\n body,\n headers: buildHeaders(this.config.headers()),\n signal: options.abortSignal,\n fetch: this.config.fetch,\n })\n\n if (!response.body) {\n throw new Error('No response body for streaming request')\n }\n\n return {\n stream: createSSEStream(response.body, warnings),\n request: { body },\n response: { headers: this.getResponseHeaders(response) },\n }\n }\n}\n","import type { LanguageModelV3 } from '@ai-sdk/provider'\nimport { ContentAgentModel, type ContentAgentModelConfig } from './sanity-agent-language-model'\nimport type {\n AgentSettings,\n Application,\n ContentAgentProviderSettings,\n GenerateOptions,\n GenerateResult,\n GenerateSettings,\n} from './types'\nimport {\n buildApiUrl,\n buildHeaders,\n extractTextFromStream,\n fetchApi,\n SanityAgentError,\n} from './utils'\n\nconst DEFAULT_BASE_URL = 'https://api.sanity.io'\nconst DEFAULT_API_VERSION = 'v2026-01-01'\n\n/**\n * A Content Agent provider instance returned by {@link createContentAgent}.\n *\n * Provides two modes of interaction:\n * - **Conversation threads** via {@link ContentAgentProvider.agent | .agent()} — stateful, multi-turn conversations with server-side message history.\n * - **One-shot prompts** via {@link ContentAgentProvider.prompt | .prompt()} — stateless, single-turn interactions.\n *\n * @category Provider\n */\nexport interface ContentAgentProvider {\n /**\n * Creates a Vercel AI SDK {@link https://sdk.vercel.ai/docs/ai-sdk-core | LanguageModelV1} for a conversation thread.\n *\n * The thread ID identifies the conversation and maintains message history server-side.\n * If a thread with that ID already exists, the conversation continues. If not, a new\n * thread is automatically created.\n *\n * Use the returned model with `generateText` or `streamText` from the `ai` package.\n *\n * @example\n * ```ts\n * import { generateText, streamText } from 'ai'\n *\n * const model = contentAgent.agent('my-thread-id', {\n * application: { key: 'projectId.datasetName' },\n * config: {\n * capabilities: { read: true, write: false },\n * },\n * })\n *\n * // Non-streaming\n * const { text } = await generateText({ model, prompt: 'What blog posts do I have?' })\n *\n * // Streaming\n * const { textStream } = await streamText({ model, prompt: 'Summarize my content' })\n * for await (const chunk of textStream) {\n * process.stdout.write(chunk)\n * }\n * ```\n *\n * @param threadId - Unique identifier for the conversation thread.\n * @param settings - Optional agent settings (application, capabilities, filters, etc.).\n */\n agent(threadId: string, settings?: AgentSettings): LanguageModelV3\n\n /**\n * Lists available applications for the organization.\n *\n * Returns all Sanity Studio applications the authenticated user has access to.\n * Use the `key` from a returned application to target it when creating an agent.\n *\n * @example\n * ```ts\n * const apps = await contentAgent.applications()\n * const app = apps.find((app) => app.title === \"My Studio\")\n *\n * const model = contentAgent.agent(\"my-thread\", {\n * application: { key: app.key },\n * })\n * ```\n */\n applications(): Promise<Application[]>\n\n /**\n * Sends a one-shot prompt to the Content Agent (stateless).\n *\n * Unlike {@link ContentAgentProvider.agent | .agent()}, this does not create or use a conversation thread.\n * Each call is independent with no message history or persistence.\n * Ideal for simple, single-turn interactions.\n *\n * @example\n * ```ts\n * const { text } = await contentAgent.prompt(\n * {\n * application: { key: 'projectId.datasetName' },\n * config: { capabilities: { read: true, write: false } },\n * instructions: 'Be concise',\n * },\n * { message: 'List my 5 most recent posts' },\n * )\n * ```\n *\n * @param settings - Generation settings (application, capabilities, instructions, etc.).\n * @param options - The prompt message and request options.\n */\n prompt(settings: GenerateSettings, options: GenerateOptions): Promise<GenerateResult>\n}\n\n/**\n * Creates a Content Agent provider instance.\n *\n * The provider is the main entry point for interacting with the Sanity Content Agent API.\n * It returns an object with methods for conversation threads and one-shot prompts.\n *\n * @category Provider\n *\n * @example Basic setup\n * ```ts\n * import { createContentAgent } from 'content-agent'\n *\n * const contentAgent = createContentAgent({\n * organizationId: 'your-org-id',\n * token: 'your-sanity-token',\n * })\n * ```\n *\n * @example Using with Vercel AI SDK for conversation threads\n * ```ts\n * import { createContentAgent } from 'content-agent'\n * import { generateText, streamText } from 'ai'\n *\n * const contentAgent = createContentAgent({\n * organizationId: 'your-org-id',\n * token: 'your-sanity-token',\n * })\n *\n * const model = contentAgent.agent('my-thread-id', {\n * application: { key: 'projectId.datasetName' },\n * config: {\n * capabilities: { read: true, write: false },\n * },\n * })\n *\n * // Non-streaming\n * const { text } = await generateText({ model, prompt: 'What blog posts do I have?' })\n *\n * // Streaming\n * const { textStream } = await streamText({ model, prompt: 'Summarize my content' })\n * for await (const chunk of textStream) {\n * process.stdout.write(chunk)\n * }\n * ```\n *\n * @example One-shot generation (stateless, no thread)\n * ```ts\n * const { text } = await contentAgent.prompt(\n * {\n * application: { key: 'projectId.datasetName' },\n * config: { capabilities: { read: true, write: false } },\n * instructions: 'Be concise',\n * },\n * { message: 'List my 5 most recent posts' },\n * )\n * ```\n *\n * @param options - Provider configuration including organization ID, token, and optional overrides.\n */\nexport function createContentAgent(options: ContentAgentProviderSettings): ContentAgentProvider {\n const baseURL = options.baseURL?.replace(/\\/$/, '') ?? DEFAULT_BASE_URL\n const apiVersion = options.apiVersion ?? DEFAULT_API_VERSION\n const { organizationId } = options\n\n const getHeaders = (): Record<string, string | undefined> => ({\n ...(options.token && { Authorization: `Bearer ${options.token}` }),\n ...options.headers,\n })\n\n const config: ContentAgentModelConfig = {\n provider: 'content-agent',\n baseURL,\n apiVersion,\n organizationId,\n headers: getHeaders,\n fetch: options.fetch,\n }\n\n const agent = (threadId: string, settings?: AgentSettings): LanguageModelV3 => {\n return new ContentAgentModel(threadId, settings, config)\n }\n\n const applications = async (): Promise<Application[]> => {\n const fetchFn = options.fetch ?? globalThis.fetch\n const url = buildApiUrl(baseURL, apiVersion, `/${organizationId}/applications`)\n const headers = buildHeaders(getHeaders())\n\n const response = await fetchFn(url, { method: 'GET', headers })\n\n if (!response.ok) {\n const errorText = await response.text()\n throw new SanityAgentError(response.status, errorText)\n }\n\n const json = (await response.json()) as { applications?: Application[] }\n return json.applications ?? []\n }\n\n const prompt = async (\n settings: GenerateSettings,\n generateOptions: GenerateOptions,\n ): Promise<GenerateResult> => {\n const body = {\n organizationId,\n message: generateOptions.message,\n stream: generateOptions.stream ?? false,\n ...(settings.application && { application: settings.application }),\n ...(settings.config && { config: settings.config }),\n ...(settings.instructions && { instructions: settings.instructions }),\n ...(settings.format && { format: settings.format }),\n }\n\n const response = await fetchApi({\n url: buildApiUrl(baseURL, apiVersion, '/prompt'),\n body,\n headers: buildHeaders(getHeaders()),\n signal: generateOptions.abortSignal,\n fetch: options.fetch,\n })\n\n if (body.stream) {\n if (!response.body) {\n throw new SanityAgentError(500, 'No response body')\n }\n return { text: await extractTextFromStream(response.body) }\n }\n\n const json = (await response.json()) as { text?: string }\n return { text: json.text ?? '' }\n }\n\n return { agent, applications, prompt }\n}\n"],"names":["text"],"mappings":";;AAcO,SAAS,aACd,eACA,mBACwB;AACxB,SAAO;AAAA,IACL;AAAA,MACE,gBAAgB;AAAA,MAChB,GAAG;AAAA,MACH,GAAG;AAAA,IAAA;AAAA,IAEL;AAAA,EAAA;AAEJ;AAOO,SAAS,YAAY,SAAiB,YAAoB,UAA0B;AACzF,SAAO,GAAG,OAAO,IAAI,UAAU,SAAS,QAAQ;AAClD;AASO,MAAM,yBAAyB,MAAM;AAAA,E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,cAAM,IAAI,iBAAiB,KAAK,kBAAkB;AAEpD,aAAO,EAAE,MAAM,MAAM,sBAAsB,SAAS,IAAI,EAAA;AAAA,IAC1D;AAGA,WAAO,EAAE,OADK,MAAM,SAAS,KAAA,GACT,QAAQ,GAAA;AAAA,EAC9B,EAAA;AAGF;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "content-agent",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Vercel AI SDK provider for Sanity Content Agent API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -30,12 +30,13 @@
|
|
|
30
30
|
"@ai-sdk/provider": "^3.0.0",
|
|
31
31
|
"@ai-sdk/provider-utils": "^2.2.8",
|
|
32
32
|
"es-toolkit": "^1.32.0",
|
|
33
|
-
"@sanity/agent-types": "0.0.
|
|
33
|
+
"@sanity/agent-types": "0.0.80"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@sanity/pkg-utils": "^10.4.1",
|
|
37
37
|
"@types/node": "^22.19.7",
|
|
38
38
|
"openapi-typescript": "^7.10.1",
|
|
39
|
+
"typedoc": "^0.28.17",
|
|
39
40
|
"typescript": "^5.9.3",
|
|
40
41
|
"vitest": "^4.0.18",
|
|
41
42
|
"@repo/package.config": "0.0.0",
|
|
@@ -58,6 +59,7 @@
|
|
|
58
59
|
"scripts": {
|
|
59
60
|
"build": "pkg build --strict --check --clean",
|
|
60
61
|
"clean": "rm -rf dist",
|
|
62
|
+
"docs:generate": "typedoc",
|
|
61
63
|
"generate-types": "openapi-typescript ../agent/docs/headless/openapi.yaml -o src/generated/openapi.ts --export-type",
|
|
62
64
|
"test": "vitest run --passWithNoTests",
|
|
63
65
|
"test:watch": "vitest"
|