primitive-functions 0.3.0-alpha.2 → 0.3.0-alpha.4
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/index.d.ts +107 -49
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -8,6 +8,20 @@
|
|
|
8
8
|
* against (#3180). The published package's RUNTIME is a stub that throws from
|
|
9
9
|
* every export on purpose: the platform substitutes its own copy at invoke
|
|
10
10
|
* time, and reaching the stub means it did not.
|
|
11
|
+
*
|
|
12
|
+
* WHICH USER A CALL IS ABOUT. Every `ctx.api` and `ctx.agents` call that is
|
|
13
|
+
* about one user says which user in `userId`. Omitted, it means the invoking
|
|
14
|
+
* user (`ctx.user`); in a run with no caller (cron, a webhook, the system
|
|
15
|
+
* door, a nested start under one of them) it must be named, or the call
|
|
16
|
+
* rejects with `FUNCTION_SUBJECT_REQUIRED`. Naming a user other than the
|
|
17
|
+
* invoking user — whether `userId` is optional or required on the call — is
|
|
18
|
+
* allowed only in a run with no caller or one an app owner or admin invoked,
|
|
19
|
+
* with the role read at the call; an ordinary member's run, and every run an
|
|
20
|
+
* agent drives (a tool, context or history run and anything it starts),
|
|
21
|
+
* rejects with `SUBJECT_USER_FORBIDDEN`. A named user who is not a member of
|
|
22
|
+
* the app rejects with `SUBJECT_USER_NOT_FOUND`. Calls that hand something
|
|
23
|
+
* to a user (`notifications.send`, `users.setProfile`, a channel grant)
|
|
24
|
+
* and app-wide reads are outside this rule.
|
|
11
25
|
*/
|
|
12
26
|
|
|
13
27
|
/**
|
|
@@ -170,7 +184,7 @@ export interface PrimitivePlatformError extends Error {
|
|
|
170
184
|
/**
|
|
171
185
|
* The route's structured `details`, or null when its refusal carries none
|
|
172
186
|
* (#3803). `AGENT_SESSION_VARIABLES_INVALID` lists `errors` as
|
|
173
|
-
* `{ path, message }
|
|
187
|
+
* `{ path, message }`.
|
|
174
188
|
*/
|
|
175
189
|
details: unknown;
|
|
176
190
|
}
|
|
@@ -228,18 +242,24 @@ export interface FunctionApi {
|
|
|
228
242
|
/** `agentSessions.get` — GET /agent-sessions/{sessionId}. Get an agent session */
|
|
229
243
|
"get"(args: {
|
|
230
244
|
"sessionId": string | number;
|
|
245
|
+
"userId"?: string | number;
|
|
231
246
|
}): Promise<any>;
|
|
232
247
|
/** `agentSessions.list` — GET /agent-sessions. List one user's agent sessions */
|
|
233
248
|
"list"(args?: {
|
|
234
|
-
"userId"?: string | number
|
|
249
|
+
"userId"?: string | number;
|
|
235
250
|
"agent"?: string | number | boolean;
|
|
236
251
|
"scope"?: string | number | boolean;
|
|
237
252
|
"limit"?: string | number | boolean;
|
|
238
253
|
"cursor"?: string | number | boolean;
|
|
239
254
|
}): Promise<any>;
|
|
255
|
+
/** `agentSessions.markRead` — POST /agent-sessions/{sessionId}/read. Mark an agent session read */
|
|
256
|
+
"markRead"(args: {
|
|
257
|
+
"sessionId": string | number;
|
|
258
|
+
}): Promise<any>;
|
|
240
259
|
/** `agentSessions.recordEvent` — POST /agent-sessions/{sessionId}/events. Record an event in an agent session (ctx.agents.recordEvent) */
|
|
241
260
|
"recordEvent"(args: {
|
|
242
261
|
"sessionId": string | number;
|
|
262
|
+
"userId"?: string | number;
|
|
243
263
|
body: unknown;
|
|
244
264
|
}): Promise<any>;
|
|
245
265
|
/** `agentSessions.removeMember` — DELETE /agent-sessions/{sessionId}/members/{userId}. Remove a member from an agent session */
|
|
@@ -490,6 +510,7 @@ export interface FunctionApi {
|
|
|
490
510
|
}): Promise<any>;
|
|
491
511
|
/** `collections.list` — GET /collections. List collections */
|
|
492
512
|
"list"(args?: {
|
|
513
|
+
"userId"?: string | number;
|
|
493
514
|
"limit"?: string | number | boolean;
|
|
494
515
|
"cursor"?: string | number | boolean;
|
|
495
516
|
}): Promise<any>;
|
|
@@ -672,12 +693,6 @@ export interface FunctionApi {
|
|
|
672
693
|
"databaseId": string | number;
|
|
673
694
|
body: unknown;
|
|
674
695
|
}): Promise<any>;
|
|
675
|
-
/** `databases.importBulk` — POST /databases/{databaseId}/operations/{name}/import-bulk. Bulk-import records via a database operation */
|
|
676
|
-
"importBulk"(args: {
|
|
677
|
-
"databaseId": string | number;
|
|
678
|
-
"name": string | number;
|
|
679
|
-
body: unknown;
|
|
680
|
-
}): Promise<any>;
|
|
681
696
|
/** `databases.list` — GET /databases. List databases */
|
|
682
697
|
"list"(args?: Record<string, never>): Promise<any>;
|
|
683
698
|
/** `databases.listGroupPermissions` — GET /databases/{databaseId}/group-permissions. List a database's group permissions */
|
|
@@ -838,7 +853,7 @@ export interface FunctionApi {
|
|
|
838
853
|
"delete"(args: {
|
|
839
854
|
"scope": string | number;
|
|
840
855
|
"aliasKey": string | number;
|
|
841
|
-
"userId"?: string | number
|
|
856
|
+
"userId"?: string | number;
|
|
842
857
|
}): Promise<any>;
|
|
843
858
|
/** `documents.aliases.listForDocument` — GET /documents/{documentId}/aliases. List aliases bound to a document */
|
|
844
859
|
"listForDocument"(args: {
|
|
@@ -848,7 +863,7 @@ export interface FunctionApi {
|
|
|
848
863
|
"resolve"(args: {
|
|
849
864
|
"scope": string | number;
|
|
850
865
|
"aliasKey": string | number;
|
|
851
|
-
"userId"?: string | number
|
|
866
|
+
"userId"?: string | number;
|
|
852
867
|
}): Promise<any>;
|
|
853
868
|
/** `documents.aliases.set` — PUT /document-aliases/{scope}/{aliasKey}. Bind a (scope, aliasKey) alias to a document */
|
|
854
869
|
"set"(args: {
|
|
@@ -1101,6 +1116,7 @@ export interface FunctionApi {
|
|
|
1101
1116
|
"model": string | number;
|
|
1102
1117
|
"recordId": string | number;
|
|
1103
1118
|
"documentFormat"?: string | number | boolean;
|
|
1119
|
+
"requestId"?: string | number | boolean;
|
|
1104
1120
|
}): Promise<any>;
|
|
1105
1121
|
/** `documents.records.patch` — PATCH /documents/{documentId}/records/{model}/{recordId}. Merge fields into an existing record in a document model */
|
|
1106
1122
|
"patch"(args: {
|
|
@@ -1158,6 +1174,10 @@ export interface FunctionApi {
|
|
|
1158
1174
|
"groupType": string | number;
|
|
1159
1175
|
"groupId": string | number;
|
|
1160
1176
|
}): Promise<any>;
|
|
1177
|
+
/** `documents.room` — GET /documents/{documentId}/room. Inspect a record-log document's room */
|
|
1178
|
+
"room"(args: {
|
|
1179
|
+
"documentId": string | number;
|
|
1180
|
+
}): Promise<any>;
|
|
1161
1181
|
/** `documents.setLinkAccess` — PUT /documents/{documentId}/link-access. Set the document's "anyone with the link" access level */
|
|
1162
1182
|
"setLinkAccess"(args: {
|
|
1163
1183
|
"documentId": string | number;
|
|
@@ -1317,10 +1337,6 @@ export interface FunctionApi {
|
|
|
1317
1337
|
}): Promise<any>;
|
|
1318
1338
|
/** `integrations.list` — GET /integrations. List integrations configured for the app */
|
|
1319
1339
|
"list"(args?: Record<string, never>): Promise<any>;
|
|
1320
|
-
/** `integrations.proxy` — POST /integrations/{integrationKey}/proxy. Proxy a request through a configured integration */
|
|
1321
|
-
"proxy"(args: {
|
|
1322
|
-
"integrationKey": string | number;
|
|
1323
|
-
}): Promise<any>;
|
|
1324
1340
|
};
|
|
1325
1341
|
"locks": {
|
|
1326
1342
|
/** `locks.list` — GET /locks. List all currently-held named locks in the app */
|
|
@@ -1345,19 +1361,26 @@ export interface FunctionApi {
|
|
|
1345
1361
|
"notifications": {
|
|
1346
1362
|
/** `notifications.list` — GET /notifications. List the caller's in-app notification inbox (newest first) */
|
|
1347
1363
|
"list"(args?: {
|
|
1364
|
+
"userId"?: string | number;
|
|
1348
1365
|
"limit"?: string | number | boolean;
|
|
1349
1366
|
"cursor"?: string | number | boolean;
|
|
1350
1367
|
}): Promise<any>;
|
|
1351
1368
|
/** `notifications.listDevices` — GET /me/push-tokens. List the caller's registered push devices */
|
|
1352
|
-
"listDevices"(args?:
|
|
1369
|
+
"listDevices"(args?: {
|
|
1370
|
+
"userId"?: string | number;
|
|
1371
|
+
}): Promise<any>;
|
|
1353
1372
|
/** `notifications.markAllRead` — POST /notifications/read-all. Mark all of the caller's notifications as read */
|
|
1354
|
-
"markAllRead"(args?:
|
|
1373
|
+
"markAllRead"(args?: {
|
|
1374
|
+
"userId"?: string | number;
|
|
1375
|
+
}): Promise<any>;
|
|
1355
1376
|
/** `notifications.markRead` — PATCH /notifications/{notificationId}/read. Mark one of the caller's notifications as read */
|
|
1356
1377
|
"markRead"(args: {
|
|
1357
1378
|
"notificationId": string | number;
|
|
1379
|
+
"userId"?: string | number;
|
|
1358
1380
|
}): Promise<any>;
|
|
1359
1381
|
/** `notifications.registerDevice` — POST /me/push-tokens. Register (upsert) the caller's device push token */
|
|
1360
1382
|
"registerDevice"(args: {
|
|
1383
|
+
"userId"?: string | number;
|
|
1361
1384
|
body: unknown;
|
|
1362
1385
|
}): Promise<any>;
|
|
1363
1386
|
/** `notifications.send` — POST /notifications/send. Send a notification to an app user (durable in-app inbox row + live WS frame) */
|
|
@@ -1365,17 +1388,16 @@ export interface FunctionApi {
|
|
|
1365
1388
|
body: unknown;
|
|
1366
1389
|
}): Promise<any>;
|
|
1367
1390
|
/** `notifications.unreadCount` — GET /notifications/unread-count. Count the caller's unread notifications */
|
|
1368
|
-
"unreadCount"(args?:
|
|
1391
|
+
"unreadCount"(args?: {
|
|
1392
|
+
"userId"?: string | number;
|
|
1393
|
+
}): Promise<any>;
|
|
1369
1394
|
/** `notifications.unregisterDevice` — DELETE /me/push-tokens/{token}. Unregister one of the caller's device push tokens */
|
|
1370
1395
|
"unregisterDevice"(args: {
|
|
1371
1396
|
"token": string | number;
|
|
1397
|
+
"userId"?: string | number;
|
|
1372
1398
|
}): Promise<any>;
|
|
1373
1399
|
};
|
|
1374
1400
|
"prompts": {
|
|
1375
|
-
/** `prompts.execute` — POST /prompts/{promptKey}/execute. Execute a saved prompt */
|
|
1376
|
-
"execute"(args: {
|
|
1377
|
-
"promptKey": string | number;
|
|
1378
|
-
}): Promise<any>;
|
|
1379
1401
|
/** `prompts.run` — POST /prompts/{promptKey}/run. Run a prompt under a server function's grants */
|
|
1380
1402
|
"run"(args: {
|
|
1381
1403
|
"promptKey": string | number;
|
|
@@ -1439,7 +1461,7 @@ export interface FunctionApi {
|
|
|
1439
1461
|
/** `users.list` — GET /users. List app users */
|
|
1440
1462
|
"list"(args?: {
|
|
1441
1463
|
"email"?: string | number | boolean;
|
|
1442
|
-
"userId"?: string | number
|
|
1464
|
+
"userId"?: string | number;
|
|
1443
1465
|
"name"?: string | number | boolean;
|
|
1444
1466
|
"limit"?: string | number | boolean;
|
|
1445
1467
|
"cursor"?: string | number | boolean;
|
|
@@ -1704,7 +1726,7 @@ export interface DocumentQueryOptions {
|
|
|
1704
1726
|
* Usually stated once on the handle, as ctx.doc(id, { documentFormat: 2 }),
|
|
1705
1727
|
* rather than per read.
|
|
1706
1728
|
*/
|
|
1707
|
-
documentFormat?: 1 | 2;
|
|
1729
|
+
documentFormat?: 1 | 2 | 3;
|
|
1708
1730
|
}
|
|
1709
1731
|
|
|
1710
1732
|
/**
|
|
@@ -1884,6 +1906,12 @@ export interface AgentSessionCreateOptions<K extends SessionAgentKeys> {
|
|
|
1884
1906
|
* Existing users of this app, not the caller, in neither list twice.
|
|
1885
1907
|
*/
|
|
1886
1908
|
viewers?: string[];
|
|
1909
|
+
/**
|
|
1910
|
+
* The member who owns the session; omitted, the invoking user. A run with
|
|
1911
|
+
* no caller must name one; naming another member follows the header's
|
|
1912
|
+
* subject rule. Initial members may not name the owner.
|
|
1913
|
+
*/
|
|
1914
|
+
userId?: string;
|
|
1887
1915
|
}
|
|
1888
1916
|
|
|
1889
1917
|
/** What `ctx.agents.createSession` answers — #3803. */
|
|
@@ -1907,9 +1935,16 @@ export interface AgentSessionInfo {
|
|
|
1907
1935
|
scope: string | null;
|
|
1908
1936
|
/** ISO-8601; null when the session's listing row is missing. */
|
|
1909
1937
|
lastActivityAt: string | null;
|
|
1938
|
+
/**
|
|
1939
|
+
* Whether the invoking user has activity in the session they have not
|
|
1940
|
+
* marked read (their client marks it); false for an admin with no role.
|
|
1941
|
+
*/
|
|
1942
|
+
hasUnread: boolean;
|
|
1943
|
+
/** When the invoking user last marked the session read (ISO-8601), or null. */
|
|
1944
|
+
lastReadAt: string | null;
|
|
1910
1945
|
/** The members, in the order they were added. */
|
|
1911
1946
|
members: { viewers: string[]; participants: string[] };
|
|
1912
|
-
/** The
|
|
1947
|
+
/** The standing on the session of the member the call acted as. */
|
|
1913
1948
|
role: "owner" | "participant" | "viewer" | "admin";
|
|
1914
1949
|
/**
|
|
1915
1950
|
* The session's status, decided from the session object (never the
|
|
@@ -1963,10 +1998,20 @@ export interface AgentSessionListItem {
|
|
|
1963
1998
|
/** ISO-8601. */
|
|
1964
1999
|
lastActivityAt: string;
|
|
1965
2000
|
createdAt: string | null;
|
|
2001
|
+
/** Whether the user has activity in the session they have not marked read. */
|
|
2002
|
+
hasUnread: boolean;
|
|
2003
|
+
/** When the user last marked the session read (ISO-8601), or null. */
|
|
2004
|
+
lastReadAt: string | null;
|
|
1966
2005
|
}
|
|
1967
2006
|
|
|
1968
|
-
/** What `ctx.agents.listSessions` takes — #3805.
|
|
2007
|
+
/** What `ctx.agents.listSessions` takes — #3805. */
|
|
1969
2008
|
export interface AgentSessionListOptions {
|
|
2009
|
+
/**
|
|
2010
|
+
* Whose sessions; omitted, the invoking user's. A run with no caller must
|
|
2011
|
+
* name one, and naming another follows the header's subject rule. A user
|
|
2012
|
+
* with no sessions here, member or not, answers an empty page.
|
|
2013
|
+
*/
|
|
2014
|
+
userId?: string;
|
|
1970
2015
|
/** Only this agent's sessions. */
|
|
1971
2016
|
agent?: string;
|
|
1972
2017
|
/** Only sessions created with exactly this scope. */
|
|
@@ -1977,6 +2022,15 @@ export interface AgentSessionListOptions {
|
|
|
1977
2022
|
cursor?: string;
|
|
1978
2023
|
}
|
|
1979
2024
|
|
|
2025
|
+
/**
|
|
2026
|
+
* Which member `ctx.agents.getSession` and `recordEvent` act as. Omitted,
|
|
2027
|
+
* the invoking user; a run with no caller must name one, and naming another
|
|
2028
|
+
* follows the header's subject rule.
|
|
2029
|
+
*/
|
|
2030
|
+
export interface AgentSessionSubjectOptions {
|
|
2031
|
+
userId?: string;
|
|
2032
|
+
}
|
|
2033
|
+
|
|
1980
2034
|
/** A page of `ctx.agents.listSessions` — #3805. */
|
|
1981
2035
|
export interface AgentSessionListPage {
|
|
1982
2036
|
items: AgentSessionListItem[];
|
|
@@ -2354,7 +2408,7 @@ export interface FunctionContext {
|
|
|
2354
2408
|
* confers nothing: every call is a `documents.records.*` operation on the
|
|
2355
2409
|
* same authority.
|
|
2356
2410
|
*/
|
|
2357
|
-
doc(documentId: string, options?: { documentFormat?: 1 | 2 }): DocumentHandle;
|
|
2411
|
+
doc(documentId: string, options?: { documentFormat?: 1 | 2 | 3 }): DocumentHandle;
|
|
2358
2412
|
/**
|
|
2359
2413
|
* Outbound HTTP, through a granted integration and nowhere else (#3183).
|
|
2360
2414
|
*
|
|
@@ -2421,30 +2475,27 @@ export interface FunctionContext {
|
|
|
2421
2475
|
): Promise<PromptRunResult<K>>;
|
|
2422
2476
|
};
|
|
2423
2477
|
/**
|
|
2424
|
-
* Agent sessions (#3803, project `agents`)
|
|
2425
|
-
*
|
|
2426
|
-
*
|
|
2427
|
-
* answers `{ sessionId, documentId }`. It is allowed only in a run fired
|
|
2428
|
-
* over HTTP (`invoke`, or a `start` task) by a signed-in user; from a
|
|
2429
|
-
* manual run, a nested start, a workflow step, cron or a webhook it
|
|
2430
|
-
* rejects with `AGENT_SESSION_ORIGIN_REFUSED`, `details.origin` naming
|
|
2431
|
-
* it. Variables failing the agent's `inputSchema` reject with
|
|
2432
|
-
* `AGENT_SESSION_VARIABLES_INVALID` and `details.errors`.
|
|
2478
|
+
* Agent sessions (#3803, project `agents`), on the header's subject rule:
|
|
2479
|
+
* each call acts for `userId`, else the invoking user, and from any kind of
|
|
2480
|
+
* run — a run with no caller must name the member.
|
|
2433
2481
|
*
|
|
2434
|
-
*
|
|
2435
|
-
*
|
|
2436
|
-
* `
|
|
2482
|
+
* `createSession` creates a session that member owns and answers
|
|
2483
|
+
* `{ sessionId, documentId }`. Variables failing the agent's
|
|
2484
|
+
* `inputSchema` reject with `AGENT_SESSION_VARIABLES_INVALID` and
|
|
2485
|
+
* `details.errors`. Once a tree has pushed, a key that is not an agent,
|
|
2486
|
+
* and variables the agent's schema refuses, are compile errors.
|
|
2487
|
+
* `participants` and `viewers` name initial members (#3805).
|
|
2437
2488
|
*
|
|
2438
|
-
* `getSession` and `listSessions` (#3805) read the
|
|
2439
|
-
*
|
|
2440
|
-
* whoever invoked the function
|
|
2441
|
-
* `AGENT_SESSION_NOT_FOUND
|
|
2442
|
-
* `
|
|
2443
|
-
* owner's, from a client.
|
|
2489
|
+
* `getSession` and `listSessions` (#3805) read the member's sessions —
|
|
2490
|
+
* the ones they own or are a member of — as that member, with no admin arm
|
|
2491
|
+
* whoever invoked the function: a session they are not in answers
|
|
2492
|
+
* `AGENT_SESSION_NOT_FOUND`, and function code never sees a session's
|
|
2493
|
+
* `object`, `turnContexts` or `lastTurn`. Renaming, deleting and
|
|
2494
|
+
* changing members are the owner's, from a client.
|
|
2444
2495
|
*
|
|
2445
|
-
* `recordEvent` (#3807) records an event
|
|
2446
|
-
*
|
|
2447
|
-
* the
|
|
2496
|
+
* `recordEvent` (#3807) records an event as the member, who must be the
|
|
2497
|
+
* session's owner or a participant (`AGENT_SESSION_PARTICIPANT_ONLY` for a
|
|
2498
|
+
* viewer); the row is authored `app`. The kind must be one the agent
|
|
2448
2499
|
* declares (`AGENT_EVENT_KIND_UNKNOWN`) and the data must match its schema
|
|
2449
2500
|
* (`AGENT_EVENT_INVALID`). An event never starts a turn; the model reads
|
|
2450
2501
|
* it in a later turn.
|
|
@@ -2453,9 +2504,16 @@ export interface FunctionContext {
|
|
|
2453
2504
|
createSession<K extends SessionAgentKeys>(
|
|
2454
2505
|
options: AgentSessionCreateOptions<K>
|
|
2455
2506
|
): Promise<AgentSessionCreateResult>;
|
|
2456
|
-
getSession(
|
|
2507
|
+
getSession(
|
|
2508
|
+
sessionId: string,
|
|
2509
|
+
options?: AgentSessionSubjectOptions
|
|
2510
|
+
): Promise<AgentSessionInfo>;
|
|
2457
2511
|
listSessions(options?: AgentSessionListOptions): Promise<AgentSessionListPage>;
|
|
2458
|
-
recordEvent(
|
|
2512
|
+
recordEvent(
|
|
2513
|
+
sessionId: string,
|
|
2514
|
+
event: AgentSessionEvent,
|
|
2515
|
+
options?: AgentSessionSubjectOptions
|
|
2516
|
+
): Promise<AgentSessionEventResult>;
|
|
2459
2517
|
};
|
|
2460
2518
|
/**
|
|
2461
2519
|
* The value of one app secret, under a `secret:<NAME>` grant (#3183).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "primitive-functions",
|
|
3
|
-
"version": "0.3.0-alpha.
|
|
3
|
+
"version": "0.3.0-alpha.4",
|
|
4
4
|
"description": "The module a Primitive server function imports. Supplied by the platform at invoke time; reserved here so the name is ours before the runtime lands.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"author": "Primitive LLC",
|