@firstflow/core 0.0.5

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/dist/index.mjs ADDED
@@ -0,0 +1,80 @@
1
+ import {
2
+ DEFAULT_FIRSTFLOW_BASE_URL,
3
+ FIRSTFLOW_SERVER_PACKAGE_VERSION,
4
+ getRuntime,
5
+ wrapClient
6
+ } from "./chunk-X3T7X4JQ.mjs";
7
+
8
+ // src/standalone.ts
9
+ function observe(input) {
10
+ const { firstflowAgentId, sessionId, userId, ...rest } = input;
11
+ getRuntime().observe({
12
+ agentId: firstflowAgentId,
13
+ conversationId: sessionId,
14
+ userId,
15
+ ...rest
16
+ });
17
+ }
18
+ function outcome(input) {
19
+ getRuntime().outcome({
20
+ conversationId: input.sessionId,
21
+ outcome: input.outcome,
22
+ intent: input.intent,
23
+ userId: input.userId
24
+ });
25
+ }
26
+ function feedback(input) {
27
+ getRuntime().feedback({
28
+ conversationId: input.sessionId,
29
+ rating: input.rating,
30
+ comment: input.comment,
31
+ messageId: input.messageId,
32
+ userId: input.userId
33
+ });
34
+ }
35
+ function track(args) {
36
+ getRuntime().track(args.firstflowAgentId, args.userId, args.event, args.properties);
37
+ }
38
+ function identify(args) {
39
+ getRuntime().identify(args.firstflowAgentId, args.userId, args.traits);
40
+ }
41
+ function trace(args) {
42
+ const { firstflowAgentId, ...input } = args;
43
+ getRuntime().trace(firstflowAgentId, input);
44
+ }
45
+
46
+ // src/agents.ts
47
+ async function listAccessibleAgents(opts) {
48
+ const base = (opts.baseUrl ?? DEFAULT_FIRSTFLOW_BASE_URL).replace(/\/$/, "");
49
+ const apiKey = opts.apiKey.trim();
50
+ if (!apiKey) return { agents: [], workspaceId: "", publishableKey: null };
51
+ const res = await fetch(`${base}/v1/agents/accessible`, {
52
+ method: "GET",
53
+ headers: { Authorization: `Bearer ${apiKey}` },
54
+ cache: "no-store"
55
+ });
56
+ if (!res.ok) {
57
+ const detail = await res.text().catch(() => "");
58
+ throw new Error(
59
+ `[Firstflow] listAccessibleAgents: HTTP ${res.status} \u2014 ${detail.slice(0, 200)}`
60
+ );
61
+ }
62
+ const json = await res.json();
63
+ return {
64
+ agents: (json.data ?? []).map((a) => ({ id: a.id, name: a.name ?? null })),
65
+ workspaceId: json.workspaceId ?? "",
66
+ publishableKey: json.publishableKey ?? null
67
+ };
68
+ }
69
+ export {
70
+ DEFAULT_FIRSTFLOW_BASE_URL,
71
+ FIRSTFLOW_SERVER_PACKAGE_VERSION,
72
+ feedback,
73
+ identify,
74
+ listAccessibleAgents,
75
+ observe,
76
+ outcome,
77
+ trace,
78
+ track,
79
+ wrapClient
80
+ };
@@ -0,0 +1,19 @@
1
+ import RealOpenAI from 'openai';
2
+
3
+ interface FirstflowRequestFields {
4
+ /** Agent this call is attributed to (primary routing key). Required to observe. */
5
+ firstflowAgentId?: string;
6
+ /** Session / conversation id for this call. Required to observe. */
7
+ sessionId?: string;
8
+ /** The end-user this call belongs to. Required to observe. */
9
+ userId?: string;
10
+ }
11
+ declare module "openai/resources/chat/completions/completions" {
12
+ interface ChatCompletionCreateParamsBase extends FirstflowRequestFields {
13
+ }
14
+ }
15
+
16
+ /** Drop-in `OpenAI` client with Firstflow observability built in. */
17
+ declare const OpenAI: typeof RealOpenAI;
18
+
19
+ export { OpenAI };
@@ -0,0 +1,19 @@
1
+ import RealOpenAI from 'openai';
2
+
3
+ interface FirstflowRequestFields {
4
+ /** Agent this call is attributed to (primary routing key). Required to observe. */
5
+ firstflowAgentId?: string;
6
+ /** Session / conversation id for this call. Required to observe. */
7
+ sessionId?: string;
8
+ /** The end-user this call belongs to. Required to observe. */
9
+ userId?: string;
10
+ }
11
+ declare module "openai/resources/chat/completions/completions" {
12
+ interface ChatCompletionCreateParamsBase extends FirstflowRequestFields {
13
+ }
14
+ }
15
+
16
+ /** Drop-in `OpenAI` client with Firstflow observability built in. */
17
+ declare const OpenAI: typeof RealOpenAI;
18
+
19
+ export { OpenAI };