@persistmemory/sdk 0.2.0 → 0.4.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/README.md CHANGED
@@ -219,19 +219,28 @@ const { space, added } = await client.spaces.merge({
219
219
  Additive, never destructive. Both sources keep exactly what they had, a memory
220
220
  in both is filed once, and undoing it is deleting the Space that comes back.
221
221
 
222
- ### The default Space
222
+ ### There is no default Space
223
223
 
224
- Where a capture lands when it names none the Telegram bot with no `/space`
225
- set, an MCP `remember` with no `spaceIds`, a conversation started from a chat.
224
+ A capture that names none is REFUSED. `client.memories.remember({ text })` with
225
+ no `spaceIds` answers 400, naming the Spaces this account has; the Telegram bot
226
+ with no `/space` set keeps nothing and says so; an MCP `remember` with no
227
+ `spaceIds` and no `work_in_space` returns an error rather than filing. Nothing
228
+ picks a Space on anybody's behalf.
229
+
230
+ `spaces.setDefault` and `spaces.getDefault` are gone with the two endpoints
231
+ they called. What replaces them is per-context rather than per-account: which
232
+ Space THIS command line, or this account's ingest address, is working in.
226
233
 
227
234
  ```ts
228
- await client.spaces.setDefault(work.id);
229
- const { space } = await client.spaces.getDefault(); // {} when there is none
230
- await client.spaces.setDefault(null); // back to nothing
235
+ await client.spaces.chooseWorking(work.id); // this profile
236
+ await client.spaces.chooseWorking(work.id, { surface: "email" }); // the inbox
237
+ const here = await client.spaces.working(); // { scope, chosen? }
238
+ await client.spaces.chooseWorking(null); // stop; nothing is kept
231
239
  ```
232
240
 
233
- `null` clears it and is not the same as omitting the field. Having no default is
234
- the normal state, not a gapnothing picks a Space on your behalf.
241
+ `null` clears it and is not the same as omitting the field. `chosen` absent
242
+ means nothing sent from that context is kept not that it is kept somewhere
243
+ else.
235
244
 
236
245
  ### Nesting, listing, updating, archiving
237
246
 
package/dist/index.cjs CHANGED
@@ -654,6 +654,14 @@ var Spaces = class {
654
654
  * `delete` never destroys a memory that is filed in another Space as well —
655
655
  * that one is detached and left alone. `deleted` and `kept` come back so you
656
656
  * can say what actually happened.
657
+ *
658
+ * `moveTo` NAMES WHERE THE STRANDED ONES GO, and is refused-into rather than
659
+ * required: most deletions strand nothing, because everything in the Space
660
+ * is also filed elsewhere, and demanding a destination for those would be a
661
+ * question about nothing. When something WOULD be left in no Space at all,
662
+ * the server answers 400 naming this field. It used to file them into the
663
+ * account's default, which no longer exists — nothing picks a Space on
664
+ * anybody's behalf, so "keep these" has no answer unless you say where.
657
665
  */
658
666
  async delete(id, params, options) {
659
667
  return this.#http.delete(
@@ -677,21 +685,55 @@ var Spaces = class {
677
685
  options
678
686
  );
679
687
  }
688
+ /* ------------------------- where this is working ------------------------- */
689
+ /*
690
+ `getDefault` AND `setDefault` ARE GONE, with the endpoints they called.
691
+
692
+ They read and wrote the account-wide Space a capture fell into when nobody
693
+ named one. Nothing falls anywhere now: a Space is chosen for the context
694
+ doing the capturing, or `remember` answers 400. Keeping the methods would
695
+ mean keeping two calls that 404, which is a worse break than removing them
696
+ because it looks like a server fault rather than a change.
697
+ */
680
698
  /**
681
- * The Space this account files into when a capture names none.
699
+ * Which Space a context is working in.
700
+ *
701
+ * `chosen` absent means NOTHING sent from that context is kept — there is no
702
+ * default behind it and nothing picks one. The reply used to carry a
703
+ * `fallback` for that case and no longer can.
682
704
  *
683
- * `{}` an object with no `space` means there is no default, which is the
684
- * normal state rather than a gap. It is also what comes back after the Space
685
- * somebody chose has been deleted.
705
+ * `profile` is the command line's own profile name, and `surface` says which
706
+ * context is being asked about: `cli` for this profile, `email` for the
707
+ * account's ingest address. Between them they are the whole of what a caller
708
+ * may say about where it is working — the server builds the scope key
709
+ * itself, so this can never read or move where a chat is filing.
686
710
  */
687
- async getDefault(options) {
688
- return this.#http.get("/api/v1/spaces/default", void 0, options);
711
+ async working(params = {}, options) {
712
+ return this.#http.get(
713
+ "/api/v1/spaces/working",
714
+ {
715
+ ...params.profile !== void 0 ? { profile: params.profile } : {},
716
+ ...params.surface !== void 0 ? { surface: params.surface } : {}
717
+ },
718
+ options
719
+ );
689
720
  }
690
- /** `null` clears it. Not the same as omitting it, which is why the type says so. */
691
- async setDefault(spaceId, options) {
721
+ /**
722
+ * Works in one from here on. `null` stops working in any.
723
+ *
724
+ * Takes an id or a NAME, because that is how a person says it. `null` rather
725
+ * than an omitted field: "clear this" and "I did not mention it" are
726
+ * different instructions, and clearing means this context keeps nothing
727
+ * until a Space is chosen again.
728
+ */
729
+ async chooseWorking(space, params = {}, options) {
692
730
  return this.#http.patch(
693
- "/api/v1/spaces/default",
694
- { spaceId },
731
+ "/api/v1/spaces/working",
732
+ {
733
+ space,
734
+ ...params.profile !== void 0 ? { profile: params.profile } : {},
735
+ ...params.surface !== void 0 ? { surface: params.surface } : {}
736
+ },
695
737
  options
696
738
  );
697
739
  }
@@ -702,17 +744,22 @@ var Spaces = class {
702
744
  /**
703
745
  * The memories filed in a Space.
704
746
  *
705
- * This endpoint answers `{ data, pagination: { limit } }` with no cursor: it
706
- * returns the first `limit` members and stops. Wrapped in a `Paginated`
707
- * anyway so it reads like every other list, and it simply yields one page -
708
- * a caller who needs more should filter `memories.list` by `spaceIds`, which
709
- * is the endpoint that actually pages.
747
+ * The cursor is PASSED. This fetch used to ignore the paginator's cursor
748
+ * on the stale belief that the endpoint had none the server has minted
749
+ * `pagination.nextCursor` since it started paging, and its own comment
750
+ * says "both SDKs iterate by reading pagination". Ignoring it meant every
751
+ * page request was identical: the loop guard saw a non-advancing fetch and
752
+ * stopped silently, so `all()` returned the first page twice and dropped
753
+ * everything after it — duplicated AND truncated data, with no error.
710
754
  */
711
755
  memories(id, params = {}, options) {
712
756
  return new Paginated(
713
- () => this.#http.get(
757
+ (cursor) => this.#http.get(
714
758
  `/api/v1/spaces/${encodeURIComponent(id)}/memories`,
715
- { ...params.limit !== void 0 ? { limit: params.limit } : {} },
759
+ {
760
+ ...params.limit !== void 0 ? { limit: params.limit } : {},
761
+ ...cursor !== void 0 ? { cursor } : {}
762
+ },
716
763
  options
717
764
  )
718
765
  );
@@ -738,6 +785,94 @@ var Spaces = class {
738
785
  options
739
786
  );
740
787
  }
788
+ /* ----------------------- who else can see it ----------------------- */
789
+ /**
790
+ * Who can see this Space, including invitations nobody has accepted.
791
+ *
792
+ * A DIFFERENT EDGE from `memories()` next door, and the difference is worth
793
+ * holding on to: that one maps a MEMORY to a Space, this one maps a PERSON
794
+ * to a Space. The server keeps them in two tables with two names for exactly
795
+ * that reason.
796
+ *
797
+ * Read `acceptedAt` before you render a row. An invitation grants nothing
798
+ * until it is accepted, so a list that draws invited and accepted people the
799
+ * same way tells its user somebody is reading their memories when nobody is.
800
+ *
801
+ * Paginated like every other list here. A Space has a handful of
802
+ * collaborators rather than thousands, so this will usually be one page -
803
+ * which costs a caller nothing and means the shape does not change if a
804
+ * Space ever has an organisation on it.
805
+ */
806
+ collaborators(id, params = {}, options) {
807
+ return new Paginated(
808
+ (cursor) => this.#http.get(
809
+ `/api/v1/sharing/spaces/${encodeURIComponent(id)}/collaborators`,
810
+ {
811
+ ...params.limit !== void 0 ? { limit: params.limit } : {},
812
+ ...cursor !== void 0 ? { cursor } : {}
813
+ },
814
+ options
815
+ )
816
+ );
817
+ }
818
+ /**
819
+ * Offers somebody sight of a Space. Answers with the invitation.
820
+ *
821
+ * AN OFFER, NOT A GRANT, and the returned `acceptedAt` will be absent to
822
+ * prove it. The recipient has to accept before they can see anything, which
823
+ * is the property that keeps "nothing enters your memory without you" true
824
+ * even when somebody else starts the sharing. Do not tell your user their
825
+ * Space "has been shared" on the strength of a 2xx here.
826
+ *
827
+ * WHAT THEY GET IS THE WHOLE SPACE: every memory already filed in it and
828
+ * every memory that lands in it afterwards. There is no narrower grant, and
829
+ * `role` does not make one - it decides what they may do BESIDES read.
830
+ *
831
+ * Worth an idempotency key when a person is behind it. A double-clicked
832
+ * "share" is two invitations to the same address, and the second one is a
833
+ * second email arriving at somebody who has already been asked.
834
+ */
835
+ async share(id, params, options) {
836
+ return this.#http.post(
837
+ `/api/v1/sharing/spaces/${encodeURIComponent(id)}/collaborators`,
838
+ params,
839
+ options
840
+ );
841
+ }
842
+ /**
843
+ * Ends somebody's access, or withdraws an invitation they never accepted.
844
+ *
845
+ * Nothing was ever copied into their account - a collaborator SEES the
846
+ * owner's memories rather than holding a duplicate - so this is one write
847
+ * and not a cascade, and there is no orphaned copy left behind.
848
+ *
849
+ * A body on a DELETE, matching `removeMemories` above. The alternative is an
850
+ * address in a path segment, where every `.`, `+` and `@` is a chance for a
851
+ * proxy or a router to normalise somebody else's email into the one that
852
+ * gets revoked.
853
+ */
854
+ async unshare(id, email, options) {
855
+ return this.#http.delete(
856
+ `/api/v1/sharing/spaces/${encodeURIComponent(id)}/collaborators`,
857
+ { email },
858
+ options
859
+ );
860
+ }
861
+ /**
862
+ * Changes what an existing collaborator may do. Never invites anybody.
863
+ *
864
+ * The quiet one. Moving somebody from `viewer` to `owner` sends no
865
+ * invitation and needs no acceptance, and afterwards they can share the
866
+ * Space onward and revoke the person who promoted them. Show your user what
867
+ * `owner` means before you send this, not after.
868
+ */
869
+ async setRole(id, params, options) {
870
+ return this.#http.patch(
871
+ `/api/v1/sharing/spaces/${encodeURIComponent(id)}/collaborators`,
872
+ params,
873
+ options
874
+ );
875
+ }
741
876
  };
742
877
 
743
878
  // src/resources/ingestion.ts