@awesomate/sdk 0.96.0 → 0.98.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
@@ -26,7 +26,7 @@
26
26
  * Docs: https://hub.awesomate.ai/docs/sdk/
27
27
  */
28
28
  /** This package's version, sent to the hub with every server call. */
29
- export declare const VERSION = "0.96.0";
29
+ export declare const VERSION = "0.98.0";
30
30
  /** Augmented by the generated awesomate.d.ts, so each kind's rows are typed. */
31
31
  export interface Kinds {
32
32
  }
@@ -696,6 +696,8 @@ export interface AwesomateErrorDetails {
696
696
  }>;
697
697
  /** With restore_to_public (files.restore() into public/ without confirmPublic): the path it would go back to. */
698
698
  target?: string;
699
+ /** With roll_incomplete (knowledge.guests.roll()): the guest's keys still live, the new one too when it would not stop. */
700
+ stillLive?: string[];
699
701
  }
700
702
  /**
701
703
  * Every failure from the hub. `message` is for you, the developer; `personMessage`, when the hub
@@ -740,6 +742,8 @@ export declare class AwesomateError extends Error {
740
742
  }>;
741
743
  /** With serverCode restore_to_public (`files.restore()`): the path in public/ it would go back to. */
742
744
  readonly target?: string;
745
+ /** With serverCode roll_incomplete (`knowledge.guests.roll()`): the guest's keys still live. Roll or remove again. */
746
+ readonly stillLive?: string[];
743
747
  constructor(
744
748
  /** Why it failed. */
745
749
  code: ErrorCode, message: string,
@@ -1933,6 +1937,66 @@ export declare class AwesomateClient {
1933
1937
  confirm?: string;
1934
1938
  title?: string;
1935
1939
  }) => Promise<SharedVideo>;
1940
+ /**
1941
+ * Guest access: a named, time-limited pass for someone outside the business (an agency, a
1942
+ * contractor) to ask the collections or tags the owner picks. Each guest is one key on the
1943
+ * account's Guest answers agent, never shown documents only the owner can see. Needs the account's
1944
+ * token at the Owner level (knowledge:read to read, knowledge:write to change), never an app key or
1945
+ * the Hub Key. A chat connection's key, or a Claude Code key while it acts for the owner, may read
1946
+ * (list, log) but never give, change, roll or remove. Every plan with Knowledge, where the
1947
+ * account has Guest access (`knowledge_guests`; feature_unavailable otherwise).
1948
+ * `id` is the key the guest holds now; after a roll, any earlier id still finds them.
1949
+ *
1950
+ * @example
1951
+ * const g = await db.knowledge.guests.give({ name: 'Jordan, ads manager', tags: ['product-info'], ends_in_days: 30 });
1952
+ * console.log(g.ready.ask_link); // shown once: send it to Jordan yourself
1953
+ */
1954
+ guests: {
1955
+ /**
1956
+ * Every guest: `guests` live or paused, newest first; `ended` ended or removed. Never a key. The
1957
+ * account's token at the Owner level with knowledge:read.
1958
+ */
1959
+ list: () => Promise<KnowledgeGuestList>;
1960
+ /**
1961
+ * Give someone access: the account's token at the Owner level with knowledge:write, never an app
1962
+ * key, the Hub Key, a chat connection's key or a Claude Code key acting for the owner. At least one
1963
+ * collection or tag. Ends in 90 days unless `ends_in_days` or
1964
+ * `ends_at` says otherwise (1 to 365 days); `cap` answers a month, half the account's unless set,
1965
+ * counting toward the account's answers. The key comes back once, in `key` and `ready`: hand it
1966
+ * to the guest and never store it. Pass your own `request_id` (a UUID) so a retry gives the same
1967
+ * guest once. A retry after the guest took the account's last place answers `too_many_guests`:
1968
+ * find them with `list()` and `roll()` them for a key.
1969
+ */
1970
+ give: (guest: KnowledgeGuestGive) => Promise<KnowledgeGuestKey>;
1971
+ /**
1972
+ * Change a guest: any field of `give()`, and only what differs is changed. `widened` says the
1973
+ * change gave them more (more to read, a later end or more answers).
1974
+ */
1975
+ update: (id: string, change: KnowledgeGuestChange) => Promise<KnowledgeGuestUpdated>;
1976
+ /**
1977
+ * A new key for the guest, ending when the old one would have, and the old key stopped: for a
1978
+ * link that went further than it should. The new key comes back once. Pass your own
1979
+ * `request_id` so a retry shows the same new key. `roll_incomplete` (serverCode) means the old
1980
+ * key would not stop, so the new one is not shown; `stillLive` on the error names the keys still
1981
+ * live (the new one too when it would not stop either): roll or remove again.
1982
+ */
1983
+ roll: (id: string, options?: {
1984
+ request_id?: string;
1985
+ }) => Promise<KnowledgeGuestKey>;
1986
+ /** End a guest's access for good: every key they held stops and their kept questions are forgotten. */
1987
+ remove: (id: string) => Promise<{
1988
+ removed: true;
1989
+ questions_forgotten: boolean;
1990
+ }>;
1991
+ /**
1992
+ * What a guest did, newest first: when, from where, and the question when it was kept. `limit`
1993
+ * is 1 to 200 (default 50); pass `next_cursor` back as `cursor` for the page after.
1994
+ */
1995
+ log: (id: string, options?: {
1996
+ limit?: number;
1997
+ cursor?: string;
1998
+ }) => Promise<KnowledgeGuestLog>;
1999
+ };
1936
2000
  };
1937
2001
  /**
1938
2002
  * Tell Contacts something happened to someone ("job_paid", "quote_sent"), so any email series
@@ -6995,6 +7059,128 @@ export interface KnowledgeDataQuery {
6995
7059
  limit?: number;
6996
7060
  [key: string]: unknown;
6997
7061
  }
7062
+ /** Where a guest stands: live, paused, ended (past its end) or removed (ended by the owner). */
7063
+ export type KnowledgeGuestState = 'live' | 'paused' | 'ended' | 'removed';
7064
+ /** One guest, from knowledge.guests. Never the key. */
7065
+ export interface KnowledgeGuest {
7066
+ /** The key the guest holds now (a roll gives a new one; an earlier id still finds them). */
7067
+ id: string;
7068
+ /** Who they are, as the owner named them. */
7069
+ name: string | null;
7070
+ agent_id: string | null;
7071
+ policy_id: string | null;
7072
+ /** Collection ids they can read. */
7073
+ collections: string[];
7074
+ /** Tags they can read. */
7075
+ tags: string[];
7076
+ /** When access was given. */
7077
+ made: string | null;
7078
+ /** When the key they hold now was made, if a roll replaced an earlier one. */
7079
+ rolled: string | null;
7080
+ last_used: string | null;
7081
+ /** When access ends. */
7082
+ ends: string | null;
7083
+ /** Answers a month. */
7084
+ cap: number | null;
7085
+ /** Answers this month (UTC); null when it could not be read. */
7086
+ answers_this_month: number | null;
7087
+ /** The most places they asked from on one day in the last 31: more than a few can mean the link was passed on. */
7088
+ places: number | null;
7089
+ /** Their questions are kept for 30 days. */
7090
+ keep_questions: boolean;
7091
+ state: KnowledgeGuestState;
7092
+ /** Keys a roll replaced. One still live means it would not stop: roll or remove again. */
7093
+ earlier: Array<{
7094
+ id: string;
7095
+ state: KnowledgeGuestState;
7096
+ }>;
7097
+ }
7098
+ /** What knowledge.guests.list() returns. */
7099
+ export interface KnowledgeGuestList {
7100
+ /** Live and paused, newest first. */
7101
+ guests: KnowledgeGuest[];
7102
+ /** Ended and removed. */
7103
+ ended: KnowledgeGuest[];
7104
+ /** The most live guests an account can have. */
7105
+ max_live: number;
7106
+ /** The answers a month a new guest gets unless you say; null when it could not be read. */
7107
+ default_cap: number | null;
7108
+ }
7109
+ /** What knowledge.guests.give() takes. Give at least one collection or tag. */
7110
+ export interface KnowledgeGuestGive {
7111
+ /** Who they are (1 to 120 characters). */
7112
+ name: string;
7113
+ /** Collection ids, up to 32. */
7114
+ collections?: string[];
7115
+ /** Tags, up to 32. */
7116
+ tags?: string[];
7117
+ /** 1 to 365. Default 90. Not with ends_at. */
7118
+ ends_in_days?: number;
7119
+ /** A date (`2027-02-24`, the end of that day UTC) or a time with its offset, up to a year out. Not with ends_in_days. */
7120
+ ends_at?: string;
7121
+ /** Answers a month. Default half the account's. */
7122
+ cap?: number;
7123
+ /** Keep their questions for 30 days, for you to read in the log. Default true. */
7124
+ keep_questions?: boolean;
7125
+ /** A UUID of your own: a retry with the same one gives the same guest once. */
7126
+ request_id?: string;
7127
+ }
7128
+ /** What knowledge.guests.update() takes: any of give()'s fields. */
7129
+ export type KnowledgeGuestChange = Partial<Omit<KnowledgeGuestGive, 'request_id'>>;
7130
+ /** A guest's key, shown once, from knowledge.guests.give() and roll(). */
7131
+ export interface KnowledgeGuestKey {
7132
+ guest: KnowledgeGuest;
7133
+ /** The key itself. Hand it to the guest; never store or log it. */
7134
+ key: string;
7135
+ /** The key ready to send: a link to ask from a browser, a Claude Code command (null when it cannot be made) and the key. */
7136
+ ready: {
7137
+ ask_link: string;
7138
+ claude_code: string | null;
7139
+ api_key: string;
7140
+ };
7141
+ /** Asked to keep questions, but Knowledge cannot keep them yet: the guest was given access without. */
7142
+ questions_not_live?: true;
7143
+ /** From roll(): earlier keys that would not stop. Roll or remove again. */
7144
+ still_live?: string[];
7145
+ }
7146
+ /** What knowledge.guests.update() returns. */
7147
+ export interface KnowledgeGuestUpdated {
7148
+ guest: KnowledgeGuest;
7149
+ /** What changed: name, scope, ends, cap, questions. */
7150
+ changed: Array<'name' | 'scope' | 'ends' | 'cap' | 'questions'>;
7151
+ /** The change gave them more: more to read, a later end or more answers. */
7152
+ widened: boolean;
7153
+ /** Asked to keep questions, but Knowledge cannot keep them yet. */
7154
+ questions_not_live?: true;
7155
+ }
7156
+ /** One thing a guest did, from knowledge.guests.log(). */
7157
+ export interface KnowledgeGuestLogRow {
7158
+ at: string | null;
7159
+ /** ask_page: the Ask link; ai_app: an AI app such as Claude Code; api: anything else. */
7160
+ where: 'ask_page' | 'ai_app' | 'api';
7161
+ /** True for a question, false for anything else (a search, a list). */
7162
+ asked: boolean;
7163
+ /** The HTTP status the guest got. */
7164
+ status: number | null;
7165
+ /** How the question was answered (such as `ok` or `no_results`), never the answer itself. */
7166
+ answer: string | null;
7167
+ /** How many sources the answer cited. */
7168
+ sources: number | null;
7169
+ /** Where they asked from, as a number: 1 for the first place on this page, 2 for the next. Never an address, and per page only. */
7170
+ place: number | null;
7171
+ /** The question, when it was kept and the caller may read it; otherwise null. */
7172
+ question: string | null;
7173
+ }
7174
+ /** What knowledge.guests.log() returns. */
7175
+ export interface KnowledgeGuestLog {
7176
+ /** The guest's id. */
7177
+ guest: string;
7178
+ rows: KnowledgeGuestLogRow[];
7179
+ /** Pass back as cursor for the next page; null on the last. */
7180
+ next_cursor: string | null;
7181
+ /** Questions are the owner's to read: true when they were left out for this caller. */
7182
+ questions_hidden?: true;
7183
+ }
6998
7184
  /** Where a session is kept: localStorage, Capacitor Preferences, or anything with these three. */
6999
7185
  export interface SessionStorageLike {
7000
7186
  /** The stored value, or null. */
package/dist/index.js CHANGED
@@ -26,7 +26,7 @@
26
26
  * Docs: https://hub.awesomate.ai/docs/sdk/
27
27
  */
28
28
  /** This package's version, sent to the hub with every server call. */
29
- export const VERSION = '0.96.0';
29
+ export const VERSION = '0.98.0';
30
30
  const DEFAULT_BASE = 'https://hub.awesomate.ai';
31
31
  /** The one check for a platform `watch_url` (mirrored in the hub's awesomate-knowledge.ts and its MCP). */
32
32
  const WATCH_URL = /^https:\/\/[^\s"'<>]+$/i;
@@ -71,6 +71,8 @@ export class AwesomateError extends Error {
71
71
  roles;
72
72
  /** With serverCode restore_to_public (`files.restore()`): the path in public/ it would go back to. */
73
73
  target;
74
+ /** With serverCode roll_incomplete (`knowledge.guests.roll()`): the guest's keys still live. Roll or remove again. */
75
+ stillLive;
74
76
  constructor(
75
77
  /** Why it failed. */
76
78
  code, message,
@@ -107,16 +109,24 @@ export class AwesomateError extends Error {
107
109
  this.roles = details.roles;
108
110
  if (details.target !== undefined)
109
111
  this.target = details.target;
112
+ if (details.stillLive !== undefined)
113
+ this.stillLive = details.stillLive;
110
114
  }
111
115
  }
112
116
  /** Every code the hub uses for "the account has switched this off in its privacy settings". */
113
117
  const CONSENT_CODES = new Set(['consent_blocked', 'consent_denied', 'consent_required', 'consent_off', 'consent_missing', 'files_consent_off']);
114
118
  const UPGRADE_CODES = new Set(['upgrade_required', 'plan_required']);
119
+ /** Guest access (knowledge.guests): a request to fix, and a guest or account that stands in the way. */
120
+ const GUEST_VALIDATION_CODES = new Set(['scope_required', 'cap_required', 'nothing_to_change']);
121
+ const GUEST_CONFLICT_CODES = new Set(['too_many_guests', 'guest_ended', 'guest_paused', 'guest_agent_paused']);
115
122
  /** A code-like word: some hub areas send their code in `error` and the sentence in `message`. */
116
123
  const CODE_LIKE = /^[a-z][a-z0-9_]*$/;
117
124
  function errorCode(status, server, body = {}) {
118
125
  if (server === 'validation' || server === 'invalid' || status === 422)
119
126
  return 'validation';
127
+ // a 400 that says the request was wrong (invalid_request, a checked body's issues), or one of Guest access's own
128
+ if (status === 400 && (server === 'invalid_request' || Array.isArray(body.issues) || (server && GUEST_VALIDATION_CODES.has(server))))
129
+ return 'validation';
120
130
  // A file the hub will not take as sent: too big, no length, or a type it refuses.
121
131
  if (status === 411 || status === 413 || status === 415)
122
132
  return 'validation';
@@ -140,7 +150,7 @@ function errorCode(status, server, body = {}) {
140
150
  // changed: a thing a setup adds to changed since checkSetup(). already / already_suggested: a list
141
151
  // already fills from that tag, or someone has suggested it (lists.proposeTagRule()).
142
152
  if (server === 'conflict' || server === 'stale' || server === 'not_draft' || server === 'not_run' || server === 'changed'
143
- || server === 'already' || server === 'already_suggested')
153
+ || server === 'already' || server === 'already_suggested' || (server && GUEST_CONFLICT_CODES.has(server)))
144
154
  return 'conflict';
145
155
  if (status === 404 && server !== 'not_live')
146
156
  return 'not_found';
@@ -180,11 +190,15 @@ function refusal(status, json) {
180
190
  const target = serverCode === 'restore_to_public' ? nonEmpty(json.target) : undefined;
181
191
  if (target)
182
192
  details.target = target;
193
+ if (serverCode === 'roll_incomplete' && Array.isArray(json.still_live))
194
+ details.stillLive = json.still_live.map(String);
195
+ const issue = Array.isArray(json.issues) ? json.issues[0] : undefined;
196
+ const issuePath = issue && typeof issue === 'object' && issue.path !== '(root)' ? nonEmpty(issue.path) : undefined;
183
197
  return {
184
198
  code: errorCode(status, serverCode, json),
185
199
  message: (codeInError ? sentence : error ?? sentence) ?? `The hub answered ${status}.`,
186
200
  serverCode,
187
- field: nonEmpty(json.field),
201
+ field: nonEmpty(json.field) ?? issuePath,
188
202
  details,
189
203
  };
190
204
  }
@@ -1817,6 +1831,66 @@ export class AwesomateClient {
1817
1831
  ...(options.enabled && options.confirm ? { confirm: options.confirm } : {}),
1818
1832
  }, false);
1819
1833
  },
1834
+ /**
1835
+ * Guest access: a named, time-limited pass for someone outside the business (an agency, a
1836
+ * contractor) to ask the collections or tags the owner picks. Each guest is one key on the
1837
+ * account's Guest answers agent, never shown documents only the owner can see. Needs the account's
1838
+ * token at the Owner level (knowledge:read to read, knowledge:write to change), never an app key or
1839
+ * the Hub Key. A chat connection's key, or a Claude Code key while it acts for the owner, may read
1840
+ * (list, log) but never give, change, roll or remove. Every plan with Knowledge, where the
1841
+ * account has Guest access (`knowledge_guests`; feature_unavailable otherwise).
1842
+ * `id` is the key the guest holds now; after a roll, any earlier id still finds them.
1843
+ *
1844
+ * @example
1845
+ * const g = await db.knowledge.guests.give({ name: 'Jordan, ads manager', tags: ['product-info'], ends_in_days: 30 });
1846
+ * console.log(g.ready.ask_link); // shown once: send it to Jordan yourself
1847
+ */
1848
+ guests: {
1849
+ /**
1850
+ * Every guest: `guests` live or paused, newest first; `ended` ended or removed. Never a key. The
1851
+ * account's token at the Owner level with knowledge:read.
1852
+ */
1853
+ list: () => this.request('GET', '/api/knowledge/guests'),
1854
+ /**
1855
+ * Give someone access: the account's token at the Owner level with knowledge:write, never an app
1856
+ * key, the Hub Key, a chat connection's key or a Claude Code key acting for the owner. At least one
1857
+ * collection or tag. Ends in 90 days unless `ends_in_days` or
1858
+ * `ends_at` says otherwise (1 to 365 days); `cap` answers a month, half the account's unless set,
1859
+ * counting toward the account's answers. The key comes back once, in `key` and `ready`: hand it
1860
+ * to the guest and never store it. Pass your own `request_id` (a UUID) so a retry gives the same
1861
+ * guest once. A retry after the guest took the account's last place answers `too_many_guests`:
1862
+ * find them with `list()` and `roll()` them for a key.
1863
+ */
1864
+ give: (guest) => this.request('POST', '/api/knowledge/guests', guest, false),
1865
+ /**
1866
+ * Change a guest: any field of `give()`, and only what differs is changed. `widened` says the
1867
+ * change gave them more (more to read, a later end or more answers).
1868
+ */
1869
+ update: (id, change) => this.request('PATCH', `/api/knowledge/guests/${encodeURIComponent(id)}`, change, false),
1870
+ /**
1871
+ * A new key for the guest, ending when the old one would have, and the old key stopped: for a
1872
+ * link that went further than it should. The new key comes back once. Pass your own
1873
+ * `request_id` so a retry shows the same new key. `roll_incomplete` (serverCode) means the old
1874
+ * key would not stop, so the new one is not shown; `stillLive` on the error names the keys still
1875
+ * live (the new one too when it would not stop either): roll or remove again.
1876
+ */
1877
+ roll: (id, options = {}) => this.request('POST', `/api/knowledge/guests/${encodeURIComponent(id)}/roll`, options.request_id ? { request_id: options.request_id } : {}, false),
1878
+ /** End a guest's access for good: every key they held stops and their kept questions are forgotten. */
1879
+ remove: (id) => this.request('DELETE', `/api/knowledge/guests/${encodeURIComponent(id)}`, undefined, false),
1880
+ /**
1881
+ * What a guest did, newest first: when, from where, and the question when it was kept. `limit`
1882
+ * is 1 to 200 (default 50); pass `next_cursor` back as `cursor` for the page after.
1883
+ */
1884
+ log: (id, options = {}) => {
1885
+ const q = new URLSearchParams();
1886
+ if (options.limit !== undefined)
1887
+ q.set('limit', String(options.limit));
1888
+ if (options.cursor)
1889
+ q.set('cursor', options.cursor);
1890
+ const qs = q.toString();
1891
+ return this.request('GET', `/api/knowledge/guests/${encodeURIComponent(id)}/log${qs ? `?${qs}` : ''}`);
1892
+ },
1893
+ },
1820
1894
  };
1821
1895
  /**
1822
1896
  * Tell Contacts something happened to someone ("job_paid", "quote_sent"), so any email series
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awesomate/sdk",
3
- "version": "0.96.0",
3
+ "version": "0.98.0",
4
4
  "description": "Your own Awesomate data from Node and the browser: query contacts and app data with generated types, and sign your app's own users in",
5
5
  "license": "MIT",
6
6
  "type": "module",