@salsita-ai/contracts 0.0.0-stage → 0.49.0-develop.2a2e8d75e7
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/CHANGELOG.md +419 -0
- package/LICENSE +61 -0
- package/README.md +28 -2
- package/dist/api/access-level.d.ts +7 -0
- package/dist/api/access-level.js +1 -0
- package/dist/api/access-token.d.ts +6 -0
- package/dist/api/access-token.js +1 -0
- package/dist/api/index.d.ts +4 -0
- package/dist/api/index.js +1 -0
- package/dist/api/session-role.d.ts +8 -0
- package/dist/api/session-role.js +1 -0
- package/dist/api/session-token.d.ts +22 -0
- package/dist/api/session-token.js +1 -0
- package/dist/assistant/browser-details-tool.d.ts +16 -0
- package/dist/assistant/browser-details-tool.js +1 -0
- package/dist/assistant/deployment-assistant.d.ts +84 -0
- package/dist/assistant/deployment-assistant.js +1 -0
- package/dist/assistant/graphql-tools.d.ts +120 -0
- package/dist/assistant/graphql-tools.js +1 -0
- package/dist/assistant/index.d.ts +6 -0
- package/dist/assistant/index.js +1 -0
- package/dist/assistant/message-metadata.d.ts +17 -0
- package/dist/assistant/message-metadata.js +1 -0
- package/dist/chat/api.d.ts +52 -0
- package/dist/chat/api.js +1 -0
- package/dist/chat/completions/messages.d.ts +3 -0
- package/dist/chat/completions/messages.js +1 -0
- package/dist/chat/completions/types.d.ts +28 -0
- package/dist/chat/completions/types.js +1 -0
- package/dist/chat/functions/augmentations.d.ts +3 -0
- package/dist/chat/functions/augmentations.js +1 -0
- package/dist/chat/functions/create.d.ts +5 -0
- package/dist/chat/functions/create.js +1 -0
- package/dist/chat/functions/process.d.ts +14 -0
- package/dist/chat/functions/process.js +1 -0
- package/dist/chat/functions/types.d.ts +21 -0
- package/dist/chat/functions/types.js +1 -0
- package/dist/chat/functions/validate.d.ts +1 -0
- package/dist/chat/functions/validate.js +2 -0
- package/dist/chat/index.d.ts +10 -0
- package/dist/chat/index.js +1 -0
- package/dist/chat/utils/types.d.ts +1 -0
- package/dist/chat/utils/types.js +1 -0
- package/dist/clerk/clerk-backend-api-client.d.ts +129 -0
- package/dist/clerk/clerk-backend-api-client.js +1 -0
- package/dist/clerk/clerk-backend-api-types.d.ts +740 -0
- package/dist/clerk/clerk-backend-api-types.js +1 -0
- package/dist/clerk/clerk-session-token.d.ts +28 -0
- package/dist/clerk/clerk-session-token.js +1 -0
- package/dist/clerk/clerk-token-service.d.ts +15 -0
- package/dist/clerk/clerk-token-service.js +1 -0
- package/dist/clerk/index.d.ts +4 -0
- package/dist/clerk/index.js +1 -0
- package/dist/domain/deployments/ai-image-domain.d.ts +10 -0
- package/dist/domain/deployments/ai-image-domain.js +1 -0
- package/dist/domain/deployments/api-token-domain.d.ts +8 -0
- package/dist/domain/deployments/api-token-domain.js +1 -0
- package/dist/domain/deployments/configuration-schema-domain.d.ts +22 -0
- package/dist/domain/deployments/configuration-schema-domain.js +1 -0
- package/dist/domain/deployments/customer-domain.d.ts +69 -0
- package/dist/domain/deployments/customer-domain.js +1 -0
- package/dist/domain/deployments/deployment-build-domain.d.ts +78 -0
- package/dist/domain/deployments/deployment-build-domain.js +1 -0
- package/dist/domain/deployments/deployment-domain.d.ts +126 -0
- package/dist/domain/deployments/deployment-domain.js +1 -0
- package/dist/domain/deployments/embedding-domain.d.ts +9 -0
- package/dist/domain/deployments/embedding-domain.js +1 -0
- package/dist/domain/deployments/environment-domain.d.ts +107 -0
- package/dist/domain/deployments/environment-domain.js +1 -0
- package/dist/domain/deployments/image-render-domain.d.ts +22 -0
- package/dist/domain/deployments/image-render-domain.js +1 -0
- package/dist/domain/deployments/index.d.ts +14 -0
- package/dist/domain/deployments/index.js +1 -0
- package/dist/domain/deployments/oauth-connection-domain.d.ts +62 -0
- package/dist/domain/deployments/oauth-connection-domain.js +1 -0
- package/dist/domain/deployments/oauth-provider-domain.d.ts +23 -0
- package/dist/domain/deployments/oauth-provider-domain.js +1 -0
- package/dist/domain/deployments/project-domain.d.ts +26 -0
- package/dist/domain/deployments/project-domain.js +1 -0
- package/dist/domain/deployments/sdk-builder-setup-domain.d.ts +13 -0
- package/dist/domain/deployments/sdk-builder-setup-domain.js +1 -0
- package/dist/domain/deployments/session-domain.d.ts +20 -0
- package/dist/domain/deployments/session-domain.js +1 -0
- package/dist/domain/feedback/feedback-domain.d.ts +55 -0
- package/dist/domain/feedback/feedback-domain.js +1 -0
- package/dist/domain/feedback/index.d.ts +1 -0
- package/dist/domain/feedback/index.js +1 -0
- package/dist/domain/index.d.ts +3 -0
- package/dist/domain/index.js +1 -0
- package/dist/domain/product-configurations/configurations-domain.d.ts +113 -0
- package/dist/domain/product-configurations/configurations-domain.js +1 -0
- package/dist/domain/product-configurations/index.d.ts +1 -0
- package/dist/domain/product-configurations/index.js +1 -0
- package/dist/webhook/core/index.d.ts +3 -0
- package/dist/webhook/core/index.js +1 -0
- package/dist/webhook/core/task-resource.d.ts +80 -0
- package/dist/webhook/core/task-resource.js +1 -0
- package/dist/webhook/core/task-type.d.ts +18 -0
- package/dist/webhook/core/task-type.js +1 -0
- package/dist/webhook/core/template.d.ts +65 -0
- package/dist/webhook/core/template.js +1 -0
- package/dist/webhook/empty-xlsx.d.ts +10 -0
- package/dist/webhook/empty-xlsx.js +1 -0
- package/dist/webhook/excel-workbook-client.d.ts +78 -0
- package/dist/webhook/excel-workbook-client.js +1 -0
- package/dist/webhook/google-sheets-client.d.ts +23 -0
- package/dist/webhook/google-sheets-client.js +1 -0
- package/dist/webhook/implementation/index.d.ts +4 -0
- package/dist/webhook/implementation/index.js +1 -0
- package/dist/webhook/implementation/webhook-api-types.d.ts +302 -0
- package/dist/webhook/implementation/webhook-api-types.js +1 -0
- package/dist/webhook/implementation/webhook-client.d.ts +85 -0
- package/dist/webhook/implementation/webhook-client.js +1 -0
- package/dist/webhook/implementation/webhook-routing.d.ts +30 -0
- package/dist/webhook/implementation/webhook-routing.js +1 -0
- package/dist/webhook/implementation/webhook-tunnel-types.d.ts +114 -0
- package/dist/webhook/implementation/webhook-tunnel-types.js +1 -0
- package/dist/webhook/index.d.ts +7 -0
- package/dist/webhook/index.js +1 -0
- package/dist/webhook/spreadsheet-adapter-factory.d.ts +10 -0
- package/dist/webhook/spreadsheet-adapter-factory.js +1 -0
- package/dist/webhook/spreadsheet-adapter.d.ts +94 -0
- package/dist/webhook/spreadsheet-adapter.js +1 -0
- package/dist/webhook/tasks/call-lambda-back-task.d.ts +22 -0
- package/dist/webhook/tasks/call-lambda-back-task.js +1 -0
- package/dist/webhook/tasks/edit-google-spreadsheet-task.d.ts +48 -0
- package/dist/webhook/tasks/edit-google-spreadsheet-task.js +1 -0
- package/dist/webhook/tasks/finalize-task.d.ts +184 -0
- package/dist/webhook/tasks/finalize-task.js +1 -0
- package/dist/webhook/tasks/generate-configuration-link-task.d.ts +56 -0
- package/dist/webhook/tasks/generate-configuration-link-task.js +1 -0
- package/dist/webhook/tasks/generate-csv-task.d.ts +30 -0
- package/dist/webhook/tasks/generate-csv-task.js +1 -0
- package/dist/webhook/tasks/generate-images-task.d.ts +404 -0
- package/dist/webhook/tasks/generate-images-task.js +1 -0
- package/dist/webhook/tasks/generate-pdf-task.d.ts +188 -0
- package/dist/webhook/tasks/generate-pdf-task.js +1 -0
- package/dist/webhook/tasks/index.d.ts +13 -0
- package/dist/webhook/tasks/index.js +1 -0
- package/dist/webhook/tasks/publish-revision-chunks-staged-task.d.ts +73 -0
- package/dist/webhook/tasks/publish-revision-chunks-staged-task.js +1 -0
- package/dist/webhook/tasks/publish-revision-chunks-task.d.ts +76 -0
- package/dist/webhook/tasks/publish-revision-chunks-task.js +1 -0
- package/dist/webhook/tasks/publish-revision-task.d.ts +38 -0
- package/dist/webhook/tasks/publish-revision-task.js +1 -0
- package/dist/webhook/tasks/send-email-task.d.ts +129 -0
- package/dist/webhook/tasks/send-email-task.js +1 -0
- package/dist/webhook/tasks/send-http-task.d.ts +27 -0
- package/dist/webhook/tasks/send-http-task.js +1 -0
- package/dist/webhook/tasks/woocommerce-add-to-cart-task.d.ts +91 -0
- package/dist/webhook/tasks/woocommerce-add-to-cart-task.js +1 -0
- package/dist/webhook/webhook-payload.d.ts +56 -0
- package/dist/webhook/webhook-payload.js +1 -0
- package/package.json +84 -3
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** AI providers a deployment's assistant can run on. */
|
|
3
|
+
export declare const ASSISTANT_AI_PROVIDERS: readonly ['openai'];
|
|
4
|
+
/**
|
|
5
|
+
* Provider-neutral model tiers of the assistant manifest, most capable first. The server maps a tier
|
|
6
|
+
* to a concrete model of the chosen provider, so retiring a model never needs a project redeploy.
|
|
7
|
+
*/
|
|
8
|
+
export declare const ASSISTANT_MODEL_TIERS: readonly ['frontier', 'advanced', 'balanced', 'fast'];
|
|
9
|
+
/** Reasoning levels of the assistant manifest; every tier's model accepts all of them. */
|
|
10
|
+
export declare const ASSISTANT_REASONING_LEVELS: readonly ['low', 'medium', 'high'];
|
|
11
|
+
export type AssistantAiProvider = (typeof ASSISTANT_AI_PROVIDERS)[number];
|
|
12
|
+
export type AssistantModelTier = (typeof ASSISTANT_MODEL_TIERS)[number];
|
|
13
|
+
export type AssistantReasoningLevel = (typeof ASSISTANT_REASONING_LEVELS)[number];
|
|
14
|
+
/**
|
|
15
|
+
* The `ai` block of the assistant manifest: which provider, model tier and reasoning level the
|
|
16
|
+
* deployment's assistant runs with. Authored in the application spec, sent when a deployment is
|
|
17
|
+
* prepared and stored with it; the server has no defaults for any of the three.
|
|
18
|
+
*/
|
|
19
|
+
export interface AssistantAiSettings {
|
|
20
|
+
readonly provider: AssistantAiProvider;
|
|
21
|
+
readonly model: AssistantModelTier;
|
|
22
|
+
readonly reasoning: AssistantReasoningLevel;
|
|
23
|
+
}
|
|
24
|
+
export declare const AssistantAiSettings: z.ZodObject<{
|
|
25
|
+
provider: z.ZodEnum<["openai"]>;
|
|
26
|
+
model: z.ZodEnum<["frontier", "advanced", "balanced", "fast"]>;
|
|
27
|
+
reasoning: z.ZodEnum<["low", "medium", "high"]>;
|
|
28
|
+
}, "strict", z.ZodTypeAny, {
|
|
29
|
+
provider: "openai";
|
|
30
|
+
model: "advanced" | "balanced" | "fast" | "frontier";
|
|
31
|
+
reasoning: "high" | "low" | "medium";
|
|
32
|
+
}, {
|
|
33
|
+
provider: "openai";
|
|
34
|
+
model: "advanced" | "balanced" | "fast" | "frontier";
|
|
35
|
+
reasoning: "high" | "low" | "medium";
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* What a deployment registers for its assistant: the GraphQL SDL generated from the manifest, the
|
|
39
|
+
* prompt the SDK generates for its own version, the integrator's instructions and the AI settings.
|
|
40
|
+
* The server stores it with the deployment and builds every run's system prompt from it; a
|
|
41
|
+
* deployment that registers none has no assistant.
|
|
42
|
+
*/
|
|
43
|
+
export interface DeploymentAssistant {
|
|
44
|
+
readonly sdl: string;
|
|
45
|
+
readonly prompt: string;
|
|
46
|
+
readonly instructions?: string;
|
|
47
|
+
readonly ai: AssistantAiSettings;
|
|
48
|
+
}
|
|
49
|
+
export declare const DeploymentAssistant: z.ZodObject<{
|
|
50
|
+
sdl: z.ZodString;
|
|
51
|
+
prompt: z.ZodString;
|
|
52
|
+
instructions: z.ZodOptional<z.ZodString>;
|
|
53
|
+
ai: z.ZodObject<{
|
|
54
|
+
provider: z.ZodEnum<["openai"]>;
|
|
55
|
+
model: z.ZodEnum<["frontier", "advanced", "balanced", "fast"]>;
|
|
56
|
+
reasoning: z.ZodEnum<["low", "medium", "high"]>;
|
|
57
|
+
}, "strict", z.ZodTypeAny, {
|
|
58
|
+
provider: "openai";
|
|
59
|
+
model: "advanced" | "balanced" | "fast" | "frontier";
|
|
60
|
+
reasoning: "high" | "low" | "medium";
|
|
61
|
+
}, {
|
|
62
|
+
provider: "openai";
|
|
63
|
+
model: "advanced" | "balanced" | "fast" | "frontier";
|
|
64
|
+
reasoning: "high" | "low" | "medium";
|
|
65
|
+
}>;
|
|
66
|
+
}, "strict", z.ZodTypeAny, {
|
|
67
|
+
sdl: string;
|
|
68
|
+
prompt: string;
|
|
69
|
+
instructions?: string | undefined;
|
|
70
|
+
ai: {
|
|
71
|
+
provider: "openai";
|
|
72
|
+
model: "advanced" | "balanced" | "fast" | "frontier";
|
|
73
|
+
reasoning: "high" | "low" | "medium";
|
|
74
|
+
};
|
|
75
|
+
}, {
|
|
76
|
+
sdl: string;
|
|
77
|
+
prompt: string;
|
|
78
|
+
instructions?: string | undefined;
|
|
79
|
+
ai: {
|
|
80
|
+
provider: "openai";
|
|
81
|
+
model: "advanced" | "balanced" | "fast" | "frontier";
|
|
82
|
+
reasoning: "high" | "low" | "medium";
|
|
83
|
+
};
|
|
84
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{z as t}from"zod";export const ASSISTANT_AI_PROVIDERS=["openai"];export const ASSISTANT_MODEL_TIERS=["frontier","advanced","balanced","fast"];export const ASSISTANT_REASONING_LEVELS=["low","medium","high"];export const AssistantAiSettings=t.object({provider:t.enum(ASSISTANT_AI_PROVIDERS),model:t.enum(ASSISTANT_MODEL_TIERS),reasoning:t.enum(ASSISTANT_REASONING_LEVELS)}).strict();export const DeploymentAssistant=t.object({sdl:t.string().min(1),prompt:t.string().min(1),instructions:t.string().min(1).optional(),ai:AssistantAiSettings}).strict();
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** One single-operation GraphQL document of a `query` or `apply` tool call, with its own variables. */
|
|
3
|
+
export interface AssistantGraphQLOperation {
|
|
4
|
+
/** The GraphQL document. It holds exactly one operation, a query or a mutation. */
|
|
5
|
+
readonly query: string;
|
|
6
|
+
readonly variables?: Readonly<Record<string, unknown>> | null;
|
|
7
|
+
readonly operationName?: string | null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Input of the assistant's `query` and `apply` tools: the operations the browser runs in order
|
|
11
|
+
* against the configurator's GraphQL schema, each one seeing the changes of the ones before it.
|
|
12
|
+
*/
|
|
13
|
+
export interface AssistantGraphQLToolInput {
|
|
14
|
+
readonly operations: ReadonlyArray<AssistantGraphQLOperation>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Parses a tool call's input in the browser, because a plain JSON Schema gives the client tool no
|
|
18
|
+
* typed input. Optional members also accept `null`, which a model may send for a value it leaves
|
|
19
|
+
* out; the tools are not sent as strict schemas, because `variables` is a free-form map.
|
|
20
|
+
*/
|
|
21
|
+
export declare const AssistantGraphQLToolInput: z.ZodObject<{
|
|
22
|
+
operations: z.ZodArray<z.ZodObject<{
|
|
23
|
+
query: z.ZodString;
|
|
24
|
+
variables: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
25
|
+
operationName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
26
|
+
}, "strip", z.ZodTypeAny, {
|
|
27
|
+
query: string;
|
|
28
|
+
variables?: Record<string, unknown> | null | undefined;
|
|
29
|
+
operationName?: string | null | undefined;
|
|
30
|
+
}, {
|
|
31
|
+
query: string;
|
|
32
|
+
variables?: Record<string, unknown> | null | undefined;
|
|
33
|
+
operationName?: string | null | undefined;
|
|
34
|
+
}>, "many">;
|
|
35
|
+
}, "strip", z.ZodTypeAny, {
|
|
36
|
+
operations: {
|
|
37
|
+
query: string;
|
|
38
|
+
variables?: Record<string, unknown> | null | undefined;
|
|
39
|
+
operationName?: string | null | undefined;
|
|
40
|
+
}[];
|
|
41
|
+
}, {
|
|
42
|
+
operations: {
|
|
43
|
+
query: string;
|
|
44
|
+
variables?: Record<string, unknown> | null | undefined;
|
|
45
|
+
operationName?: string | null | undefined;
|
|
46
|
+
}[];
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* Client-side tool of the assistant chat that reads the configuration: the browser runs the
|
|
50
|
+
* operations against the configurator's GraphQL schema from the committed state and discards every
|
|
51
|
+
* change, so mutations in the list answer "what if" questions. The result is the list of standard
|
|
52
|
+
* GraphQL results with `committed: false`.
|
|
53
|
+
*
|
|
54
|
+
* The server passes the definition to the model without an implementation, so every call becomes a
|
|
55
|
+
* client-tool interrupt; the SDK registers the browser implementation via `.client()`.
|
|
56
|
+
*/
|
|
57
|
+
export declare const queryTool: import("@tanstack/ai").ToolDefinition<{
|
|
58
|
+
type: string;
|
|
59
|
+
properties: {
|
|
60
|
+
operations: {
|
|
61
|
+
type: string;
|
|
62
|
+
minItems: number;
|
|
63
|
+
description: string;
|
|
64
|
+
items: {
|
|
65
|
+
type: string;
|
|
66
|
+
properties: {
|
|
67
|
+
query: {
|
|
68
|
+
type: string;
|
|
69
|
+
description: string;
|
|
70
|
+
};
|
|
71
|
+
variables: {
|
|
72
|
+
type: string;
|
|
73
|
+
description: string;
|
|
74
|
+
};
|
|
75
|
+
operationName: {
|
|
76
|
+
type: string;
|
|
77
|
+
description: string;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
required: string[];
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
required: string[];
|
|
85
|
+
}, undefined, "query", false, undefined>;
|
|
86
|
+
/**
|
|
87
|
+
* Client-side tool of the assistant chat that changes the configuration: the browser runs the same
|
|
88
|
+
* kind of list as {@link queryTool} and commits its changes as one undo step when every operation
|
|
89
|
+
* succeeds. It is registered for every session; in a session that may not change the configuration
|
|
90
|
+
* the browser refuses the call without running anything.
|
|
91
|
+
*/
|
|
92
|
+
export declare const applyTool: import("@tanstack/ai").ToolDefinition<{
|
|
93
|
+
type: string;
|
|
94
|
+
properties: {
|
|
95
|
+
operations: {
|
|
96
|
+
type: string;
|
|
97
|
+
minItems: number;
|
|
98
|
+
description: string;
|
|
99
|
+
items: {
|
|
100
|
+
type: string;
|
|
101
|
+
properties: {
|
|
102
|
+
query: {
|
|
103
|
+
type: string;
|
|
104
|
+
description: string;
|
|
105
|
+
};
|
|
106
|
+
variables: {
|
|
107
|
+
type: string;
|
|
108
|
+
description: string;
|
|
109
|
+
};
|
|
110
|
+
operationName: {
|
|
111
|
+
type: string;
|
|
112
|
+
description: string;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
required: string[];
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
required: string[];
|
|
120
|
+
}, undefined, "apply", false, undefined>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{toolDefinition as e}from"@tanstack/ai";import{z as t}from"zod";export const AssistantGraphQLToolInput=t.object({operations:t.array(t.object({query:t.string(),variables:t.record(t.unknown()).nullish(),operationName:t.string().nullish()})).min(1)});let o={type:"object",properties:{operations:{type:"array",minItems:1,description:"The operations to run, in order. Each one sees the changes of the ones before it.",items:{type:"object",properties:{query:{type:"string",description:"A GraphQL document with exactly one operation, a query or a mutation."},variables:{type:"object",description:"Values of the variables the document declares. Prefer literals written into the document."},operationName:{type:"string",description:"The name of the operation, when the document names it."}},required:["query"]}}},required:["operations"]};export const queryTool=e({name:"query",description:"Runs GraphQL operations against the open configuration and returns their results. Nothing is changed: mutations in the list are applied to a temporary copy that is discarded after the call, which shows what a change would do.",inputSchema:o});export const applyTool=e({name:"apply",description:"Runs GraphQL operations against the open configuration and keeps their changes as one undo step. All or nothing: when any operation fails, nothing is changed. The result says whether the changes were committed.",inputSchema:o});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { browserDetailsTool } from './browser-details-tool.js';
|
|
2
|
+
export { ASSISTANT_AI_PROVIDERS, ASSISTANT_MODEL_TIERS, ASSISTANT_REASONING_LEVELS, AssistantAiSettings, DeploymentAssistant, } from './deployment-assistant.js';
|
|
3
|
+
export { AssistantGraphQLToolInput, applyTool, queryTool } from './graphql-tools.js';
|
|
4
|
+
export type { AssistantGraphQLOperation } from './graphql-tools.js';
|
|
5
|
+
export type { AssistantAiProvider, AssistantModelTier, AssistantReasoningLevel } from './deployment-assistant.js';
|
|
6
|
+
export { AssistantMessageMetadata } from './message-metadata.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{browserDetailsTool}from"./browser-details-tool.js";export{ASSISTANT_AI_PROVIDERS,ASSISTANT_MODEL_TIERS,ASSISTANT_REASONING_LEVELS,AssistantAiSettings,DeploymentAssistant}from"./deployment-assistant.js";export{AssistantGraphQLToolInput,applyTool,queryTool}from"./graphql-tools.js";export{AssistantMessageMetadata}from"./message-metadata.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Metadata the assistant chat client attaches to each user message (AG-UI message `metadata`). It is
|
|
4
|
+
* persisted with the message, and the server shows `sentAt` to the model next to the message so the
|
|
5
|
+
* model knows when each message was written — the seed of the per-turn history diff.
|
|
6
|
+
*/
|
|
7
|
+
export interface AssistantMessageMetadata {
|
|
8
|
+
/** Client send time of the user message, as an ISO 8601 timestamp with offset. */
|
|
9
|
+
readonly sentAt: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const AssistantMessageMetadata: z.ZodObject<{
|
|
12
|
+
sentAt: z.ZodString;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
sentAt: string;
|
|
15
|
+
}, {
|
|
16
|
+
sentAt: string;
|
|
17
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{z as t}from"zod";export const AssistantMessageMetadata=t.object({sentAt:t.string().datetime({offset:!0})});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type OpenAI from 'openai';
|
|
2
|
+
import type { Uploadable } from 'openai/core/uploads';
|
|
3
|
+
/**
|
|
4
|
+
* Generate a completion from a prompt and message history
|
|
5
|
+
* @param openai OpenAI instance
|
|
6
|
+
* @param params completion options
|
|
7
|
+
* @param prompt base prompt
|
|
8
|
+
* @param messages message history- last message should be user message
|
|
9
|
+
* @param tools available functions to call
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare const createCompletion: (openai: OpenAI, params: Omit<OpenAI.Chat.Completions.ChatCompletionCreateParams, 'stream' | 'messages'>, prompt: string, messages: OpenAI.ChatCompletionMessageParam[], tools?: OpenAI.ChatCompletionTool[]) => Promise<import("openai/core/streaming.mjs").Stream<OpenAI.ChatCompletionChunk> & {
|
|
13
|
+
_request_id?: string | null;
|
|
14
|
+
}>;
|
|
15
|
+
/**
|
|
16
|
+
* Generate a text transcription from an audio file
|
|
17
|
+
* @param openai OpenAI instance
|
|
18
|
+
* @param params transcription options
|
|
19
|
+
* @param file audio file
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
export declare const createTranscription: (openai: OpenAI, params: Omit<OpenAI.Audio.Transcriptions.TranscriptionCreateParamsNonStreaming, 'file' | 'model'>, file: Uploadable) => Promise<OpenAI.Audio.Transcription & {
|
|
23
|
+
_request_id?: string | null;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* Generate a speech audio file from a text message
|
|
27
|
+
* @param openai OpenAI instance
|
|
28
|
+
* @param params speech options
|
|
29
|
+
* @param message text message
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
export declare const createSpeech: (openai: OpenAI, params: Omit<OpenAI.Audio.Speech.SpeechCreateParams, 'input' | 'model' | 'voice'>, message: string) => Promise<Response>;
|
|
33
|
+
/**
|
|
34
|
+
* Generate a function call completion from a prompt and message
|
|
35
|
+
* @param openai OpenAI instance
|
|
36
|
+
* @param params completion options
|
|
37
|
+
* @param prompt base prompt
|
|
38
|
+
* @param message input message
|
|
39
|
+
* @param tools available functions to call
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
export declare const createFunctionCallCompletion: (openai: OpenAI, params: Omit<OpenAI.Chat.Completions.ChatCompletionCreateParams, 'stream' | 'messages'>, prompt: string, message: string, tools: OpenAI.ChatCompletionTool[]) => Promise<OpenAI.ChatCompletionMessageFunctionToolCall.Function[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Generate an embedding from a text input
|
|
45
|
+
* @param openai OpenAI instance
|
|
46
|
+
* @param params embedding options
|
|
47
|
+
* @param input text input
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
export declare const createEmbedding: (openai: OpenAI, params: Omit<OpenAI.EmbeddingCreateParams, 'model' | 'input'> & {
|
|
51
|
+
model?: OpenAI.EmbeddingCreateParams['model'];
|
|
52
|
+
}, input: string) => Promise<number[] | undefined>;
|
package/dist/chat/api.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const createCompletion=async(e,t,o,c,n)=>e.chat.completions.create({...t,messages:[{role:"system",content:o},...c],...n&&n.length>0?{tools:n,tool_choice:"auto"}:{},stream:!0});export const createTranscription=async(e,t,o)=>e.audio.transcriptions.create({...t,model:"whisper-1",file:o});export const createSpeech=async(e,t,o)=>e.audio.speech.create({...t,input:o,model:"tts-1",voice:"alloy"});export const createFunctionCallCompletion=async(e,t,o,c,n)=>{let a=await e.chat.completions.create({...t,messages:[{role:"system",content:o},{role:"user",content:c}],...n.length>0?{tools:n,tool_choice:1===n.length?n[0]:"auto"}:{}});return a.choices[0]?.message.tool_calls?.filter(e=>"function"===e.type).map(e=>e.function)??[]};export const createEmbedding=async(e,t,o)=>{let c=await e.embeddings.create({model:"text-embedding-3-small",...t,input:o});return c.data[0]?.embedding};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type OpenAI from 'openai';
|
|
2
|
+
export declare const createAssistantMessage: (content?: string, toolCalls?: OpenAI.Chat.Completions.ChatCompletionMessageToolCall[]) => OpenAI.ChatCompletionAssistantMessageParam;
|
|
3
|
+
export declare const createToolCallResultMessage: (content: string, toolCallId: string) => OpenAI.Chat.Completions.ChatCompletionToolMessageParam;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const createAssistantMessage=(t,o)=>({role:"assistant",...t?{content:t}:void 0,...o?{tool_calls:o.filter(t=>"function"===t.type).map(t=>({id:t.id,function:t.function,type:"function"}))}:void 0});export const createToolCallResultMessage=(t,o)=>({role:"tool",content:t,tool_call_id:o});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type OpenAI from 'openai';
|
|
2
|
+
export declare const ChunkType: {
|
|
3
|
+
readonly content: 'content';
|
|
4
|
+
readonly calls: 'calls';
|
|
5
|
+
readonly error: 'error';
|
|
6
|
+
readonly augment: 'augment';
|
|
7
|
+
};
|
|
8
|
+
export interface ChatMessageContentChunk {
|
|
9
|
+
type: typeof ChunkType.content;
|
|
10
|
+
content: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ChatToolCalls {
|
|
13
|
+
type: typeof ChunkType.calls;
|
|
14
|
+
tool_calls: OpenAI.Chat.Completions.ChatCompletionMessageFunctionToolCall[];
|
|
15
|
+
}
|
|
16
|
+
export interface ChatErrorChunk {
|
|
17
|
+
type: typeof ChunkType.error;
|
|
18
|
+
error: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ChatMessageAugmentation {
|
|
21
|
+
type: typeof ChunkType.augment;
|
|
22
|
+
augmentation: Record<string, unknown>;
|
|
23
|
+
}
|
|
24
|
+
export type ChatStreamChunk = ChatMessageContentChunk | ChatToolCalls | ChatErrorChunk | ChatMessageAugmentation;
|
|
25
|
+
export declare const isChatMessageContentChunk: (chunk: ChatStreamChunk) => chunk is ChatMessageContentChunk;
|
|
26
|
+
export declare const isChatMessageAugmentation: (chunk: ChatStreamChunk) => chunk is ChatMessageAugmentation;
|
|
27
|
+
export declare const isChatToolCalls: (chunk: ChatStreamChunk) => chunk is ChatToolCalls;
|
|
28
|
+
export declare const isChatError: (chunk: ChatStreamChunk) => chunk is ChatErrorChunk;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const ChunkType={content:"content",calls:"calls",error:"error",augment:"augment"};export const isChatMessageContentChunk=t=>t.type===ChunkType.content;export const isChatMessageAugmentation=t=>t.type===ChunkType.augment;export const isChatToolCalls=t=>t.type===ChunkType.calls;export const isChatError=t=>t.type===ChunkType.error;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const simpleAugmentationHandler=t=>e=>({result:e[t]?JSON.stringify(e):""});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { JSONSchemaType } from 'ajv';
|
|
2
|
+
import type { Empty } from '../utils/types.js';
|
|
3
|
+
import type { ChatExecutableFunction, ChatFunction, ChatFunctionDefinition } from './types.js';
|
|
4
|
+
export declare const createChatExecutableFunction: <C extends Empty = Empty, R extends Empty = Empty, P = undefined>(name: string, parameters: JSONSchemaType<P> | undefined, func: ChatFunction<C, R, P>) => ChatExecutableFunction<C, R, P>;
|
|
5
|
+
export declare const createChatFunctionDefinition: <C extends Empty = Empty, R extends Empty = Empty, P = undefined>(name: string, description: string, parameters: JSONSchemaType<P> | undefined, func: ChatFunction<C, R, P>) => ChatFunctionDefinition<C, R, P>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createValidator as t}from"./validate.js";export const createChatExecutableFunction=(e,a,n)=>({name:e,function:n,validate:t(a)});export const createChatFunctionDefinition=(t,e,a,n)=>({description:e,parameters:a,...createChatExecutableFunction(t,a,n)});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type OpenAI from 'openai';
|
|
2
|
+
import type { Empty } from '../utils/types.js';
|
|
3
|
+
import type { ChatExecutableFunction, ChatFunctionDefinition, ChatFunctionResult } from './types.js';
|
|
4
|
+
export declare const createCompletionTool: <C extends Empty = Empty, R extends Empty = Empty>({ name, description, parameters, }: OpenAI.FunctionDefinition | ChatFunctionDefinition<C, R, any>) => OpenAI.ChatCompletionFunctionTool;
|
|
5
|
+
/**
|
|
6
|
+
* Processes tool calls and generates array of return messages.
|
|
7
|
+
*
|
|
8
|
+
* @param toolCalls - array of tool calls from assistant message
|
|
9
|
+
* @param functions - array of available functions
|
|
10
|
+
* @param context - context object to pass to functions
|
|
11
|
+
* @param resultProcessor - optional function used to process each function call result
|
|
12
|
+
* @returns return messages
|
|
13
|
+
*/
|
|
14
|
+
export declare const processToolCalls: <C extends Empty = Empty, R extends Empty = Empty>(toolCalls: OpenAI.ChatCompletionMessageToolCall[], functions: Array<ChatExecutableFunction<C, R, any>>, context: C, resultProcessor?: (result: ChatFunctionResult<R>, call: OpenAI.ChatCompletionMessageToolCall) => void) => Promise<OpenAI.ChatCompletionToolMessageParam[]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const createCompletionTool=({name:t,description:n,parameters:o})=>({type:"function",function:{name:t,description:n,parameters:o}});export const processToolCalls=async(t,n,o,e)=>{let l=[];for(let r of t){let{id:t}=r,c={tool_call_id:t,role:"tool"};if("function"!==r.type){l.push({...c,content:`Tool call type '${r.type}' is not supported — only function tool calls can be processed by this handler.`});continue}let{function:i}=r;try{let t=n?.find(t=>t.name===i.name);if(!t){l.push({...c,content:`Function \`${i.name}\` not found`});continue}let s=JSON.parse(i.arguments??"{}"),a=t.validate(s);if(a){l.push({...c,content:a});continue}let u=await t.function(s,o);e?.(u,r),l.push({...c,content:u.result})}catch(o){let n=o instanceof Error?o.message:String(o);throw Error(`Call ${t} of function \`${i.name}\` resulted in error: ${n}`)}}return l};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type OpenAI from 'openai';
|
|
2
|
+
import type { Empty } from '../utils/types.js';
|
|
3
|
+
export type ChatFunctionResult<R extends Empty = Empty> = {
|
|
4
|
+
result: string;
|
|
5
|
+
} & R;
|
|
6
|
+
export type ChatFunction<C extends Empty = Empty, R extends Empty = Empty, P = undefined> = (arg: P, context: C) => ChatFunctionResult<R> | Promise<ChatFunctionResult<R>>;
|
|
7
|
+
export interface ChatExecutableFunction<C extends Empty = Empty, R extends Empty = Empty, P = undefined> {
|
|
8
|
+
name: string;
|
|
9
|
+
function: ChatFunction<C, R, P>;
|
|
10
|
+
validate: (data: unknown) => string | undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Function call definition and implementation
|
|
14
|
+
*/
|
|
15
|
+
export interface ChatFunctionDefinition<C extends Empty = Empty, R extends Empty = Empty, P = undefined> extends OpenAI.FunctionDefinition, ChatExecutableFunction<C, R, P> {
|
|
16
|
+
}
|
|
17
|
+
export interface ChatDocument {
|
|
18
|
+
name: string;
|
|
19
|
+
description: string;
|
|
20
|
+
content: string;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createValidator: <P extends Record<string, unknown>>(parameters?: P) => (data: unknown) => string | undefined;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{Ajv as e}from"ajv";let r=new e({allErrors:!0});export const createValidator=e=>{let t=r.compile(e??{type:"object",properties:{},required:[]});return e=>{if(!t(e)){let e;return(e=t.errors)&&e.length>0?`Invalid arguments:
|
|
2
|
+
${e.map(e=>`- ${e.instancePath?`${e.instancePath}: `:""}${e.message}`).join("\n ")}`:"Invalid arguments."}}};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { createCompletion, createFunctionCallCompletion, createTranscription as createSpeechToTextCompletion, createSpeech as createTextToSpeechCompletion, createEmbedding, } from './api.js';
|
|
2
|
+
export { createAssistantMessage, createToolCallResultMessage } from './completions/messages.js';
|
|
3
|
+
export { ChunkType, isChatMessageContentChunk, isChatMessageAugmentation, isChatToolCalls, isChatError, } from './completions/types.js';
|
|
4
|
+
export type { ChatMessageContentChunk, ChatToolCalls, ChatErrorChunk, ChatStreamChunk, ChatMessageAugmentation, } from './completions/types.js';
|
|
5
|
+
export { createValidator } from './functions/validate.js';
|
|
6
|
+
export { createChatFunctionDefinition as createFunctionDefintion, createChatExecutableFunction, } from './functions/create.js';
|
|
7
|
+
export { simpleAugmentationHandler } from './functions/augmentations.js';
|
|
8
|
+
export { processToolCalls, createCompletionTool } from './functions/process.js';
|
|
9
|
+
export type { ChatFunction, ChatExecutableFunction, ChatFunctionDefinition, ChatFunctionResult, } from './functions/types.js';
|
|
10
|
+
export type { Empty } from './utils/types.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{createCompletion,createFunctionCallCompletion,createTranscription as createSpeechToTextCompletion,createSpeech as createTextToSpeechCompletion,createEmbedding}from"./api.js";export{createAssistantMessage,createToolCallResultMessage}from"./completions/messages.js";export{ChunkType,isChatMessageContentChunk,isChatMessageAugmentation,isChatToolCalls,isChatError}from"./completions/types.js";export{createValidator}from"./functions/validate.js";export{createChatFunctionDefinition as createFunctionDefintion,createChatExecutableFunction}from"./functions/create.js";export{simpleAugmentationHandler}from"./functions/augmentations.js";export{processToolCalls,createCompletionTool}from"./functions/process.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Empty = Record<string, unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { Logger } from '@salsita-ai/common/utils';
|
|
2
|
+
import { type UserInvite, type UserUpdate } from './clerk-backend-api-types.js';
|
|
3
|
+
export declare class ClerkBackendApiClient {
|
|
4
|
+
private readonly _clerkApiKey;
|
|
5
|
+
private readonly _context;
|
|
6
|
+
constructor(_clerkApiKey: string, _context: {
|
|
7
|
+
logger: Omit<Logger, 'appendToGlobalContext' | 'verbose'>;
|
|
8
|
+
});
|
|
9
|
+
private _fetchClerkApi;
|
|
10
|
+
private _createError;
|
|
11
|
+
banUser(userId: string): Promise<{
|
|
12
|
+
id: string;
|
|
13
|
+
emailAddress: string;
|
|
14
|
+
fullName: string | null;
|
|
15
|
+
role: import("./clerk-backend-api-types.js").ClerkRole;
|
|
16
|
+
tags: string[];
|
|
17
|
+
status: import("./clerk-backend-api-types.js").ClerkUserStatus;
|
|
18
|
+
createdAt: number;
|
|
19
|
+
lastSignInAt: number | null;
|
|
20
|
+
}>;
|
|
21
|
+
deleteUser(userId: string): Promise<{
|
|
22
|
+
deleted: boolean;
|
|
23
|
+
}>;
|
|
24
|
+
fetchInvitations(params: {
|
|
25
|
+
limit: number;
|
|
26
|
+
offset: number;
|
|
27
|
+
query?: string;
|
|
28
|
+
}): Promise<{
|
|
29
|
+
id: string;
|
|
30
|
+
emailAddress: string;
|
|
31
|
+
status: import("./clerk-backend-api-types.js").ClerkInvitationStatus;
|
|
32
|
+
role: import("./clerk-backend-api-types.js").ClerkRole;
|
|
33
|
+
tags: string[];
|
|
34
|
+
expiresAt: number;
|
|
35
|
+
createdAt: number;
|
|
36
|
+
updatedAt: number;
|
|
37
|
+
}[]>;
|
|
38
|
+
fetchOrgs(): Promise<{
|
|
39
|
+
total_count: number;
|
|
40
|
+
data: {
|
|
41
|
+
id: string;
|
|
42
|
+
name: string;
|
|
43
|
+
userTags: {
|
|
44
|
+
id: string;
|
|
45
|
+
label: string;
|
|
46
|
+
}[];
|
|
47
|
+
}[];
|
|
48
|
+
}>;
|
|
49
|
+
fetchOrgOrThrow(): Promise<{
|
|
50
|
+
id: string;
|
|
51
|
+
name: string;
|
|
52
|
+
userTags: {
|
|
53
|
+
id: string;
|
|
54
|
+
label: string;
|
|
55
|
+
}[];
|
|
56
|
+
}>;
|
|
57
|
+
fetchUser(userId: string): Promise<{
|
|
58
|
+
id: string;
|
|
59
|
+
emailAddress: string;
|
|
60
|
+
fullName: string | null;
|
|
61
|
+
role: import("./clerk-backend-api-types.js").ClerkRole;
|
|
62
|
+
tags: string[];
|
|
63
|
+
status: import("./clerk-backend-api-types.js").ClerkUserStatus;
|
|
64
|
+
createdAt: number;
|
|
65
|
+
lastSignInAt: number | null;
|
|
66
|
+
}>;
|
|
67
|
+
fetchUsers(params: {
|
|
68
|
+
limit: number;
|
|
69
|
+
offset: number;
|
|
70
|
+
query?: string;
|
|
71
|
+
}): Promise<{
|
|
72
|
+
id: string;
|
|
73
|
+
emailAddress: string;
|
|
74
|
+
fullName: string | null;
|
|
75
|
+
role: import("./clerk-backend-api-types.js").ClerkRole;
|
|
76
|
+
tags: string[];
|
|
77
|
+
status: import("./clerk-backend-api-types.js").ClerkUserStatus;
|
|
78
|
+
createdAt: number;
|
|
79
|
+
lastSignInAt: number | null;
|
|
80
|
+
}[]>;
|
|
81
|
+
inviteUser(invite: UserInvite): Promise<{
|
|
82
|
+
id: string;
|
|
83
|
+
emailAddress: string;
|
|
84
|
+
status: import("./clerk-backend-api-types.js").ClerkInvitationStatus;
|
|
85
|
+
role: import("./clerk-backend-api-types.js").ClerkRole;
|
|
86
|
+
tags: string[];
|
|
87
|
+
expiresAt: number;
|
|
88
|
+
createdAt: number;
|
|
89
|
+
updatedAt: number;
|
|
90
|
+
}>;
|
|
91
|
+
verifyOAuthUser(oauthProviderBaseUrl: string, accessToken: string): Promise<{
|
|
92
|
+
id: string;
|
|
93
|
+
}>;
|
|
94
|
+
refreshToken(oauthProviderBaseUrl: string, clientId: string, clientSecret: string, refreshToken: string): Promise<{
|
|
95
|
+
accessToken: string;
|
|
96
|
+
refreshToken: string;
|
|
97
|
+
expirationTime: number;
|
|
98
|
+
}>;
|
|
99
|
+
revokeInvitation(invitationId: string): Promise<{
|
|
100
|
+
id: string;
|
|
101
|
+
emailAddress: string;
|
|
102
|
+
status: import("./clerk-backend-api-types.js").ClerkInvitationStatus;
|
|
103
|
+
role: import("./clerk-backend-api-types.js").ClerkRole;
|
|
104
|
+
tags: string[];
|
|
105
|
+
expiresAt: number;
|
|
106
|
+
createdAt: number;
|
|
107
|
+
updatedAt: number;
|
|
108
|
+
}>;
|
|
109
|
+
unbanUser(userId: string): Promise<{
|
|
110
|
+
id: string;
|
|
111
|
+
emailAddress: string;
|
|
112
|
+
fullName: string | null;
|
|
113
|
+
role: import("./clerk-backend-api-types.js").ClerkRole;
|
|
114
|
+
tags: string[];
|
|
115
|
+
status: import("./clerk-backend-api-types.js").ClerkUserStatus;
|
|
116
|
+
createdAt: number;
|
|
117
|
+
lastSignInAt: number | null;
|
|
118
|
+
}>;
|
|
119
|
+
updateUser(invite: UserUpdate): Promise<{
|
|
120
|
+
id: string;
|
|
121
|
+
emailAddress: string;
|
|
122
|
+
fullName: string | null;
|
|
123
|
+
role: import("./clerk-backend-api-types.js").ClerkRole;
|
|
124
|
+
tags: string[];
|
|
125
|
+
status: import("./clerk-backend-api-types.js").ClerkUserStatus;
|
|
126
|
+
createdAt: number;
|
|
127
|
+
lastSignInAt: number | null;
|
|
128
|
+
}>;
|
|
129
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ClerkError as e,ClerkErrorResponse as r,Invitation as t,InvitationsResponse as a,OAuthRefreshTokenResult as n,OAuthUserInfo as s,OrganizationsResponse as i,User as o,UserDelete as c,UserResponse as h}from"./clerk-backend-api-types.js";let l=(e,r)=>{let t=new URL(e,"https://api.clerk.com");if(void 0!==r)for(let[e,a]of Object.entries(r))t.searchParams.append(e,String(a));return t};export class ClerkBackendApiClient{_clerkApiKey;_context;constructor(e,r){this._clerkApiKey=e,this._context=r}async _fetchClerkApi(e,r,t,a){let n=await fetch(r,{method:e,headers:{Authorization:`Bearer ${this._clerkApiKey}`,...a?{"Content-Type":"application/json"}:{}},body:a}),s=await n.json();try{return t.parse(s)}catch(e){throw this._createError(e,s)}}_createError(t,a){try{let t=r.parse(a),n="errors"in t?t.errors[0]:t;if(n)return new e(n)}catch{}return this._context.logger.error("Failed to parse Clerk error response:",{response:a}),Error("Unknown Clerk error",{cause:t})}banUser(e){return this._fetchClerkApi("POST",l(`/v1/users/${e}/ban`),o)}deleteUser(e){return this._fetchClerkApi("DELETE",l(`/v1/users/${e}`),c)}async fetchInvitations(e){let{limit:r,offset:t,query:n=""}=e,s=l("/v1/invitations",{limit:r,offset:t,orderBy:"created_at",...n.length>0?{query:n}:null});return await this._fetchClerkApi("GET",s,a)}async fetchOrgs(){return this._fetchClerkApi("GET",l("/v1/organizations"),i)}async fetchOrgOrThrow(){let e=await this.fetchOrgs();if(e.total_count>1)throw Error("Clerk: fetchOrgOrThrow expects exactly one organization, found more");let r=e.data[0];if(!r)throw Error("Clerk: fetchOrgOrThrow expects exactly one organization, found none");return r}async fetchUser(e){return this._fetchClerkApi("GET",l(`/v1/users/${e}`),o)}async fetchUsers(e){let{limit:r,offset:t,query:a=""}=e,n=l("/v1/users",{limit:r,offset:t,orderBy:"-created_at",...a.length>0?{query:a}:null});return await this._fetchClerkApi("GET",n,h)}async inviteUser(e){let r=l("/v1/invitations");return this._fetchClerkApi("POST",r,t,JSON.stringify({email_address:e.emailAddress,public_metadata:{role:e.role,tags:e.tags},ignore_existing:!0}))}async verifyOAuthUser(e,r){let t=null;try{let a=new URL("/oauth/userinfo",e),n=await fetch(a,{method:"GET",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"}});return t=await n.json(),{id:s.parse(t).user_id}}catch(e){throw this._createError(e,t)}}async refreshToken(e,r,t,a){let s=null;try{let i=new URL("/oauth/token",e),o=await fetch(i,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"refresh_token",refresh_token:a,client_id:r,client_secret:t})});s=await o.json();let c=n.parse(s);return{accessToken:c.access_token,refreshToken:c.refresh_token,expirationTime:Date.now()/1e3+c.expires_in}}catch(e){throw this._createError(e,s)}}async revokeInvitation(e){return this._fetchClerkApi("POST",l(`/v1/invitations/${e}/revoke`),t)}async unbanUser(e){return this._fetchClerkApi("POST",l(`/v1/users/${e}/unban`),o)}async updateUser(e){let r=null;try{let t=l(`/v1/users/${e.id}`),a=await fetch(t,{method:"PATCH",headers:{Authorization:`Bearer ${this._clerkApiKey}`,"Content-Type":"application/json"},body:JSON.stringify({private_metadata:{role:e.role,tags:e.tags}})});if(200!==a.status)throw Error(`Failed to update user ${e.id}: ${a.statusText}`);return r=await a.json(),o.parse(r)}catch(e){throw this._createError(e,r)}}}
|