@uniformdev/automations-sdk 20.50.2-alpha.109

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/LICENSE.txt ADDED
@@ -0,0 +1,2 @@
1
+ © 2026 Uniform Systems, Inc. All Rights Reserved.
2
+ See details of Uniform Systems, Inc. Master Subscription Agreement here: https://uniform.dev/eula
@@ -0,0 +1,108 @@
1
+ import { ApiClient, ClientOptions } from '@uniformdev/context/api';
2
+ import { UIMessage } from 'ai';
3
+
4
+ /**
5
+ * Options for {@link ScoutClient}.
6
+ *
7
+ * Construct from an automation's `context.uniformCredentials`.
8
+ */
9
+ interface ScoutClientOptions extends ClientOptions {
10
+ /** The Uniform project to invoke Scout in. */
11
+ projectId: string;
12
+ /**
13
+ * The Uniform AI API host where Scout runs.
14
+ *
15
+ * @default 'https://ai.uniform.global'
16
+ */
17
+ aiApiHost?: string;
18
+ }
19
+ /** Parameters for a Scout invocation. */
20
+ interface ScoutInvokeParams {
21
+ /**
22
+ * Stable thread id this turn belongs to. The caller owns it: generate one (e.g. `crypto.randomUUID()`)
23
+ * for a one-shot invocation, or reuse the same id across calls to continue a multi-turn conversation
24
+ * (history is kept server-side per thread).
25
+ */
26
+ threadId: string;
27
+ /**
28
+ * Conversation messages in the Vercel AI SDK {@link UIMessage} shape. The server takes the
29
+ * trailing entry as the new user turn; prior history is kept server-side per thread, so
30
+ * multi-turn callers can send just the new message.
31
+ */
32
+ messages: UIMessage[];
33
+ }
34
+ /** Aggregated result of {@link ScoutClient.invoke}. */
35
+ interface ScoutInvokeResult {
36
+ /** `completed` on success; `over-credit-limit` when the team is out of AI credits. */
37
+ outcome: 'completed' | 'skipped' | 'over-credit-limit';
38
+ /** The final assistant message text. */
39
+ text: string;
40
+ /** The full thread messages after the turn (UI message shape). */
41
+ messages: UIMessage[];
42
+ }
43
+ /**
44
+ * The raw HTTP request details for the headless Scout endpoint, for callers that want to drive
45
+ * the request themselves (e.g. hand to a streaming transport). See {@link ScoutClient.getRequest}.
46
+ */
47
+ interface ScoutRequest {
48
+ /** The fully-qualified endpoint URL (thread id baked in). */
49
+ url: string;
50
+ /** Auth + content-type headers. Does not set `accept`; the caller chooses JSON vs SSE. */
51
+ headers: Record<string, string>;
52
+ }
53
+ /**
54
+ * Client for invoking Scout (Uniform's AI agent) headlessly from automation code or other
55
+ * non-interactive callers. Runs a turn against Scout's autonomous server-side toolset under
56
+ * the caller's identity, consuming AI credits.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * import { ScoutClient } from '@uniformdev/automations-sdk/ai';
61
+ *
62
+ * const scout = new ScoutClient(context.uniformCredentials);
63
+ * const { text } = await scout.invoke({
64
+ * threadId: crypto.randomUUID(),
65
+ * messages: [{ id: crypto.randomUUID(), role: 'user', parts: [{ type: 'text', text: 'Review this entry for brand tone.' }] }],
66
+ * });
67
+ * ```
68
+ */
69
+ declare class ScoutClient extends ApiClient<ScoutClientOptions> {
70
+ #private;
71
+ constructor(options: ScoutClientOptions);
72
+ /**
73
+ * Invokes Scout and returns the aggregated result once the turn completes.
74
+ *
75
+ * This is the right fit for automations and other headless callers, where no user is watching
76
+ * output stream in. If you do need to forward incremental output to a chat surface (a Slack
77
+ * relay, a browser `useChat` app), don't reach for a bespoke client — the endpoint at
78
+ * `POST {aiApiHost}/projects/:projectId/threads/:threadId/messages` is a standard
79
+ * [Vercel AI SDK UI message stream](https://sdk.vercel.ai) backend when called with
80
+ * `Accept: text/event-stream`, so point the AI SDK's transport / `readUIMessageStream` at it.
81
+ *
82
+ * @param params - The thread id and the conversation messages for this turn.
83
+ */
84
+ invoke(params: ScoutInvokeParams): Promise<ScoutInvokeResult>;
85
+ /**
86
+ * Returns the endpoint URL + auth headers for a thread's headless Scout endpoint, so you can
87
+ * drive the request yourself.
88
+ *
89
+ * Use this to wire a streaming consumer without the SDK owning the transport: hand `url` and
90
+ * `headers` to the Vercel AI SDK's `DefaultChatTransport` and set `Accept:
91
+ * text/event-stream` on the request (the transport does not add it). The endpoint speaks the
92
+ * Vercel UI message stream protocol when called with that Accept header (otherwise it returns
93
+ * JSON, like {@link invoke}).
94
+ *
95
+ * @param threadId - The thread the request targets.
96
+ * @example
97
+ * ```ts
98
+ * const { url, headers } = scout.getRequest(threadId);
99
+ * const transport = new DefaultChatTransport({
100
+ * api: url,
101
+ * headers: { ...headers, accept: 'text/event-stream' },
102
+ * });
103
+ * ```
104
+ */
105
+ getRequest(threadId: string): ScoutRequest;
106
+ }
107
+
108
+ export { ScoutClient, type ScoutClientOptions, type ScoutInvokeParams, type ScoutInvokeResult, type ScoutRequest };
@@ -0,0 +1,78 @@
1
+ import {
2
+ __privateAdd,
3
+ __privateGet,
4
+ __privateMethod,
5
+ __privateSet
6
+ } from "../chunk-I6KKUHEY.mjs";
7
+
8
+ // src/ai/ScoutClient.ts
9
+ import { ApiClient } from "@uniformdev/context/api";
10
+ var DEFAULT_AI_HOST = "https://ai.uniform.global";
11
+ var _aiApiHost, _ScoutClient_instances, endpoint_fn;
12
+ var ScoutClient = class extends ApiClient {
13
+ constructor(options) {
14
+ var _a;
15
+ super(options);
16
+ __privateAdd(this, _ScoutClient_instances);
17
+ __privateAdd(this, _aiApiHost);
18
+ __privateSet(this, _aiApiHost, ((_a = options.aiApiHost) != null ? _a : DEFAULT_AI_HOST).replace(/\/+$/, ""));
19
+ }
20
+ /**
21
+ * Invokes Scout and returns the aggregated result once the turn completes.
22
+ *
23
+ * This is the right fit for automations and other headless callers, where no user is watching
24
+ * output stream in. If you do need to forward incremental output to a chat surface (a Slack
25
+ * relay, a browser `useChat` app), don't reach for a bespoke client — the endpoint at
26
+ * `POST {aiApiHost}/projects/:projectId/threads/:threadId/messages` is a standard
27
+ * [Vercel AI SDK UI message stream](https://sdk.vercel.ai) backend when called with
28
+ * `Accept: text/event-stream`, so point the AI SDK's transport / `readUIMessageStream` at it.
29
+ *
30
+ * @param params - The thread id and the conversation messages for this turn.
31
+ */
32
+ async invoke(params) {
33
+ return this.apiClient(new URL(__privateMethod(this, _ScoutClient_instances, endpoint_fn).call(this, params.threadId)), {
34
+ method: "POST",
35
+ body: JSON.stringify({ messages: params.messages })
36
+ });
37
+ }
38
+ /**
39
+ * Returns the endpoint URL + auth headers for a thread's headless Scout endpoint, so you can
40
+ * drive the request yourself.
41
+ *
42
+ * Use this to wire a streaming consumer without the SDK owning the transport: hand `url` and
43
+ * `headers` to the Vercel AI SDK's `DefaultChatTransport` and set `Accept:
44
+ * text/event-stream` on the request (the transport does not add it). The endpoint speaks the
45
+ * Vercel UI message stream protocol when called with that Accept header (otherwise it returns
46
+ * JSON, like {@link invoke}).
47
+ *
48
+ * @param threadId - The thread the request targets.
49
+ * @example
50
+ * ```ts
51
+ * const { url, headers } = scout.getRequest(threadId);
52
+ * const transport = new DefaultChatTransport({
53
+ * api: url,
54
+ * headers: { ...headers, accept: 'text/event-stream' },
55
+ * });
56
+ * ```
57
+ */
58
+ getRequest(threadId) {
59
+ const headers = { "content-type": "application/json" };
60
+ if (this.options.apiKey) {
61
+ headers["x-api-key"] = this.options.apiKey;
62
+ } else if (this.options.bearerToken) {
63
+ headers["authorization"] = `Bearer ${this.options.bearerToken}`;
64
+ }
65
+ return { url: __privateMethod(this, _ScoutClient_instances, endpoint_fn).call(this, threadId), headers };
66
+ }
67
+ };
68
+ _aiApiHost = new WeakMap();
69
+ _ScoutClient_instances = new WeakSet();
70
+ endpoint_fn = function(threadId) {
71
+ return new URL(
72
+ `/projects/${this.options.projectId}/threads/${threadId}/messages`,
73
+ __privateGet(this, _aiApiHost)
74
+ ).toString();
75
+ };
76
+ export {
77
+ ScoutClient
78
+ };