@awesomate/sdk 0.18.1 → 0.20.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 +151 -1
- package/dist/index.js +69 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* Docs: https://hub.awesomate.ai/docs/sdk/
|
|
25
25
|
*/
|
|
26
26
|
/** This package's version, sent to the hub with every server call. */
|
|
27
|
-
export declare const VERSION = "0.
|
|
27
|
+
export declare const VERSION = "0.20.0";
|
|
28
28
|
/** Augmented by the generated awesomate.d.ts, so each kind's rows are typed. */
|
|
29
29
|
export interface Kinds {
|
|
30
30
|
}
|
|
@@ -157,6 +157,87 @@ export interface Page<R> {
|
|
|
157
157
|
/** When the hub read the rows. */
|
|
158
158
|
asAt: string;
|
|
159
159
|
}
|
|
160
|
+
/** Someone on the account, as Tasks names them. */
|
|
161
|
+
export interface TaskPerson {
|
|
162
|
+
email: string;
|
|
163
|
+
name: string | null;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* One card on the account's Tasks board: something waiting on a person (a quote to accept, an
|
|
167
|
+
* email to approve) or a task someone gave. The card's main action happens on its own page
|
|
168
|
+
* (`openPath` in the hub); Tasks only moves the card (not now, pass on) and finishes given tasks.
|
|
169
|
+
*/
|
|
170
|
+
export interface TaskCard {
|
|
171
|
+
/** Stable id of the card; pass it to notNow() and passOn(). */
|
|
172
|
+
key: string;
|
|
173
|
+
kind: string;
|
|
174
|
+
/** Where it came from, in the owner's words ("Build requests", "Contacts"). */
|
|
175
|
+
from: string;
|
|
176
|
+
title: string;
|
|
177
|
+
/** What is being asked, as a question. */
|
|
178
|
+
question: string;
|
|
179
|
+
context: string | null;
|
|
180
|
+
/** 1 routine to 5 urgent. */
|
|
181
|
+
priority: number;
|
|
182
|
+
createdAt: string;
|
|
183
|
+
dueAt: string | null;
|
|
184
|
+
/** The hub page that shows it in full. */
|
|
185
|
+
openPath: string;
|
|
186
|
+
/** Who has it, when it was passed on; null means anyone on the account. */
|
|
187
|
+
holder: TaskPerson | null;
|
|
188
|
+
/** When it comes back, if put off with Not now. */
|
|
189
|
+
snoozedUntil: string | null;
|
|
190
|
+
canAct: boolean;
|
|
191
|
+
/** Who it can be passed to. */
|
|
192
|
+
passTo: TaskPerson[];
|
|
193
|
+
/** Set for a task someone gave (give()); null for everything else. */
|
|
194
|
+
task: {
|
|
195
|
+
/** Pass it to update(), done() and drop(). */
|
|
196
|
+
id: number;
|
|
197
|
+
detail: string | null;
|
|
198
|
+
linkPath: string | null;
|
|
199
|
+
author: TaskPerson;
|
|
200
|
+
canFinish: boolean;
|
|
201
|
+
canDrop: boolean;
|
|
202
|
+
canEdit: boolean;
|
|
203
|
+
} | null;
|
|
204
|
+
}
|
|
205
|
+
/** The Tasks board, as the account's token sees it (the owner, so `scope: 'all'` works). */
|
|
206
|
+
export interface TaskBoard {
|
|
207
|
+
scope: 'mine' | 'all';
|
|
208
|
+
me: TaskPerson & {
|
|
209
|
+
role: string;
|
|
210
|
+
};
|
|
211
|
+
/** Who a task can be given to. */
|
|
212
|
+
people: Array<TaskPerson & {
|
|
213
|
+
me: boolean;
|
|
214
|
+
}>;
|
|
215
|
+
/** Waiting for a decision now. */
|
|
216
|
+
toDecide: TaskCard[];
|
|
217
|
+
/** Put off with Not now; back when the time comes. */
|
|
218
|
+
later: TaskCard[];
|
|
219
|
+
/** With someone else. */
|
|
220
|
+
waiting: TaskCard[];
|
|
221
|
+
/** Recently decided, for the record. */
|
|
222
|
+
decided: Array<{
|
|
223
|
+
key: string;
|
|
224
|
+
kind: string;
|
|
225
|
+
from: string;
|
|
226
|
+
text: string;
|
|
227
|
+
by: TaskPerson | null;
|
|
228
|
+
at: string;
|
|
229
|
+
}>;
|
|
230
|
+
}
|
|
231
|
+
/** A task to give: to someone on the account by email, or to the owner when `forEmail` is left out. */
|
|
232
|
+
export interface GiveTask {
|
|
233
|
+
title: string;
|
|
234
|
+
detail?: string;
|
|
235
|
+
forEmail?: string;
|
|
236
|
+
/** ISO time it is due. */
|
|
237
|
+
dueAt?: string;
|
|
238
|
+
/** A hub path the task points at, e.g. /contacts/people/... */
|
|
239
|
+
linkPath?: string;
|
|
240
|
+
}
|
|
160
241
|
/** A file or folder in the account's Files (the folders on its automation account: public/, private/, temp/). */
|
|
161
242
|
export interface FileEntry {
|
|
162
243
|
/** Relative to the files folder, starting with its top folder: public/images/logo.png. */
|
|
@@ -179,6 +260,22 @@ export interface FilesUsage {
|
|
|
179
260
|
partial: boolean;
|
|
180
261
|
measured_at: string;
|
|
181
262
|
}
|
|
263
|
+
/** An answer from the app's agent to a typed question (app.ask()). */
|
|
264
|
+
export interface AgentAnswer {
|
|
265
|
+
/** answered: from the business's content, with sources; none: the content has no answer (or not for this person). */
|
|
266
|
+
status: 'answered' | 'none';
|
|
267
|
+
answer: string;
|
|
268
|
+
/** Where the answer came from: show them with it. */
|
|
269
|
+
sources: Array<{
|
|
270
|
+
title: string;
|
|
271
|
+
url: string | null;
|
|
272
|
+
}>;
|
|
273
|
+
/**
|
|
274
|
+
* The platform's sentence about keeping questions it could not answer. It comes with a person's
|
|
275
|
+
* first answer only: show it with that answer.
|
|
276
|
+
*/
|
|
277
|
+
questionNotice: string | null;
|
|
278
|
+
}
|
|
182
279
|
/** A file uploaded from an app. Keep `handle` in a record (a kind's file attribute); it opens the file again. */
|
|
183
280
|
export interface AppFile {
|
|
184
281
|
handle: string;
|
|
@@ -297,6 +394,44 @@ export declare class AwesomateClient {
|
|
|
297
394
|
trashPath: string;
|
|
298
395
|
}>;
|
|
299
396
|
};
|
|
397
|
+
private tasksCall;
|
|
398
|
+
/**
|
|
399
|
+
* The account's Tasks: what is waiting on its people, and tasks they give each other. An app's
|
|
400
|
+
* server or an n8n workflow can give someone a task ("call this customer back") and finish it.
|
|
401
|
+
* Needs the account's token, and Tasks on the account (a feature_unavailable refusal says
|
|
402
|
+
* when it is not).
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* await db.tasks.give({ title: 'Call Sam back about the leak', forEmail: 'jo@brightwater.example', dueAt: '2026-10-06T09:00:00+11:00' });
|
|
406
|
+
*/
|
|
407
|
+
readonly tasks: {
|
|
408
|
+
/** The board: waiting now, put off, with someone else, recently decided. `all` shows everyone's, not only yours. */
|
|
409
|
+
board: (options?: {
|
|
410
|
+
scope?: "mine" | "all";
|
|
411
|
+
}) => Promise<TaskBoard>;
|
|
412
|
+
/** Give a task. The person gets it on their board, and an email when they are not the one giving it. */
|
|
413
|
+
give: (task: GiveTask) => Promise<{
|
|
414
|
+
key: string;
|
|
415
|
+
id: number;
|
|
416
|
+
holder: TaskPerson;
|
|
417
|
+
emailed: boolean;
|
|
418
|
+
}>;
|
|
419
|
+
/** Change a given task: whoever wrote it, or the owner. */
|
|
420
|
+
update: (id: number | string, patch: Partial<Omit<GiveTask, "forEmail">>) => Promise<void>;
|
|
421
|
+
/** Mark a given task done: the person who has it, whoever wrote it, or the owner. */
|
|
422
|
+
done: (id: number | string) => Promise<void>;
|
|
423
|
+
/** Take a given task off the board without doing it: whoever wrote it, or the owner. */
|
|
424
|
+
drop: (id: number | string) => Promise<void>;
|
|
425
|
+
/** Put a card off until a time (at most 90 days), for this person only. */
|
|
426
|
+
notNow: (key: string, until: Date | string) => Promise<{
|
|
427
|
+
until: string;
|
|
428
|
+
}>;
|
|
429
|
+
/** Hand a card to someone on the account who can act on it. */
|
|
430
|
+
passOn: (key: string, toEmail: string, reason?: string) => Promise<{
|
|
431
|
+
holder: TaskPerson;
|
|
432
|
+
emailed: boolean;
|
|
433
|
+
}>;
|
|
434
|
+
};
|
|
300
435
|
/** The kinds this token can read, their columns, operators and examples. */
|
|
301
436
|
schema(): Promise<{
|
|
302
437
|
kinds: Array<{
|
|
@@ -981,6 +1116,21 @@ export declare class AwesomateAppClient {
|
|
|
981
1116
|
/** The file a handle names, for someone signed in to this app. */
|
|
982
1117
|
download: (handle: string) => Promise<Blob>;
|
|
983
1118
|
};
|
|
1119
|
+
/**
|
|
1120
|
+
* Ask the app's agent a typed question, as this signed-in person: a help box that answers from
|
|
1121
|
+
* the business's content, with sources. The agent is the one the account picked for the app (the
|
|
1122
|
+
* same one Talk uses). Show `questionNotice` with the answer when it comes (a person's first).
|
|
1123
|
+
* The agent answers only from content this person may see; the voice persona does not apply.
|
|
1124
|
+
* A refusal's serverCode says why: no_agent, channel_off, person_daily (30 a day per person),
|
|
1125
|
+
* agent_daily, answers_used_up; personMessage is the sentence to show.
|
|
1126
|
+
*
|
|
1127
|
+
* @example
|
|
1128
|
+
* const a = await app.ask('What time do you open on Saturday?');
|
|
1129
|
+
* render(a.answer, a.sources, a.questionNotice);
|
|
1130
|
+
*/
|
|
1131
|
+
ask(question: string, options?: {
|
|
1132
|
+
session?: string;
|
|
1133
|
+
}): Promise<AgentAnswer>;
|
|
984
1134
|
/**
|
|
985
1135
|
* The agent this app talks with by voice, or null when the account has not picked one. Pass it
|
|
986
1136
|
* to AwesomateAgent.mount as agentId; the hub decides which agent answers, never the page.
|
package/dist/index.js
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* Docs: https://hub.awesomate.ai/docs/sdk/
|
|
25
25
|
*/
|
|
26
26
|
/** This package's version, sent to the hub with every server call. */
|
|
27
|
-
export const VERSION = '0.
|
|
27
|
+
export const VERSION = '0.20.0';
|
|
28
28
|
const DEFAULT_BASE = 'https://hub.awesomate.ai';
|
|
29
29
|
const ERROR_CODES = ['unauthenticated', 'forbidden', 'not_found', 'validation', 'consent_blocked', 'rate_limited', 'conflict', 'unavailable'];
|
|
30
30
|
/**
|
|
@@ -230,6 +230,56 @@ export class AwesomateClient {
|
|
|
230
230
|
/** Move to the trash. Not erased, and no longer counted toward the Files space. */
|
|
231
231
|
remove: async (path) => this.filesCall('DELETE', `/api/files?path=${encodeURIComponent(path)}`),
|
|
232
232
|
};
|
|
233
|
+
tasksCall(method, path, body) {
|
|
234
|
+
if (this.appKey) {
|
|
235
|
+
return Promise.reject(new AwesomateError('forbidden', 'Tasks needs the account\'s token (amt_pat_...), not an app key.', 0));
|
|
236
|
+
}
|
|
237
|
+
return this.request(method, path, body, false);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* The account's Tasks: what is waiting on its people, and tasks they give each other. An app's
|
|
241
|
+
* server or an n8n workflow can give someone a task ("call this customer back") and finish it.
|
|
242
|
+
* Needs the account's token, and Tasks on the account (a feature_unavailable refusal says
|
|
243
|
+
* when it is not).
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* await db.tasks.give({ title: 'Call Sam back about the leak', forEmail: 'jo@brightwater.example', dueAt: '2026-10-06T09:00:00+11:00' });
|
|
247
|
+
*/
|
|
248
|
+
tasks = {
|
|
249
|
+
/** The board: waiting now, put off, with someone else, recently decided. `all` shows everyone's, not only yours. */
|
|
250
|
+
board: (options = {}) => this.tasksCall('GET', `/api/my-tasks${options.scope === 'all' ? '?scope=all' : ''}`),
|
|
251
|
+
/** Give a task. The person gets it on their board, and an email when they are not the one giving it. */
|
|
252
|
+
give: async (task) => {
|
|
253
|
+
const r = await this.tasksCall('POST', '/api/my-tasks/tasks', task);
|
|
254
|
+
return { key: r.key, id: r.id, holder: r.holder, emailed: r.emailed };
|
|
255
|
+
},
|
|
256
|
+
/** Change a given task: whoever wrote it, or the owner. */
|
|
257
|
+
update: async (id, patch) => {
|
|
258
|
+
await this.tasksCall('PATCH', `/api/my-tasks/tasks/${encodeURIComponent(String(id))}`, patch);
|
|
259
|
+
},
|
|
260
|
+
/** Mark a given task done: the person who has it, whoever wrote it, or the owner. */
|
|
261
|
+
done: async (id) => {
|
|
262
|
+
await this.tasksCall('POST', `/api/my-tasks/tasks/${encodeURIComponent(String(id))}/done`);
|
|
263
|
+
},
|
|
264
|
+
/** Take a given task off the board without doing it: whoever wrote it, or the owner. */
|
|
265
|
+
drop: async (id) => {
|
|
266
|
+
await this.tasksCall('POST', `/api/my-tasks/tasks/${encodeURIComponent(String(id))}/drop`);
|
|
267
|
+
},
|
|
268
|
+
/** Put a card off until a time (at most 90 days), for this person only. */
|
|
269
|
+
notNow: async (key, until) => {
|
|
270
|
+
const r = await this.tasksCall('POST', `/api/my-tasks/items/${encodeURIComponent(key)}/not-now`, {
|
|
271
|
+
until: until instanceof Date ? until.toISOString() : until,
|
|
272
|
+
});
|
|
273
|
+
return { until: r.until };
|
|
274
|
+
},
|
|
275
|
+
/** Hand a card to someone on the account who can act on it. */
|
|
276
|
+
passOn: async (key, toEmail, reason) => {
|
|
277
|
+
const r = await this.tasksCall('POST', `/api/my-tasks/items/${encodeURIComponent(key)}/pass-on`, {
|
|
278
|
+
toEmail, ...(reason ? { reason } : {}),
|
|
279
|
+
});
|
|
280
|
+
return { holder: r.holder, emailed: r.emailed };
|
|
281
|
+
},
|
|
282
|
+
};
|
|
233
283
|
/** The kinds this token can read, their columns, operators and examples. */
|
|
234
284
|
schema() {
|
|
235
285
|
return this.request('GET', '/api/my-crm/v1/rows/schema');
|
|
@@ -271,7 +321,7 @@ export class AwesomateClient {
|
|
|
271
321
|
async get(kind, id, options = {}) {
|
|
272
322
|
try {
|
|
273
323
|
const qs = options.tz ? `?tz=${encodeURIComponent(options.tz)}` : '';
|
|
274
|
-
const r = await this.request('GET', `/api/my-crm/v1/rows/${encodeURIComponent(kind)}/${encodeURIComponent(id)}${qs}`);
|
|
324
|
+
const r = await this.request('GET', `/api/my-crm/v1/rows/${encodeURIComponent(kind)}/${encodeURIComponent(String(id))}${qs}`);
|
|
275
325
|
return r.row;
|
|
276
326
|
}
|
|
277
327
|
catch (err) {
|
|
@@ -658,7 +708,7 @@ export class AwesomateAppClient {
|
|
|
658
708
|
/** One record by id, or null when there is none this user may read. */
|
|
659
709
|
async get(kind, id) {
|
|
660
710
|
try {
|
|
661
|
-
return (await this.data('GET', `/rows/${encodeURIComponent(kind)}/${encodeURIComponent(id)}`)).row;
|
|
711
|
+
return (await this.data('GET', `/rows/${encodeURIComponent(kind)}/${encodeURIComponent(String(id))}`)).row;
|
|
662
712
|
}
|
|
663
713
|
catch (err) {
|
|
664
714
|
if (err instanceof AwesomateError && err.code === 'not_found')
|
|
@@ -759,6 +809,22 @@ export class AwesomateAppClient {
|
|
|
759
809
|
/** The file a handle names, for someone signed in to this app. */
|
|
760
810
|
download: async (handle) => this.authed(async (token) => (await this.rawData('GET', `/files/${encodeURIComponent(handle)}`, token)).blob()),
|
|
761
811
|
};
|
|
812
|
+
/**
|
|
813
|
+
* Ask the app's agent a typed question, as this signed-in person: a help box that answers from
|
|
814
|
+
* the business's content, with sources. The agent is the one the account picked for the app (the
|
|
815
|
+
* same one Talk uses). Show `questionNotice` with the answer when it comes (a person's first).
|
|
816
|
+
* The agent answers only from content this person may see; the voice persona does not apply.
|
|
817
|
+
* A refusal's serverCode says why: no_agent, channel_off, person_daily (30 a day per person),
|
|
818
|
+
* agent_daily, answers_used_up; personMessage is the sentence to show.
|
|
819
|
+
*
|
|
820
|
+
* @example
|
|
821
|
+
* const a = await app.ask('What time do you open on Saturday?');
|
|
822
|
+
* render(a.answer, a.sources, a.questionNotice);
|
|
823
|
+
*/
|
|
824
|
+
async ask(question, options = {}) {
|
|
825
|
+
const r = await this.data('POST', '/agents/ask', { question, ...(options.session ? { session: options.session } : {}) });
|
|
826
|
+
return { status: r.status, answer: r.answer, sources: r.sources ?? [], questionNotice: r.question_notice ?? null };
|
|
827
|
+
}
|
|
762
828
|
/**
|
|
763
829
|
* The agent this app talks with by voice, or null when the account has not picked one. Pass it
|
|
764
830
|
* to AwesomateAgent.mount as agentId; the hub decides which agent answers, never the page.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@awesomate/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.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",
|