retell-utils 0.3.2 → 0.3.3

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.
@@ -0,0 +1,94 @@
1
+ import { z } from "zod";
2
+ /** Response engine variant: Retell-hosted LLM. */
3
+ export declare const ResponseEngineRetellLlmSchema: z.ZodObject<{
4
+ type: z.ZodLiteral<"retell-llm">;
5
+ llm_id: z.ZodString;
6
+ version: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
7
+ }, z.core.$strip>;
8
+ /** Response engine variant: custom (self-hosted) LLM. */
9
+ export declare const ResponseEngineCustomLlmSchema: z.ZodObject<{
10
+ type: z.ZodLiteral<"custom-llm">;
11
+ llm_websocket_url: z.ZodString;
12
+ }, z.core.$strip>;
13
+ /** Response engine variant: conversation flow. */
14
+ export declare const ResponseEngineConversationFlowSchema: z.ZodObject<{
15
+ type: z.ZodLiteral<"conversation-flow">;
16
+ conversation_flow_id: z.ZodString;
17
+ version: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
18
+ }, z.core.$strip>;
19
+ /**
20
+ * Discriminated union of all response engine types. Used in both voice and chat
21
+ * agent responses.
22
+ */
23
+ export declare const ResponseEngineSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
24
+ type: z.ZodLiteral<"retell-llm">;
25
+ llm_id: z.ZodString;
26
+ version: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
27
+ }, z.core.$strip>, z.ZodObject<{
28
+ type: z.ZodLiteral<"custom-llm">;
29
+ llm_websocket_url: z.ZodString;
30
+ }, z.core.$strip>, z.ZodObject<{
31
+ type: z.ZodLiteral<"conversation-flow">;
32
+ conversation_flow_id: z.ZodString;
33
+ version: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
34
+ }, z.core.$strip>], "type">;
35
+ /**
36
+ * Zod schema for a voice agent response from the Retell API. Validates
37
+ * structural fields (IDs, response engine, version) and passes through all
38
+ * other fields for forward compatibility.
39
+ */
40
+ export declare const VoiceAgentResponseSchema: z.ZodObject<{
41
+ agent_id: z.ZodString;
42
+ agent_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
43
+ response_engine: z.ZodDiscriminatedUnion<[z.ZodObject<{
44
+ type: z.ZodLiteral<"retell-llm">;
45
+ llm_id: z.ZodString;
46
+ version: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
47
+ }, z.core.$strip>, z.ZodObject<{
48
+ type: z.ZodLiteral<"custom-llm">;
49
+ llm_websocket_url: z.ZodString;
50
+ }, z.core.$strip>, z.ZodObject<{
51
+ type: z.ZodLiteral<"conversation-flow">;
52
+ conversation_flow_id: z.ZodString;
53
+ version: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
54
+ }, z.core.$strip>], "type">;
55
+ voice_id: z.ZodString;
56
+ version: z.ZodOptional<z.ZodNumber>;
57
+ is_published: z.ZodOptional<z.ZodBoolean>;
58
+ last_modification_timestamp: z.ZodNumber;
59
+ language: z.ZodOptional<z.ZodString>;
60
+ data_storage_setting: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
61
+ everything: "everything";
62
+ everything_except_pii: "everything_except_pii";
63
+ basic_attributes_only: "basic_attributes_only";
64
+ }>>>;
65
+ }, z.core.$loose>;
66
+ /**
67
+ * Zod schema for a chat agent response from the Retell API. Same philosophy as
68
+ * VoiceAgentResponseSchema: validate structural fields, passthrough the rest.
69
+ */
70
+ export declare const ChatAgentResponseSchema: z.ZodObject<{
71
+ agent_id: z.ZodString;
72
+ agent_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
73
+ response_engine: z.ZodDiscriminatedUnion<[z.ZodObject<{
74
+ type: z.ZodLiteral<"retell-llm">;
75
+ llm_id: z.ZodString;
76
+ version: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
77
+ }, z.core.$strip>, z.ZodObject<{
78
+ type: z.ZodLiteral<"custom-llm">;
79
+ llm_websocket_url: z.ZodString;
80
+ }, z.core.$strip>, z.ZodObject<{
81
+ type: z.ZodLiteral<"conversation-flow">;
82
+ conversation_flow_id: z.ZodString;
83
+ version: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
84
+ }, z.core.$strip>], "type">;
85
+ version: z.ZodOptional<z.ZodNumber>;
86
+ is_published: z.ZodOptional<z.ZodBoolean>;
87
+ last_modification_timestamp: z.ZodNumber;
88
+ language: z.ZodOptional<z.ZodString>;
89
+ data_storage_setting: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
90
+ everything: "everything";
91
+ everything_except_pii: "everything_except_pii";
92
+ basic_attributes_only: "basic_attributes_only";
93
+ }>>>;
94
+ }, z.core.$loose>;
package/dist/agent.js ADDED
@@ -0,0 +1,71 @@
1
+ import { z } from "zod";
2
+ import { DataStorageSettingSchema } from "./enums.js";
3
+ // ---------------------------------------------------------------------------
4
+ // Response engine (shared by voice and chat agents)
5
+ // ---------------------------------------------------------------------------
6
+ /** Response engine variant: Retell-hosted LLM. */
7
+ export const ResponseEngineRetellLlmSchema = z.object({
8
+ type: z.literal("retell-llm"),
9
+ llm_id: z.string(),
10
+ version: z.number().nullable().optional(),
11
+ });
12
+ /** Response engine variant: custom (self-hosted) LLM. */
13
+ export const ResponseEngineCustomLlmSchema = z.object({
14
+ type: z.literal("custom-llm"),
15
+ llm_websocket_url: z.string(),
16
+ });
17
+ /** Response engine variant: conversation flow. */
18
+ export const ResponseEngineConversationFlowSchema = z.object({
19
+ type: z.literal("conversation-flow"),
20
+ conversation_flow_id: z.string(),
21
+ version: z.number().nullable().optional(),
22
+ });
23
+ /**
24
+ * Discriminated union of all response engine types. Used in both voice and chat
25
+ * agent responses.
26
+ */
27
+ export const ResponseEngineSchema = z.discriminatedUnion("type", [
28
+ ResponseEngineRetellLlmSchema,
29
+ ResponseEngineCustomLlmSchema,
30
+ ResponseEngineConversationFlowSchema,
31
+ ]);
32
+ // ---------------------------------------------------------------------------
33
+ // Voice agent response
34
+ // ---------------------------------------------------------------------------
35
+ /**
36
+ * Zod schema for a voice agent response from the Retell API. Validates
37
+ * structural fields (IDs, response engine, version) and passes through all
38
+ * other fields for forward compatibility.
39
+ */
40
+ export const VoiceAgentResponseSchema = z
41
+ .object({
42
+ agent_id: z.string(),
43
+ agent_name: z.string().nullable().optional(),
44
+ response_engine: ResponseEngineSchema,
45
+ voice_id: z.string(),
46
+ version: z.number().optional(),
47
+ is_published: z.boolean().optional(),
48
+ last_modification_timestamp: z.number(),
49
+ language: z.string().optional(),
50
+ data_storage_setting: DataStorageSettingSchema.nullable().optional(),
51
+ })
52
+ .passthrough();
53
+ // ---------------------------------------------------------------------------
54
+ // Chat agent response
55
+ // ---------------------------------------------------------------------------
56
+ /**
57
+ * Zod schema for a chat agent response from the Retell API. Same philosophy as
58
+ * VoiceAgentResponseSchema: validate structural fields, passthrough the rest.
59
+ */
60
+ export const ChatAgentResponseSchema = z
61
+ .object({
62
+ agent_id: z.string(),
63
+ agent_name: z.string().nullable().optional(),
64
+ response_engine: ResponseEngineSchema,
65
+ version: z.number().optional(),
66
+ is_published: z.boolean().optional(),
67
+ last_modification_timestamp: z.number(),
68
+ language: z.string().optional(),
69
+ data_storage_setting: DataStorageSettingSchema.nullable().optional(),
70
+ })
71
+ .passthrough();
package/dist/flow.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Zod schema for a conversation flow response. Validates structural fields and
4
+ * passes through the rest (nodes, components, etc.) for forward compatibility.
5
+ */
6
+ export declare const ConversationFlowResponseSchema: z.ZodObject<{
7
+ conversation_flow_id: z.ZodString;
8
+ version: z.ZodNumber;
9
+ is_published: z.ZodOptional<z.ZodBoolean>;
10
+ global_prompt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
11
+ nodes: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{}, z.core.$loose>>>>;
12
+ }, z.core.$loose>;
package/dist/flow.js ADDED
@@ -0,0 +1,15 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Zod schema for a conversation flow response. Validates structural fields and
4
+ * passes through the rest (nodes, components, etc.) for forward compatibility.
5
+ */
6
+ export const ConversationFlowResponseSchema = z
7
+ .object({
8
+ conversation_flow_id: z.string(),
9
+ version: z.number(),
10
+ /** SDK types omit this, but the API returns it. */
11
+ is_published: z.boolean().optional(),
12
+ global_prompt: z.string().nullable().optional(),
13
+ nodes: z.array(z.looseObject({})).nullable().optional(),
14
+ })
15
+ .passthrough();
package/dist/index.d.ts CHANGED
@@ -8,3 +8,8 @@ export { createCallAnalysisSchema, createChatAnalysisSchema } from "./analysis.j
8
8
  export { type CallSchemaConfig, CallSchemas, callSchemaDefaults, createCallSchemas, } from "./call.js";
9
9
  export { type ChatSchemaConfig, ChatSchemas, chatSchemaDefaults, createChatSchemas, } from "./chat.js";
10
10
  export { WebhookSchemas, createWebhookSchemas } from "./webhook.js";
11
+ export { ChatAgentResponseSchema, ResponseEngineConversationFlowSchema, ResponseEngineCustomLlmSchema, ResponseEngineRetellLlmSchema, ResponseEngineSchema, VoiceAgentResponseSchema, } from "./agent.js";
12
+ export { LlmResponseSchema } from "./llm.js";
13
+ export { ConversationFlowResponseSchema } from "./flow.js";
14
+ export { InputMatchRuleSchema, TestCaseDefinitionSchema, TestCaseResponseEngineSchema, ToolMockSchema, } from "./test-case.js";
15
+ export { retellPagination } from "./pagination.js";
package/dist/index.js CHANGED
@@ -18,3 +18,13 @@ export { CallSchemas, callSchemaDefaults, createCallSchemas, } from "./call.js";
18
18
  export { ChatSchemas, chatSchemaDefaults, createChatSchemas, } from "./chat.js";
19
19
  // Webhook schemas + factory
20
20
  export { WebhookSchemas, createWebhookSchemas } from "./webhook.js";
21
+ // Agent config schemas
22
+ export { ChatAgentResponseSchema, ResponseEngineConversationFlowSchema, ResponseEngineCustomLlmSchema, ResponseEngineRetellLlmSchema, ResponseEngineSchema, VoiceAgentResponseSchema, } from "./agent.js";
23
+ // LLM config schemas
24
+ export { LlmResponseSchema } from "./llm.js";
25
+ // Conversation flow config schemas
26
+ export { ConversationFlowResponseSchema } from "./flow.js";
27
+ // Test case schemas
28
+ export { InputMatchRuleSchema, TestCaseDefinitionSchema, TestCaseResponseEngineSchema, ToolMockSchema, } from "./test-case.js";
29
+ // Pagination utility
30
+ export { retellPagination } from "./pagination.js";
package/dist/llm.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Zod schema for a Retell LLM response. Validates structural fields and passes
4
+ * through all other fields (tools, states, etc.) for forward compatibility.
5
+ */
6
+ export declare const LlmResponseSchema: z.ZodObject<{
7
+ llm_id: z.ZodString;
8
+ last_modification_timestamp: z.ZodNumber;
9
+ version: z.ZodOptional<z.ZodNumber>;
10
+ is_published: z.ZodOptional<z.ZodBoolean>;
11
+ general_prompt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
12
+ begin_message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
13
+ }, z.core.$loose>;
package/dist/llm.js ADDED
@@ -0,0 +1,16 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Zod schema for a Retell LLM response. Validates structural fields and passes
4
+ * through all other fields (tools, states, etc.) for forward compatibility.
5
+ */
6
+ export const LlmResponseSchema = z
7
+ .object({
8
+ llm_id: z.string(),
9
+ last_modification_timestamp: z.number(),
10
+ version: z.number().optional(),
11
+ /** SDK types omit this, but the API returns it. */
12
+ is_published: z.boolean().optional(),
13
+ general_prompt: z.string().nullable().optional(),
14
+ begin_message: z.string().nullable().optional(),
15
+ })
16
+ .passthrough();
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Fetches all pages from a paginated Retell API list endpoint. The Retell API
3
+ * uses cursor-based pagination where the last item's ID and version are passed
4
+ * as the cursor for the next page.
5
+ */
6
+ export declare function retellPagination<T>(
7
+ /** The list API call, receiving pagination options. */
8
+ op: (opts: {
9
+ limit?: number;
10
+ pagination_key?: string;
11
+ pagination_key_version?: number;
12
+ }) => Promise<T[]>,
13
+ /** The property name used as the pagination key (e.g. "agent_id", "llm_id"). */
14
+ idKey: keyof T & string, limit?: number): Promise<T[]>;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Fetches all pages from a paginated Retell API list endpoint. The Retell API
3
+ * uses cursor-based pagination where the last item's ID and version are passed
4
+ * as the cursor for the next page.
5
+ */
6
+ export async function retellPagination(
7
+ /** The list API call, receiving pagination options. */
8
+ op,
9
+ /** The property name used as the pagination key (e.g. "agent_id", "llm_id"). */
10
+ idKey, limit = 1000) {
11
+ const results = [];
12
+ let paginationKey;
13
+ let paginationKeyVersion;
14
+ while (true) {
15
+ const page = await op({
16
+ limit,
17
+ pagination_key: paginationKey,
18
+ pagination_key_version: paginationKeyVersion,
19
+ });
20
+ for (const item of page)
21
+ results.push(item);
22
+ if (page.length < limit)
23
+ break;
24
+ const lastItem = page.at(-1);
25
+ if (!lastItem)
26
+ break;
27
+ const id = lastItem[idKey];
28
+ if (typeof id !== "string")
29
+ break;
30
+ paginationKey = id;
31
+ const version = lastItem.version;
32
+ paginationKeyVersion = typeof version === "number" ? version : undefined;
33
+ }
34
+ return results;
35
+ }
@@ -0,0 +1,62 @@
1
+ import { z } from "zod";
2
+ /** Zod schema for input match rule types in test case tool mocks. */
3
+ export declare const InputMatchRuleSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
4
+ type: z.ZodLiteral<"any">;
5
+ }, z.core.$strip>, z.ZodObject<{
6
+ type: z.ZodLiteral<"partial_match">;
7
+ args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
8
+ }, z.core.$strip>], "type">;
9
+ /** Zod schema for tool mock configurations in test cases. */
10
+ export declare const ToolMockSchema: z.ZodObject<{
11
+ tool_name: z.ZodString;
12
+ input_match_rule: z.ZodDiscriminatedUnion<[z.ZodObject<{
13
+ type: z.ZodLiteral<"any">;
14
+ }, z.core.$strip>, z.ZodObject<{
15
+ type: z.ZodLiteral<"partial_match">;
16
+ args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
17
+ }, z.core.$strip>], "type">;
18
+ output: z.ZodString;
19
+ result: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
20
+ }, z.core.$strip>;
21
+ /** Zod schema for response engine references in test cases. */
22
+ export declare const TestCaseResponseEngineSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
23
+ type: z.ZodLiteral<"retell-llm">;
24
+ llm_id: z.ZodString;
25
+ version: z.ZodOptional<z.ZodNumber>;
26
+ }, z.core.$strip>, z.ZodObject<{
27
+ type: z.ZodLiteral<"conversation-flow">;
28
+ conversation_flow_id: z.ZodString;
29
+ version: z.ZodOptional<z.ZodNumber>;
30
+ }, z.core.$strip>], "type">;
31
+ /** Zod schema for a test case definition from the Retell API. */
32
+ export declare const TestCaseDefinitionSchema: z.ZodObject<{
33
+ test_case_definition_id: z.ZodString;
34
+ name: z.ZodString;
35
+ response_engine: z.ZodDiscriminatedUnion<[z.ZodObject<{
36
+ type: z.ZodLiteral<"retell-llm">;
37
+ llm_id: z.ZodString;
38
+ version: z.ZodOptional<z.ZodNumber>;
39
+ }, z.core.$strip>, z.ZodObject<{
40
+ type: z.ZodLiteral<"conversation-flow">;
41
+ conversation_flow_id: z.ZodString;
42
+ version: z.ZodOptional<z.ZodNumber>;
43
+ }, z.core.$strip>], "type">;
44
+ dynamic_variables: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
45
+ metrics: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString>>>;
46
+ user_prompt: z.ZodString;
47
+ creation_timestamp: z.ZodNumber;
48
+ user_modified_timestamp: z.ZodNumber;
49
+ type: z.ZodLiteral<"simulation">;
50
+ tool_mocks: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
51
+ tool_name: z.ZodString;
52
+ input_match_rule: z.ZodDiscriminatedUnion<[z.ZodObject<{
53
+ type: z.ZodLiteral<"any">;
54
+ }, z.core.$strip>, z.ZodObject<{
55
+ type: z.ZodLiteral<"partial_match">;
56
+ args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
57
+ }, z.core.$strip>], "type">;
58
+ output: z.ZodString;
59
+ result: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
60
+ }, z.core.$strip>>>>;
61
+ llm_model: z.ZodString;
62
+ }, z.core.$strip>;
@@ -0,0 +1,43 @@
1
+ import { z } from "zod";
2
+ /** Zod schema for input match rule types in test case tool mocks. */
3
+ export const InputMatchRuleSchema = z.discriminatedUnion("type", [
4
+ z.object({ type: z.literal("any") }),
5
+ z.object({
6
+ type: z.literal("partial_match"),
7
+ args: z.record(z.string(), z.unknown()),
8
+ }),
9
+ ]);
10
+ /** Zod schema for tool mock configurations in test cases. */
11
+ export const ToolMockSchema = z.object({
12
+ tool_name: z.string(),
13
+ input_match_rule: InputMatchRuleSchema,
14
+ output: z.string(),
15
+ result: z.boolean().nullable().optional(),
16
+ });
17
+ /** Zod schema for response engine references in test cases. */
18
+ export const TestCaseResponseEngineSchema = z.discriminatedUnion("type", [
19
+ z.object({
20
+ type: z.literal("retell-llm"),
21
+ llm_id: z.string(),
22
+ version: z.number().optional(),
23
+ }),
24
+ z.object({
25
+ type: z.literal("conversation-flow"),
26
+ conversation_flow_id: z.string(),
27
+ version: z.number().optional(),
28
+ }),
29
+ ]);
30
+ /** Zod schema for a test case definition from the Retell API. */
31
+ export const TestCaseDefinitionSchema = z.object({
32
+ test_case_definition_id: z.string(),
33
+ name: z.string(),
34
+ response_engine: TestCaseResponseEngineSchema,
35
+ dynamic_variables: z.record(z.string(), z.unknown()).optional().default({}),
36
+ metrics: z.array(z.string()).optional().default([]),
37
+ user_prompt: z.string(),
38
+ creation_timestamp: z.number(),
39
+ user_modified_timestamp: z.number(),
40
+ type: z.literal("simulation"),
41
+ tool_mocks: z.array(ToolMockSchema).optional().default([]),
42
+ llm_model: z.string(),
43
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "retell-utils",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Type-safe Zod schemas for Retell AI API resources with lifecycle-aware discriminated unions and generic customization",
5
5
  "type": "module",
6
6
  "zshy": {
@@ -17,8 +17,8 @@
17
17
  "test": "bun test",
18
18
  "prepublishOnly": "bun run build"
19
19
  },
20
- "peerDependencies": {
21
- "zod": "^4.0.0"
20
+ "dependencies": {
21
+ "zod": "^4.3.5"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/bun": "latest",
@@ -27,7 +27,6 @@
27
27
  "prettier": "latest",
28
28
  "prettier-plugin-jsdoc": "^1.8.0",
29
29
  "typescript": "^5.8.3",
30
- "zod": "^4.3.5",
31
30
  "zshy": "^0.7.0"
32
31
  },
33
32
  "license": "MIT",