primitive-functions 0.3.0-alpha.17 → 0.3.0-alpha.18
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 +36 -8
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -11703,6 +11703,25 @@ export type PromptRunErrorCode =
|
|
|
11703
11703
|
| "PROMPT_STRICT_OUTPUT_SCHEMA_MISSING"
|
|
11704
11704
|
| "PROMPT_SCHEMA_NOT_TRANSLATABLE";
|
|
11705
11705
|
|
|
11706
|
+
/**
|
|
11707
|
+
* What a prompt run measured. Each field is absent when the provider did not
|
|
11708
|
+
* report it.
|
|
11709
|
+
*/
|
|
11710
|
+
export interface PromptRunMetrics {
|
|
11711
|
+
/** How long the run took, in milliseconds. */
|
|
11712
|
+
durationMs?: number;
|
|
11713
|
+
/** Tokens the provider counted in the request. */
|
|
11714
|
+
inputTokens?: number;
|
|
11715
|
+
/** Tokens the provider counted in the answer. */
|
|
11716
|
+
outputTokens?: number;
|
|
11717
|
+
/** `inputTokens` and `outputTokens` together. */
|
|
11718
|
+
totalTokens?: number;
|
|
11719
|
+
/** Reasoning tokens, reported separately from `outputTokens`. */
|
|
11720
|
+
reasoningTokens?: number;
|
|
11721
|
+
/** The price of the call in USD, as the provider reported it. */
|
|
11722
|
+
cost?: number;
|
|
11723
|
+
}
|
|
11724
|
+
|
|
11706
11725
|
/** A prompt that declares an output shape, when the answer matched it. */
|
|
11707
11726
|
export interface PromptRunSuccess<TParsed> {
|
|
11708
11727
|
success: true;
|
|
@@ -11711,7 +11730,7 @@ export interface PromptRunSuccess<TParsed> {
|
|
|
11711
11730
|
parsed: TParsed;
|
|
11712
11731
|
error?: null;
|
|
11713
11732
|
errorCode?: null;
|
|
11714
|
-
metrics?:
|
|
11733
|
+
metrics?: PromptRunMetrics;
|
|
11715
11734
|
configId: string;
|
|
11716
11735
|
/**
|
|
11717
11736
|
* `true` when the provider stopped at the output token limit
|
|
@@ -11734,7 +11753,7 @@ export interface PromptRunFailure {
|
|
|
11734
11753
|
error: string | null;
|
|
11735
11754
|
errorCode?: PromptRunErrorCode | null;
|
|
11736
11755
|
parsed?: undefined;
|
|
11737
|
-
metrics?:
|
|
11756
|
+
metrics?: PromptRunMetrics;
|
|
11738
11757
|
configId: string;
|
|
11739
11758
|
/**
|
|
11740
11759
|
* The upstream provider's HTTP status, when the call reached a provider and
|
|
@@ -11766,7 +11785,7 @@ export interface PromptRunOpenResult {
|
|
|
11766
11785
|
parsed?: unknown;
|
|
11767
11786
|
error?: string | null;
|
|
11768
11787
|
errorCode?: PromptRunErrorCode | null;
|
|
11769
|
-
metrics?:
|
|
11788
|
+
metrics?: PromptRunMetrics;
|
|
11770
11789
|
configId: string;
|
|
11771
11790
|
/** The upstream provider's HTTP status on a provider failure. */
|
|
11772
11791
|
upstreamStatus?: number;
|
|
@@ -13095,6 +13114,7 @@ export type AuthorizeHelper<TInput, TAuth> = [TInput] extends [unknown]
|
|
|
13095
13114
|
* import { allow, defineFunction, deny } from "primitive-functions";
|
|
13096
13115
|
*
|
|
13097
13116
|
* export default defineFunction({
|
|
13117
|
+
* input: [],
|
|
13098
13118
|
* authorize: async (input: { orgId: string }, auth) =>
|
|
13099
13119
|
* auth.user ? allow({ orgId: input.orgId }) : deny("FORBIDDEN"),
|
|
13100
13120
|
* handler: async (input, ctx) => ({ orgId: ctx.auth.orgId }),
|
|
@@ -13171,6 +13191,7 @@ export declare function requireRole(
|
|
|
13171
13191
|
* import { defineFunction, requireMember } from "primitive-functions";
|
|
13172
13192
|
*
|
|
13173
13193
|
* export default defineFunction("team-report", {
|
|
13194
|
+
* input: [],
|
|
13174
13195
|
* authorize: requireMember((input) => input.teamId, "manager"),
|
|
13175
13196
|
* handler: async (input, ctx) => ({ team: ctx.auth.groupId, as: ctx.auth.role }),
|
|
13176
13197
|
* });
|
|
@@ -13212,6 +13233,7 @@ export declare function requireDocumentOwner<TInput = any>(
|
|
|
13212
13233
|
* import { defineFunction, requirePublicDb3 } from "primitive-functions";
|
|
13213
13234
|
*
|
|
13214
13235
|
* export default defineFunction({
|
|
13236
|
+
* input: [],
|
|
13215
13237
|
* authorize: requirePublicDb3((input: { db3Id: string }) => input.db3Id),
|
|
13216
13238
|
* handler: async (input, ctx) => ctx.api.db3.get({ db3Id: ctx.auth.db3Id }),
|
|
13217
13239
|
* });
|
|
@@ -13294,6 +13316,7 @@ export interface InvitationAuth {
|
|
|
13294
13316
|
* import { defineFunction, requireInvitation } from "primitive-functions";
|
|
13295
13317
|
*
|
|
13296
13318
|
* export default defineFunction({
|
|
13319
|
+
* input: [],
|
|
13297
13320
|
* authorize: requireInvitation((input: { inviteToken: string }) => input.inviteToken),
|
|
13298
13321
|
* handler: async (input, ctx) => ({ shared: ctx.auth.shared.map((item) => item.title) }),
|
|
13299
13322
|
* });
|
|
@@ -13320,6 +13343,7 @@ export declare function requireInvitation<TInput = any>(
|
|
|
13320
13343
|
* import { defineFunction, requireToken } from "primitive-functions";
|
|
13321
13344
|
*
|
|
13322
13345
|
* export default defineFunction({
|
|
13346
|
+
* input: [],
|
|
13323
13347
|
* authorize: requireToken((input: { token: string }) => input.token),
|
|
13324
13348
|
* handler: async (input, ctx) => ({ orderId: ctx.auth.args.orderId }),
|
|
13325
13349
|
* });
|
|
@@ -13366,6 +13390,7 @@ export interface CallerRules<TInput = any, TAuth = unknown, TAgentAuth = TAuth>
|
|
|
13366
13390
|
* import { allowCallers, defineFunction, requireRole } from "primitive-functions";
|
|
13367
13391
|
*
|
|
13368
13392
|
* export default defineFunction({
|
|
13393
|
+
* input: [],
|
|
13369
13394
|
* authorize: allowCallers({ cron: true, manual: true, users: requireRole("admin") }),
|
|
13370
13395
|
* handler: async () => ({ swept: true }),
|
|
13371
13396
|
* });
|
|
@@ -13435,6 +13460,7 @@ export interface FunctionAuthorizedContext<TAuth> {
|
|
|
13435
13460
|
*
|
|
13436
13461
|
* ```ts
|
|
13437
13462
|
* export default defineFunction("get-class", {
|
|
13463
|
+
* input: [],
|
|
13438
13464
|
* authorize: async (input, auth) => allow({ classId: input.classId }),
|
|
13439
13465
|
* handler: async (input, ctx) => ctx.auth.classId,
|
|
13440
13466
|
* });
|
|
@@ -13635,11 +13661,13 @@ export type AuthorizedFunctionHandler<TInput, TOutput, TAuth> = FunctionHandler<
|
|
|
13635
13661
|
* adds an `authorize` method that decides who may run the handler; what its
|
|
13636
13662
|
* `allow` resolves is the handler's `ctx.auth`. `input` lists the
|
|
13637
13663
|
* top-level input keys the handler may read, and its `input` is typed as
|
|
13638
|
-
* the declared input picked to them
|
|
13639
|
-
*
|
|
13640
|
-
*
|
|
13641
|
-
*
|
|
13642
|
-
*
|
|
13664
|
+
* the declared input picked to them; `input: []` says the handler reads
|
|
13665
|
+
* none. With no list the handler's `input` is typed `{}`, push refuses the
|
|
13666
|
+
* function unless its TOML declares a trigger, and a caller's call is refused
|
|
13667
|
+
* `FUNCTION_INPUT_LIST_MISSING`. An annotation on the handler's parameter
|
|
13668
|
+
* never adds a key the list does not name. With explicit type arguments the
|
|
13669
|
+
* list is the fourth, as a tuple (`<In, Out, Auth, ["classId"]>`), and is
|
|
13670
|
+
* still written on the definition. `authorize` always reads the whole input:
|
|
13643
13671
|
*
|
|
13644
13672
|
* ```ts
|
|
13645
13673
|
* export default defineFunction("get-class", {
|
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.18",
|
|
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",
|