@salsita-ai/contracts 0.50.0-develop.bfba230ad7 → 0.50.0-develop.d6ed5efd42
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/README.md +1 -1
- package/dist/assistant/deployment-assistant.d.ts +5 -6
- package/dist/assistant/index.d.ts +2 -0
- package/dist/assistant/index.js +1 -1
- package/dist/assistant/tool-error.d.ts +30 -0
- package/dist/assistant/tool-error.js +1 -0
- package/dist/domain/deployments/deployment-domain.d.ts +2 -0
- package/dist/webhook/implementation/index.d.ts +1 -1
- package/dist/webhook/implementation/index.js +1 -1
- package/dist/webhook/implementation/webhook-api-types.d.ts +92 -0
- package/dist/webhook/implementation/webhook-api-types.js +1 -1
- package/dist/webhook/implementation/webhook-client.d.ts +2 -1
- package/dist/webhook/implementation/webhook-client.js +1 -1
- package/dist/webhook/implementation/webhook-routing.d.ts +3 -1
- package/dist/webhook/implementation/webhook-routing.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ There is no package-root export. Import from the path that owns the boundary; th
|
|
|
19
19
|
| `clerk` | Clerk backend client and services and the shared user, invitation, role, and token schemas. |
|
|
20
20
|
| `domain` | Branded deployment, customer, project, environment, configuration, and revision data: types, schemas, constructors, and the state values clients compare against. |
|
|
21
21
|
| `chat` | Chat completion and stream chunks, tool definitions, validation, speech, and embeddings. |
|
|
22
|
-
| `assistant` | Experimental assistant: shared client-tool definitions
|
|
22
|
+
| `assistant` | Experimental assistant: shared client-tool definitions, user-message metadata, server-recorded tool errors and the deployment webhook setup shape. |
|
|
23
23
|
| `webhook` | Webhook clients and building blocks, finalization tasks and resources, spreadsheet adapters. |
|
|
24
24
|
|
|
25
25
|
Runtime schemas and TypeScript types are kept aligned, so a value that passes the schema has the declared type.
|
|
@@ -13,8 +13,8 @@ export type AssistantModelTier = (typeof ASSISTANT_MODEL_TIERS)[number];
|
|
|
13
13
|
export type AssistantReasoningLevel = (typeof ASSISTANT_REASONING_LEVELS)[number];
|
|
14
14
|
/**
|
|
15
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
|
|
17
|
-
*
|
|
16
|
+
* deployment's assistant runs with. Authored in the application spec and resolved through its deployment webhook;
|
|
17
|
+
* the server has no defaults for any of the three.
|
|
18
18
|
*/
|
|
19
19
|
export interface AssistantAiSettings {
|
|
20
20
|
readonly provider: AssistantAiProvider;
|
|
@@ -35,10 +35,9 @@ export declare const AssistantAiSettings: z.ZodObject<{
|
|
|
35
35
|
reasoning: "high" | "low" | "medium";
|
|
36
36
|
}>;
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* deployment that registers none has no assistant.
|
|
38
|
+
* The setup returned by a deployment webhook: GraphQL SDL, SDK-generated prompt, integrator
|
|
39
|
+
* instructions and AI settings. The server caches validated answers and builds run prompts from
|
|
40
|
+
* them; a null setup means the assistant is unavailable for that session.
|
|
42
41
|
*/
|
|
43
42
|
export interface DeploymentAssistant {
|
|
44
43
|
readonly sdl: string;
|
|
@@ -4,3 +4,5 @@ export { AssistantGraphQLToolInput, applyTool, queryTool } from './graphql-tools
|
|
|
4
4
|
export type { AssistantGraphQLOperation } from './graphql-tools.js';
|
|
5
5
|
export type { AssistantAiProvider, AssistantModelTier, AssistantReasoningLevel } from './deployment-assistant.js';
|
|
6
6
|
export { AssistantMessageMetadata } from './message-metadata.js';
|
|
7
|
+
export { ASSISTANT_TOOL_ERROR_CODES, AssistantToolError } from './tool-error.js';
|
|
8
|
+
export type { AssistantToolErrorCode } from './tool-error.js';
|
package/dist/assistant/index.js
CHANGED
|
@@ -1 +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";
|
|
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";export{ASSISTANT_TOOL_ERROR_CODES,AssistantToolError}from"./tool-error.js";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Why the server recorded an error in place of the result of an assistant tool call:
|
|
4
|
+
* - `cancelled`: the user stopped the reply while the call was waiting for its result
|
|
5
|
+
* - `no_result`: the thread stopped waiting for the call when the user wrote a new message
|
|
6
|
+
* - `tool_budget`: the reply had used its tool calls for one user message, so the call was not run
|
|
7
|
+
*/
|
|
8
|
+
export declare const ASSISTANT_TOOL_ERROR_CODES: readonly ['cancelled', 'no_result', 'tool_budget'];
|
|
9
|
+
export type AssistantToolErrorCode = (typeof ASSISTANT_TOOL_ERROR_CODES)[number];
|
|
10
|
+
/**
|
|
11
|
+
* An error in place of the result of an assistant tool call. `error` is text for the model, in the
|
|
12
|
+
* `{ error }` form TanStack AI itself records for a tool that threw or was cancelled. `code` is set
|
|
13
|
+
* on the errors the server records and tells the assistant panel what to say to the user; it is
|
|
14
|
+
* read as any string, so a panel older than the server shows a code it does not know as a general
|
|
15
|
+
* failure.
|
|
16
|
+
*/
|
|
17
|
+
export interface AssistantToolError {
|
|
18
|
+
readonly error: string;
|
|
19
|
+
readonly code?: string | undefined;
|
|
20
|
+
}
|
|
21
|
+
export declare const AssistantToolError: z.ZodObject<{
|
|
22
|
+
error: z.ZodString;
|
|
23
|
+
code: z.ZodOptional<z.ZodString>;
|
|
24
|
+
}, "strip", z.ZodTypeAny, {
|
|
25
|
+
error: string;
|
|
26
|
+
code?: string | undefined;
|
|
27
|
+
}, {
|
|
28
|
+
error: string;
|
|
29
|
+
code?: string | undefined;
|
|
30
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{z as o}from"zod";export const ASSISTANT_TOOL_ERROR_CODES=["cancelled","no_result","tool_budget"];export const AssistantToolError=o.object({error:o.string(),code:o.string().optional()});
|
|
@@ -86,6 +86,7 @@ export interface Deployment {
|
|
|
86
86
|
readonly id: DeploymentId;
|
|
87
87
|
readonly environmentId: EnvironmentId;
|
|
88
88
|
readonly isActive: boolean;
|
|
89
|
+
readonly assistantEnabled: boolean;
|
|
89
90
|
readonly resourcesUrl: ResourceUrl;
|
|
90
91
|
readonly useAuthHook: boolean;
|
|
91
92
|
readonly lambdaWebhookUrl: LambdaWebhookUrl | null;
|
|
@@ -107,6 +108,7 @@ export interface NewDeployment {
|
|
|
107
108
|
readonly id: DeploymentId;
|
|
108
109
|
readonly environmentId: EnvironmentId;
|
|
109
110
|
readonly isActive: boolean;
|
|
111
|
+
readonly assistantEnabled: boolean;
|
|
110
112
|
readonly resourcesUrl: ResourceUrl;
|
|
111
113
|
readonly useAuthHook: boolean;
|
|
112
114
|
readonly lambdaWebhookUrl: LambdaWebhookUrl | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { routeWebhookRequests } from './webhook-routing.js';
|
|
2
2
|
export { TunneledWebhookRequest, TunneledWebhookResponse, WebhookTunnelPollRequest, WebhookTunnelPollResponse, WebhookTunnelRespondRequest, } from './webhook-tunnel-types.js';
|
|
3
3
|
export { WebhookClient, createUrlWebhookHttpClient, fetchWebhookHttpClient, type WebhookHttpClient, } from './webhook-client.js';
|
|
4
|
-
export { AuthHandlerResponse, AuthUserIdSource, RefreshPayload, CodePayload, AuthPayload, AnonymousPayload, FinalizeWebhookPayload, CallbackPayload, CallbackResponse, FetchBackendDataPayload, FetchBackendDataHandlerResponse, } from './webhook-api-types.js';
|
|
4
|
+
export { AssistantSetupPayload, AssistantSetupResponse, AuthHandlerResponse, AuthUserIdSource, RefreshPayload, CodePayload, AuthPayload, AnonymousPayload, FinalizeWebhookPayload, CallbackPayload, CallbackResponse, FetchBackendDataPayload, FetchBackendDataHandlerResponse, } from './webhook-api-types.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{routeWebhookRequests}from"./webhook-routing.js";export{TunneledWebhookRequest,TunneledWebhookResponse,WebhookTunnelPollRequest,WebhookTunnelPollResponse,WebhookTunnelRespondRequest}from"./webhook-tunnel-types.js";export{WebhookClient,createUrlWebhookHttpClient,fetchWebhookHttpClient}from"./webhook-client.js";export{AuthHandlerResponse,AuthUserIdSource,RefreshPayload,CodePayload,AuthPayload,AnonymousPayload,FinalizeWebhookPayload,CallbackPayload,CallbackResponse,FetchBackendDataPayload,FetchBackendDataHandlerResponse}from"./webhook-api-types.js";
|
|
1
|
+
export{routeWebhookRequests}from"./webhook-routing.js";export{TunneledWebhookRequest,TunneledWebhookResponse,WebhookTunnelPollRequest,WebhookTunnelPollResponse,WebhookTunnelRespondRequest}from"./webhook-tunnel-types.js";export{WebhookClient,createUrlWebhookHttpClient,fetchWebhookHttpClient}from"./webhook-client.js";export{AssistantSetupPayload,AssistantSetupResponse,AuthHandlerResponse,AuthUserIdSource,RefreshPayload,CodePayload,AuthPayload,AnonymousPayload,FinalizeWebhookPayload,CallbackPayload,CallbackResponse,FetchBackendDataPayload,FetchBackendDataHandlerResponse}from"./webhook-api-types.js";
|
|
@@ -300,3 +300,95 @@ export declare const FetchBackendDataHandlerResponse: z.ZodObject<{
|
|
|
300
300
|
}, {
|
|
301
301
|
backendData: Record<string, unknown>;
|
|
302
302
|
}>;
|
|
303
|
+
/** Session inputs used by the lambda to resolve the assistant setup. */
|
|
304
|
+
export declare const AssistantSetupPayload: z.ZodObject<{
|
|
305
|
+
deploymentId: z.ZodEffects<z.ZodString, DeploymentId, string>;
|
|
306
|
+
sessionRole: z.ZodNativeEnum<{
|
|
307
|
+
readonly Anonymous: 'anonymous';
|
|
308
|
+
readonly User: 'user';
|
|
309
|
+
readonly Admin: 'admin';
|
|
310
|
+
readonly SuperAdmin: 'superadmin';
|
|
311
|
+
}>;
|
|
312
|
+
sessionPayload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
313
|
+
sub: z.ZodOptional<z.ZodString>;
|
|
314
|
+
access: z.ZodNativeEnum<{
|
|
315
|
+
readonly Owner: 'o';
|
|
316
|
+
readonly ReadRevision: 'rr';
|
|
317
|
+
readonly Read: 'r';
|
|
318
|
+
}>;
|
|
319
|
+
}, "strip", z.ZodTypeAny, {
|
|
320
|
+
deploymentId: string & import("@salsita-ai/common/utils").Brand<"DeploymentId">;
|
|
321
|
+
sessionRole: "admin" | "anonymous" | "superadmin" | "user";
|
|
322
|
+
sessionPayload: Record<string, unknown>;
|
|
323
|
+
sub?: string | undefined;
|
|
324
|
+
access: "o" | "r" | "rr";
|
|
325
|
+
}, {
|
|
326
|
+
deploymentId: string;
|
|
327
|
+
sessionRole: "admin" | "anonymous" | "superadmin" | "user";
|
|
328
|
+
sessionPayload: Record<string, unknown>;
|
|
329
|
+
sub?: string | undefined;
|
|
330
|
+
access: "o" | "r" | "rr";
|
|
331
|
+
}>;
|
|
332
|
+
export type AssistantSetupPayload = z.infer<typeof AssistantSetupPayload>;
|
|
333
|
+
/** A deployment's assistant setup, or a session for which no assistant is available. */
|
|
334
|
+
export declare const AssistantSetupResponse: z.ZodObject<{
|
|
335
|
+
setup: z.ZodNullable<z.ZodObject<{
|
|
336
|
+
sdl: z.ZodString;
|
|
337
|
+
prompt: z.ZodString;
|
|
338
|
+
instructions: z.ZodOptional<z.ZodString>;
|
|
339
|
+
ai: z.ZodObject<{
|
|
340
|
+
provider: z.ZodEnum<["openai"]>;
|
|
341
|
+
model: z.ZodEnum<["frontier", "advanced", "balanced", "fast"]>;
|
|
342
|
+
reasoning: z.ZodEnum<["low", "medium", "high"]>;
|
|
343
|
+
}, "strict", z.ZodTypeAny, {
|
|
344
|
+
provider: "openai";
|
|
345
|
+
model: "advanced" | "balanced" | "fast" | "frontier";
|
|
346
|
+
reasoning: "high" | "low" | "medium";
|
|
347
|
+
}, {
|
|
348
|
+
provider: "openai";
|
|
349
|
+
model: "advanced" | "balanced" | "fast" | "frontier";
|
|
350
|
+
reasoning: "high" | "low" | "medium";
|
|
351
|
+
}>;
|
|
352
|
+
}, "strict", z.ZodTypeAny, {
|
|
353
|
+
sdl: string;
|
|
354
|
+
prompt: string;
|
|
355
|
+
instructions?: string | undefined;
|
|
356
|
+
ai: {
|
|
357
|
+
provider: "openai";
|
|
358
|
+
model: "advanced" | "balanced" | "fast" | "frontier";
|
|
359
|
+
reasoning: "high" | "low" | "medium";
|
|
360
|
+
};
|
|
361
|
+
}, {
|
|
362
|
+
sdl: string;
|
|
363
|
+
prompt: string;
|
|
364
|
+
instructions?: string | undefined;
|
|
365
|
+
ai: {
|
|
366
|
+
provider: "openai";
|
|
367
|
+
model: "advanced" | "balanced" | "fast" | "frontier";
|
|
368
|
+
reasoning: "high" | "low" | "medium";
|
|
369
|
+
};
|
|
370
|
+
}>>;
|
|
371
|
+
}, "strict", z.ZodTypeAny, {
|
|
372
|
+
setup: {
|
|
373
|
+
sdl: string;
|
|
374
|
+
prompt: string;
|
|
375
|
+
instructions?: string | undefined;
|
|
376
|
+
ai: {
|
|
377
|
+
provider: "openai";
|
|
378
|
+
model: "advanced" | "balanced" | "fast" | "frontier";
|
|
379
|
+
reasoning: "high" | "low" | "medium";
|
|
380
|
+
};
|
|
381
|
+
} | null;
|
|
382
|
+
}, {
|
|
383
|
+
setup: {
|
|
384
|
+
sdl: string;
|
|
385
|
+
prompt: string;
|
|
386
|
+
instructions?: string | undefined;
|
|
387
|
+
ai: {
|
|
388
|
+
provider: "openai";
|
|
389
|
+
model: "advanced" | "balanced" | "fast" | "frontier";
|
|
390
|
+
reasoning: "high" | "low" | "medium";
|
|
391
|
+
};
|
|
392
|
+
} | null;
|
|
393
|
+
}>;
|
|
394
|
+
export type AssistantSetupResponse = z.infer<typeof AssistantSetupResponse>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{z as o}from"zod";import{usingType as n}from"@salsita-ai/common/utils";import{SessionRole as
|
|
1
|
+
import{z as o}from"zod";import{usingType as n}from"@salsita-ai/common/utils";import{AccessLevel as e,SessionRole as t}from"../../api/index.js";import{DeploymentAssistant as r}from"../../assistant/index.js";import{ConfigurationId as s,DeploymentId as a,FrontendUrl as i,RevisionId as l}from"../../domain/index.js";import{CallLambdaBackResourceType as c}from"../tasks/index.js";export const CallbackPayload=o.object({replayData:o.record(o.unknown()),resources:o.record(o.object({type:o.literal(c.Link),link:o.string()}))});export const CallbackResponse=o.object({result:o.record(o.unknown()).optional()});export const AuthUserIdSource=o.enum(["clerk","custom"]);export const AuthHandlerResponse=o.discriminatedUnion("success",[o.object({success:o.literal(!0),data:o.record(o.unknown()),role:o.nativeEnum(t),refreshToken:o.string().optional(),expirationTime:o.number().optional(),scopes:o.array(o.string()).optional(),userId:o.string().optional(),userIdSource:AuthUserIdSource.optional()}),o.object({success:o.literal(!1)})]);export const RefreshPayload=o.object({type:o.literal("refresh"),refreshToken:o.string()});export const CodePayload=o.object({type:o.literal("code"),accessToken:o.string(),refreshToken:o.string().optional(),idToken:o.string().optional()});export const AnonymousPayload=o.object({type:o.literal("anonymous")});export const AuthPayload=o.union([RefreshPayload,CodePayload,AnonymousPayload]);export const FinalizeWebhookPayload=o.object({configurationId:o.string().transform(n(s)),revisionId:o.string().transform(n(l)),deploymentId:o.string().transform(n(a)),frontendUrl:o.string().transform(n(i)),rootEntityType:o.string(),entities:o.array(o.object({type:o.string(),id:o.string()}).and(o.record(o.unknown()))),modelVersion:o.number().positive(),data:o.record(o.unknown()),frontendData:o.record(o.unknown()).optional(),locale:o.string(),sessionRole:o.nativeEnum(t),sessionPayload:o.record(o.unknown()),publishedAdminRevisionPath:o.string().optional(),publishedChunkUrls:o.record(o.string()).optional(),chunksUploadUrl:o.string().optional(),connectedProviderAccessTokens:o.record(o.string()).optional()});export const FetchBackendDataPayload=o.object({deploymentId:o.string().transform(n(a)),frontendUrl:o.string().transform(n(i)),frontendData:o.record(o.unknown()).optional(),sessionRole:o.nativeEnum(t),sessionPayload:o.record(o.unknown()),publishedAdminRevisionPath:o.string().optional(),publishedChunkUrls:o.record(o.string()).optional()});export const FetchBackendDataHandlerResponse=o.object({backendData:o.record(o.unknown())});export const AssistantSetupPayload=o.object({deploymentId:o.string().transform(n(a)),sessionRole:o.nativeEnum(t),sessionPayload:o.record(o.unknown()),sub:o.string().optional(),access:o.nativeEnum(e)});export const AssistantSetupResponse=o.object({setup:r.nullable()}).strict();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ApplicationType } from '../../domain/index.js';
|
|
2
|
-
import { type CallbackPayload, CallbackResponse, type FetchBackendDataPayload, type FinalizeWebhookPayload } from './webhook-api-types.js';
|
|
2
|
+
import { type AssistantSetupPayload, AssistantSetupResponse, type CallbackPayload, CallbackResponse, type FetchBackendDataPayload, type FinalizeWebhookPayload } from './webhook-api-types.js';
|
|
3
3
|
export type WebhookHttpClient = (url: string, init: RequestInit) => Promise<Response>;
|
|
4
4
|
export declare const fetchWebhookHttpClient: WebhookHttpClient;
|
|
5
5
|
export declare const createUrlWebhookHttpClient: (baseUrl: string, httpClient?: WebhookHttpClient) => WebhookHttpClient;
|
|
@@ -79,6 +79,7 @@ export declare class WebhookClient {
|
|
|
79
79
|
resources: import("../index.js").FinalizeTaskResource<string>[];
|
|
80
80
|
}>;
|
|
81
81
|
callback: (payload: CallbackPayload<Record<string, unknown>, string>) => Promise<CallbackResponse<Record<string, unknown>>>;
|
|
82
|
+
assistantSetup: (payload: AssistantSetupPayload) => Promise<AssistantSetupResponse>;
|
|
82
83
|
fetchBackendData: (payload: FetchBackendDataPayload<Record<string, unknown>, Record<string, unknown>>) => Promise<{
|
|
83
84
|
backendData: Record<string, unknown>;
|
|
84
85
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{WebhookFinalizeTaskConfiguration as t}from"../tasks/index.js";import{
|
|
1
|
+
import{WebhookFinalizeTaskConfiguration as t}from"../tasks/index.js";import{AssistantSetupResponse as e,AuthHandlerResponse as a,CallbackResponse as o,FetchBackendDataHandlerResponse as i}from"./webhook-api-types.js";import{getAssistantSetupRoute as n,getAuthRoute as r,getCallbackRoute as s,getFetchBackendDataRoute as l,getFinalizeRoute as h}from"./webhook-routing.js";export const fetchWebhookHttpClient=(t,e)=>fetch(t,e);export const createUrlWebhookHttpClient=(t,e=fetchWebhookHttpClient)=>(a,o)=>e(`${t}${a}`,o);export class WebhookClient{_httpClient;constructor(t,e=fetchWebhookHttpClient){this._httpClient="string"==typeof t?createUrlWebhookHttpClient(t,e):t}handleRefreshFlow=async t=>{let e=await this._httpClient(r(),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"refresh",refreshToken:t})});if(!e.ok)throw Error(`Refresh webhook call failed: ${await e.text()}`);return a.parse(await e.json())};handleCodeFlow=async(t,e,o)=>{let i=await this._httpClient(r(),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"code",accessToken:t,refreshToken:e,idToken:o})});if(!i.ok)throw Error(`Refresh webhook call failed: ${await i.text()}`);return a.parse(await i.json())};handleAnonymousFlow=async()=>{let t=await this._httpClient(r(),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"anonymous"})});if(!t.ok)throw Error(`Refresh webhook call failed: ${await t.text()}`);return a.parse(await t.json())};finalize=async(e,a)=>{let o=await this._httpClient(h(a),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!o.ok)throw Error("Lambda call failed: "+await o.text());let i=await o.json();return t.parse(i)};callback=async t=>{let e=await this._httpClient(s(),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!e.ok)throw Error("Lambda call failed: "+await e.text());let a=await e.json();return o.parse(a)};assistantSetup=async t=>{let a=await this._httpClient(n(),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok)throw Error(`Assistant setup lambda call failed: ${await a.text()}`);return e.parse(await a.json())};fetchBackendData=async t=>{let e=await this._httpClient(l(),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!e.ok)throw Error("Lambda call failed: "+await e.text());return i.parse(await e.json())}}
|
|
@@ -3,7 +3,8 @@ import type { Logger } from '@salsita-ai/common/utils';
|
|
|
3
3
|
import { ApplicationType } from '../../domain/index.js';
|
|
4
4
|
import { type WebhookFinalizeTaskConfiguration } from '../tasks/index.js';
|
|
5
5
|
import type { AuthHandlerResponse, CallbackResponse, FetchBackendDataHandlerResponse } from './webhook-api-types.js';
|
|
6
|
-
import { AuthPayload, CallbackPayload, FetchBackendDataPayload, FinalizeWebhookPayload } from './webhook-api-types.js';
|
|
6
|
+
import { AssistantSetupPayload, AssistantSetupResponse, AuthPayload, CallbackPayload, FetchBackendDataPayload, FinalizeWebhookPayload } from './webhook-api-types.js';
|
|
7
|
+
export declare const getAssistantSetupRoute: () => string;
|
|
7
8
|
export declare const getAuthRoute: () => string;
|
|
8
9
|
export declare const getFinalizeRoute: (applicationType: ApplicationType) => string;
|
|
9
10
|
export declare const getCallbackRoute: () => string;
|
|
@@ -18,6 +19,7 @@ type AuthHandler = (body: AuthPayload, e: APIGatewayProxyEventV2) => Promise<Aut
|
|
|
18
19
|
type FetchBackendDataHandler = (body: FetchBackendDataPayload<Record<string, unknown>, Record<string, unknown>>, e: APIGatewayProxyEventV2) => Promise<FetchBackendDataHandlerResponse>;
|
|
19
20
|
export declare const routeWebhookRequests: (handlers: {
|
|
20
21
|
configurator?: {
|
|
22
|
+
onAssistantSetup?: (body: AssistantSetupPayload, e: APIGatewayProxyEventV2) => Promise<AssistantSetupResponse>;
|
|
21
23
|
onFetchBackendData?: FetchBackendDataHandler;
|
|
22
24
|
onCallback?: CallbackHandler;
|
|
23
25
|
onFinalize?: FinalizeHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{P as o,match as t}from"ts-pattern";import{ApplicationType as r}from"../../domain/index.js";import{validateTaskConfiguration as n}from"../tasks/index.js";import{
|
|
1
|
+
import{P as o,match as t}from"ts-pattern";import{ApplicationType as r}from"../../domain/index.js";import{validateTaskConfiguration as n}from"../tasks/index.js";import{AssistantSetupPayload as e,AssistantSetupResponse as i,AuthPayload as a,CallbackPayload as s,FetchBackendDataPayload as f,FinalizeWebhookPayload as u}from"./webhook-api-types.js";let c="assistantSetup",h="auth",d="finalize",p="callback",l="fetchBackendData";export const getAssistantSetupRoute=()=>`?o=${c}`;export const getAuthRoute=()=>`?o=${h}`;export const getFinalizeRoute=o=>`?o=${d}&t=${o}`;export const getCallbackRoute=()=>`?o=${p}`;export const getFetchBackendDataRoute=()=>`?o=${l}`;export const handleWebhookSafely=(o,t)=>async r=>{try{return await o(r)}catch(n){let o=`Webhook failed: ${n instanceof Error?n.message:"Unknown error"}`,r="object"==typeof n&&n instanceof Error?n:Error(o);return t.error(o,{},r),{statusCode:500,body:JSON.stringify({message:o})}}};export const routeWebhookRequests=(g,w)=>handleWebhookSafely(async y=>{if(!y.body)throw Error("No body found in the webhook event!");let b=JSON.parse(y.isBase64Encoded?Buffer.from(y.body,"base64").toString():y.body);return t(y.queryStringParameters?.o).with(c,async()=>{if(!g.configurator?.onAssistantSetup)throw Error("Assistant setup operation is not configured for this webhook!");let o=await g.configurator.onAssistantSetup(e.parse(b),y);return{statusCode:200,body:JSON.stringify(i.parse(o))}}).with(h,async()=>{if(w.info("Handling auth operation."),!g.onAuth)throw Error("Auth operation is not configured for this webhook!");let o=a.parse(b);return{statusCode:200,body:JSON.stringify(await g.onAuth(o,y))}}).with(p,async()=>{if(w.info("Handling configurator callback operation."),!g.configurator?.onCallback)throw Error("Auth operation is not configured for this webhook!");let o=s.parse(b);return{statusCode:200,body:JSON.stringify(await g.configurator.onCallback(o,y))}}).with(o.union(void 0,d),()=>t(y.queryStringParameters?.t).with(r.Admin,async()=>{if(w.info("Handling admin finalize operation."),!g.admin?.onFinalize)throw Error("Admin finalize operation is not configured for this webhook!");let o=u.parse(b),t=await g.admin.onFinalize(o,y);return n(t),{statusCode:200,body:JSON.stringify(t)}}).with(o.union(void 0,r.Configurator),async()=>{if(w.info("Handling configurator finalize operation."),!g.configurator?.onFinalize)throw Error("Configurator finalize operation is not configured for this webhook!");let o=u.parse(b),t=await g.configurator.onFinalize(o,y);return n(t),{statusCode:200,body:JSON.stringify(t)}}).otherwise(o=>{throw Error(`Can not parse application type - unknown type: ${o}!`)})).with(l,async()=>{if(w.info("Handling fetch backend data operation."),!g.configurator?.onFetchBackendData)throw Error("Fetch backend data operation is not configured for this webhook!");let o=f.parse(b);return{statusCode:200,body:JSON.stringify(await g.configurator.onFetchBackendData(o,y))}}).otherwise(o=>{throw Error(`Can not parse webhook operation - unknown operation: ${o}!`)})},w);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salsita-ai/contracts",
|
|
3
|
-
"version": "0.50.0-develop.
|
|
3
|
+
"version": "0.50.0-develop.d6ed5efd42",
|
|
4
4
|
"description": "Shared API, authentication, domain, chat, and webhook contracts for Phoenix.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"salsita",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"uuid": "14.0.0",
|
|
57
57
|
"valid-url": "1.0.9",
|
|
58
58
|
"zod": "3.25.76",
|
|
59
|
-
"@salsita-ai/common": "0.50.0-develop.
|
|
59
|
+
"@salsita-ai/common": "0.50.0-develop.d6ed5efd42"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@lingui/core": "5.9.5",
|