@botiverse/raft-sdk 0.3.0 → 1.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -338,13 +338,8 @@ interface RaftNextStep {
338
338
  kind: string;
339
339
  /** The exact CLI command an agent would run for this step, when one exists. */
340
340
  command?: string;
341
- /**
342
- * Structured arguments for the step: plain, serialisable data (never a
343
- * closure), so a runtime whose next step runs in another process can store
344
- * it and act on it later — for example spread a held send's `args` into the
345
- * next `messages.send`.
346
- */
347
- args?: Record<string, unknown>;
341
+ /** Structured arguments for the step (target, seq, …). */
342
+ args?: Record<string, string | number | boolean | null>;
348
343
  /** One sentence explaining why this is the next step. */
349
344
  why: string;
350
345
  }
@@ -414,17 +409,6 @@ interface RaftMessage {
414
409
  /** The wire envelope, for fields this projection does not name. */
415
410
  raw: AgentApiMessageEnvelope;
416
411
  }
417
- /**
418
- * An envelope carries a reply target only when it names its conversation
419
- * (`channel_type` + `channel_name`, or a third-party event). Some Server
420
- * responses embed bare envelopes (for example `recentUnread: [{ content }]`);
421
- * those must not be rendered with a made-up target.
422
- */
423
- export declare function hasAgentMessageIdentity(envelope: AgentApiMessageEnvelope): boolean;
424
- /** Project one envelope; `null` when it has no conversation identity (skip it rather than render `#undefined`). */
425
- export declare function projectRaftMessage(envelope: AgentApiMessageEnvelope): RaftMessage | null;
426
- /** Project a list, skipping envelopes without a conversation identity. */
427
- export declare function projectRaftMessages(envelopes: readonly AgentApiMessageEnvelope[]): RaftMessage[];
428
412
  //#endregion
429
413
  //#region ../shared/src/agentOps/frontier.d.ts
430
414
  interface SeenAttestation {
@@ -444,8 +428,6 @@ export declare class SeenFrontier {
444
428
  private readonly targets;
445
429
  private readonly aliases;
446
430
  static fromSnapshot(snapshot: SeenFrontierSnapshot | null | undefined): SeenFrontier;
447
- /** Merge a snapshot into this frontier by the same monotonic rules (never lowers a mark). */
448
- absorb(snapshot: SeenFrontierSnapshot | null | undefined): void;
449
431
  /** Remember that the Server resolved `requested` to `canonical` (a thread spelling, a `~agent` suffix, …). */
450
432
  recordAlias(requested: string, canonical: string): void;
451
433
  canonical(target: string): string;
@@ -453,17 +435,6 @@ export declare class SeenFrontier {
453
435
  recordUpTo(target: string, seq: number): void;
454
436
  /** Record bodies that were rendered without proving contiguity. */
455
437
  recordExact(target: string, seqs: readonly number[]): void;
456
- /**
457
- * Attest that the model saw the context a held send/claim returned. Call it
458
- * only after the held messages actually reached the model (the SDK cannot
459
- * know that, so it never records this implicitly). Returns false and records
460
- * nothing when the context was withheld or the Server sent no boundary.
461
- */
462
- recordHeld(held: {
463
- target: string;
464
- seenUpToSeq: number | null;
465
- withheld: boolean;
466
- }): boolean;
467
438
  /** What to attest on a send or claim to `target`; omits `seenUpToSeq` when nothing contiguous is known. */
468
439
  attestation(target: string): SeenAttestation;
469
440
  snapshot(): SeenFrontierSnapshot;
@@ -593,27 +564,8 @@ interface RaftSent {
593
564
  /** Newer messages the Server returned alongside the acceptance, if any. */
594
565
  recentUnread: RaftMessage[];
595
566
  }
596
- /**
597
- * Plain data that continues a held send in a later process: spread it into
598
- * the next `messages.send({ ...original, ...continuation })`. `seen` is set
599
- * only when the Server reported a boundary and nothing was withheld.
600
- * Spreading `seen` asserts that the model saw the held messages (the same
601
- * attestation as `frontier.recordHeld`); drop it if the held text was stored
602
- * without being handed to the model, and the next send will be held again
603
- * with the same context instead of passing on a false attestation.
604
- */
605
- interface RaftSendContinuation {
606
- idempotencyKey: string;
607
- seen?: {
608
- upToSeq: number;
609
- };
610
- }
611
567
  interface RaftHeldBase {
612
568
  target: string;
613
- /** The idempotency key of the held message; a later send with this key is the same logical message. */
614
- idempotencyKey: string;
615
- /** Serialisable continuation for the next step (also carried in `next.args`). */
616
- continuation: RaftSendContinuation;
617
569
  /** How many newer messages the agent has not seen in this conversation. */
618
570
  newMessageCount: number;
619
571
  /** The newest of them, previewed; the Server may omit older ones. */
@@ -628,11 +580,9 @@ interface RaftHeldBase {
628
580
  }
629
581
  interface RaftHeld extends RaftHeldBase {
630
582
  /**
631
- * In-process sugar over `continuation`: send the same message again after the
632
- * runtime has handled the held context. `seen: "held"` attests the Server's
633
- * `seenUpToSeq` (say this only if the model saw the held messages);
634
- * `seen: "anyway"` bypasses the freshness check. Runtimes whose next step
635
- * runs elsewhere store `continuation` (or `next.args`) instead.
583
+ * Send the same message again after the runtime has handled the held context.
584
+ * `seen: "held"` attests the Server's `seenUpToSeq` (say this only if the model
585
+ * saw the held messages); `seen: "anyway"` bypasses the freshness check.
636
586
  */
637
587
  resend(options: {
638
588
  seen: "held" | "anyway";
@@ -640,28 +590,6 @@ interface RaftHeld extends RaftHeldBase {
640
590
  }
641
591
  type SendMessageOutcome = RaftOutcome<RaftSent, "sent"> | RaftOutcome<RaftHeld, "held">;
642
592
  //#endregion
643
- //#region ../shared/src/agentText/tasks.d.ts
644
- interface AgentClaimConflict {
645
- kind: "claim_conflict";
646
- conflictScope: "implementation_execution";
647
- blockedActions: string[];
648
- unblockedActionExamples: string[];
649
- currentAssignee: {
650
- type: "user" | "agent";
651
- name: string | null;
652
- } | null;
653
- taskStatus: string | null;
654
- claimedAt: string | null;
655
- observedAt: string;
656
- }
657
- interface AgentClaimResult {
658
- taskNumber?: number;
659
- messageId?: string;
660
- success: boolean;
661
- reason?: string;
662
- conflict?: AgentClaimConflict;
663
- }
664
- //#endregion
665
593
  //#region ../shared/src/agentOps/tasks.d.ts
666
594
  interface ClaimTasksRequest {
667
595
  /** Channel target the tasks live in, for example `#proj-sdk`. */
@@ -684,8 +612,6 @@ interface RaftClaimRow {
684
612
  name: string | null;
685
613
  } | null;
686
614
  conflict: AgentApiTaskClaimResult["conflict"] | null;
687
- /** The Server's row, as the CLI formatter reads it. */
688
- raw: AgentClaimResult;
689
615
  }
690
616
  interface RaftClaimResult {
691
617
  target: string;
@@ -693,64 +619,11 @@ interface RaftClaimResult {
693
619
  /** At least one row authorises work. */
694
620
  anyAuthorised: boolean;
695
621
  }
696
- interface RaftClaimHeld extends Omit<RaftHeldBase, "idempotencyKey" | "continuation"> {
697
- /** The claim to repeat once the held context has been handled (plain data; also in `next.args`). */
698
- request: ClaimTasksRequest;
699
- /** In-process sugar: retry the identical claim. */
622
+ interface RaftClaimHeld extends RaftHeldBase {
623
+ /** Retry the identical claim after the runtime has handled the held context. */
700
624
  retry(): Promise<ClaimTasksOutcome>;
701
625
  }
702
626
  type ClaimTasksOutcome = RaftOutcome<RaftClaimResult, "claimed" | "partial" | "refused"> | RaftOutcome<RaftClaimHeld, "held">;
703
- type RaftTaskStatus = "todo" | "in_progress" | "in_review" | "done" | "closed";
704
- interface ListTasksRequest {
705
- /** Channel board, for example `#proj-sdk`; omit with `mine: true` for your own tasks across channels. */
706
- target?: string;
707
- mine?: boolean;
708
- status?: RaftTaskStatus | "all";
709
- }
710
- interface RaftTaskBoard {
711
- scope: "channel" | "mine";
712
- target: string | null;
713
- tasks: AgentApiTaskListResponse["tasks"];
714
- coverage: AgentApiTaskListResponse["coverage"] | null;
715
- }
716
- interface CreateTasksRequest {
717
- target: string;
718
- tasks: Array<{
719
- title: string;
720
- createsResource?: boolean;
721
- }>;
722
- /** `@handle`; yourself to start in_progress, or (owner/admin) someone else to reserve a todo. */
723
- assignee?: string;
724
- }
725
- type RaftTasksCreated = AgentApiTaskCreateResponse & {
726
- target: string;
727
- };
728
- interface TaskRef {
729
- target: string;
730
- taskNumber: number;
731
- }
732
- interface AssignTaskRequest extends TaskRef {
733
- /** `@handle`, or null to clear the assignment. */
734
- assignee: string | null;
735
- /** Optimistic-concurrency token from a task you just read; lose rather than clobber. */
736
- expectedRevision?: number;
737
- }
738
- interface UpdateTaskStatusRequest extends TaskRef {
739
- status: RaftTaskStatus;
740
- }
741
- type UpdateTaskStatusOutcome = RaftOutcome<UpdateTaskStatusRequest, "updated"> | RaftOutcome<RaftClaimHeldLike<UpdateTaskStatusRequest>, "held">;
742
- /** A hold on a task write: the held context plus the request to repeat, as data. */
743
- type RaftClaimHeldLike<TRequest> = Omit<RaftHeldBase, "idempotencyKey" | "continuation"> & {
744
- request: TRequest;
745
- };
746
- interface AmendTaskRequest extends TaskRef {
747
- title?: string;
748
- /** New description; `null` clears it. */
749
- description?: string | null;
750
- }
751
- type AmendTaskOutcome = RaftOutcome<AgentApiTaskAmendSuccessResponse & {
752
- target: string;
753
- }, "amended"> | RaftOutcome<RaftClaimHeldLike<AmendTaskRequest>, "held">;
754
627
  //#endregion
755
628
  //#region ../shared/src/agentOps/wake.d.ts
756
629
  export declare const RAFT_INBOX_NOTICE_SCHEMA: "raft-agent-inbox-notice.v1";
@@ -807,187 +680,6 @@ interface VerifyNoticeInput {
807
680
  export declare function verifyInboxNotice(input: VerifyNoticeInput): Promise<VerifyNoticeResult>;
808
681
  type RaftWebhookStatus = AgentApiPushWebhookStatusResponse;
809
682
  //#endregion
810
- //#region ../shared/src/agentOps/channels.d.ts
811
- interface RaftChannelRef {
812
- target: string;
813
- channelId: string;
814
- }
815
- interface RaftChannelMuteState extends RaftChannelRef {
816
- activityMuted: boolean;
817
- muteFromSeq: number | null;
818
- stillArrives: string[];
819
- }
820
- //#endregion
821
- //#region ../shared/src/agentText/server.d.ts
822
- interface AgentPageInfo {
823
- total: number;
824
- offset: number;
825
- limit: number;
826
- nextCommand?: string;
827
- }
828
- //#endregion
829
- //#region ../shared/src/agentOps/server.d.ts
830
- type ServerInfoSection = "channels" | "agents" | "humans";
831
- interface ServerInfoRequest {
832
- /** Omit for the compact summary; `full` for the whole overview; a section for a paged listing. */
833
- view?: "summary" | "full" | ServerInfoSection;
834
- offset?: number;
835
- /** Default 50. */
836
- limit?: number;
837
- /** Channels only: restrict to joined channels. */
838
- joined?: boolean;
839
- }
840
- interface RaftServerInfo {
841
- view: NonNullable<ServerInfoRequest["view"]>;
842
- server: AgentApiServerInfoResponse;
843
- /** Present for a paged section. */
844
- page: (AgentPageInfo & {
845
- section: ServerInfoSection;
846
- }) | null;
847
- }
848
- //#endregion
849
- //#region ../shared/src/agentOps/attachments.d.ts
850
- /** Explicit type wins; otherwise sniff the bytes, then the filename extension, then octet-stream. */
851
- export declare function inferAttachmentMimeType(filename: string, bytes: Uint8Array, explicit?: string | null): string;
852
- interface UploadAttachmentRequest {
853
- /** Conversation the attachment will be used in: `#channel`, `dm:@peer`, or a thread target. */
854
- target: string;
855
- filename: string;
856
- bytes: Uint8Array;
857
- /** Explicit MIME type; inferred from the bytes and filename when omitted. */
858
- mimeType?: string;
859
- }
860
- type RaftAttachmentUploaded = AgentApiAttachmentUploadResponse & {
861
- target: string;
862
- mimeType: string | null;
863
- };
864
- interface RaftAttachmentBytes {
865
- attachmentId: string;
866
- bytes: Uint8Array;
867
- }
868
- //#endregion
869
- //#region ../shared/src/agentOps/search.d.ts
870
- interface SearchMessagesRequest {
871
- /** Free-text query; may be omitted when filtering by target or sender only. */
872
- query?: string;
873
- /** Restrict to a channel, DM, or thread target. */
874
- target?: string;
875
- /** Restrict to a sender handle. */
876
- sender?: string;
877
- sort?: "relevance" | "recent";
878
- /** ISO timestamps, both inclusive server-side. */
879
- before?: string;
880
- after?: string;
881
- /** 1..50; Server default 20. */
882
- limit?: number;
883
- offset?: number;
884
- }
885
- interface RaftSearchPage {
886
- query: string;
887
- results: AgentApiMessageSearchResponse["results"];
888
- /** Server-reported; `null` when an older Server did not say. */
889
- hasMore: boolean | null;
890
- }
891
- interface ReactRequest {
892
- messageId: string;
893
- emoji: string;
894
- }
895
- //#endregion
896
- //#region ../shared/src/agentText/mentions.d.ts
897
- type AgentMentionActionKind = "notify" | "add";
898
- interface AgentPendingMentionAction {
899
- resolutionId: string;
900
- messageId: string;
901
- targetType: string;
902
- targetHandle: string;
903
- reason: string;
904
- availableActions: string[];
905
- expiresAt?: string | null;
906
- }
907
- type AgentMentionActionResultStatus = "queued" | "delivered" | "dropped" | "stale" | "expired" | "no_permission" | "not_found" | "ambiguous";
908
- interface AgentMentionActionResult {
909
- resolutionId: string;
910
- status: AgentMentionActionResultStatus;
911
- action?: AgentMentionActionKind | null;
912
- messageId?: string | null;
913
- channelId?: string | null;
914
- targetType?: string | null;
915
- targetId?: string | null;
916
- targetHandle?: string | null;
917
- message?: string | null;
918
- reason?: string | null;
919
- dedupedResolutionIds?: string[];
920
- }
921
- //#endregion
922
- //#region ../shared/src/agentOps/mentions.d.ts
923
- interface RaftPendingMentions {
924
- actions: AgentPendingMentionAction[];
925
- /** Server-reported; `null` when it did not say (completeness not asserted). */
926
- hasMore: boolean | null;
927
- limit: number | undefined;
928
- }
929
- interface ExecuteMentionActionRequest {
930
- action: AgentMentionActionKind;
931
- resolutionIds: string[];
932
- }
933
- //#endregion
934
- //#region ../shared/src/agentOps/manual.d.ts
935
- interface ManualContext {
936
- intent: string;
937
- reason: string;
938
- }
939
- //#endregion
940
- //#region ../shared/src/agentOps/state.d.ts
941
- export declare const RAFT_STATE_SCHEMA: "raft-sdk-state.v1";
942
- interface RaftStateContinuation {
943
- target: string;
944
- idempotencyKey: string;
945
- /** Hex SHA-256 of target, content and attachment ids; a resend with the same hash is the same logical message. */
946
- contentHash: string;
947
- /** ISO time the send was held. */
948
- heldAt: string;
949
- }
950
- interface RaftState {
951
- schema: typeof RAFT_STATE_SCHEMA;
952
- /** Revision, incremented on every save by this SDK. Compare-and-set stores compare against it. */
953
- version: number;
954
- /** Last committed inbox cursor; the next pull passes it as `since`. */
955
- cursor: number | null;
956
- /** Cursor of the batch returned but not yet committed. */
957
- pendingCursor: number | null;
958
- frontier: SeenFrontierSnapshot;
959
- continuations?: RaftStateContinuation[];
960
- }
961
- interface RaftStateStore {
962
- load(): Promise<RaftState | null>;
963
- /**
964
- * Persist `state`. `expectedVersion` is the version this client loaded
965
- * (`undefined` when the store was empty). Throw to reject a stale write;
966
- * stores without compare-and-set may ignore it.
967
- */
968
- save(state: RaftState, options: {
969
- expectedVersion: number | undefined;
970
- }): Promise<void>;
971
- }
972
- type RaftStateSaveErrorHandler = (error: unknown, context: {
973
- phase: "load" | "save";
974
- version: number | undefined;
975
- }) => void;
976
- export declare const RAFT_STATE_CONTINUATIONS_PER_TARGET = 3;
977
- export declare const RAFT_STATE_CONTINUATIONS_TOTAL = 20;
978
- /** Validate a loaded value; anything unrecognised is treated as an empty store (safe: see file header). */
979
- export declare function parseRaftState(value: unknown): RaftState | null;
980
- /** Hex SHA-256 identifying one logical message (WebCrypto; Workers-safe). */
981
- export declare function hashRaftSendContent(target: string, content: string, attachmentIds?: readonly string[]): Promise<string>;
982
- //#endregion
983
- //#region ../shared/src/agentOps/actions.d.ts
984
- type PrepareActionCardRequest = AgentApiActionPrepareBody;
985
- interface RaftPreparedCard {
986
- target: string;
987
- /** The card message; a human commits it by clicking its action verb. */
988
- messageId: string;
989
- }
990
- //#endregion
991
683
  //#region ../shared/src/agentApiRawClient.d.ts
992
684
  type AgentApiRawClientErrorReason = "missing_route" | "missing_path_param" | "request_contract_mismatch" | "transport_error" | "http_error" | "empty_response" | "response_contract_mismatch";
993
685
  interface AgentApiRawTransportRequest<K extends AgentApiRouteKey = AgentApiRouteKey> {
@@ -996,6 +688,25 @@ interface AgentApiRawTransportRequest<K extends AgentApiRouteKey = AgentApiRoute
996
688
  path: string;
997
689
  body?: unknown;
998
690
  }
691
+ type AgentApiRawSuccess<K extends AgentApiRouteKey> = {
692
+ ok: true;
693
+ routeKey: K;
694
+ status: number;
695
+ data: AgentApiResponseByRoute[K];
696
+ };
697
+ type AgentApiRawFailure<K extends AgentApiRouteKey = AgentApiRouteKey> = {
698
+ ok: false;
699
+ routeKey?: K;
700
+ status?: number;
701
+ reason: AgentApiRawClientErrorReason;
702
+ message: string;
703
+ errorCode?: string | null;
704
+ suggestedNextAction?: string | null;
705
+ proxy?: unknown;
706
+ cause?: unknown;
707
+ response?: unknown;
708
+ };
709
+ type AgentApiRawResult<K extends AgentApiRouteKey> = AgentApiRawSuccess<K> | AgentApiRawFailure<K>;
999
710
  type AgentApiRawClientResource = AgentApiContract[AgentApiRouteKey]["client"]["resource"];
1000
711
  type AgentApiRawClientResourceMethod<R extends AgentApiRawClientResource> = { [K in AgentApiRouteKey]: AgentApiContract[K]["client"] extends {
1001
712
  resource: R;
@@ -1005,6 +716,9 @@ type AgentApiRouteKeyForClient<R extends AgentApiRawClientResource, M extends Ag
1005
716
  resource: R;
1006
717
  method: M;
1007
718
  } ? K : never; }[AgentApiRouteKey];
719
+ type AgentApiRawClientMethodArgs<K extends AgentApiRouteKey> = [AgentApiRequestParamsByRoute[K]] extends [never] ? [AgentApiRequestQueryByRoute[K]] extends [never] ? [AgentApiRequestBodyByRoute[K]] extends [never] ? [] : [body: AgentApiRequestBodyByRoute[K]] : [query: AgentApiRequestQueryByRoute[K]] : [AgentApiRequestQueryByRoute[K]] extends [never] ? [AgentApiRequestBodyByRoute[K]] extends [never] ? [params: AgentApiRequestParamsByRoute[K]] : [params: AgentApiRequestParamsByRoute[K], body: AgentApiRequestBodyByRoute[K]] : [AgentApiRequestBodyByRoute[K]] extends [never] ? [params: AgentApiRequestParamsByRoute[K], query: AgentApiRequestQueryByRoute[K]] : [params: AgentApiRequestParamsByRoute[K], query: AgentApiRequestQueryByRoute[K], body: AgentApiRequestBodyByRoute[K]];
720
+ type AgentApiRawClientMethod<K extends AgentApiRouteKey> = (...args: AgentApiRawClientMethodArgs<K>) => Promise<AgentApiRawResult<K>>;
721
+ type AgentApiRawClient = { [R in AgentApiRawClientResource]: { [M in AgentApiRawClientResourceMethod<R>]: AgentApiRawClientMethod<AgentApiRouteKeyForClient<R, M>>; }; };
1008
722
  //#endregion
1009
723
  //#region ../shared/src/index.d.ts
1010
724
  /**
@@ -1593,16 +1307,6 @@ declare const agentApiThreadUnfollowBodySchema: z.ZodObject<{
1593
1307
  thread: z.ZodString;
1594
1308
  reason: z.ZodOptional<z.ZodString>;
1595
1309
  }, z.core.$loose>;
1596
- declare const agentApiThreadListItemSchema: z.ZodObject<{
1597
- target: z.ZodString;
1598
- threadChannelId: z.ZodString;
1599
- parentChannelRef: z.ZodString;
1600
- parentMessageId: z.ZodString;
1601
- parentMessageShortId: z.ZodString;
1602
- followedAt: z.ZodString;
1603
- reason: z.ZodString;
1604
- doneAt: z.ZodNullable<z.ZodString>;
1605
- }, z.core.$loose>;
1606
1310
  declare const agentApiThreadListResponseSchema: z.ZodObject<{
1607
1311
  threads: z.ZodArray<z.ZodObject<{
1608
1312
  target: z.ZodString;
@@ -8334,7 +8038,6 @@ type AgentApiChannelLifecycleBody = z.infer<typeof agentApiChannelLifecycleBodyS
8334
8038
  type AgentApiAttachmentDownloadParams = z.infer<typeof agentApiAttachmentDownloadParamsSchema>;
8335
8039
  type AgentApiChannelMembersQuery = z.infer<typeof agentApiChannelMembersQuerySchema>;
8336
8040
  type AgentApiThreadUnfollowBody = z.infer<typeof agentApiThreadUnfollowBodySchema>;
8337
- type AgentApiThreadListItem = z.infer<typeof agentApiThreadListItemSchema>;
8338
8041
  type AgentApiThreadListResponse = z.infer<typeof agentApiThreadListResponseSchema>;
8339
8042
  type AgentApiInboxListQuery = z.infer<typeof agentApiInboxListQuerySchema>;
8340
8043
  type AgentApiInboxListResponse = z.infer<typeof agentApiInboxListResponseSchema>;
@@ -8930,6 +8633,16 @@ interface AgentApiClientFailure<K extends AgentApiRouteKey = AgentApiRouteKey> {
8930
8633
  error: AgentApiClientError;
8931
8634
  }
8932
8635
  type AgentApiClientResult<K extends AgentApiRouteKey> = AgentApiClientSuccess<K> | AgentApiClientFailure<K>;
8636
+ type AgentApiClientMethod<K extends AgentApiRouteKey> = (...args: Parameters<AgentApiRawClientMethod<K>>) => Promise<AgentApiClientResult<K>>;
8637
+ type AgentApiClientMethods = { [R in keyof AgentApiRawClient]: { [M in keyof AgentApiRawClient[R]]: AgentApiRawClient[R][M] extends AgentApiRawClientMethod<infer K> ? AgentApiClientMethod<K> : never; }; };
8638
+ interface AgentApiClientRequestOptions<K extends AgentApiRouteKey> {
8639
+ params?: AgentApiRequestParamsByRoute[K];
8640
+ query?: AgentApiRequestQueryByRoute[K];
8641
+ body?: AgentApiRequestBodyByRoute[K];
8642
+ }
8643
+ type AgentApiClient = AgentApiClientMethods & {
8644
+ request<K extends AgentApiRouteKey>(routeKey: K, options?: AgentApiClientRequestOptions<K>): Promise<AgentApiClientResult<K>>;
8645
+ };
8933
8646
  type AgentApiAuthHeaders = Record<string, string>;
8934
8647
  type AgentApiAuthStrategy = AgentApiAuthHeaders | ((request: AgentApiRawTransportRequest) => AgentApiAuthHeaders | Promise<AgentApiAuthHeaders>);
8935
8648
  interface AgentApiFetchTransportOptions {
@@ -9044,24 +8757,12 @@ interface RaftRouteInfo extends RaftRouteMeta {
9044
8757
  annotations: RaftRouteAnnotations;
9045
8758
  }
9046
8759
  /**
9047
- * `routes.<resource>.<method>({ params, query, body })` (one named object, typed per route) for every route in the
8760
+ * `routes.<resource>.<method>(params?, query?, body?)` for every route in the
9048
8761
  * contract, plus route introspection. Reads retry (bounded); writes and
9049
8762
  * destructive reads make exactly one attempt regardless of client retry
9050
8763
  * settings, because the contract says repeating them is not safe.
9051
8764
  */
9052
- type RoutePart<Name extends string, T> = [T] extends [never] ? { [P in Name]?: never; } : {} extends T ? { [P in Name]?: T; } : { [P in Name]: T; };
9053
- /**
9054
- * The single input every route takes: `{ params, query, body }`, typed per
9055
- * route. A part the route does not have is `never` (passing it is a compile
9056
- * error); a part with required fields is a required property.
9057
- */
9058
- type RaftRouteInput<K extends RaftRouteKey> = RoutePart<"params", AgentApiRequestParamsByRoute[K]> & RoutePart<"query", AgentApiRequestQueryByRoute[K]> & RoutePart<"body", AgentApiRequestBodyByRoute[K]>;
9059
- type RaftRouteMethod<K extends RaftRouteKey> = {} extends RaftRouteInput<K> ? (input?: RaftRouteInput<K>) => Promise<RaftRouteResult<K>> : (input: RaftRouteInput<K>) => Promise<RaftRouteResult<K>>;
9060
- /** `routes.<resource>.<method>({ params, query, body })` for every route in the contract. */
9061
- type RaftRouteMethods = { [R in AgentApiRawClientResource]: { [M in AgentApiRawClientResourceMethod<R>]: RaftRouteMethod<AgentApiRouteKeyForClient<R, M>>; }; };
9062
- type RaftRoutes = RaftRouteMethods & {
9063
- /** The same call by route key: `request("actionPrepare", { body })`. */
9064
- request<K extends RaftRouteKey>(routeKey: K, input?: RaftRouteInput<K>): Promise<RaftRouteResult<K>>;
8765
+ type RaftRoutes = AgentApiClient & {
9065
8766
  /** Content hash of the route manifest this SDK was built against. */
9066
8767
  manifestVersion: string;
9067
8768
  /** Static description of one route: capability, side effect, idempotency, audience, retry policy. */
@@ -9082,7 +8783,12 @@ interface CreateRaftRoutesOptions {
9082
8783
  beforeRequest?: infer F;
9083
8784
  } | undefined ? F : never;
9084
8785
  }
9085
- /** Build the public routes layer directly (convenience over createRaftRouteClient + raftRoutesFromClient). */
8786
+ /**
8787
+ * Build the routes layer over two transports: a retrying one for routes the
8788
+ * contract marks retry-safe, and a single-attempt one for everything else.
8789
+ * The split is decided per route from `AGENT_API_ROUTE_META`, never by the
8790
+ * caller and never by the HTTP method.
8791
+ */
9086
8792
  export declare function createRaftRoutes(options: CreateRaftRoutesOptions): RaftRoutes;
9087
8793
  //#endregion
9088
8794
  //#region src/context.d.ts
@@ -9192,7 +8898,7 @@ type RaftClient = AgentApiMessageClient & RaftManageClient & {
9192
8898
  join(request: RaftChannelJoinRequest): Promise<RaftChannelJoinResult>;
9193
8899
  };
9194
8900
  /**
9195
- * Every Agent API route as `routes.<resource>.<method>({ params, query, body })` (one named object, typed per route),
8901
+ * Every Agent API route as `routes.<resource>.<method>(params?, query?, body?)`,
9196
8902
  * typed from the shared contract, with per-route metadata via `routes.describe`.
9197
8903
  * Retry policy follows the contract: reads may retry, writes make one attempt.
9198
8904
  */
@@ -9327,22 +9033,6 @@ interface CreateRaftOptions {
9327
9033
  * is held once and returns the unread context, which is the safe default.
9328
9034
  */
9329
9035
  frontier?: SeenFrontierSnapshot | null;
9330
- /**
9331
- * Persist the client's state (committed and pending inbox cursors, the seen
9332
- * frontier, held-send keys) across tool calls and processes. The store
9333
- * implements `load()` and `save(state, { expectedVersion })`; the SDK loads
9334
- * once before the first operation and saves after each successful operation
9335
- * that changed the state (one attempt, never fails the operation).
9336
- */
9337
- state?: RaftStateStore;
9338
- /** Called when loading or saving the state fails or is rejected as stale. */
9339
- onStateSaveError?: RaftStateSaveErrorHandler;
9340
- }
9341
- interface RaftInboxCommitResult {
9342
- /** The committed cursor, or null when there was nothing to commit. */
9343
- cursor: number | null;
9344
- /** Whether the state was persisted (true when no store is configured). */
9345
- saved: boolean;
9346
9036
  }
9347
9037
  interface Raft {
9348
9038
  identity: {
@@ -9364,22 +9054,8 @@ interface Raft {
9364
9054
  };
9365
9055
  };
9366
9056
  inbox: {
9367
- /**
9368
- * One bounded pull. Nothing is acknowledged by it. Without `since`, sends
9369
- * the last committed cursor (from `state`), which is what acknowledges the
9370
- * previously committed batch on the Server; the returned batch's cursor is
9371
- * recorded as pending until you `commit()` it.
9372
- */
9057
+ /** One bounded pull. Nothing is acknowledged until the next call passes `data.cursor` as `since` (cursor mode). */
9373
9058
  check(request?: CheckInboxRequest): Promise<CheckInboxOutcome>;
9374
- /**
9375
- * Mark a batch as processed. With no argument, commits the pending cursor
9376
- * from the last `check()` (possibly in an earlier process, via `state`);
9377
- * also accepts `{ cursor }` or a batch. Records only; the next `check()`
9378
- * acknowledges it on the Server. The SDK never commits on its own.
9379
- */
9380
- commit(target?: {
9381
- cursor: number | null;
9382
- }): Promise<RaftInboxCommitResult>;
9383
9059
  /**
9384
9060
  * Pull until the Server reports nothing more, like `raft message check`, as
9385
9061
  * an async iterator: the pull that acknowledges a batch is only sent when
@@ -9397,141 +9073,16 @@ interface Raft {
9397
9073
  send(request: SendMessageRequest): Promise<SendMessageOutcome>;
9398
9074
  /** Reply where a received message came from. */
9399
9075
  reply(message: Pick<RaftMessage, "target">, request: Omit<SendMessageRequest, "target">): Promise<SendMessageOutcome>;
9400
- /** Find a specific message (`raft message search`); previews neutralise @handles and #channels. */
9401
- search(request: SearchMessagesRequest): Promise<RaftOutcome<RaftSearchPage, "results" | "empty">>;
9402
- /** Resolve one message id to its canonical form and reply target. */
9403
- resolve(request: {
9404
- messageId: string;
9405
- }): Promise<RaftOutcome<RaftMessage, "message">>;
9406
- react(request: ReactRequest): Promise<RaftOutcome<ReactRequest, "added" | "removed">>;
9407
- unreact(request: ReactRequest): Promise<RaftOutcome<ReactRequest, "added" | "removed">>;
9408
- };
9409
- attachments: {
9410
- /** Small-file multipart upload into a conversation; the upload alone posts nothing. */
9411
- upload(request: UploadAttachmentRequest): Promise<RaftOutcome<RaftAttachmentUploaded, "uploaded">>;
9412
- download(request: {
9413
- attachmentId: string;
9414
- }): Promise<RaftOutcome<RaftAttachmentBytes, "downloaded">>;
9415
- comments(request: {
9416
- attachmentId: string;
9417
- limit?: number;
9418
- }): Promise<RaftOutcome<AgentApiAttachmentCommentsResponse & {
9419
- attachmentId: string;
9420
- }, "comments" | "empty">>;
9421
- };
9422
- mentions: {
9423
- /** @mentions you sent that reached nobody, with the recovery commands. */
9424
- pending(request?: {
9425
- limit?: number;
9426
- }): Promise<RaftOutcome<RaftPendingMentions, "pending" | "empty">>;
9427
- /** `notify` the target of an unreached mention, or `add` them to the conversation. */
9428
- execute(request: ExecuteMentionActionRequest): Promise<RaftOutcome<{
9429
- action: AgentMentionActionKind;
9430
- results: AgentMentionActionResult[];
9431
- }, "executed">>;
9432
- /** Per-target delivery outcome for a message you sent. */
9433
- deliveries(request: {
9434
- messageId: string;
9435
- }): Promise<RaftOutcome<AgentApiSenderMentionDeliveriesResponse, "deliveries" | "empty">>;
9436
- };
9437
- actions: {
9438
- /**
9439
- * Post an action card for a human to confirm (channel:create,
9440
- * channel:add_member, agent:create, and the integration card types). The
9441
- * human who clicks it executes it as themselves.
9442
- */
9443
- prepare(request: PrepareActionCardRequest): Promise<RaftOutcome<RaftPreparedCard, "prepared">>;
9444
- };
9445
- manual: {
9446
- /** Fetch a Manual topic; `intent` and `reason` are required and must never carry prompts, credentials, or message payloads. */
9447
- get(request: {
9448
- topic: string;
9449
- } & ManualContext): Promise<RaftOutcome<AgentApiKnowledgeGetResponse, "topic">>;
9450
- search(request: {
9451
- query: string;
9452
- scope?: string;
9453
- } & ManualContext): Promise<RaftOutcome<AgentApiKnowledgeSearchResponse, "results" | "empty">>;
9454
9076
  };
9455
9077
  tasks: {
9456
9078
  /** Claim before working. Refusals are rows, not exceptions; a hold comes back as `state: "held"` with `retry`. */
9457
9079
  claim(request: ClaimTasksRequest): Promise<ClaimTasksOutcome>;
9458
- /** A channel's task board, or your own tasks across channels with `mine: true`. */
9459
- list(request: ListTasksRequest): Promise<RaftOutcome<RaftTaskBoard, "board" | "empty">>;
9460
- create(request: CreateTasksRequest): Promise<RaftOutcome<RaftTasksCreated, "created">>;
9461
- unclaim(request: TaskRef): Promise<RaftOutcome<TaskRef, "unclaimed">>;
9462
- assign(request: AssignTaskRequest): Promise<RaftOutcome<{
9463
- target: string;
9464
- taskNumber: number;
9465
- assignee: string | null;
9466
- revision: number;
9467
- }, "assigned" | "unassigned">>;
9468
- /** todo → in_progress → in_review → done; `closed` from anywhere. A hold comes back as `state: "held"` with `data.request`. */
9469
- updateStatus(request: UpdateTaskStatusRequest): Promise<UpdateTaskStatusOutcome>;
9470
- amend(request: AmendTaskRequest): Promise<AmendTaskOutcome>;
9471
- history(request: TaskRef): Promise<RaftOutcome<AgentApiTaskHistoryResponse & {
9472
- target: string;
9473
- }, "history">>;
9474
- /** Convert a top-level message into an unassigned task. */
9475
- convert(request: {
9476
- target: string;
9477
- messageId: string;
9478
- }): Promise<RaftOutcome<{
9479
- target: string;
9480
- task: AgentApiTaskCreateResponse["tasks"][number];
9481
- }, "converted">>;
9482
- delete(request: TaskRef): Promise<RaftOutcome<TaskRef, "deleted">>;
9483
- };
9484
- channels: {
9485
- /** Explicit, idempotent. Never a side effect of sending. */
9486
- join(request: {
9487
- target: string;
9488
- }): Promise<RaftOutcome<RaftChannelRef, "joined" | "already_joined">>;
9489
- leave(request: {
9490
- target: string;
9491
- }): Promise<RaftOutcome<RaftChannelRef, "left" | "not_joined">>;
9492
- /** Mute ordinary Activity delivery; @mentions, DMs, and followed threads still arrive. */
9493
- mute(request: {
9494
- target: string;
9495
- }): Promise<RaftOutcome<RaftChannelMuteState, "muted" | "unmuted">>;
9496
- unmute(request: {
9497
- target: string;
9498
- }): Promise<RaftOutcome<RaftChannelMuteState, "muted" | "unmuted">>;
9499
- members(request: {
9500
- target: string;
9501
- }): Promise<RaftOutcome<AgentApiChannelMembersResponse, "members">>;
9502
- };
9503
- threads: {
9504
- list(): Promise<RaftOutcome<AgentApiThreadListItem[], "threads" | "empty">>;
9505
- unfollow(request: {
9506
- target: string;
9507
- reason?: string;
9508
- }): Promise<RaftOutcome<{
9509
- target: string;
9510
- }, "unfollowed">>;
9511
- };
9512
- server: {
9513
- /** Summary by default; `view: "channels" | "agents" | "humans"` pages a section; `view: "full"` is the whole overview. */
9514
- info(request?: ServerInfoRequest): Promise<RaftOutcome<RaftServerInfo, "info">>;
9515
- };
9516
- profile: {
9517
- show(request?: {
9518
- target?: string;
9519
- }): Promise<RaftOutcome<AgentApiProfileView, "profile">>;
9520
- update(request: AgentApiProfileUpdateBody): Promise<RaftOutcome<AgentApiProfileView, "updated">>;
9521
9080
  };
9522
9081
  /** What this process has shown its model, per target; export it to survive restarts. */
9523
9082
  frontier: SeenFrontier;
9524
- state: {
9525
- /** Save now (for example after `frontier.recordHeld`). Best effort; returns whether it succeeded. */
9526
- save(): Promise<boolean>;
9527
- /** Load the persisted state now (operations do this automatically). */
9528
- load(): Promise<void>;
9529
- /** The current state value, as it would be saved. */
9530
- snapshot(): RaftState;
9531
- };
9532
9083
  /** Every Agent API route, typed from the shared contract. */
9533
9084
  routes: RaftRoutes;
9534
9085
  }
9535
9086
  export declare function createRaft(options: CreateRaftOptions): Raft;
9536
9087
  //#endregion
9537
- export type { AmendTaskOutcome, AmendTaskRequest, AssignTaskRequest, BootstrapRaftCredentialOptions, CheckInboxOutcome, CheckInboxRequest, ClaimTasksOutcome, ClaimTasksRequest, CreateRaftClientFromStoreOptions, CreateRaftClientOptions, CreateRaftOptions, CreateRaftRoutesOptions, CreateTasksRequest, DrainInboxRequest, ExecuteMentionActionRequest, ListInboxRequest, ListTasksRequest, ManualContext, PrepareActionCardRequest, Raft, RaftAckMode, RaftActionPrepareRequest, RaftActionPrepared, RaftApiError, RaftApiResult, RaftAppConfig, RaftAppConfigPatch, RaftAttachmentBytes, RaftAttachmentUploaded, RaftAvatarUpload, RaftChannelJoinClient, RaftChannelJoinClientResult, RaftChannelJoinError, RaftChannelJoinFailure, RaftChannelJoinOperation, RaftChannelJoinRequest, RaftChannelJoinResult, RaftChannelJoinSuccess, RaftChannelJoinTransportError, RaftChannelMuteState, RaftChannelRef, RaftClaimHeld, RaftClaimHeldLike, RaftClaimResult, RaftClaimRow, RaftClaimRowState, RaftClient, RaftClientError, RaftClientFailure, RaftClientResult, RaftClientSuccess, RaftClientThrottleOptions, RaftClientTransportRequest, RaftContextAgent, RaftContextData, RaftContextError, RaftContextResult, RaftContextServer, RaftCredentialErrorCode, RaftCredentialIdentity, RaftCredentialStore, RaftEvent, RaftEventAttachment, RaftEventExternalMessage, RaftEventsReceiveData, RaftEventsReceiveError, RaftEventsReceiveRequest, RaftEventsReceiveResult, RaftFailure, RaftHeld, RaftHeldBase, RaftHistoryPage, RaftInboxBatch, RaftInboxCommitResult, RaftInboxConversation, RaftInboxDrainSummary, RaftInboxListing, RaftInboxNotice, RaftManageClient, RaftMessage, RaftMessageAttachment, RaftMessageTask, RaftNextStep, RaftNoticeFlag, RaftNoticeTarget, RaftOpError, RaftOpErrorCode, RaftOutcome, RaftPendingMentions, RaftPreparedCard, RaftProfile, RaftProfileUpdate, RaftRouteAnnotations, RaftRouteInfo, RaftRouteKey, RaftRouteMeta, RaftRouteResult, RaftRouteRetryPolicy, RaftRoutes, RaftSdkConfigurationErrorCode, RaftSearchPage, RaftSendContinuation, RaftSenderType, RaftSent, RaftServerInfo, RaftServerProfile, RaftServerUpdate, RaftState, RaftStateContinuation, RaftStateSaveErrorHandler, RaftStateStore, RaftTaskBoard, RaftTaskStatus, RaftTasksCreated, RaftWebhookStatus, ReactRequest, ReadHistoryRequest, SearchMessagesRequest, SeenAttestation, SeenFrontierSnapshot, SendMessageOutcome, SendMessageRequest, ServerInfoRequest, ServerInfoSection, StoredRaftCredential, TaskRef, UpdateTaskStatusOutcome, UpdateTaskStatusRequest, UploadAttachmentRequest, VerifyNoticeInput, VerifyNoticeRejection, VerifyNoticeResult };
9088
+ export type { BootstrapRaftCredentialOptions, CheckInboxOutcome, CheckInboxRequest, ClaimTasksOutcome, ClaimTasksRequest, CreateRaftClientFromStoreOptions, CreateRaftClientOptions, CreateRaftOptions, CreateRaftRoutesOptions, DrainInboxRequest, ListInboxRequest, Raft, RaftAckMode, RaftActionPrepareRequest, RaftActionPrepared, RaftApiError, RaftApiResult, RaftAppConfig, RaftAppConfigPatch, RaftAvatarUpload, RaftChannelJoinClient, RaftChannelJoinClientResult, RaftChannelJoinError, RaftChannelJoinFailure, RaftChannelJoinOperation, RaftChannelJoinRequest, RaftChannelJoinResult, RaftChannelJoinSuccess, RaftChannelJoinTransportError, RaftClaimHeld, RaftClaimResult, RaftClaimRow, RaftClaimRowState, RaftClient, RaftClientError, RaftClientFailure, RaftClientResult, RaftClientSuccess, RaftClientThrottleOptions, RaftClientTransportRequest, RaftContextAgent, RaftContextData, RaftContextError, RaftContextResult, RaftContextServer, RaftCredentialErrorCode, RaftCredentialIdentity, RaftCredentialStore, RaftEvent, RaftEventAttachment, RaftEventExternalMessage, RaftEventsReceiveData, RaftEventsReceiveError, RaftEventsReceiveRequest, RaftEventsReceiveResult, RaftFailure, RaftHeld, RaftHeldBase, RaftHistoryPage, RaftInboxBatch, RaftInboxConversation, RaftInboxDrainSummary, RaftInboxListing, RaftInboxNotice, RaftManageClient, RaftMessage, RaftMessageAttachment, RaftMessageTask, RaftNextStep, RaftNoticeFlag, RaftNoticeTarget, RaftOpError, RaftOpErrorCode, RaftOutcome, RaftProfile, RaftProfileUpdate, RaftRouteAnnotations, RaftRouteInfo, RaftRouteKey, RaftRouteMeta, RaftRouteResult, RaftRouteRetryPolicy, RaftRoutes, RaftSdkConfigurationErrorCode, RaftSenderType, RaftSent, RaftServerProfile, RaftServerUpdate, RaftWebhookStatus, ReadHistoryRequest, SeenAttestation, SeenFrontierSnapshot, SendMessageOutcome, SendMessageRequest, StoredRaftCredential, VerifyNoticeInput, VerifyNoticeRejection, VerifyNoticeResult };