@happyrobot-ai/sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.d.ts +85 -0
- package/client.js +115 -0
- package/client.mjs +3 -0
- package/core/errors.d.ts +48 -0
- package/core/errors.js +82 -0
- package/core/errors.mjs +3 -0
- package/core/http.d.ts +26 -0
- package/core/http.js +189 -0
- package/core/http.mjs +3 -0
- package/core/pagination.d.ts +22 -0
- package/core/pagination.js +43 -0
- package/core/pagination.mjs +3 -0
- package/core/sse.d.ts +20 -0
- package/core/sse.js +104 -0
- package/core/sse.mjs +3 -0
- package/core/types.d.ts +50 -0
- package/core/types.js +6 -0
- package/core/types.mjs +3 -0
- package/helpers/index.d.ts +14 -0
- package/helpers/index.js +18 -0
- package/helpers/index.mjs +3 -0
- package/helpers/template-workflows.d.ts +49 -0
- package/helpers/template-workflows.js +46 -0
- package/helpers/template-workflows.mjs +3 -0
- package/helpers/trigger-and-wait.d.ts +37 -0
- package/helpers/trigger-and-wait.js +62 -0
- package/helpers/trigger-and-wait.mjs +3 -0
- package/helpers/voice-agent.d.ts +47 -0
- package/helpers/voice-agent.js +47 -0
- package/helpers/voice-agent.mjs +3 -0
- package/index.d.ts +75 -0
- package/index.js +90 -0
- package/index.mjs +3 -0
- package/package.json +42 -0
- package/resources/adversarial-suites.d.ts +42 -0
- package/resources/adversarial-suites.js +96 -0
- package/resources/adversarial-suites.mjs +3 -0
- package/resources/adversarial-tests.d.ts +36 -0
- package/resources/adversarial-tests.js +78 -0
- package/resources/adversarial-tests.mjs +3 -0
- package/resources/api-key.d.ts +23 -0
- package/resources/api-key.js +24 -0
- package/resources/api-key.mjs +3 -0
- package/resources/audit-remarks.d.ts +22 -0
- package/resources/audit-remarks.js +44 -0
- package/resources/audit-remarks.mjs +3 -0
- package/resources/billing.d.ts +25 -0
- package/resources/billing.js +34 -0
- package/resources/billing.mjs +3 -0
- package/resources/contacts.d.ts +40 -0
- package/resources/contacts.js +61 -0
- package/resources/contacts.mjs +3 -0
- package/resources/custom-evals.d.ts +28 -0
- package/resources/custom-evals.js +62 -0
- package/resources/custom-evals.mjs +3 -0
- package/resources/integrations.d.ts +95 -0
- package/resources/integrations.js +220 -0
- package/resources/integrations.mjs +3 -0
- package/resources/issues.d.ts +14 -0
- package/resources/issues.js +25 -0
- package/resources/issues.mjs +3 -0
- package/resources/knowledge-bases.d.ts +35 -0
- package/resources/knowledge-bases.js +68 -0
- package/resources/knowledge-bases.mjs +3 -0
- package/resources/mcp.d.ts +20 -0
- package/resources/mcp.js +42 -0
- package/resources/mcp.mjs +3 -0
- package/resources/messages.d.ts +17 -0
- package/resources/messages.js +37 -0
- package/resources/messages.mjs +3 -0
- package/resources/nodes.d.ts +50 -0
- package/resources/nodes.js +86 -0
- package/resources/nodes.mjs +3 -0
- package/resources/northstars.d.ts +29 -0
- package/resources/northstars.js +69 -0
- package/resources/northstars.mjs +3 -0
- package/resources/phone-numbers.d.ts +47 -0
- package/resources/phone-numbers.js +121 -0
- package/resources/phone-numbers.mjs +3 -0
- package/resources/runs.d.ts +31 -0
- package/resources/runs.js +71 -0
- package/resources/runs.mjs +3 -0
- package/resources/sessions.d.ts +36 -0
- package/resources/sessions.js +62 -0
- package/resources/sessions.mjs +3 -0
- package/resources/sip-trunks.d.ts +32 -0
- package/resources/sip-trunks.js +78 -0
- package/resources/sip-trunks.mjs +3 -0
- package/resources/usage.d.ts +27 -0
- package/resources/usage.js +70 -0
- package/resources/usage.mjs +3 -0
- package/resources/variables.d.ts +23 -0
- package/resources/variables.js +54 -0
- package/resources/variables.mjs +3 -0
- package/resources/versions.d.ts +38 -0
- package/resources/versions.js +90 -0
- package/resources/versions.mjs +3 -0
- package/resources/workflow-folders.d.ts +26 -0
- package/resources/workflow-folders.js +62 -0
- package/resources/workflow-folders.mjs +3 -0
- package/resources/workflows.d.ts +55 -0
- package/resources/workflows.js +134 -0
- package/resources/workflows.mjs +3 -0
package/core/sse.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Lightweight SSE (Server-Sent Events) stream parser.
|
|
4
|
+
*
|
|
5
|
+
* Consumes a `Response` body and yields typed `SSEEvent` objects.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.iterateSSE = iterateSSE;
|
|
9
|
+
/**
|
|
10
|
+
* Async generator that reads an SSE stream from a `Response` and yields
|
|
11
|
+
* parsed events. Comments and empty keep-alive lines are silently skipped.
|
|
12
|
+
*
|
|
13
|
+
* @param response - A fetch `Response` whose body is `text/event-stream`.
|
|
14
|
+
*/
|
|
15
|
+
async function* iterateSSE(response) {
|
|
16
|
+
const body = response.body;
|
|
17
|
+
if (!body)
|
|
18
|
+
return;
|
|
19
|
+
const reader = body.getReader();
|
|
20
|
+
const decoder = new TextDecoder();
|
|
21
|
+
let buffer = "";
|
|
22
|
+
let currentEvent = "message";
|
|
23
|
+
let currentData = "";
|
|
24
|
+
let currentId;
|
|
25
|
+
try {
|
|
26
|
+
while (true) {
|
|
27
|
+
const { done, value } = await reader.read();
|
|
28
|
+
if (done)
|
|
29
|
+
break;
|
|
30
|
+
buffer += decoder.decode(value, { stream: true });
|
|
31
|
+
// SSE events are separated by blank lines (\n\n)
|
|
32
|
+
const parts = buffer.split("\n");
|
|
33
|
+
buffer = parts.pop(); // keep incomplete line in buffer
|
|
34
|
+
for (const line of parts) {
|
|
35
|
+
if (line === "") {
|
|
36
|
+
// Blank line = end of event
|
|
37
|
+
if (currentData) {
|
|
38
|
+
try {
|
|
39
|
+
yield {
|
|
40
|
+
event: currentEvent,
|
|
41
|
+
data: JSON.parse(currentData),
|
|
42
|
+
...(currentId !== undefined && { id: currentId }),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// Non-JSON data — yield as raw string
|
|
47
|
+
yield {
|
|
48
|
+
event: currentEvent,
|
|
49
|
+
data: currentData,
|
|
50
|
+
...(currentId !== undefined && { id: currentId }),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Reset for next event
|
|
55
|
+
currentEvent = "message";
|
|
56
|
+
currentData = "";
|
|
57
|
+
currentId = undefined;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
// Skip comments
|
|
61
|
+
if (line.startsWith(":"))
|
|
62
|
+
continue;
|
|
63
|
+
const colonIdx = line.indexOf(":");
|
|
64
|
+
if (colonIdx === -1)
|
|
65
|
+
continue;
|
|
66
|
+
const field = line.slice(0, colonIdx);
|
|
67
|
+
// Strip optional leading space after colon per SSE spec
|
|
68
|
+
const val = line[colonIdx + 1] === " " ? line.slice(colonIdx + 2) : line.slice(colonIdx + 1);
|
|
69
|
+
switch (field) {
|
|
70
|
+
case "event":
|
|
71
|
+
currentEvent = val;
|
|
72
|
+
break;
|
|
73
|
+
case "data":
|
|
74
|
+
currentData += (currentData ? "\n" : "") + val;
|
|
75
|
+
break;
|
|
76
|
+
case "id":
|
|
77
|
+
currentId = val;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Flush any remaining event in the buffer
|
|
83
|
+
if (currentData) {
|
|
84
|
+
try {
|
|
85
|
+
yield {
|
|
86
|
+
event: currentEvent,
|
|
87
|
+
data: JSON.parse(currentData),
|
|
88
|
+
...(currentId !== undefined && { id: currentId }),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
yield {
|
|
93
|
+
event: currentEvent,
|
|
94
|
+
data: currentData,
|
|
95
|
+
...(currentId !== undefined && { id: currentId }),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
reader.releaseLock();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=sse.js.map
|
package/core/sse.mjs
ADDED
package/core/types.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration types for the HappyRobot SDK client.
|
|
3
|
+
*/
|
|
4
|
+
export interface ClientConfig {
|
|
5
|
+
/** API key (sk_live_... or sk_test_...). Required. */
|
|
6
|
+
apiKey: string;
|
|
7
|
+
/** Base URL of the API. Defaults to "https://platform.happyrobot.ai/api/v2". */
|
|
8
|
+
baseUrl?: string;
|
|
9
|
+
/** Request timeout in milliseconds. Defaults to 30000. */
|
|
10
|
+
timeout?: number;
|
|
11
|
+
/** Max retries on 429/5xx. Defaults to 2. Uses exponential backoff. */
|
|
12
|
+
maxRetries?: number;
|
|
13
|
+
/** Custom fetch implementation for testing or custom runtimes. */
|
|
14
|
+
fetch?: typeof globalThis.fetch;
|
|
15
|
+
}
|
|
16
|
+
export interface RequestConfig {
|
|
17
|
+
/** HTTP method. */
|
|
18
|
+
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
19
|
+
/** URL path relative to baseUrl (e.g. "/workflows"). */
|
|
20
|
+
path: string;
|
|
21
|
+
/** Query parameters (appended as URL search params). */
|
|
22
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
23
|
+
/** JSON request body. */
|
|
24
|
+
body?: unknown;
|
|
25
|
+
/** Additional headers. */
|
|
26
|
+
headers?: Record<string, string>;
|
|
27
|
+
/** Override timeout for this request. */
|
|
28
|
+
timeout?: number;
|
|
29
|
+
/** Override max retries for this request. */
|
|
30
|
+
maxRetries?: number;
|
|
31
|
+
}
|
|
32
|
+
/** Standard paginated response with offset-based pagination. */
|
|
33
|
+
export interface PaginatedResponse<T> {
|
|
34
|
+
data: T[];
|
|
35
|
+
pagination: PaginationMetadata;
|
|
36
|
+
}
|
|
37
|
+
export interface PaginationMetadata {
|
|
38
|
+
page: number;
|
|
39
|
+
page_size: number;
|
|
40
|
+
total_pages: number;
|
|
41
|
+
total_records: number;
|
|
42
|
+
has_next_page: boolean;
|
|
43
|
+
has_previous_page: boolean;
|
|
44
|
+
}
|
|
45
|
+
/** Standard list query parameters for offset-paginated endpoints. */
|
|
46
|
+
export interface PaginationQuery {
|
|
47
|
+
page?: number;
|
|
48
|
+
page_size?: number;
|
|
49
|
+
sort?: "asc" | "desc";
|
|
50
|
+
}
|
package/core/types.js
ADDED
package/core/types.mjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level convenience helpers.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { createVoiceAgent, triggerAndWait, createFromTemplate } from "@happyrobot/sdk/helpers";
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export { createVoiceAgent } from "./voice-agent";
|
|
10
|
+
export type { CreateVoiceAgentOptions, CreateVoiceAgentResult } from "./voice-agent";
|
|
11
|
+
export { triggerAndWait } from "./trigger-and-wait";
|
|
12
|
+
export type { TriggerAndWaitOptions, TriggerAndWaitResult } from "./trigger-and-wait";
|
|
13
|
+
export { createFromTemplate } from "./template-workflows";
|
|
14
|
+
export type { CreateFromTemplateOptions, CreateFromTemplateResult } from "./template-workflows";
|
package/helpers/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* High-level convenience helpers.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { createVoiceAgent, triggerAndWait, createFromTemplate } from "@happyrobot/sdk/helpers";
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.createFromTemplate = exports.triggerAndWait = exports.createVoiceAgent = void 0;
|
|
12
|
+
var voice_agent_1 = require("./voice-agent");
|
|
13
|
+
Object.defineProperty(exports, "createVoiceAgent", { enumerable: true, get: function () { return voice_agent_1.createVoiceAgent; } });
|
|
14
|
+
var trigger_and_wait_1 = require("./trigger-and-wait");
|
|
15
|
+
Object.defineProperty(exports, "triggerAndWait", { enumerable: true, get: function () { return trigger_and_wait_1.triggerAndWait; } });
|
|
16
|
+
var template_workflows_1 = require("./template-workflows");
|
|
17
|
+
Object.defineProperty(exports, "createFromTemplate", { enumerable: true, get: function () { return template_workflows_1.createFromTemplate; } });
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level helper: create a workflow from any template.
|
|
3
|
+
*/
|
|
4
|
+
import type { HappyRobotClient } from "../client";
|
|
5
|
+
import type { CreateWorkflowResponse, WorkflowPublishResponse } from "../types/workflows.types";
|
|
6
|
+
export interface CreateFromTemplateOptions {
|
|
7
|
+
/** Template identifier (e.g. "voice-agent", "whatsapp-agent", "email-agent"). */
|
|
8
|
+
template: string;
|
|
9
|
+
/** Display name for the workflow. */
|
|
10
|
+
name: string;
|
|
11
|
+
/** Agent system prompt. */
|
|
12
|
+
prompt?: string;
|
|
13
|
+
/** Agent initial message. */
|
|
14
|
+
initialMessage?: string;
|
|
15
|
+
/** LLM model override. */
|
|
16
|
+
model?: {
|
|
17
|
+
type: "static";
|
|
18
|
+
static: {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/** Additional template-specific inputs. */
|
|
24
|
+
inputs?: Record<string, unknown>;
|
|
25
|
+
/** Publish after creation. Defaults to false. */
|
|
26
|
+
publish?: boolean;
|
|
27
|
+
/** Target environment when publishing. Defaults to "production". */
|
|
28
|
+
environment?: "production" | "staging" | "development";
|
|
29
|
+
/** Folder ID. */
|
|
30
|
+
folderId?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface CreateFromTemplateResult {
|
|
33
|
+
workflow: CreateWorkflowResponse;
|
|
34
|
+
publishResult?: WorkflowPublishResponse;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create a workflow from any template with optional publishing.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const { workflow } = await createFromTemplate(client, {
|
|
42
|
+
* template: "email-agent",
|
|
43
|
+
* name: "Email Responder",
|
|
44
|
+
* prompt: "You handle customer emails...",
|
|
45
|
+
* publish: true,
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function createFromTemplate(client: HappyRobotClient, options: CreateFromTemplateOptions): Promise<CreateFromTemplateResult>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* High-level helper: create a workflow from any template.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createFromTemplate = createFromTemplate;
|
|
7
|
+
/**
|
|
8
|
+
* Create a workflow from any template with optional publishing.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const { workflow } = await createFromTemplate(client, {
|
|
13
|
+
* template: "email-agent",
|
|
14
|
+
* name: "Email Responder",
|
|
15
|
+
* prompt: "You handle customer emails...",
|
|
16
|
+
* publish: true,
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
async function createFromTemplate(client, options) {
|
|
21
|
+
const { template, name, prompt, initialMessage, model, inputs = {}, publish = false, environment = "production", folderId, } = options;
|
|
22
|
+
const workflow = await client.workflows.create({
|
|
23
|
+
name,
|
|
24
|
+
folder_id: folderId,
|
|
25
|
+
from_template: {
|
|
26
|
+
template,
|
|
27
|
+
inputs: {
|
|
28
|
+
agent_name: name,
|
|
29
|
+
prompt: {
|
|
30
|
+
prompt_md: prompt,
|
|
31
|
+
initial_message: initialMessage,
|
|
32
|
+
model,
|
|
33
|
+
},
|
|
34
|
+
...inputs,
|
|
35
|
+
},
|
|
36
|
+
}, // Template input shapes vary by template type
|
|
37
|
+
});
|
|
38
|
+
let publishResult;
|
|
39
|
+
if (publish && workflow.id) {
|
|
40
|
+
publishResult = await client.workflows.publish(workflow.id, {
|
|
41
|
+
environment,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return { workflow, publishResult };
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=template-workflows.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level helper: trigger a workflow run and poll until it completes.
|
|
3
|
+
*/
|
|
4
|
+
import type { HappyRobotClient } from "../client";
|
|
5
|
+
import type { RunDetail } from "../types/runs.types";
|
|
6
|
+
import type { SessionItem } from "../types/sessions.types";
|
|
7
|
+
export interface TriggerAndWaitOptions {
|
|
8
|
+
/** Workflow ID or slug. */
|
|
9
|
+
workflowId: string;
|
|
10
|
+
/** Trigger payload. */
|
|
11
|
+
payload?: Record<string, unknown>;
|
|
12
|
+
/** Target environment. */
|
|
13
|
+
environment?: "production" | "staging" | "development";
|
|
14
|
+
/** Maximum time to wait in milliseconds. Defaults to 300_000 (5 min). */
|
|
15
|
+
timeoutMs?: number;
|
|
16
|
+
/** Poll interval in milliseconds. Defaults to 2_000 (2 sec). */
|
|
17
|
+
pollIntervalMs?: number;
|
|
18
|
+
/** Fetch sessions when run completes. Defaults to true. */
|
|
19
|
+
fetchSessions?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface TriggerAndWaitResult {
|
|
22
|
+
run: RunDetail;
|
|
23
|
+
sessions: SessionItem[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Trigger a workflow run and poll until it reaches a terminal status.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const { run, sessions } = await triggerAndWait(client, {
|
|
31
|
+
* workflowId: "my-workflow",
|
|
32
|
+
* payload: { phone: "+1234567890" },
|
|
33
|
+
* timeoutMs: 300_000,
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function triggerAndWait(client: HappyRobotClient, options: TriggerAndWaitOptions): Promise<TriggerAndWaitResult>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* High-level helper: trigger a workflow run and poll until it completes.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.triggerAndWait = triggerAndWait;
|
|
7
|
+
const errors_1 = require("../core/errors");
|
|
8
|
+
const TERMINAL_STATUSES = new Set([
|
|
9
|
+
"completed",
|
|
10
|
+
"succeeded",
|
|
11
|
+
"failed",
|
|
12
|
+
"canceled",
|
|
13
|
+
"skipped",
|
|
14
|
+
]);
|
|
15
|
+
/**
|
|
16
|
+
* Trigger a workflow run and poll until it reaches a terminal status.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const { run, sessions } = await triggerAndWait(client, {
|
|
21
|
+
* workflowId: "my-workflow",
|
|
22
|
+
* payload: { phone: "+1234567890" },
|
|
23
|
+
* timeoutMs: 300_000,
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
async function triggerAndWait(client, options) {
|
|
28
|
+
const { workflowId, payload, environment = "production", timeoutMs = 300_000, pollIntervalMs = 2_000, fetchSessions = true, } = options;
|
|
29
|
+
// 1. Trigger the run
|
|
30
|
+
const { run_id } = await client.workflows.triggerRun(workflowId, {
|
|
31
|
+
payload,
|
|
32
|
+
environment,
|
|
33
|
+
});
|
|
34
|
+
if (!run_id) {
|
|
35
|
+
throw new Error("No run_id returned from trigger");
|
|
36
|
+
}
|
|
37
|
+
// 2. Poll until terminal
|
|
38
|
+
const deadline = Date.now() + timeoutMs;
|
|
39
|
+
while (Date.now() < deadline) {
|
|
40
|
+
const run = await client.runs.get(run_id);
|
|
41
|
+
if (TERMINAL_STATUSES.has(run.status)) {
|
|
42
|
+
// 3. Optionally fetch sessions
|
|
43
|
+
let sessions = [];
|
|
44
|
+
if (fetchSessions) {
|
|
45
|
+
try {
|
|
46
|
+
const sessionsResponse = await client.runs.getSessions(run_id);
|
|
47
|
+
sessions = sessionsResponse.data;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
// Sessions may not exist for non-voice runs
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return { run, sessions };
|
|
54
|
+
}
|
|
55
|
+
await sleep(pollIntervalMs);
|
|
56
|
+
}
|
|
57
|
+
throw new errors_1.TimeoutError(timeoutMs);
|
|
58
|
+
}
|
|
59
|
+
function sleep(ms) {
|
|
60
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=trigger-and-wait.js.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level helper: create a voice agent workflow end-to-end.
|
|
3
|
+
*/
|
|
4
|
+
import type { HappyRobotClient } from "../client";
|
|
5
|
+
import type { CreateWorkflowResponse, WorkflowPublishResponse } from "../types/workflows.types";
|
|
6
|
+
export interface CreateVoiceAgentOptions {
|
|
7
|
+
/** Display name for the workflow. */
|
|
8
|
+
name: string;
|
|
9
|
+
/** Template to use. Defaults to "voice-agent" (outbound). */
|
|
10
|
+
template?: "voice-agent" | "inbound-voice-agent";
|
|
11
|
+
/** Agent system prompt. */
|
|
12
|
+
prompt?: string;
|
|
13
|
+
/** Agent initial message. */
|
|
14
|
+
initialMessage?: string;
|
|
15
|
+
/** LLM model override (TemplatedValue format). */
|
|
16
|
+
model?: {
|
|
17
|
+
type: "static";
|
|
18
|
+
static: {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/** Whether to publish after creation. Defaults to false. */
|
|
24
|
+
publish?: boolean;
|
|
25
|
+
/** Target environment when publishing. Defaults to "production". */
|
|
26
|
+
environment?: "production" | "staging" | "development";
|
|
27
|
+
/** Folder to place the workflow in. */
|
|
28
|
+
folderId?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface CreateVoiceAgentResult {
|
|
31
|
+
workflow: CreateWorkflowResponse;
|
|
32
|
+
publishResult?: WorkflowPublishResponse;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create a voice agent workflow from a template with optional publishing.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const { workflow } = await createVoiceAgent(client, {
|
|
40
|
+
* name: "Sales Agent",
|
|
41
|
+
* prompt: "You are a helpful sales assistant...",
|
|
42
|
+
* initialMessage: "Hi, how can I help you today?",
|
|
43
|
+
* publish: true,
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function createVoiceAgent(client: HappyRobotClient, options: CreateVoiceAgentOptions): Promise<CreateVoiceAgentResult>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* High-level helper: create a voice agent workflow end-to-end.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createVoiceAgent = createVoiceAgent;
|
|
7
|
+
/**
|
|
8
|
+
* Create a voice agent workflow from a template with optional publishing.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const { workflow } = await createVoiceAgent(client, {
|
|
13
|
+
* name: "Sales Agent",
|
|
14
|
+
* prompt: "You are a helpful sales assistant...",
|
|
15
|
+
* initialMessage: "Hi, how can I help you today?",
|
|
16
|
+
* publish: true,
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
async function createVoiceAgent(client, options) {
|
|
21
|
+
const { name, template = "voice-agent", prompt, initialMessage, model, publish = false, environment = "production", folderId, } = options;
|
|
22
|
+
// 1. Create workflow from template
|
|
23
|
+
const workflow = await client.workflows.create({
|
|
24
|
+
name,
|
|
25
|
+
folder_id: folderId,
|
|
26
|
+
from_template: {
|
|
27
|
+
template,
|
|
28
|
+
inputs: {
|
|
29
|
+
agent_name: name,
|
|
30
|
+
prompt: {
|
|
31
|
+
prompt_md: prompt,
|
|
32
|
+
initial_message: initialMessage,
|
|
33
|
+
model,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
// 2. Optionally publish
|
|
39
|
+
let publishResult;
|
|
40
|
+
if (publish && workflow.id) {
|
|
41
|
+
publishResult = await client.workflows.publish(workflow.id, {
|
|
42
|
+
environment,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return { workflow, publishResult };
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=voice-agent.js.map
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @happyrobot/sdk — TypeScript SDK for the HappyRobot Public API.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { HappyRobotClient } from "@happyrobot/sdk";
|
|
7
|
+
*
|
|
8
|
+
* const client = new HappyRobotClient({ apiKey: "sk_live_..." });
|
|
9
|
+
*
|
|
10
|
+
* // List all workflows
|
|
11
|
+
* const { data } = await client.workflows.list();
|
|
12
|
+
*
|
|
13
|
+
* // Iterate all workflows across pages
|
|
14
|
+
* for await (const wf of client.workflows.listAll()) {
|
|
15
|
+
* console.log(wf.name);
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* // Trigger a run
|
|
19
|
+
* const { run_id } = await client.workflows.triggerRun("my-workflow", {
|
|
20
|
+
* payload: { phone: "+1234567890" },
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export { HappyRobotClient } from "./client";
|
|
25
|
+
export type { ClientConfig, RequestConfig, PaginatedResponse, PaginationMetadata, PaginationQuery } from "./core/types";
|
|
26
|
+
export { HappyRobotError, ApiError, AuthenticationError, NotFoundError, ValidationError, RateLimitError, TimeoutError, NetworkError, } from "./core/errors";
|
|
27
|
+
export type { ApiErrorBody } from "./core/errors";
|
|
28
|
+
export { paginate } from "./core/pagination";
|
|
29
|
+
export { iterateSSE } from "./core/sse";
|
|
30
|
+
export type { SSEEvent } from "./core/sse";
|
|
31
|
+
export { WorkflowsResource } from "./resources/workflows";
|
|
32
|
+
export { VersionsResource } from "./resources/versions";
|
|
33
|
+
export { NodesResource } from "./resources/nodes";
|
|
34
|
+
export type { TestNodeBody, TestNodeOutput, TestNodeResponse } from "./resources/nodes";
|
|
35
|
+
export { RunsResource } from "./resources/runs";
|
|
36
|
+
export { SessionsResource } from "./resources/sessions";
|
|
37
|
+
export { MessagesResource } from "./resources/messages";
|
|
38
|
+
export { VariablesResource } from "./resources/variables";
|
|
39
|
+
export { PhoneNumbersResource } from "./resources/phone-numbers";
|
|
40
|
+
export { SipTrunksResource } from "./resources/sip-trunks";
|
|
41
|
+
export { IntegrationsResource } from "./resources/integrations";
|
|
42
|
+
export { ContactsResource } from "./resources/contacts";
|
|
43
|
+
export { KnowledgeBasesResource } from "./resources/knowledge-bases";
|
|
44
|
+
export { WorkflowFoldersResource } from "./resources/workflow-folders";
|
|
45
|
+
export { MCPResource } from "./resources/mcp";
|
|
46
|
+
export { UsageResource } from "./resources/usage";
|
|
47
|
+
export { BillingResource } from "./resources/billing";
|
|
48
|
+
export { ApiKeyResource } from "./resources/api-key";
|
|
49
|
+
export { AdversarialSuitesResource } from "./resources/adversarial-suites";
|
|
50
|
+
export { AdversarialTestsResource } from "./resources/adversarial-tests";
|
|
51
|
+
export { NorthstarsResource } from "./resources/northstars";
|
|
52
|
+
export { CustomEvalsResource } from "./resources/custom-evals";
|
|
53
|
+
export { IssuesResource } from "./resources/issues";
|
|
54
|
+
export { AuditRemarksResource } from "./resources/audit-remarks";
|
|
55
|
+
export type * from "./types/workflows.types";
|
|
56
|
+
export type * from "./types/versions.types";
|
|
57
|
+
export type * from "./types/nodes.types";
|
|
58
|
+
export type * from "./types/runs.types";
|
|
59
|
+
export type * from "./types/sessions.types";
|
|
60
|
+
export type * from "./types/phone-numbers.types";
|
|
61
|
+
export type * from "./types/sip-trunks.types";
|
|
62
|
+
export type * from "./types/integrations.types";
|
|
63
|
+
export type * from "./types/contacts.types";
|
|
64
|
+
export type * from "./types/knowledge-bases.types";
|
|
65
|
+
export type * from "./types/usage.types";
|
|
66
|
+
export type * from "./types/variables.types";
|
|
67
|
+
export type * from "./types/messages.types";
|
|
68
|
+
export type * from "./types/mcp.types";
|
|
69
|
+
export type * from "./types/workflow-folders.types";
|
|
70
|
+
export type * from "./types/adversarial-suites.types";
|
|
71
|
+
export type * from "./types/adversarial-tests.types";
|
|
72
|
+
export type * from "./types/northstars.types";
|
|
73
|
+
export type * from "./types/custom-evals.types";
|
|
74
|
+
export type * from "./types/issues.types";
|
|
75
|
+
export type * from "./types/audit-remarks.types";
|