primitive-functions 0.2.1 → 0.3.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/index.d.ts +153 -59
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -110,11 +110,17 @@ export interface HeaderResult {
|
|
|
110
110
|
export interface PrimitivePlatformError extends Error {
|
|
111
111
|
status: number;
|
|
112
112
|
errorCode: string | null;
|
|
113
|
+
/**
|
|
114
|
+
* The route's structured `details`, or null when its refusal carries none
|
|
115
|
+
* (#3803). `AGENT_SESSION_VARIABLES_INVALID` lists `errors` as
|
|
116
|
+
* `{ path, message }`; `AGENT_SESSION_ORIGIN_REFUSED` names `origin`.
|
|
117
|
+
*/
|
|
118
|
+
details: unknown;
|
|
113
119
|
}
|
|
114
120
|
|
|
115
121
|
/**
|
|
116
122
|
* The typed HTTP profile, generated from the platform's OpenAPI document. Its
|
|
117
|
-
* namespaces mirror the operation ids: analytics, blobBuckets, channels, collections, configVars, connections, databaseTypeConfigs, databases, documents, email, functions, groups, integrations, locks, notifications, prompts, resourceMetadata, secrets, users.
|
|
123
|
+
* namespaces mirror the operation ids: agentSessions, analytics, blobBuckets, channels, collections, configVars, connections, databaseTypeConfigs, databases, documents, email, functions, groups, integrations, locks, notifications, prompts, resourceMetadata, secrets, users.
|
|
118
124
|
* Methods take one options object carrying the operation's path parameters,
|
|
119
125
|
* query parameters, request headers (under their wire names) and `body`.
|
|
120
126
|
*
|
|
@@ -131,6 +137,12 @@ export interface PrimitivePlatformError extends Error {
|
|
|
131
137
|
* stays refused: same-run composition is an import.
|
|
132
138
|
*/
|
|
133
139
|
export interface FunctionApi {
|
|
140
|
+
"agentSessions": {
|
|
141
|
+
/** `agentSessions.create` — POST /agent-sessions. Create an agent session (ctx.agents.createSession) */
|
|
142
|
+
"create"(args: {
|
|
143
|
+
body: unknown;
|
|
144
|
+
}): Promise<any>;
|
|
145
|
+
};
|
|
134
146
|
"analytics": {
|
|
135
147
|
/** `analytics.cohortRetention` — GET /analytics/cohort-retention. Cohort retention metrics */
|
|
136
148
|
"cohortRetention"(args?: {
|
|
@@ -509,56 +521,6 @@ export interface FunctionApi {
|
|
|
509
521
|
"databaseId": string | number;
|
|
510
522
|
body: unknown;
|
|
511
523
|
}): Promise<any>;
|
|
512
|
-
"adminData": {
|
|
513
|
-
/**
|
|
514
|
-
* `databases.adminData.batch` — POST /databases/{databaseId}/admin-data/batch. DEPRECATED — direct database batch; use databases/{databaseId}/records/batch
|
|
515
|
-
* @deprecated Use databases/{databaseId}/records/batch
|
|
516
|
-
*/
|
|
517
|
-
"batch"(args: {
|
|
518
|
-
"databaseId": string | number;
|
|
519
|
-
body: unknown;
|
|
520
|
-
}): Promise<any>;
|
|
521
|
-
/**
|
|
522
|
-
* `databases.adminData.count` — POST /databases/{databaseId}/admin-data/count. DEPRECATED — direct database count; use databases/{databaseId}/records/count
|
|
523
|
-
* @deprecated Use databases/{databaseId}/records/count
|
|
524
|
-
*/
|
|
525
|
-
"count"(args: {
|
|
526
|
-
"databaseId": string | number;
|
|
527
|
-
body: unknown;
|
|
528
|
-
}): Promise<any>;
|
|
529
|
-
/**
|
|
530
|
-
* `databases.adminData.delete` — POST /databases/{databaseId}/admin-data/delete. DEPRECATED — direct database delete; use databases/{databaseId}/records/delete
|
|
531
|
-
* @deprecated Use databases/{databaseId}/records/delete
|
|
532
|
-
*/
|
|
533
|
-
"delete"(args: {
|
|
534
|
-
"databaseId": string | number;
|
|
535
|
-
body: unknown;
|
|
536
|
-
}): Promise<any>;
|
|
537
|
-
/**
|
|
538
|
-
* `databases.adminData.patch` — POST /databases/{databaseId}/admin-data/patch. DEPRECATED — direct database patch; use databases/{databaseId}/records/patch
|
|
539
|
-
* @deprecated Use databases/{databaseId}/records/patch
|
|
540
|
-
*/
|
|
541
|
-
"patch"(args: {
|
|
542
|
-
"databaseId": string | number;
|
|
543
|
-
body: unknown;
|
|
544
|
-
}): Promise<any>;
|
|
545
|
-
/**
|
|
546
|
-
* `databases.adminData.query` — POST /databases/{databaseId}/admin-data/query. DEPRECATED — direct database query; use databases/{databaseId}/records/query
|
|
547
|
-
* @deprecated Use databases/{databaseId}/records/query
|
|
548
|
-
*/
|
|
549
|
-
"query"(args: {
|
|
550
|
-
"databaseId": string | number;
|
|
551
|
-
body: unknown;
|
|
552
|
-
}): Promise<any>;
|
|
553
|
-
/**
|
|
554
|
-
* `databases.adminData.save` — POST /databases/{databaseId}/admin-data/save. DEPRECATED — direct database save; use databases/{databaseId}/records/save
|
|
555
|
-
* @deprecated Use databases/{databaseId}/records/save
|
|
556
|
-
*/
|
|
557
|
-
"save"(args: {
|
|
558
|
-
"databaseId": string | number;
|
|
559
|
-
body: unknown;
|
|
560
|
-
}): Promise<any>;
|
|
561
|
-
};
|
|
562
524
|
/** `databases.create` — POST /databases. Create a database */
|
|
563
525
|
"create"(args: {
|
|
564
526
|
body: unknown;
|
|
@@ -830,13 +792,6 @@ export interface FunctionApi {
|
|
|
830
792
|
"X-Blob-Sha256": string | number;
|
|
831
793
|
body: ArrayBuffer | Uint8Array | string;
|
|
832
794
|
}): Promise<any>;
|
|
833
|
-
/**
|
|
834
|
-
* `documents.blobs.uploadWithoutId` — PUT /documents/{documentId}/blobs. Deprecated: upload a document blob without a client-specified id
|
|
835
|
-
* @deprecated Deprecated in the app API spec; see its description.
|
|
836
|
-
*/
|
|
837
|
-
"uploadWithoutId"(args: {
|
|
838
|
-
"documentId": string | number;
|
|
839
|
-
}): Promise<any>;
|
|
840
795
|
};
|
|
841
796
|
/** `documents.clearLinkAccess` — DELETE /documents/{documentId}/link-access. Turn off the document's link access */
|
|
842
797
|
"clearLinkAccess"(args: {
|
|
@@ -1247,7 +1202,7 @@ export interface FunctionApi {
|
|
|
1247
1202
|
"status"(args: {
|
|
1248
1203
|
body: unknown;
|
|
1249
1204
|
}): Promise<any>;
|
|
1250
|
-
/** `locks.tryAcquire` — POST /locks/acquire. Attempt to acquire a named lock (
|
|
1205
|
+
/** `locks.tryAcquire` — POST /locks/acquire. Attempt to acquire a named lock (one attempt, or with waitMs a bounded server-side wait) */
|
|
1251
1206
|
"tryAcquire"(args: {
|
|
1252
1207
|
body: unknown;
|
|
1253
1208
|
}): Promise<any>;
|
|
@@ -1744,6 +1699,39 @@ export type AgentVariables<K extends AgentKeys> = PromptSchemas[K] extends {
|
|
|
1744
1699
|
? V
|
|
1745
1700
|
: never;
|
|
1746
1701
|
|
|
1702
|
+
/**
|
|
1703
|
+
* The keys `ctx.agents.createSession` accepts — #3803: every declared agent,
|
|
1704
|
+
* or `string` before the tree has pushed any prompt (the `PromptKeys`
|
|
1705
|
+
* rule).
|
|
1706
|
+
*/
|
|
1707
|
+
export type SessionAgentKeys = [keyof PromptSchemas] extends [never]
|
|
1708
|
+
? string
|
|
1709
|
+
: AgentKeys;
|
|
1710
|
+
|
|
1711
|
+
/**
|
|
1712
|
+
* What `ctx.agents.createSession` takes — #3803. Typed by the agent's key:
|
|
1713
|
+
* `variables` is that agent's `inputSchema` (any object before a push),
|
|
1714
|
+
* and the platform validates it again against the schema as pushed.
|
|
1715
|
+
*/
|
|
1716
|
+
export interface AgentSessionCreateOptions<K extends SessionAgentKeys> {
|
|
1717
|
+
/** The key of an agent prompt (`kind = "agent"`). */
|
|
1718
|
+
agent: K;
|
|
1719
|
+
/** The session's variables; at most 16 KiB of JSON. */
|
|
1720
|
+
variables?: K extends AgentKeys ? AgentVariables<K> : Record<string, unknown>;
|
|
1721
|
+
/** Free text the app groups sessions by, 1 to 256 characters. */
|
|
1722
|
+
scope?: string;
|
|
1723
|
+
/** 1 to 255 characters; defaults to the agent's display name. */
|
|
1724
|
+
title?: string;
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
/** What `ctx.agents.createSession` answers — #3803. */
|
|
1728
|
+
export interface AgentSessionCreateResult {
|
|
1729
|
+
/** The session: what the app keeps and uses for everything but opening. */
|
|
1730
|
+
sessionId: string;
|
|
1731
|
+
/** The session's conversation document, opened with the document client. */
|
|
1732
|
+
documentId: string;
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1747
1735
|
/** One agent's client tools, by name: each one's `input` and `output` (#3798). */
|
|
1748
1736
|
export type AgentClientTools<K extends AgentKeys> = PromptSchemas[K] extends {
|
|
1749
1737
|
agent: { clientTools: infer T };
|
|
@@ -1957,6 +1945,52 @@ export interface FunctionStartResult {
|
|
|
1957
1945
|
existing?: boolean;
|
|
1958
1946
|
}
|
|
1959
1947
|
|
|
1948
|
+
/** A held named lock, as `ctx.locks.acquire` hands it back — #3930. */
|
|
1949
|
+
export interface LockHandle {
|
|
1950
|
+
key: string;
|
|
1951
|
+
handleId: string;
|
|
1952
|
+
leaseExpiresAt: string;
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1955
|
+
/** How long to hold, and how long to wait — #3930. */
|
|
1956
|
+
export interface LockAcquireOptions {
|
|
1957
|
+
/** The lease, in milliseconds (at most 24 h). Renew or release before it lapses. */
|
|
1958
|
+
ttlMs: number;
|
|
1959
|
+
/**
|
|
1960
|
+
* How long to wait for the key, in milliseconds, at most one hour. Under the
|
|
1961
|
+
* request runtime it must also fit the invocation's remaining budget.
|
|
1962
|
+
*/
|
|
1963
|
+
timeoutMs: number;
|
|
1964
|
+
/**
|
|
1965
|
+
* Who this hold belongs to. Defaults to `ctx.runId` when the invocation
|
|
1966
|
+
* has a run, so a resumed slice re-takes its own hold with a fresh handle
|
|
1967
|
+
* rather than waiting on it.
|
|
1968
|
+
*/
|
|
1969
|
+
owner?: string;
|
|
1970
|
+
}
|
|
1971
|
+
|
|
1972
|
+
/**
|
|
1973
|
+
* The answer to a blocking acquire — #3930. Never a throw for "not acquired":
|
|
1974
|
+
* a refusal carries the last contention seen, and `rateLimited` says the
|
|
1975
|
+
* last attempt was refused by the acquire rate limit rather than by a holder.
|
|
1976
|
+
*/
|
|
1977
|
+
export type LockAcquireResult =
|
|
1978
|
+
| { acquired: true; handle: LockHandle }
|
|
1979
|
+
| {
|
|
1980
|
+
acquired: false;
|
|
1981
|
+
timedOut: true;
|
|
1982
|
+
rateLimited: boolean;
|
|
1983
|
+
heldBy: string | null;
|
|
1984
|
+
holderKind: string | null;
|
|
1985
|
+
owner: string | null;
|
|
1986
|
+
leaseExpiresAt: string | null;
|
|
1987
|
+
};
|
|
1988
|
+
|
|
1989
|
+
/** The answer to `ctx.locks.release`. */
|
|
1990
|
+
export type LockReleaseResult =
|
|
1991
|
+
| { released: true }
|
|
1992
|
+
| { released: false; reason: "not_holder" | "not_held" };
|
|
1993
|
+
|
|
1960
1994
|
export interface FunctionContext {
|
|
1961
1995
|
/** The HTTP caller, or null for a webhook or cron fire. */
|
|
1962
1996
|
user: FunctionUser | null;
|
|
@@ -2079,6 +2113,25 @@ export interface FunctionContext {
|
|
|
2079
2113
|
args?: PromptRunArgs
|
|
2080
2114
|
): Promise<PromptRunResult<K>>;
|
|
2081
2115
|
};
|
|
2116
|
+
/**
|
|
2117
|
+
* Agent sessions (#3803, project `agents`).
|
|
2118
|
+
*
|
|
2119
|
+
* `createSession` creates a session owned by this invocation's caller and
|
|
2120
|
+
* answers `{ sessionId, documentId }`. It is allowed only in a run fired
|
|
2121
|
+
* over HTTP (`invoke`, or a `start` task) by a signed-in user; from a
|
|
2122
|
+
* manual run, a nested start, a workflow step, cron or a webhook it
|
|
2123
|
+
* rejects with `AGENT_SESSION_ORIGIN_REFUSED`, `details.origin` naming
|
|
2124
|
+
* it. Variables failing the agent's `inputSchema` reject with
|
|
2125
|
+
* `AGENT_SESSION_VARIABLES_INVALID` and `details.errors`.
|
|
2126
|
+
*
|
|
2127
|
+
* Once a tree has pushed, a key that is not an agent, and variables the
|
|
2128
|
+
* agent's schema refuses, are compile errors.
|
|
2129
|
+
*/
|
|
2130
|
+
agents: {
|
|
2131
|
+
createSession<K extends SessionAgentKeys>(
|
|
2132
|
+
options: AgentSessionCreateOptions<K>
|
|
2133
|
+
): Promise<AgentSessionCreateResult>;
|
|
2134
|
+
};
|
|
2082
2135
|
/**
|
|
2083
2136
|
* The value of one app secret, under a `secret:<NAME>` grant (#3183).
|
|
2084
2137
|
*
|
|
@@ -2144,6 +2197,47 @@ export interface FunctionContext {
|
|
|
2144
2197
|
): Promise<ChannelGrantResult>;
|
|
2145
2198
|
publish(channel: string, payload: unknown): Promise<SendResult>;
|
|
2146
2199
|
};
|
|
2200
|
+
/**
|
|
2201
|
+
* Named locks that WAIT — #3930. `ctx.api.locks.tryAcquire` is one attempt;
|
|
2202
|
+
* these wait for the key, up to `timeoutMs` (at most one hour).
|
|
2203
|
+
*
|
|
2204
|
+
* The owner defaults to `ctx.runId`, so a run never waits on its own hold:
|
|
2205
|
+
* a resumed slice, or a second call on a key the run already holds, re-takes
|
|
2206
|
+
* it at once with a fresh handle.
|
|
2207
|
+
*
|
|
2208
|
+
* Under the TASK runtime the wait is durable: each attempt is a step that
|
|
2209
|
+
* asks the platform to wait server-side for up to 30 s, so a wait costs one
|
|
2210
|
+
* platform call and one acquire slot per half-minute, no CPU, and the
|
|
2211
|
+
* slice's budget is refreshed at every attempt. It is not a suspension — the
|
|
2212
|
+
* engine does not hibernate a wait shorter than five minutes. Under the
|
|
2213
|
+
* REQUEST runtime the whole wait must fit the invocation's remaining budget,
|
|
2214
|
+
* or the call fails `FUNCTION_RUNTIME_REFUSED` before any attempt (a
|
|
2215
|
+
* webhook delivery has 5 s): hand longer waits to a task with
|
|
2216
|
+
* `ctx.functions.start`.
|
|
2217
|
+
*/
|
|
2218
|
+
locks: {
|
|
2219
|
+
/**
|
|
2220
|
+
* Wait for `key`. Answers `acquired: true` with the handle, or
|
|
2221
|
+
* `acquired: false, timedOut: true` with the last contention seen.
|
|
2222
|
+
*/
|
|
2223
|
+
acquire(key: string, options: LockAcquireOptions): Promise<LockAcquireResult>;
|
|
2224
|
+
/** Release a handle `acquire` handed back. */
|
|
2225
|
+
release(handle: LockHandle): Promise<LockReleaseResult>;
|
|
2226
|
+
/**
|
|
2227
|
+
* Acquire, run `fn`, and release in `finally` — on a return and on a
|
|
2228
|
+
* throw. Answers `fn`'s value; `fn`'s own error propagates after the
|
|
2229
|
+
* release. Throws an error named `LOCK_TIMEOUT` (`code` the same, the
|
|
2230
|
+
* contention in `details`) without running `fn` when the key is not
|
|
2231
|
+
* acquired within `timeoutMs`. A nested `withLock` on the same key in
|
|
2232
|
+
* one run re-enters, and its release frees the outer hold: use distinct
|
|
2233
|
+
* keys, or one wrapper.
|
|
2234
|
+
*/
|
|
2235
|
+
withLock<T>(
|
|
2236
|
+
key: string,
|
|
2237
|
+
options: LockAcquireOptions,
|
|
2238
|
+
fn: (handle: LockHandle) => Promise<T>
|
|
2239
|
+
): Promise<T>;
|
|
2240
|
+
};
|
|
2147
2241
|
}
|
|
2148
2242
|
|
|
2149
2243
|
/** How the wait between one step's retries grows. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "primitive-functions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-alpha.0",
|
|
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",
|