@pstdio/pocketcoder-sdk 0.4.0 → 0.5.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.
Files changed (3) hide show
  1. package/dist/index.d.ts +388 -329
  2. package/dist/index.js +79 -10
  3. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -98,6 +98,8 @@ type ErrorCode = keyof typeof ERROR_CODES;
98
98
  //#region ../contracts/src/workspace.d.ts
99
99
  declare const WORKSPACE_STATES: readonly ["queued", "provisioning", "connected", "ready", "preserving", "terminating", "succeeded", "failed", "canceled", "expired", "preserved"];
100
100
  type WorkspaceState = (typeof WORKSPACE_STATES)[number];
101
+ declare const AGENT_STATES: readonly ["unknown", "running", "stable"];
102
+ type AgentState = (typeof AGENT_STATES)[number];
101
103
  declare const WorkspaceCreateRequestSchema: z.ZodObject<{
102
104
  external_id: z.ZodString;
103
105
  template: z.ZodObject<{
@@ -483,33 +485,6 @@ declare class AdministrationApi {
483
485
  }>;
484
486
  }
485
487
  //#endregion
486
- //#region src/attachments.d.ts
487
- type UploadBody = NonNullable<RequestInit["body"]>;
488
- interface AttachmentUploadInput {
489
- id?: string;
490
- name: string;
491
- mediaType?: string;
492
- body: UploadBody;
493
- sizeBytes: number;
494
- signal?: AbortSignal;
495
- onProgress?: (uploadedBytes: number, totalBytes: number) => void;
496
- }
497
- interface AgentMessageInput {
498
- content: string;
499
- attachmentIds?: string[];
500
- signal?: AbortSignal;
501
- }
502
- declare class AttachmentsApi {
503
- private readonly transport;
504
- constructor(transport: PocketCoderTransport);
505
- upload(workspaceId: string, input: AttachmentUploadInput): Promise<AttachmentDescriptor>;
506
- }
507
- declare class AgentApi {
508
- private readonly transport;
509
- constructor(transport: PocketCoderTransport);
510
- sendMessage(workspaceId: string, input: AgentMessageInput): Promise<void>;
511
- }
512
- //#endregion
513
488
  //#region src/common.d.ts
514
489
  interface Page<T> {
515
490
  items: T[];
@@ -520,256 +495,6 @@ interface CursorListQuery {
520
495
  cursor?: string;
521
496
  }
522
497
  //#endregion
523
- //#region src/checkpoints.d.ts
524
- declare class CheckpointsApi {
525
- private readonly transport;
526
- constructor(transport: PocketCoderTransport);
527
- list(workspaceId: string, query?: CursorListQuery & {
528
- state?: CheckpointState;
529
- }, options?: RequestOptions): Promise<Page<{
530
- id: string;
531
- workspace_id: string;
532
- state: "deleted" | "creating" | "ready" | "failed" | "deleting";
533
- reason_code: string | null;
534
- template: {
535
- name: string;
536
- version: string;
537
- digest: string;
538
- };
539
- manifest_digest: string | null;
540
- logical_bytes: number | null;
541
- stored_bytes: number | null;
542
- file_count: number | null;
543
- mounts: string[];
544
- conversation_restore: "unknown" | "supported" | "filesystem_only";
545
- label: string | null;
546
- created_at: string;
547
- ready_at: string | null;
548
- expires_at: string | null;
549
- }>>;
550
- get(id: string, options?: RequestOptions): Promise<{
551
- id: string;
552
- workspace_id: string;
553
- state: "deleted" | "creating" | "ready" | "failed" | "deleting";
554
- reason_code: string | null;
555
- template: {
556
- name: string;
557
- version: string;
558
- digest: string;
559
- };
560
- manifest_digest: string | null;
561
- logical_bytes: number | null;
562
- stored_bytes: number | null;
563
- file_count: number | null;
564
- mounts: string[];
565
- conversation_restore: "unknown" | "supported" | "filesystem_only";
566
- label: string | null;
567
- created_at: string;
568
- ready_at: string | null;
569
- expires_at: string | null;
570
- }>;
571
- verify(id: string, key: string, options?: RequestOptions): Promise<{
572
- id: string;
573
- kind: "preserve" | "restore" | "verify" | "delete";
574
- state: "failed" | "pending" | "running" | "succeeded";
575
- workspace_id: string | null;
576
- checkpoint_id: string | null;
577
- result_workspace_id: string | null;
578
- reason_code: string | null;
579
- created_at: string;
580
- updated_at: string;
581
- completed_at: string | null;
582
- }>;
583
- delete(id: string, key: string, options?: RequestOptions): Promise<{
584
- id: string;
585
- kind: "preserve" | "restore" | "verify" | "delete";
586
- state: "failed" | "pending" | "running" | "succeeded";
587
- workspace_id: string | null;
588
- checkpoint_id: string | null;
589
- result_workspace_id: string | null;
590
- reason_code: string | null;
591
- created_at: string;
592
- updated_at: string;
593
- completed_at: string | null;
594
- }>;
595
- restore(id: string, input: RestoreRequest, key: string, options?: RequestOptions): Promise<{
596
- workspace: {
597
- id: string;
598
- external_id: string;
599
- template: {
600
- name: string;
601
- version: string;
602
- digest: string;
603
- };
604
- state: "ready" | "failed" | "succeeded" | "queued" | "provisioning" | "connected" | "preserving" | "terminating" | "canceled" | "expired" | "preserved";
605
- reason_code: "child_exit_success" | "child_exit_failure" | "setup_failed" | "bootstrap_failed" | "registration_timeout" | "health_failed" | "child_crash" | "provider_lost" | "disconnect_timeout" | "canceled_by_caller" | "deadline_expired" | "idle_expired" | "queue_timeout" | "launch_failed" | "preserve_requested" | "preserved_by_policy" | "checkpoint_created" | "checkpoint_failed" | "checkpoint_corrupt" | "checkpoint_quota_exceeded" | "checkpoint_storage_lost" | "restore_requested" | "restore_failed" | "image_unavailable" | "source_resolution_failed" | "secret_resolution_failed" | "operation_conflict" | "network_policy_failed" | null;
606
- agent_state: "unknown" | "running" | "stable";
607
- change_cursor: number;
608
- provider_kind: string | null;
609
- provisioning_mode: "cold" | "warm" | null;
610
- network: {
611
- state: "ready" | "disabled" | "starting" | "degraded";
612
- };
613
- health: Record<string, string>;
614
- created_at: string;
615
- updated_at: string;
616
- connected_at: string | null;
617
- ready_at: string | null;
618
- deadline_at: string;
619
- terminal_at: string | null;
620
- metadata: Record<string, string>;
621
- origin_workspace_id: string | null;
622
- restored_from_checkpoint_id: string | null;
623
- source: {
624
- kind: "git";
625
- repository: string;
626
- requested_revision: string;
627
- resolved_commit: string | null;
628
- } | null;
629
- persistence: {
630
- enabled: boolean;
631
- conversation_restore: "unknown" | "supported" | "filesystem_only";
632
- conversation_resume: {
633
- status: "unknown" | "supported" | "unsupported";
634
- reason: "filesystem_only" | "capability_unknown" | null;
635
- };
636
- latest_checkpoint_id: string | null;
637
- };
638
- outputs: Record<string, unknown>;
639
- failure: {
640
- reason_code: "child_exit_success" | "child_exit_failure" | "setup_failed" | "bootstrap_failed" | "registration_timeout" | "health_failed" | "child_crash" | "provider_lost" | "disconnect_timeout" | "canceled_by_caller" | "deadline_expired" | "idle_expired" | "queue_timeout" | "launch_failed" | "preserve_requested" | "preserved_by_policy" | "checkpoint_created" | "checkpoint_failed" | "checkpoint_corrupt" | "checkpoint_quota_exceeded" | "checkpoint_storage_lost" | "restore_requested" | "restore_failed" | "image_unavailable" | "source_resolution_failed" | "secret_resolution_failed" | "operation_conflict" | "network_policy_failed";
641
- log_tail: string;
642
- log_tail_truncated: boolean;
643
- last_log_seq: number | null;
644
- } | null;
645
- };
646
- operation: {
647
- id: string;
648
- kind: "preserve" | "restore" | "verify" | "delete";
649
- state: "failed" | "pending" | "running" | "succeeded";
650
- workspace_id: string | null;
651
- checkpoint_id: string | null;
652
- result_workspace_id: string | null;
653
- reason_code: string | null;
654
- created_at: string;
655
- updated_at: string;
656
- completed_at: string | null;
657
- };
658
- }>;
659
- private operationRequest;
660
- }
661
- declare class OperationsApi {
662
- private readonly transport;
663
- constructor(transport: PocketCoderTransport);
664
- get(id: string, options?: RequestOptions): Promise<{
665
- id: string;
666
- kind: "preserve" | "restore" | "verify" | "delete";
667
- state: "failed" | "pending" | "running" | "succeeded";
668
- workspace_id: string | null;
669
- checkpoint_id: string | null;
670
- result_workspace_id: string | null;
671
- reason_code: string | null;
672
- created_at: string;
673
- updated_at: string;
674
- completed_at: string | null;
675
- }>;
676
- }
677
- //#endregion
678
- //#region src/conversations.d.ts
679
- type ConversationMessage = ConversationMessageResource;
680
- type ConversationPage = Page<ConversationMessageResource>;
681
- declare class ConversationsApi {
682
- private readonly transport;
683
- constructor(transport: PocketCoderTransport);
684
- list(id: string, query?: CursorListQuery, options?: RequestOptions): Promise<Page<{
685
- message_id: string;
686
- role: "user" | "assistant" | "system" | "tool";
687
- content: string;
688
- occurred_at: string;
689
- metadata: Record<string, string>;
690
- seq: number;
691
- }>>;
692
- }
693
- //#endregion
694
- //#region src/diagnostics.d.ts
695
- declare class WorkspaceCursorApi<T> {
696
- private readonly transport;
697
- private readonly resource;
698
- private readonly schema;
699
- constructor(transport: PocketCoderTransport, resource: string, schema: z.ZodType<{
700
- items: T[];
701
- next_cursor: string | null;
702
- }>);
703
- list(workspaceId: string, query?: CursorListQuery, options?: RequestOptions): Promise<Page<T>>;
704
- }
705
- declare class LogsApi extends WorkspaceCursorApi<LogChunk> {
706
- constructor(transport: PocketCoderTransport);
707
- }
708
- declare class NetworkEventsApi extends WorkspaceCursorApi<NetworkEvent> {
709
- constructor(transport: PocketCoderTransport);
710
- }
711
- declare class OutputsApi extends WorkspaceCursorApi<OutputResource> {
712
- constructor(transport: PocketCoderTransport);
713
- }
714
- //#endregion
715
- //#region src/templates.d.ts
716
- type TemplateSummary = TemplateListItem;
717
- declare class TemplatesApi {
718
- private readonly transport;
719
- constructor(transport: PocketCoderTransport);
720
- page(query?: CursorListQuery, options?: RequestOptions): Promise<Page<{
721
- name: string;
722
- version: string;
723
- digest: string;
724
- status: "active" | "available" | "retired";
725
- description?: string | undefined;
726
- }>>;
727
- list(options?: RequestOptions): Promise<{
728
- name: string;
729
- version: string;
730
- digest: string;
731
- status: "active" | "available" | "retired";
732
- description?: string | undefined;
733
- }[]>;
734
- }
735
- //#endregion
736
- //#region src/terminals.d.ts
737
- interface TerminalConnectOptions {
738
- sessionId?: string;
739
- }
740
- declare class TerminalConnection {
741
- readonly socket: WebSocket;
742
- private readonly messageListeners;
743
- private readonly openListeners;
744
- private readonly closeListeners;
745
- private readonly errorListeners;
746
- private readonly pendingMessages;
747
- private opened;
748
- private closedEvent;
749
- private errored;
750
- constructor(socket: WebSocket);
751
- onMessage(listener: (message: ServerTerminalMessage) => void): () => void;
752
- onOpen(listener: () => void): () => void;
753
- onClose(listener: (event: CloseEvent) => void): () => void;
754
- onError(listener: () => void): () => void;
755
- sendInput(value: Uint8Array | string): void;
756
- resize(rows: number, cols: number): void;
757
- close(code?: number, reason?: string): void;
758
- private handleMessage;
759
- }
760
- declare class TerminalsApi {
761
- private readonly transport;
762
- constructor(transport: PocketCoderTransport);
763
- connect(workspaceId: string, options?: TerminalConnectOptions): TerminalConnection;
764
- list(workspaceId: string, query?: {
765
- cursor?: string;
766
- limit?: number;
767
- }, options?: RequestOptions): Promise<{
768
- items: TerminalSession[];
769
- nextCursor: string | null;
770
- }>;
771
- }
772
- //#endregion
773
498
  //#region src/workspaces.d.ts
774
499
  interface WorkspaceCreateInput {
775
500
  externalId: string;
@@ -800,7 +525,7 @@ declare class WorkspacesApi {
800
525
  version: string;
801
526
  digest: string;
802
527
  };
803
- state: "ready" | "failed" | "succeeded" | "queued" | "provisioning" | "connected" | "preserving" | "terminating" | "canceled" | "expired" | "preserved";
528
+ state: "queued" | "provisioning" | "connected" | "ready" | "preserving" | "terminating" | "succeeded" | "failed" | "canceled" | "expired" | "preserved";
804
529
  reason_code: "child_exit_success" | "child_exit_failure" | "setup_failed" | "bootstrap_failed" | "registration_timeout" | "health_failed" | "child_crash" | "provider_lost" | "disconnect_timeout" | "canceled_by_caller" | "deadline_expired" | "idle_expired" | "queue_timeout" | "launch_failed" | "preserve_requested" | "preserved_by_policy" | "checkpoint_created" | "checkpoint_failed" | "checkpoint_corrupt" | "checkpoint_quota_exceeded" | "checkpoint_storage_lost" | "restore_requested" | "restore_failed" | "image_unavailable" | "source_resolution_failed" | "secret_resolution_failed" | "operation_conflict" | "network_policy_failed" | null;
805
530
  agent_state: "unknown" | "running" | "stable";
806
531
  change_cursor: number;
@@ -850,7 +575,7 @@ declare class WorkspacesApi {
850
575
  version: string;
851
576
  digest: string;
852
577
  };
853
- state: "ready" | "failed" | "succeeded" | "queued" | "provisioning" | "connected" | "preserving" | "terminating" | "canceled" | "expired" | "preserved";
578
+ state: "queued" | "provisioning" | "connected" | "ready" | "preserving" | "terminating" | "succeeded" | "failed" | "canceled" | "expired" | "preserved";
854
579
  reason_code: "child_exit_success" | "child_exit_failure" | "setup_failed" | "bootstrap_failed" | "registration_timeout" | "health_failed" | "child_crash" | "provider_lost" | "disconnect_timeout" | "canceled_by_caller" | "deadline_expired" | "idle_expired" | "queue_timeout" | "launch_failed" | "preserve_requested" | "preserved_by_policy" | "checkpoint_created" | "checkpoint_failed" | "checkpoint_corrupt" | "checkpoint_quota_exceeded" | "checkpoint_storage_lost" | "restore_requested" | "restore_failed" | "image_unavailable" | "source_resolution_failed" | "secret_resolution_failed" | "operation_conflict" | "network_policy_failed" | null;
855
580
  agent_state: "unknown" | "running" | "stable";
856
581
  change_cursor: number;
@@ -900,7 +625,7 @@ declare class WorkspacesApi {
900
625
  version: string;
901
626
  digest: string;
902
627
  };
903
- state: "ready" | "failed" | "succeeded" | "queued" | "provisioning" | "connected" | "preserving" | "terminating" | "canceled" | "expired" | "preserved";
628
+ state: "queued" | "provisioning" | "connected" | "ready" | "preserving" | "terminating" | "succeeded" | "failed" | "canceled" | "expired" | "preserved";
904
629
  reason_code: "child_exit_success" | "child_exit_failure" | "setup_failed" | "bootstrap_failed" | "registration_timeout" | "health_failed" | "child_crash" | "provider_lost" | "disconnect_timeout" | "canceled_by_caller" | "deadline_expired" | "idle_expired" | "queue_timeout" | "launch_failed" | "preserve_requested" | "preserved_by_policy" | "checkpoint_created" | "checkpoint_failed" | "checkpoint_corrupt" | "checkpoint_quota_exceeded" | "checkpoint_storage_lost" | "restore_requested" | "restore_failed" | "image_unavailable" | "source_resolution_failed" | "secret_resolution_failed" | "operation_conflict" | "network_policy_failed" | null;
905
630
  agent_state: "unknown" | "running" | "stable";
906
631
  change_cursor: number;
@@ -950,7 +675,7 @@ declare class WorkspacesApi {
950
675
  version: string;
951
676
  digest: string;
952
677
  };
953
- state: "ready" | "failed" | "succeeded" | "queued" | "provisioning" | "connected" | "preserving" | "terminating" | "canceled" | "expired" | "preserved";
678
+ state: "queued" | "provisioning" | "connected" | "ready" | "preserving" | "terminating" | "succeeded" | "failed" | "canceled" | "expired" | "preserved";
954
679
  reason_code: "child_exit_success" | "child_exit_failure" | "setup_failed" | "bootstrap_failed" | "registration_timeout" | "health_failed" | "child_crash" | "provider_lost" | "disconnect_timeout" | "canceled_by_caller" | "deadline_expired" | "idle_expired" | "queue_timeout" | "launch_failed" | "preserve_requested" | "preserved_by_policy" | "checkpoint_created" | "checkpoint_failed" | "checkpoint_corrupt" | "checkpoint_quota_exceeded" | "checkpoint_storage_lost" | "restore_requested" | "restore_failed" | "image_unavailable" | "source_resolution_failed" | "secret_resolution_failed" | "operation_conflict" | "network_policy_failed" | null;
955
680
  agent_state: "unknown" | "running" | "stable";
956
681
  change_cursor: number;
@@ -1000,7 +725,7 @@ declare class WorkspacesApi {
1000
725
  version: string;
1001
726
  digest: string;
1002
727
  };
1003
- state: "ready" | "failed" | "succeeded" | "queued" | "provisioning" | "connected" | "preserving" | "terminating" | "canceled" | "expired" | "preserved";
728
+ state: "queued" | "provisioning" | "connected" | "ready" | "preserving" | "terminating" | "succeeded" | "failed" | "canceled" | "expired" | "preserved";
1004
729
  reason_code: "child_exit_success" | "child_exit_failure" | "setup_failed" | "bootstrap_failed" | "registration_timeout" | "health_failed" | "child_crash" | "provider_lost" | "disconnect_timeout" | "canceled_by_caller" | "deadline_expired" | "idle_expired" | "queue_timeout" | "launch_failed" | "preserve_requested" | "preserved_by_policy" | "checkpoint_created" | "checkpoint_failed" | "checkpoint_corrupt" | "checkpoint_quota_exceeded" | "checkpoint_storage_lost" | "restore_requested" | "restore_failed" | "image_unavailable" | "source_resolution_failed" | "secret_resolution_failed" | "operation_conflict" | "network_policy_failed" | null;
1005
730
  agent_state: "unknown" | "running" | "stable";
1006
731
  change_cursor: number;
@@ -1053,7 +778,7 @@ declare class WorkspacesApi {
1053
778
  version: string;
1054
779
  digest: string;
1055
780
  };
1056
- state: "ready" | "failed" | "succeeded" | "queued" | "provisioning" | "connected" | "preserving" | "terminating" | "canceled" | "expired" | "preserved";
781
+ state: "queued" | "provisioning" | "connected" | "ready" | "preserving" | "terminating" | "succeeded" | "failed" | "canceled" | "expired" | "preserved";
1057
782
  reason_code: "child_exit_success" | "child_exit_failure" | "setup_failed" | "bootstrap_failed" | "registration_timeout" | "health_failed" | "child_crash" | "provider_lost" | "disconnect_timeout" | "canceled_by_caller" | "deadline_expired" | "idle_expired" | "queue_timeout" | "launch_failed" | "preserve_requested" | "preserved_by_policy" | "checkpoint_created" | "checkpoint_failed" | "checkpoint_corrupt" | "checkpoint_quota_exceeded" | "checkpoint_storage_lost" | "restore_requested" | "restore_failed" | "image_unavailable" | "source_resolution_failed" | "secret_resolution_failed" | "operation_conflict" | "network_policy_failed" | null;
1058
783
  agent_state: "unknown" | "running" | "stable";
1059
784
  change_cursor: number;
@@ -1106,7 +831,7 @@ declare class WorkspacesApi {
1106
831
  version: string;
1107
832
  digest: string;
1108
833
  };
1109
- state: "ready" | "failed" | "succeeded" | "queued" | "provisioning" | "connected" | "preserving" | "terminating" | "canceled" | "expired" | "preserved";
834
+ state: "queued" | "provisioning" | "connected" | "ready" | "preserving" | "terminating" | "succeeded" | "failed" | "canceled" | "expired" | "preserved";
1110
835
  reason_code: "child_exit_success" | "child_exit_failure" | "setup_failed" | "bootstrap_failed" | "registration_timeout" | "health_failed" | "child_crash" | "provider_lost" | "disconnect_timeout" | "canceled_by_caller" | "deadline_expired" | "idle_expired" | "queue_timeout" | "launch_failed" | "preserve_requested" | "preserved_by_policy" | "checkpoint_created" | "checkpoint_failed" | "checkpoint_corrupt" | "checkpoint_quota_exceeded" | "checkpoint_storage_lost" | "restore_requested" | "restore_failed" | "image_unavailable" | "source_resolution_failed" | "secret_resolution_failed" | "operation_conflict" | "network_policy_failed" | null;
1111
836
  agent_state: "unknown" | "running" | "stable";
1112
837
  change_cursor: number;
@@ -1140,15 +865,150 @@ declare class WorkspacesApi {
1140
865
  };
1141
866
  latest_checkpoint_id: string | null;
1142
867
  };
1143
- outputs: Record<string, unknown>;
1144
- failure: {
1145
- reason_code: "child_exit_success" | "child_exit_failure" | "setup_failed" | "bootstrap_failed" | "registration_timeout" | "health_failed" | "child_crash" | "provider_lost" | "disconnect_timeout" | "canceled_by_caller" | "deadline_expired" | "idle_expired" | "queue_timeout" | "launch_failed" | "preserve_requested" | "preserved_by_policy" | "checkpoint_created" | "checkpoint_failed" | "checkpoint_corrupt" | "checkpoint_quota_exceeded" | "checkpoint_storage_lost" | "restore_requested" | "restore_failed" | "image_unavailable" | "source_resolution_failed" | "secret_resolution_failed" | "operation_conflict" | "network_policy_failed";
1146
- log_tail: string;
1147
- log_tail_truncated: boolean;
1148
- last_log_seq: number | null;
1149
- } | null;
868
+ outputs: Record<string, unknown>;
869
+ failure: {
870
+ reason_code: "child_exit_success" | "child_exit_failure" | "setup_failed" | "bootstrap_failed" | "registration_timeout" | "health_failed" | "child_crash" | "provider_lost" | "disconnect_timeout" | "canceled_by_caller" | "deadline_expired" | "idle_expired" | "queue_timeout" | "launch_failed" | "preserve_requested" | "preserved_by_policy" | "checkpoint_created" | "checkpoint_failed" | "checkpoint_corrupt" | "checkpoint_quota_exceeded" | "checkpoint_storage_lost" | "restore_requested" | "restore_failed" | "image_unavailable" | "source_resolution_failed" | "secret_resolution_failed" | "operation_conflict" | "network_policy_failed";
871
+ log_tail: string;
872
+ log_tail_truncated: boolean;
873
+ last_log_seq: number | null;
874
+ } | null;
875
+ }>;
876
+ waitForAgentInput(id: string, timeoutMs: number, options?: RequestOptions): Promise<{
877
+ id: string;
878
+ external_id: string;
879
+ template: {
880
+ name: string;
881
+ version: string;
882
+ digest: string;
883
+ };
884
+ state: "queued" | "provisioning" | "connected" | "ready" | "preserving" | "terminating" | "succeeded" | "failed" | "canceled" | "expired" | "preserved";
885
+ reason_code: "child_exit_success" | "child_exit_failure" | "setup_failed" | "bootstrap_failed" | "registration_timeout" | "health_failed" | "child_crash" | "provider_lost" | "disconnect_timeout" | "canceled_by_caller" | "deadline_expired" | "idle_expired" | "queue_timeout" | "launch_failed" | "preserve_requested" | "preserved_by_policy" | "checkpoint_created" | "checkpoint_failed" | "checkpoint_corrupt" | "checkpoint_quota_exceeded" | "checkpoint_storage_lost" | "restore_requested" | "restore_failed" | "image_unavailable" | "source_resolution_failed" | "secret_resolution_failed" | "operation_conflict" | "network_policy_failed" | null;
886
+ agent_state: "unknown" | "running" | "stable";
887
+ change_cursor: number;
888
+ provider_kind: string | null;
889
+ provisioning_mode: "cold" | "warm" | null;
890
+ network: {
891
+ state: "ready" | "disabled" | "starting" | "degraded";
892
+ };
893
+ health: Record<string, string>;
894
+ created_at: string;
895
+ updated_at: string;
896
+ connected_at: string | null;
897
+ ready_at: string | null;
898
+ deadline_at: string;
899
+ terminal_at: string | null;
900
+ metadata: Record<string, string>;
901
+ origin_workspace_id: string | null;
902
+ restored_from_checkpoint_id: string | null;
903
+ source: {
904
+ kind: "git";
905
+ repository: string;
906
+ requested_revision: string;
907
+ resolved_commit: string | null;
908
+ } | null;
909
+ persistence: {
910
+ enabled: boolean;
911
+ conversation_restore: "unknown" | "supported" | "filesystem_only";
912
+ conversation_resume: {
913
+ status: "unknown" | "supported" | "unsupported";
914
+ reason: "filesystem_only" | "capability_unknown" | null;
915
+ };
916
+ latest_checkpoint_id: string | null;
917
+ };
918
+ outputs: Record<string, unknown>;
919
+ failure: {
920
+ reason_code: "child_exit_success" | "child_exit_failure" | "setup_failed" | "bootstrap_failed" | "registration_timeout" | "health_failed" | "child_crash" | "provider_lost" | "disconnect_timeout" | "canceled_by_caller" | "deadline_expired" | "idle_expired" | "queue_timeout" | "launch_failed" | "preserve_requested" | "preserved_by_policy" | "checkpoint_created" | "checkpoint_failed" | "checkpoint_corrupt" | "checkpoint_quota_exceeded" | "checkpoint_storage_lost" | "restore_requested" | "restore_failed" | "image_unavailable" | "source_resolution_failed" | "secret_resolution_failed" | "operation_conflict" | "network_policy_failed";
921
+ log_tail: string;
922
+ log_tail_truncated: boolean;
923
+ last_log_seq: number | null;
924
+ } | null;
925
+ }>;
926
+ preserve(id: string, input: PreserveRequest, key: string, options?: RequestOptions): Promise<{
927
+ workspace: {
928
+ id: string;
929
+ external_id: string;
930
+ template: {
931
+ name: string;
932
+ version: string;
933
+ digest: string;
934
+ };
935
+ state: "queued" | "provisioning" | "connected" | "ready" | "preserving" | "terminating" | "succeeded" | "failed" | "canceled" | "expired" | "preserved";
936
+ reason_code: "child_exit_success" | "child_exit_failure" | "setup_failed" | "bootstrap_failed" | "registration_timeout" | "health_failed" | "child_crash" | "provider_lost" | "disconnect_timeout" | "canceled_by_caller" | "deadline_expired" | "idle_expired" | "queue_timeout" | "launch_failed" | "preserve_requested" | "preserved_by_policy" | "checkpoint_created" | "checkpoint_failed" | "checkpoint_corrupt" | "checkpoint_quota_exceeded" | "checkpoint_storage_lost" | "restore_requested" | "restore_failed" | "image_unavailable" | "source_resolution_failed" | "secret_resolution_failed" | "operation_conflict" | "network_policy_failed" | null;
937
+ agent_state: "unknown" | "running" | "stable";
938
+ change_cursor: number;
939
+ provider_kind: string | null;
940
+ provisioning_mode: "cold" | "warm" | null;
941
+ network: {
942
+ state: "ready" | "disabled" | "starting" | "degraded";
943
+ };
944
+ health: Record<string, string>;
945
+ created_at: string;
946
+ updated_at: string;
947
+ connected_at: string | null;
948
+ ready_at: string | null;
949
+ deadline_at: string;
950
+ terminal_at: string | null;
951
+ metadata: Record<string, string>;
952
+ origin_workspace_id: string | null;
953
+ restored_from_checkpoint_id: string | null;
954
+ source: {
955
+ kind: "git";
956
+ repository: string;
957
+ requested_revision: string;
958
+ resolved_commit: string | null;
959
+ } | null;
960
+ persistence: {
961
+ enabled: boolean;
962
+ conversation_restore: "unknown" | "supported" | "filesystem_only";
963
+ conversation_resume: {
964
+ status: "unknown" | "supported" | "unsupported";
965
+ reason: "filesystem_only" | "capability_unknown" | null;
966
+ };
967
+ latest_checkpoint_id: string | null;
968
+ };
969
+ outputs: Record<string, unknown>;
970
+ failure: {
971
+ reason_code: "child_exit_success" | "child_exit_failure" | "setup_failed" | "bootstrap_failed" | "registration_timeout" | "health_failed" | "child_crash" | "provider_lost" | "disconnect_timeout" | "canceled_by_caller" | "deadline_expired" | "idle_expired" | "queue_timeout" | "launch_failed" | "preserve_requested" | "preserved_by_policy" | "checkpoint_created" | "checkpoint_failed" | "checkpoint_corrupt" | "checkpoint_quota_exceeded" | "checkpoint_storage_lost" | "restore_requested" | "restore_failed" | "image_unavailable" | "source_resolution_failed" | "secret_resolution_failed" | "operation_conflict" | "network_policy_failed";
972
+ log_tail: string;
973
+ log_tail_truncated: boolean;
974
+ last_log_seq: number | null;
975
+ } | null;
976
+ };
977
+ checkpoint: {
978
+ id: string;
979
+ workspace_id: string;
980
+ state: "ready" | "failed" | "creating" | "deleting" | "deleted";
981
+ reason_code: string | null;
982
+ template: {
983
+ name: string;
984
+ version: string;
985
+ digest: string;
986
+ };
987
+ manifest_digest: string | null;
988
+ logical_bytes: number | null;
989
+ stored_bytes: number | null;
990
+ file_count: number | null;
991
+ mounts: string[];
992
+ conversation_restore: "unknown" | "supported" | "filesystem_only";
993
+ label: string | null;
994
+ created_at: string;
995
+ ready_at: string | null;
996
+ expires_at: string | null;
997
+ };
998
+ operation: {
999
+ id: string;
1000
+ kind: "preserve" | "restore" | "verify" | "delete";
1001
+ state: "succeeded" | "failed" | "running" | "pending";
1002
+ workspace_id: string | null;
1003
+ checkpoint_id: string | null;
1004
+ result_workspace_id: string | null;
1005
+ reason_code: string | null;
1006
+ created_at: string;
1007
+ updated_at: string;
1008
+ completed_at: string | null;
1009
+ };
1150
1010
  }>;
1151
- preserve(id: string, input: PreserveRequest, key: string, options?: RequestOptions): Promise<{
1011
+ recreate(id: string, input: RestoreRequest, key: string, options?: RequestOptions): Promise<{
1152
1012
  workspace: {
1153
1013
  id: string;
1154
1014
  external_id: string;
@@ -1157,7 +1017,7 @@ declare class WorkspacesApi {
1157
1017
  version: string;
1158
1018
  digest: string;
1159
1019
  };
1160
- state: "ready" | "failed" | "succeeded" | "queued" | "provisioning" | "connected" | "preserving" | "terminating" | "canceled" | "expired" | "preserved";
1020
+ state: "queued" | "provisioning" | "connected" | "ready" | "preserving" | "terminating" | "succeeded" | "failed" | "canceled" | "expired" | "preserved";
1161
1021
  reason_code: "child_exit_success" | "child_exit_failure" | "setup_failed" | "bootstrap_failed" | "registration_timeout" | "health_failed" | "child_crash" | "provider_lost" | "disconnect_timeout" | "canceled_by_caller" | "deadline_expired" | "idle_expired" | "queue_timeout" | "launch_failed" | "preserve_requested" | "preserved_by_policy" | "checkpoint_created" | "checkpoint_failed" | "checkpoint_corrupt" | "checkpoint_quota_exceeded" | "checkpoint_storage_lost" | "restore_requested" | "restore_failed" | "image_unavailable" | "source_resolution_failed" | "secret_resolution_failed" | "operation_conflict" | "network_policy_failed" | null;
1162
1022
  agent_state: "unknown" | "running" | "stable";
1163
1023
  change_cursor: number;
@@ -1199,31 +1059,10 @@ declare class WorkspacesApi {
1199
1059
  last_log_seq: number | null;
1200
1060
  } | null;
1201
1061
  };
1202
- checkpoint: {
1203
- id: string;
1204
- workspace_id: string;
1205
- state: "deleted" | "creating" | "ready" | "failed" | "deleting";
1206
- reason_code: string | null;
1207
- template: {
1208
- name: string;
1209
- version: string;
1210
- digest: string;
1211
- };
1212
- manifest_digest: string | null;
1213
- logical_bytes: number | null;
1214
- stored_bytes: number | null;
1215
- file_count: number | null;
1216
- mounts: string[];
1217
- conversation_restore: "unknown" | "supported" | "filesystem_only";
1218
- label: string | null;
1219
- created_at: string;
1220
- ready_at: string | null;
1221
- expires_at: string | null;
1222
- };
1223
1062
  operation: {
1224
1063
  id: string;
1225
1064
  kind: "preserve" | "restore" | "verify" | "delete";
1226
- state: "failed" | "pending" | "running" | "succeeded";
1065
+ state: "succeeded" | "failed" | "running" | "pending";
1227
1066
  workspace_id: string | null;
1228
1067
  checkpoint_id: string | null;
1229
1068
  result_workspace_id: string | null;
@@ -1233,7 +1072,7 @@ declare class WorkspacesApi {
1233
1072
  completed_at: string | null;
1234
1073
  };
1235
1074
  }>;
1236
- recreate(id: string, input: RestoreRequest, key: string, options?: RequestOptions): Promise<{
1075
+ resume(id: string, input: RestoreRequest, key: string, options?: RequestOptions): Promise<{
1237
1076
  workspace: {
1238
1077
  id: string;
1239
1078
  external_id: string;
@@ -1242,7 +1081,7 @@ declare class WorkspacesApi {
1242
1081
  version: string;
1243
1082
  digest: string;
1244
1083
  };
1245
- state: "ready" | "failed" | "succeeded" | "queued" | "provisioning" | "connected" | "preserving" | "terminating" | "canceled" | "expired" | "preserved";
1084
+ state: "queued" | "provisioning" | "connected" | "ready" | "preserving" | "terminating" | "succeeded" | "failed" | "canceled" | "expired" | "preserved";
1246
1085
  reason_code: "child_exit_success" | "child_exit_failure" | "setup_failed" | "bootstrap_failed" | "registration_timeout" | "health_failed" | "child_crash" | "provider_lost" | "disconnect_timeout" | "canceled_by_caller" | "deadline_expired" | "idle_expired" | "queue_timeout" | "launch_failed" | "preserve_requested" | "preserved_by_policy" | "checkpoint_created" | "checkpoint_failed" | "checkpoint_corrupt" | "checkpoint_quota_exceeded" | "checkpoint_storage_lost" | "restore_requested" | "restore_failed" | "image_unavailable" | "source_resolution_failed" | "secret_resolution_failed" | "operation_conflict" | "network_policy_failed" | null;
1247
1086
  agent_state: "unknown" | "running" | "stable";
1248
1087
  change_cursor: number;
@@ -1287,7 +1126,7 @@ declare class WorkspacesApi {
1287
1126
  operation: {
1288
1127
  id: string;
1289
1128
  kind: "preserve" | "restore" | "verify" | "delete";
1290
- state: "failed" | "pending" | "running" | "succeeded";
1129
+ state: "succeeded" | "failed" | "running" | "pending";
1291
1130
  workspace_id: string | null;
1292
1131
  checkpoint_id: string | null;
1293
1132
  result_workspace_id: string | null;
@@ -1296,8 +1135,118 @@ declare class WorkspacesApi {
1296
1135
  updated_at: string;
1297
1136
  completed_at: string | null;
1298
1137
  };
1138
+ resume: {
1139
+ status: "supported";
1140
+ reason: null;
1141
+ source_workspace_id: string;
1142
+ checkpoint_id: string;
1143
+ };
1299
1144
  }>;
1300
- resume(id: string, input: RestoreRequest, key: string, options?: RequestOptions): Promise<{
1145
+ private jsonOperation;
1146
+ }
1147
+ //#endregion
1148
+ //#region src/attachments.d.ts
1149
+ type UploadBody = NonNullable<RequestInit["body"]>;
1150
+ interface AttachmentUploadInput {
1151
+ id?: string;
1152
+ name: string;
1153
+ mediaType?: string;
1154
+ body: UploadBody;
1155
+ sizeBytes: number;
1156
+ signal?: AbortSignal;
1157
+ onProgress?: (uploadedBytes: number, totalBytes: number) => void;
1158
+ }
1159
+ interface AgentMessageInput {
1160
+ content: string;
1161
+ attachmentIds?: string[];
1162
+ signal?: AbortSignal;
1163
+ readyTimeoutMs?: number;
1164
+ }
1165
+ declare class AttachmentsApi {
1166
+ private readonly transport;
1167
+ constructor(transport: PocketCoderTransport);
1168
+ upload(workspaceId: string, input: AttachmentUploadInput): Promise<AttachmentDescriptor>;
1169
+ }
1170
+ declare class AgentApi {
1171
+ private readonly transport;
1172
+ private readonly workspaces;
1173
+ constructor(transport: PocketCoderTransport, workspaces: WorkspacesApi);
1174
+ sendMessage(workspaceId: string, input: AgentMessageInput): Promise<void>;
1175
+ }
1176
+ //#endregion
1177
+ //#region src/checkpoints.d.ts
1178
+ declare class CheckpointsApi {
1179
+ private readonly transport;
1180
+ constructor(transport: PocketCoderTransport);
1181
+ list(workspaceId: string, query?: CursorListQuery & {
1182
+ state?: CheckpointState;
1183
+ }, options?: RequestOptions): Promise<Page<{
1184
+ id: string;
1185
+ workspace_id: string;
1186
+ state: "ready" | "failed" | "creating" | "deleting" | "deleted";
1187
+ reason_code: string | null;
1188
+ template: {
1189
+ name: string;
1190
+ version: string;
1191
+ digest: string;
1192
+ };
1193
+ manifest_digest: string | null;
1194
+ logical_bytes: number | null;
1195
+ stored_bytes: number | null;
1196
+ file_count: number | null;
1197
+ mounts: string[];
1198
+ conversation_restore: "unknown" | "supported" | "filesystem_only";
1199
+ label: string | null;
1200
+ created_at: string;
1201
+ ready_at: string | null;
1202
+ expires_at: string | null;
1203
+ }>>;
1204
+ get(id: string, options?: RequestOptions): Promise<{
1205
+ id: string;
1206
+ workspace_id: string;
1207
+ state: "ready" | "failed" | "creating" | "deleting" | "deleted";
1208
+ reason_code: string | null;
1209
+ template: {
1210
+ name: string;
1211
+ version: string;
1212
+ digest: string;
1213
+ };
1214
+ manifest_digest: string | null;
1215
+ logical_bytes: number | null;
1216
+ stored_bytes: number | null;
1217
+ file_count: number | null;
1218
+ mounts: string[];
1219
+ conversation_restore: "unknown" | "supported" | "filesystem_only";
1220
+ label: string | null;
1221
+ created_at: string;
1222
+ ready_at: string | null;
1223
+ expires_at: string | null;
1224
+ }>;
1225
+ verify(id: string, key: string, options?: RequestOptions): Promise<{
1226
+ id: string;
1227
+ kind: "preserve" | "restore" | "verify" | "delete";
1228
+ state: "succeeded" | "failed" | "running" | "pending";
1229
+ workspace_id: string | null;
1230
+ checkpoint_id: string | null;
1231
+ result_workspace_id: string | null;
1232
+ reason_code: string | null;
1233
+ created_at: string;
1234
+ updated_at: string;
1235
+ completed_at: string | null;
1236
+ }>;
1237
+ delete(id: string, key: string, options?: RequestOptions): Promise<{
1238
+ id: string;
1239
+ kind: "preserve" | "restore" | "verify" | "delete";
1240
+ state: "succeeded" | "failed" | "running" | "pending";
1241
+ workspace_id: string | null;
1242
+ checkpoint_id: string | null;
1243
+ result_workspace_id: string | null;
1244
+ reason_code: string | null;
1245
+ created_at: string;
1246
+ updated_at: string;
1247
+ completed_at: string | null;
1248
+ }>;
1249
+ restore(id: string, input: RestoreRequest, key: string, options?: RequestOptions): Promise<{
1301
1250
  workspace: {
1302
1251
  id: string;
1303
1252
  external_id: string;
@@ -1306,7 +1255,7 @@ declare class WorkspacesApi {
1306
1255
  version: string;
1307
1256
  digest: string;
1308
1257
  };
1309
- state: "ready" | "failed" | "succeeded" | "queued" | "provisioning" | "connected" | "preserving" | "terminating" | "canceled" | "expired" | "preserved";
1258
+ state: "queued" | "provisioning" | "connected" | "ready" | "preserving" | "terminating" | "succeeded" | "failed" | "canceled" | "expired" | "preserved";
1310
1259
  reason_code: "child_exit_success" | "child_exit_failure" | "setup_failed" | "bootstrap_failed" | "registration_timeout" | "health_failed" | "child_crash" | "provider_lost" | "disconnect_timeout" | "canceled_by_caller" | "deadline_expired" | "idle_expired" | "queue_timeout" | "launch_failed" | "preserve_requested" | "preserved_by_policy" | "checkpoint_created" | "checkpoint_failed" | "checkpoint_corrupt" | "checkpoint_quota_exceeded" | "checkpoint_storage_lost" | "restore_requested" | "restore_failed" | "image_unavailable" | "source_resolution_failed" | "secret_resolution_failed" | "operation_conflict" | "network_policy_failed" | null;
1311
1260
  agent_state: "unknown" | "running" | "stable";
1312
1261
  change_cursor: number;
@@ -1351,7 +1300,7 @@ declare class WorkspacesApi {
1351
1300
  operation: {
1352
1301
  id: string;
1353
1302
  kind: "preserve" | "restore" | "verify" | "delete";
1354
- state: "failed" | "pending" | "running" | "succeeded";
1303
+ state: "succeeded" | "failed" | "running" | "pending";
1355
1304
  workspace_id: string | null;
1356
1305
  checkpoint_id: string | null;
1357
1306
  result_workspace_id: string | null;
@@ -1360,14 +1309,119 @@ declare class WorkspacesApi {
1360
1309
  updated_at: string;
1361
1310
  completed_at: string | null;
1362
1311
  };
1363
- resume: {
1364
- status: "supported";
1365
- reason: null;
1366
- source_workspace_id: string;
1367
- checkpoint_id: string;
1368
- };
1369
1312
  }>;
1370
- private jsonOperation;
1313
+ private operationRequest;
1314
+ }
1315
+ declare class OperationsApi {
1316
+ private readonly transport;
1317
+ constructor(transport: PocketCoderTransport);
1318
+ get(id: string, options?: RequestOptions): Promise<{
1319
+ id: string;
1320
+ kind: "preserve" | "restore" | "verify" | "delete";
1321
+ state: "succeeded" | "failed" | "running" | "pending";
1322
+ workspace_id: string | null;
1323
+ checkpoint_id: string | null;
1324
+ result_workspace_id: string | null;
1325
+ reason_code: string | null;
1326
+ created_at: string;
1327
+ updated_at: string;
1328
+ completed_at: string | null;
1329
+ }>;
1330
+ }
1331
+ //#endregion
1332
+ //#region src/conversations.d.ts
1333
+ type ConversationMessage = ConversationMessageResource;
1334
+ type ConversationPage = Page<ConversationMessageResource>;
1335
+ declare class ConversationsApi {
1336
+ private readonly transport;
1337
+ constructor(transport: PocketCoderTransport);
1338
+ list(id: string, query?: CursorListQuery, options?: RequestOptions): Promise<Page<{
1339
+ message_id: string;
1340
+ role: "user" | "assistant" | "system" | "tool";
1341
+ content: string;
1342
+ occurred_at: string;
1343
+ metadata: Record<string, string>;
1344
+ seq: number;
1345
+ }>>;
1346
+ }
1347
+ //#endregion
1348
+ //#region src/diagnostics.d.ts
1349
+ declare class WorkspaceCursorApi<T> {
1350
+ private readonly transport;
1351
+ private readonly resource;
1352
+ private readonly schema;
1353
+ constructor(transport: PocketCoderTransport, resource: string, schema: z.ZodType<{
1354
+ items: T[];
1355
+ next_cursor: string | null;
1356
+ }>);
1357
+ list(workspaceId: string, query?: CursorListQuery, options?: RequestOptions): Promise<Page<T>>;
1358
+ }
1359
+ declare class LogsApi extends WorkspaceCursorApi<LogChunk> {
1360
+ constructor(transport: PocketCoderTransport);
1361
+ }
1362
+ declare class NetworkEventsApi extends WorkspaceCursorApi<NetworkEvent> {
1363
+ constructor(transport: PocketCoderTransport);
1364
+ }
1365
+ declare class OutputsApi extends WorkspaceCursorApi<OutputResource> {
1366
+ constructor(transport: PocketCoderTransport);
1367
+ }
1368
+ //#endregion
1369
+ //#region src/templates.d.ts
1370
+ type TemplateSummary = TemplateListItem;
1371
+ declare class TemplatesApi {
1372
+ private readonly transport;
1373
+ constructor(transport: PocketCoderTransport);
1374
+ page(query?: CursorListQuery, options?: RequestOptions): Promise<Page<{
1375
+ name: string;
1376
+ version: string;
1377
+ digest: string;
1378
+ status: "active" | "available" | "retired";
1379
+ description?: string | undefined;
1380
+ }>>;
1381
+ list(options?: RequestOptions): Promise<{
1382
+ name: string;
1383
+ version: string;
1384
+ digest: string;
1385
+ status: "active" | "available" | "retired";
1386
+ description?: string | undefined;
1387
+ }[]>;
1388
+ }
1389
+ //#endregion
1390
+ //#region src/terminals.d.ts
1391
+ interface TerminalConnectOptions {
1392
+ sessionId?: string;
1393
+ }
1394
+ declare class TerminalConnection {
1395
+ readonly socket: WebSocket;
1396
+ private readonly messageListeners;
1397
+ private readonly openListeners;
1398
+ private readonly closeListeners;
1399
+ private readonly errorListeners;
1400
+ private readonly pendingMessages;
1401
+ private opened;
1402
+ private closedEvent;
1403
+ private errored;
1404
+ constructor(socket: WebSocket);
1405
+ onMessage(listener: (message: ServerTerminalMessage) => void): () => void;
1406
+ onOpen(listener: () => void): () => void;
1407
+ onClose(listener: (event: CloseEvent) => void): () => void;
1408
+ onError(listener: () => void): () => void;
1409
+ sendInput(value: Uint8Array | string): void;
1410
+ resize(rows: number, cols: number): void;
1411
+ close(code?: number, reason?: string): void;
1412
+ private handleMessage;
1413
+ }
1414
+ declare class TerminalsApi {
1415
+ private readonly transport;
1416
+ constructor(transport: PocketCoderTransport);
1417
+ connect(workspaceId: string, options?: TerminalConnectOptions): TerminalConnection;
1418
+ list(workspaceId: string, query?: {
1419
+ cursor?: string;
1420
+ limit?: number;
1421
+ }, options?: RequestOptions): Promise<{
1422
+ items: TerminalSession[];
1423
+ nextCursor: string | null;
1424
+ }>;
1371
1425
  }
1372
1426
  //#endregion
1373
1427
  //#region src/client.d.ts
@@ -1413,6 +1467,11 @@ declare class WorkspaceTerminalError extends Error {
1413
1467
  readonly workspace: WorkspaceResource;
1414
1468
  constructor(workspace: WorkspaceResource);
1415
1469
  }
1470
+ declare class AgentNotReadyError extends Error {
1471
+ readonly workspaceId: string;
1472
+ readonly agentState: AgentState;
1473
+ constructor(workspaceId: string, agentState: AgentState, timeoutMs: number);
1474
+ }
1416
1475
  declare function isPocketCoderErrorCode(value: unknown): value is ErrorCode;
1417
1476
  //#endregion
1418
1477
  //#region src/workspace-turn-resolver.d.ts
@@ -1452,4 +1511,4 @@ declare class WorkspaceTurnResolver {
1452
1511
  private assertLineage;
1453
1512
  }
1454
1513
  //#endregion
1455
- export { AdministrationApi, AgentApi, type AgentMessageInput, type AttachmentDescriptor, type AttachmentUploadInput, AttachmentsApi, type CheckpointResource, type CheckpointState, CheckpointsApi, type ClientErrorCode, ConversationGoneError, type ConversationMessage, type ConversationPage, ConversationsApi, type CursorListQuery, type LogChunk, LogsApi, type NetworkEvent, NetworkEventsApi, type OperationKind, type OperationResource, type OperationState, OperationsApi, type OutputResource, OutputsApi, type Page, PocketCoderClient, type PocketCoderClientConfig, PocketCoderError, type PreserveRequest, type RequestOptions, type ResolveWorkspaceTurnOptions, type ResolvedWorkspaceTurn, type RestoreRequest, type ResumeWorkspaceContext, type ServerTerminalMessage, type StorageState, TERMINAL_WORKSPACE_STATES, type TemplateSummary, TemplatesApi, type TerminalConnectOptions, TerminalConnection, type TerminalSession, TerminalsApi, type WebSocketFactory, type WorkspaceCreateInput, type WorkspaceListQuery, type WorkspaceResource, type WorkspaceState, type WorkspaceSummary, WorkspaceTerminalError, WorkspaceTurnResolutionError, type WorkspaceTurnResolutionErrorCode, WorkspaceTurnResolver, type WorkspaceTurnResolverOptions, WorkspacesApi, isPocketCoderErrorCode, splitAttachmentManifest };
1514
+ export { AdministrationApi, AgentApi, type AgentMessageInput, AgentNotReadyError, type AttachmentDescriptor, type AttachmentUploadInput, AttachmentsApi, type CheckpointResource, type CheckpointState, CheckpointsApi, type ClientErrorCode, ConversationGoneError, type ConversationMessage, type ConversationPage, ConversationsApi, type CursorListQuery, type LogChunk, LogsApi, type NetworkEvent, NetworkEventsApi, type OperationKind, type OperationResource, type OperationState, OperationsApi, type OutputResource, OutputsApi, type Page, PocketCoderClient, type PocketCoderClientConfig, PocketCoderError, type PreserveRequest, type RequestOptions, type ResolveWorkspaceTurnOptions, type ResolvedWorkspaceTurn, type RestoreRequest, type ResumeWorkspaceContext, type ServerTerminalMessage, type StorageState, TERMINAL_WORKSPACE_STATES, type TemplateSummary, TemplatesApi, type TerminalConnectOptions, TerminalConnection, type TerminalSession, TerminalsApi, type WebSocketFactory, type WorkspaceCreateInput, type WorkspaceListQuery, type WorkspaceResource, type WorkspaceState, type WorkspaceSummary, WorkspaceTerminalError, WorkspaceTurnResolutionError, type WorkspaceTurnResolutionErrorCode, WorkspaceTurnResolver, type WorkspaceTurnResolverOptions, WorkspacesApi, isPocketCoderErrorCode, splitAttachmentManifest };
package/dist/index.js CHANGED
@@ -703,7 +703,8 @@ const HarnessSchema = z.object({
703
703
  const AgentSchema = HarnessSchema.extend({
704
704
  type: z.string().regex(/^[a-z0-9][a-z0-9-]{0,63}$/).default("custom"),
705
705
  transport: z.enum(["pty", "acp"]).default("pty"),
706
- termWidth: z.number().int().min(10).max(65535).optional()
706
+ termWidth: z.number().int().min(10).max(65535).optional(),
707
+ stateFile: z.string().refine(isAbsolutePath, "expected an absolute path").optional()
707
708
  });
708
709
  const TerminalSchema = z.object({
709
710
  command: CommandSchema,
@@ -751,7 +752,8 @@ const TimeoutsSchema = z.object({
751
752
  });
752
753
  const ResourcesSchema = z.object({
753
754
  cpu: z.string().regex(/^\d+(\.\d+)?m?$/),
754
- memory: z.string().regex(/^\d+(Mi|Gi)$/)
755
+ memory: z.string().regex(/^\d+(Mi|Gi)$/),
756
+ ephemeralStorage: z.string().regex(/^\d+(Mi|Gi)$/).optional()
755
757
  });
756
758
  const RepositorySchema = z.object({
757
759
  url: z.url().refine((value) => {
@@ -817,11 +819,14 @@ const TemplateSpecSchema = z.object({
817
819
  message: "either agent or harness is required"
818
820
  });
819
821
  if (!spec.agent) return;
820
- if (spec.agent.transport === "acp" && spec.agent.termWidth !== void 0) ctx.addIssue({
821
- code: "custom",
822
- path: ["agent", "termWidth"],
823
- message: "termWidth is only valid for PTY transport"
824
- });
822
+ if (spec.agent.transport === "acp") for (const field of ["termWidth", "stateFile"]) {
823
+ if (spec.agent[field] === void 0) continue;
824
+ ctx.addIssue({
825
+ code: "custom",
826
+ path: ["agent", field],
827
+ message: `${field} is only valid for PTY transport`
828
+ });
829
+ }
825
830
  for (const field of [
826
831
  "harness",
827
832
  "services",
@@ -901,6 +906,7 @@ function agentApiHarness(spec) {
901
906
  spec.agent.type,
902
907
  ...spec.agent.transport === "acp" ? ["--experimental-acp"] : [],
903
908
  ...spec.agent.termWidth === void 0 ? [] : ["--term-width", String(spec.agent.termWidth)],
909
+ ...spec.agent.stateFile === void 0 ? [] : ["--state-file", spec.agent.stateFile],
904
910
  "--port",
905
911
  "3284",
906
912
  "--",
@@ -1108,6 +1114,7 @@ function validatePersistence(spec, ctx) {
1108
1114
  const mounts = spec.persistence.mounts;
1109
1115
  for (const [index, mount] of mounts.entries()) validatePersistenceMount(spec, mounts, mount, index, seenNames, ctx);
1110
1116
  validateSourceMount(spec, mounts, ctx);
1117
+ validateAgentStateFile(spec, mounts, ctx);
1111
1118
  if (spec.persistence.conversationRestore === "supported" && (!spec.persistence.sessionCompatibility || mounts.length < 2)) ctx.addIssue({
1112
1119
  code: "custom",
1113
1120
  path: [
@@ -1118,6 +1125,43 @@ function validatePersistence(spec, ctx) {
1118
1125
  message: "supported conversation restore requires sessionCompatibility and a separate harness-state mount"
1119
1126
  });
1120
1127
  }
1128
+ function validateAgentStateFile(spec, mounts, ctx) {
1129
+ if (!isAgentApiNative(spec)) return;
1130
+ const stateFile = spec.agent.stateFile;
1131
+ const normalized = stateFile !== void 0 && isNormalizedFilesystemPath(stateFile);
1132
+ if (stateFile !== void 0 && !normalized) ctx.addIssue({
1133
+ code: "custom",
1134
+ path: [
1135
+ "spec",
1136
+ "agent",
1137
+ "stateFile"
1138
+ ],
1139
+ message: "stateFile must be a normalized absolute filesystem path"
1140
+ });
1141
+ if (spec.agent.transport === "acp" && spec.persistence.conversationRestore === "supported") {
1142
+ ctx.addIssue({
1143
+ code: "custom",
1144
+ path: [
1145
+ "spec",
1146
+ "persistence",
1147
+ "conversationRestore"
1148
+ ],
1149
+ message: "supported conversation restore requires PTY transport"
1150
+ });
1151
+ return;
1152
+ }
1153
+ if (spec.persistence.conversationRestore !== "supported") return;
1154
+ if (normalized && mounts.some((mount) => stateFile.startsWith(`${mount.target}/`))) return;
1155
+ ctx.addIssue({
1156
+ code: "custom",
1157
+ path: [
1158
+ "spec",
1159
+ "agent",
1160
+ "stateFile"
1161
+ ],
1162
+ message: "supported conversation restore requires agent.stateFile below a persistence mount"
1163
+ });
1164
+ }
1121
1165
  function validatePersistenceMount(spec, mounts, mount, index, seenNames, ctx) {
1122
1166
  const path = [
1123
1167
  "spec",
@@ -1782,6 +1826,16 @@ var WorkspaceTerminalError = class extends Error {
1782
1826
  this.workspace = workspace;
1783
1827
  }
1784
1828
  };
1829
+ var AgentNotReadyError = class extends Error {
1830
+ workspaceId;
1831
+ agentState;
1832
+ constructor(workspaceId, agentState, timeoutMs) {
1833
+ super(`agent in workspace ${workspaceId} was still ${agentState} after ${timeoutMs}ms and cannot accept a message`);
1834
+ this.name = "AgentNotReadyError";
1835
+ this.workspaceId = workspaceId;
1836
+ this.agentState = agentState;
1837
+ }
1838
+ };
1785
1839
  function isPocketCoderErrorCode(value) {
1786
1840
  return typeof value === "string" && value in ERROR_CODES;
1787
1841
  }
@@ -1803,6 +1857,7 @@ function responseError(response, body) {
1803
1857
  }
1804
1858
  //#endregion
1805
1859
  //#region src/attachments.ts
1860
+ const DEFAULT_READY_TIMEOUT_MS = 12e4;
1806
1861
  function contentDisposition(name) {
1807
1862
  const clean = name.replace(/[\r\n]/g, "");
1808
1863
  if (/^[ -~]*$/.test(clean)) return `attachment; filename="${clean.replace(/(["\\])/g, "\\$1")}"`;
@@ -1841,10 +1896,13 @@ var AttachmentsApi = class {
1841
1896
  };
1842
1897
  var AgentApi = class {
1843
1898
  transport;
1844
- constructor(transport) {
1899
+ workspaces;
1900
+ constructor(transport, workspaces) {
1845
1901
  this.transport = transport;
1902
+ this.workspaces = workspaces;
1846
1903
  }
1847
1904
  async sendMessage(workspaceId, input) {
1905
+ await this.workspaces.waitForAgentInput(workspaceId, input.readyTimeoutMs ?? DEFAULT_READY_TIMEOUT_MS, input.signal ? { signal: input.signal } : {});
1848
1906
  const response = await this.transport.raw(`/v1/workspaces/${encodeURIComponent(workspaceId)}/agent/message`, {
1849
1907
  method: "POST",
1850
1908
  ...input.signal ? { signal: input.signal } : {},
@@ -2284,6 +2342,17 @@ var WorkspacesApi = class {
2284
2342
  }
2285
2343
  return workspace;
2286
2344
  }
2345
+ async waitForAgentInput(id, timeoutMs, options = {}) {
2346
+ const deadline = Date.now() + timeoutMs;
2347
+ let workspace = await this.get(id, options);
2348
+ while (workspace.agent_state !== "stable") {
2349
+ if (TERMINAL_STATES.includes(workspace.state)) throw new WorkspaceTerminalError(workspace);
2350
+ const remainingMs = deadline - Date.now();
2351
+ if (remainingMs <= 0) throw new AgentNotReadyError(workspace.id, workspace.agent_state, timeoutMs);
2352
+ workspace = (await this.change(workspace.id, workspace.change_cursor, Math.max(1, Math.min(30, Math.ceil(remainingMs / 1e3))), options)).workspace;
2353
+ }
2354
+ return workspace;
2355
+ }
2287
2356
  preserve(id, input, key, options = {}) {
2288
2357
  return this.jsonOperation(`/v1/workspaces/${encodeURIComponent(id)}/preserve`, input, key, PreserveResponseSchema, options);
2289
2358
  }
@@ -2323,7 +2392,7 @@ var PocketCoderClient = class {
2323
2392
  this.templates = new TemplatesApi(this.transport);
2324
2393
  this.workspaces = new WorkspacesApi(this.transport);
2325
2394
  this.attachments = new AttachmentsApi(this.transport);
2326
- this.agent = new AgentApi(this.transport);
2395
+ this.agent = new AgentApi(this.transport, this.workspaces);
2327
2396
  this.conversations = new ConversationsApi(this.transport);
2328
2397
  this.checkpoints = new CheckpointsApi(this.transport);
2329
2398
  this.operations = new OperationsApi(this.transport);
@@ -2482,4 +2551,4 @@ var WorkspaceTurnResolver = class {
2482
2551
  }
2483
2552
  };
2484
2553
  //#endregion
2485
- export { AdministrationApi, AgentApi, AttachmentsApi, CheckpointsApi, ConversationGoneError, ConversationsApi, LogsApi, NetworkEventsApi, OperationsApi, OutputsApi, PocketCoderClient, PocketCoderError, TERMINAL_WORKSPACE_STATES, TemplatesApi, TerminalConnection, TerminalsApi, WorkspaceTerminalError, WorkspaceTurnResolutionError, WorkspaceTurnResolver, WorkspacesApi, isPocketCoderErrorCode, splitAttachmentManifest };
2554
+ export { AdministrationApi, AgentApi, AgentNotReadyError, AttachmentsApi, CheckpointsApi, ConversationGoneError, ConversationsApi, LogsApi, NetworkEventsApi, OperationsApi, OutputsApi, PocketCoderClient, PocketCoderError, TERMINAL_WORKSPACE_STATES, TemplatesApi, TerminalConnection, TerminalsApi, WorkspaceTerminalError, WorkspaceTurnResolutionError, WorkspaceTurnResolver, WorkspacesApi, isPocketCoderErrorCode, splitAttachmentManifest };
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "type:library"
7
7
  ]
8
8
  },
9
- "version": "0.4.0",
9
+ "version": "0.5.0",
10
10
  "private": false,
11
11
  "description": "Runtime-validated TypeScript client for the PocketCoder control plane.",
12
12
  "type": "module",