@trayai/helix-sdk 1.14.0 → 1.16.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/CHANGELOG.md +54 -0
- package/README.md +15 -5
- package/dist/broker/index.d.ts +4 -27
- package/dist/chunk-TYQ5RKIZ.js +7 -0
- package/dist/define-agent-B6KPsK4S.d.ts +488 -0
- package/dist/index.d.ts +9 -8
- package/dist/index.js +3 -3
- package/dist/internal/index.d.ts +4 -4
- package/dist/internal/index.js +1 -1
- package/dist/region-schema-DAE9PT3S.d.ts +35 -0
- package/dist/testing/index.d.ts +1 -2
- package/dist/{types-BSbvztCi.d.ts → types-c1QXQC1s.d.ts} +33 -3
- package/package.json +3 -3
- package/dist/chunk-GMEVZH35.js +0 -7
- package/dist/define-agent-BEUgQ_5-.d.ts +0 -911
- package/dist/region-schema-COfWyGI9.d.ts +0 -9
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { H as HelixSchema, P as PlatformContext, I as InferSchemaOutput } from './types-c1QXQC1s.js';
|
|
3
|
+
|
|
4
|
+
interface SdkRuntimeConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Execution mode. `"lambda"` is set via `setSdkConfig({ mode: "lambda", ... })`
|
|
7
|
+
* before the first handler invocation. `"dev"` is the default for `helix dev`
|
|
8
|
+
* and local invocations.
|
|
9
|
+
*/
|
|
10
|
+
mode: "lambda" | "dev";
|
|
11
|
+
/**
|
|
12
|
+
* Execution ID for the current invocation. Set via `setSdkConfig(...)` at
|
|
13
|
+
* handler entry in lambda mode. In `dev` mode, define-function falls back to
|
|
14
|
+
* the `x-tray-execution-id` header (or a random UUID).
|
|
15
|
+
*/
|
|
16
|
+
executionId?: string;
|
|
17
|
+
/**
|
|
18
|
+
* User ID for the current invocation. Set via `setSdkConfig(...)` at handler
|
|
19
|
+
* entry in lambda mode. In `dev` mode, define-function reads from the
|
|
20
|
+
* `x-tray-user-id` header.
|
|
21
|
+
*/
|
|
22
|
+
userId?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Email of the calling user for the current invocation. Set via
|
|
25
|
+
* `setSdkConfig(...)` at handler entry in lambda mode. In `dev` mode,
|
|
26
|
+
* define-function reads from the `x-tray-user-email` header. Only exposed
|
|
27
|
+
* on `ctx.identity` when `userId` is also set.
|
|
28
|
+
*/
|
|
29
|
+
userEmail?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Display name of the calling user for the current invocation. Set via
|
|
32
|
+
* `setSdkConfig(...)` at handler entry in lambda mode. In `dev` mode,
|
|
33
|
+
* define-function reads from the `x-tray-user-name` header. Only exposed
|
|
34
|
+
* on `ctx.identity` when `userId` is also set.
|
|
35
|
+
*/
|
|
36
|
+
userName?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Deployment ID for the current invocation. Set via `setSdkConfig(...)` at
|
|
39
|
+
* handler entry. Only meaningful in `lambda` mode; `dev` mode has no
|
|
40
|
+
* deployment concept yet.
|
|
41
|
+
*/
|
|
42
|
+
deploymentId?: string | null;
|
|
43
|
+
/**
|
|
44
|
+
* Running dev server's own base URL (e.g. `http://localhost:3000`). Set by
|
|
45
|
+
* the CLI's `sdk-context` Nitro plugin in `dev` mode so `ctx.files()` can
|
|
46
|
+
* build local signed URLs pointing at `/_helix/files/**`. Absent in `lambda`
|
|
47
|
+
* mode — production signed URLs point at the platform API host instead.
|
|
48
|
+
*/
|
|
49
|
+
devServerUrl?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Absolute path to the project root in `dev` mode, set by the CLI's
|
|
52
|
+
* `sdk-context` Nitro plugin. Used by `ctx.files()`'s local dev store to
|
|
53
|
+
* resolve `.helix/files/` on disk. Absent in `lambda` mode.
|
|
54
|
+
*/
|
|
55
|
+
projectRoot?: string;
|
|
56
|
+
/**
|
|
57
|
+
* The calling execution's id, set via `setSdkConfig(...)` only for a
|
|
58
|
+
* function-call-triggered invocation (`ctx.callFunctionAsync`, SUR-929).
|
|
59
|
+
* The shim explicitly clears this (passes `undefined`) on every other
|
|
60
|
+
* invocation kind so a warm container never leaks a prior call's parentage.
|
|
61
|
+
*/
|
|
62
|
+
parentExecutionId?: string | null;
|
|
63
|
+
}
|
|
64
|
+
interface BrokerSecrets {
|
|
65
|
+
internalJwt?: string;
|
|
66
|
+
helixExecutionJwt?: string;
|
|
67
|
+
devToken?: string;
|
|
68
|
+
}
|
|
69
|
+
interface SdkConfigInput extends Partial<SdkRuntimeConfig>, BrokerSecrets {
|
|
70
|
+
}
|
|
71
|
+
declare function setSdkConfig(options: SdkConfigInput): void;
|
|
72
|
+
declare function getSdkConfig(): Readonly<SdkRuntimeConfig>;
|
|
73
|
+
|
|
74
|
+
declare const projectIdSchema: z.ZodGUID;
|
|
75
|
+
declare const workspaceIdSchema: z.ZodString;
|
|
76
|
+
/**
|
|
77
|
+
* Agent session storage (helix-spec 14 → Sessions & Memory → Pluggable
|
|
78
|
+
* Backend). v1 supports only the bring-your-own-DynamoDB backend — the
|
|
79
|
+
* managed Helix session store does not exist yet, so `store: "dynamodb"` is
|
|
80
|
+
* currently the only durable option (in-memory otherwise). The table is
|
|
81
|
+
* accessed through the credentials broker with the named authentication's
|
|
82
|
+
* AWS credentials; no keys in the runtime.
|
|
83
|
+
*/
|
|
84
|
+
declare const agentSessionsSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
85
|
+
store: z.ZodLiteral<"managed">;
|
|
86
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
87
|
+
store: z.ZodLiteral<"dynamodb">;
|
|
88
|
+
auth: z.ZodString;
|
|
89
|
+
table: z.ZodString;
|
|
90
|
+
region: z.ZodString;
|
|
91
|
+
}, z.core.$strip>], "store">;
|
|
92
|
+
type AgentSessionsConfig = z.infer<typeof agentSessionsSchema>;
|
|
93
|
+
/**
|
|
94
|
+
* AI provider declaration (helix-spec 11). The Vercel AI SDK builds
|
|
95
|
+
* provider-native requests client-side, so `ctx.ai(alias)` must know which
|
|
96
|
+
* `@ai-sdk/*` package serves the alias BEFORE any request exists — and
|
|
97
|
+
* platform authentications carry no service identifier, so the project
|
|
98
|
+
* declares it here: `aiProviders: { <authAlias>: "<service>" }`. The
|
|
99
|
+
* `openai-compatible` service (self-hosted vLLM, Ollama, …) additionally
|
|
100
|
+
* needs the endpoint base URL, so it uses the object form. `bedrock` likewise
|
|
101
|
+
* needs the object form: the provider package derives the regional runtime
|
|
102
|
+
* endpoint (`bedrock-runtime.<region>.amazonaws.com`) from `region`, or takes
|
|
103
|
+
* `baseUrl` verbatim for VPC / custom endpoints.
|
|
104
|
+
*
|
|
105
|
+
* `baseUrl` must be https: every `ctx.ai` request egresses through the
|
|
106
|
+
* credentials broker's raw forward proxy, and `createBrokerFetch` rejects
|
|
107
|
+
* non-https destinations unconditionally (no dev/local exception) — so an
|
|
108
|
+
* http endpoint (a bare local Ollama/vLLM instance, say) would load fine here
|
|
109
|
+
* and then fail on every request. Catching it in the schema turns that into
|
|
110
|
+
* one clear config error instead of a confusing first-call failure.
|
|
111
|
+
*/
|
|
112
|
+
declare const AI_SERVICES: readonly ["openai", "anthropic", "google", "mistral", "cohere", "bedrock", "openai-compatible"];
|
|
113
|
+
type AiService = (typeof AI_SERVICES)[number];
|
|
114
|
+
declare const aiProviderEntrySchema: z.ZodUnion<readonly [z.ZodEnum<{
|
|
115
|
+
openai: "openai";
|
|
116
|
+
anthropic: "anthropic";
|
|
117
|
+
google: "google";
|
|
118
|
+
mistral: "mistral";
|
|
119
|
+
cohere: "cohere";
|
|
120
|
+
}>, z.ZodObject<{
|
|
121
|
+
service: z.ZodEnum<{
|
|
122
|
+
openai: "openai";
|
|
123
|
+
anthropic: "anthropic";
|
|
124
|
+
google: "google";
|
|
125
|
+
mistral: "mistral";
|
|
126
|
+
cohere: "cohere";
|
|
127
|
+
bedrock: "bedrock";
|
|
128
|
+
"openai-compatible": "openai-compatible";
|
|
129
|
+
}>;
|
|
130
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
131
|
+
region: z.ZodOptional<z.ZodString>;
|
|
132
|
+
}, z.core.$strip>]>;
|
|
133
|
+
type AiProviderEntry = z.infer<typeof aiProviderEntrySchema>;
|
|
134
|
+
declare const trayConfigSchema: z.ZodPipe<z.ZodObject<{
|
|
135
|
+
name: z.ZodString;
|
|
136
|
+
projectId: z.ZodOptional<z.ZodGUID>;
|
|
137
|
+
workspaceId: z.ZodOptional<z.ZodString>;
|
|
138
|
+
region: z.ZodOptional<z.ZodString>;
|
|
139
|
+
env: z.ZodOptional<z.ZodLiteral<"production">>;
|
|
140
|
+
authentications: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
141
|
+
config: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
142
|
+
agentSessions: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
143
|
+
store: z.ZodLiteral<"managed">;
|
|
144
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
145
|
+
store: z.ZodLiteral<"dynamodb">;
|
|
146
|
+
auth: z.ZodString;
|
|
147
|
+
table: z.ZodString;
|
|
148
|
+
region: z.ZodString;
|
|
149
|
+
}, z.core.$strip>], "store">>;
|
|
150
|
+
aiProviders: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodEnum<{
|
|
151
|
+
openai: "openai";
|
|
152
|
+
anthropic: "anthropic";
|
|
153
|
+
google: "google";
|
|
154
|
+
mistral: "mistral";
|
|
155
|
+
cohere: "cohere";
|
|
156
|
+
}>, z.ZodObject<{
|
|
157
|
+
service: z.ZodEnum<{
|
|
158
|
+
openai: "openai";
|
|
159
|
+
anthropic: "anthropic";
|
|
160
|
+
google: "google";
|
|
161
|
+
mistral: "mistral";
|
|
162
|
+
cohere: "cohere";
|
|
163
|
+
bedrock: "bedrock";
|
|
164
|
+
"openai-compatible": "openai-compatible";
|
|
165
|
+
}>;
|
|
166
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
167
|
+
region: z.ZodOptional<z.ZodString>;
|
|
168
|
+
}, z.core.$strip>]>>>;
|
|
169
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
170
|
+
region: string;
|
|
171
|
+
name: string;
|
|
172
|
+
authentications: Record<string, string>;
|
|
173
|
+
config: Record<string, unknown>;
|
|
174
|
+
projectId?: string | undefined;
|
|
175
|
+
workspaceId?: string | undefined;
|
|
176
|
+
agentSessions?: {
|
|
177
|
+
store: "managed";
|
|
178
|
+
} | {
|
|
179
|
+
store: "dynamodb";
|
|
180
|
+
auth: string;
|
|
181
|
+
table: string;
|
|
182
|
+
region: string;
|
|
183
|
+
} | undefined;
|
|
184
|
+
aiProviders?: Record<string, "openai" | "anthropic" | "google" | "mistral" | "cohere" | {
|
|
185
|
+
service: "openai" | "anthropic" | "google" | "mistral" | "cohere" | "bedrock" | "openai-compatible";
|
|
186
|
+
baseUrl?: string | undefined;
|
|
187
|
+
region?: string | undefined;
|
|
188
|
+
}> | undefined;
|
|
189
|
+
}, {
|
|
190
|
+
name: string;
|
|
191
|
+
authentications: Record<string, string>;
|
|
192
|
+
config: Record<string, unknown>;
|
|
193
|
+
projectId?: string | undefined;
|
|
194
|
+
workspaceId?: string | undefined;
|
|
195
|
+
region?: string | undefined;
|
|
196
|
+
env?: "production" | undefined;
|
|
197
|
+
agentSessions?: {
|
|
198
|
+
store: "managed";
|
|
199
|
+
} | {
|
|
200
|
+
store: "dynamodb";
|
|
201
|
+
auth: string;
|
|
202
|
+
table: string;
|
|
203
|
+
region: string;
|
|
204
|
+
} | undefined;
|
|
205
|
+
aiProviders?: Record<string, "openai" | "anthropic" | "google" | "mistral" | "cohere" | {
|
|
206
|
+
service: "openai" | "anthropic" | "google" | "mistral" | "cohere" | "bedrock" | "openai-compatible";
|
|
207
|
+
baseUrl?: string | undefined;
|
|
208
|
+
region?: string | undefined;
|
|
209
|
+
}> | undefined;
|
|
210
|
+
}>>;
|
|
211
|
+
/** User-facing config type — auth/config optional; Zod defaults fill at load time. */
|
|
212
|
+
type TrayConfig = z.input<typeof trayConfigSchema>;
|
|
213
|
+
/**
|
|
214
|
+
* Runtime validator for the LoadedTrayConfig discriminated union.
|
|
215
|
+
* Used to validate BroadcastChannel payloads before calling setActiveConfig —
|
|
216
|
+
* prevents malformed cross-channel data from corrupting the worker-local
|
|
217
|
+
* config slot.
|
|
218
|
+
*/
|
|
219
|
+
declare const loadedTrayConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
220
|
+
name: z.ZodString;
|
|
221
|
+
workspaceId: z.ZodOptional<z.ZodString>;
|
|
222
|
+
region: z.ZodString;
|
|
223
|
+
authentications: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
224
|
+
config: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
225
|
+
agentSessions: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
226
|
+
store: z.ZodLiteral<"managed">;
|
|
227
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
228
|
+
store: z.ZodLiteral<"dynamodb">;
|
|
229
|
+
auth: z.ZodString;
|
|
230
|
+
table: z.ZodString;
|
|
231
|
+
region: z.ZodString;
|
|
232
|
+
}, z.core.$strip>], "store">>;
|
|
233
|
+
aiProviders: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodEnum<{
|
|
234
|
+
openai: "openai";
|
|
235
|
+
anthropic: "anthropic";
|
|
236
|
+
google: "google";
|
|
237
|
+
mistral: "mistral";
|
|
238
|
+
cohere: "cohere";
|
|
239
|
+
}>, z.ZodObject<{
|
|
240
|
+
service: z.ZodEnum<{
|
|
241
|
+
openai: "openai";
|
|
242
|
+
anthropic: "anthropic";
|
|
243
|
+
google: "google";
|
|
244
|
+
mistral: "mistral";
|
|
245
|
+
cohere: "cohere";
|
|
246
|
+
bedrock: "bedrock";
|
|
247
|
+
"openai-compatible": "openai-compatible";
|
|
248
|
+
}>;
|
|
249
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
250
|
+
region: z.ZodOptional<z.ZodString>;
|
|
251
|
+
}, z.core.$strip>]>>>;
|
|
252
|
+
kind: z.ZodLiteral<"provisioned">;
|
|
253
|
+
projectId: z.ZodGUID;
|
|
254
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
255
|
+
name: z.ZodString;
|
|
256
|
+
workspaceId: z.ZodOptional<z.ZodString>;
|
|
257
|
+
region: z.ZodString;
|
|
258
|
+
authentications: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
259
|
+
config: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
260
|
+
agentSessions: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
261
|
+
store: z.ZodLiteral<"managed">;
|
|
262
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
263
|
+
store: z.ZodLiteral<"dynamodb">;
|
|
264
|
+
auth: z.ZodString;
|
|
265
|
+
table: z.ZodString;
|
|
266
|
+
region: z.ZodString;
|
|
267
|
+
}, z.core.$strip>], "store">>;
|
|
268
|
+
aiProviders: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodEnum<{
|
|
269
|
+
openai: "openai";
|
|
270
|
+
anthropic: "anthropic";
|
|
271
|
+
google: "google";
|
|
272
|
+
mistral: "mistral";
|
|
273
|
+
cohere: "cohere";
|
|
274
|
+
}>, z.ZodObject<{
|
|
275
|
+
service: z.ZodEnum<{
|
|
276
|
+
openai: "openai";
|
|
277
|
+
anthropic: "anthropic";
|
|
278
|
+
google: "google";
|
|
279
|
+
mistral: "mistral";
|
|
280
|
+
cohere: "cohere";
|
|
281
|
+
bedrock: "bedrock";
|
|
282
|
+
"openai-compatible": "openai-compatible";
|
|
283
|
+
}>;
|
|
284
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
285
|
+
region: z.ZodOptional<z.ZodString>;
|
|
286
|
+
}, z.core.$strip>]>>>;
|
|
287
|
+
kind: z.ZodLiteral<"unprovisioned">;
|
|
288
|
+
}, z.core.$strip>], "kind">;
|
|
289
|
+
/** Base fields on all config variants — schema output minus projectId. */
|
|
290
|
+
type LoadedTrayConfigBase = Omit<z.output<typeof trayConfigSchema>, "projectId">;
|
|
291
|
+
/**
|
|
292
|
+
* Discriminated union returned by loadConfig / ConfigService#get.
|
|
293
|
+
* - "provisioned" — projectId present, no optional-chaining needed.
|
|
294
|
+
* - "unprovisioned" — `projectId?: never` structurally excludes it.
|
|
295
|
+
* workspaceId is optional on both variants — independent of provisioning.
|
|
296
|
+
*/
|
|
297
|
+
type LoadedTrayConfig = ({
|
|
298
|
+
kind: "provisioned";
|
|
299
|
+
projectId: string;
|
|
300
|
+
} & LoadedTrayConfigBase) | ({
|
|
301
|
+
kind: "unprovisioned";
|
|
302
|
+
projectId?: never;
|
|
303
|
+
} & LoadedTrayConfigBase);
|
|
304
|
+
type ProvisionedTrayConfig = Extract<LoadedTrayConfig, {
|
|
305
|
+
kind: "provisioned";
|
|
306
|
+
}>;
|
|
307
|
+
type UnprovisionedTrayConfig = Extract<LoadedTrayConfig, {
|
|
308
|
+
kind: "unprovisioned";
|
|
309
|
+
}>;
|
|
310
|
+
/**
|
|
311
|
+
* Env var naming an alternate config file (relative paths resolve against cwd).
|
|
312
|
+
* Sits between the explicit `configFile` option (the CLI's `--config` flag) and
|
|
313
|
+
* the `helix.config.ts` default in resolution precedence.
|
|
314
|
+
*/
|
|
315
|
+
declare const HELIX_CONFIG_ENV = "HELIX_CONFIG";
|
|
316
|
+
/** Options accepted by every config entry point that resolves the config file. */
|
|
317
|
+
interface ConfigFileOptions {
|
|
318
|
+
/**
|
|
319
|
+
* Explicit config file path (the CLI's `--config` flag). Resolution
|
|
320
|
+
* precedence: this option → `HELIX_CONFIG` env var → `helix.config.ts`
|
|
321
|
+
* (then legacy `tray.config.*`) in cwd.
|
|
322
|
+
*/
|
|
323
|
+
configFile?: string;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* The effective config-file override, if any: the explicit `configFile` option
|
|
327
|
+
* (CLI `--config` flag) wins over the `HELIX_CONFIG` env var. Returns the raw
|
|
328
|
+
* (possibly relative) path — callers resolve it against their cwd.
|
|
329
|
+
*/
|
|
330
|
+
declare function resolveConfigOverride(configFile?: string): string | undefined;
|
|
331
|
+
/**
|
|
332
|
+
* Absolute path of the project config file in `cwd`, preferring `helix.config.*`
|
|
333
|
+
* and falling back to a legacy `tray.config.*`. Returns undefined when neither exists.
|
|
334
|
+
* A config-file override (option or HELIX_CONFIG) replaces the default search
|
|
335
|
+
* entirely: only the named file is considered.
|
|
336
|
+
*/
|
|
337
|
+
declare function resolveConfigFile(cwd: string, options?: ConfigFileOptions): string | undefined;
|
|
338
|
+
/**
|
|
339
|
+
* One-shot stateless read of the project config. NO caching — every call hits disk.
|
|
340
|
+
* Reads `helix.config.ts` (legacy `tray.config.*` fallback) unless an override
|
|
341
|
+
* names another file — `options.configFile` (CLI `--config` flag) first, then
|
|
342
|
+
* the `HELIX_CONFIG` env var. For hot-reload or stable snapshot, use
|
|
343
|
+
* {@link createConfigService} instead.
|
|
344
|
+
*/
|
|
345
|
+
declare function loadConfig(cwd?: string, options?: ConfigFileOptions): Promise<LoadedTrayConfig>;
|
|
346
|
+
/** Phase that surfaced an error inside ConfigService watcher. */
|
|
347
|
+
type WatchErrorPhase = "attach" | "reload" | "validation";
|
|
348
|
+
/** Stable code on errors thrown by {@link requireWorkspaceId}. Narrow by this, not instanceof. */
|
|
349
|
+
declare const WORKSPACE_ID_REQUIRED_CODE: "WORKSPACE_ID_REQUIRED";
|
|
350
|
+
/**
|
|
351
|
+
* Shape of errors thrown by {@link requireWorkspaceId}.
|
|
352
|
+
* Type alias — no class hierarchy; callers narrow via `error.code === WORKSPACE_ID_REQUIRED_CODE`.
|
|
353
|
+
*
|
|
354
|
+
* The thrown message references CLI (`helix workspace select` / `helix workspace set`)
|
|
355
|
+
* and MCP (`tray_list_workspaces` / `tray_set_workspace_id`) commands — keep those
|
|
356
|
+
* names in sync with the message literal in requireWorkspaceId.
|
|
357
|
+
*/
|
|
358
|
+
type WorkspaceIdRequiredError = Error & {
|
|
359
|
+
readonly code: typeof WORKSPACE_ID_REQUIRED_CODE;
|
|
360
|
+
};
|
|
361
|
+
/**
|
|
362
|
+
* Returns workspaceId from config, or throws a plain Error with code WORKSPACE_ID_REQUIRED.
|
|
363
|
+
* Pure, no I/O. workspaceId is independent of provisioning state.
|
|
364
|
+
*/
|
|
365
|
+
declare function requireWorkspaceId(config: LoadedTrayConfig): string;
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* `defineTool` (helix-spec 12) — the subset agents consume (helix-spec 14).
|
|
369
|
+
*
|
|
370
|
+
* A tool is a *definition*: name, description, input schema, approval policy,
|
|
371
|
+
* and handler together in one default export. Tools are:
|
|
372
|
+
*
|
|
373
|
+
* - invoked **in-process** by importing the definition and calling it — the
|
|
374
|
+
* handler runs inside the current execution with the caller's context (via
|
|
375
|
+
* getContext()), input validated against the schema;
|
|
376
|
+
* - given to agents via `defineAgent({ tools: [...] })`, where the agent
|
|
377
|
+
* runtime compiles them to AI SDK tools (the same validation + handler,
|
|
378
|
+
* `needsApproval` compiled to the loop's native approval mechanism).
|
|
379
|
+
*
|
|
380
|
+
* MCP exposure (spec 12's `mcp.tools`) is not built yet — tools exist today
|
|
381
|
+
* for in-process use and agents.
|
|
382
|
+
*/
|
|
383
|
+
declare const TOOL_DEFINITION_KIND = "helix-tool";
|
|
384
|
+
interface DefineToolConfig<TSchema extends HelixSchema = HelixSchema> {
|
|
385
|
+
/** Tool name (snake_case convention). */
|
|
386
|
+
name: string;
|
|
387
|
+
/** Human-readable description for AI agents. */
|
|
388
|
+
description: string;
|
|
389
|
+
/** Input schema (Zod 3 or 4), validated before the handler runs. */
|
|
390
|
+
input: TSchema;
|
|
391
|
+
/**
|
|
392
|
+
* Require human approval before an agent may execute this tool — boolean,
|
|
393
|
+
* or an (optionally async) predicate of the validated input. Enforced in
|
|
394
|
+
* agent loops (the loop pauses; see ctx.agent). Direct in-process
|
|
395
|
+
* invocation is not gated — calling the tool yourself is the confirmation.
|
|
396
|
+
*/
|
|
397
|
+
needsApproval?: boolean | ((input: InferSchemaOutput<TSchema, unknown>) => boolean | Promise<boolean>);
|
|
398
|
+
/** Handler — receives the caller's ctx with `input` validated and typed. */
|
|
399
|
+
handler: (ctx: PlatformContext & {
|
|
400
|
+
input: InferSchemaOutput<TSchema, unknown>;
|
|
401
|
+
}) => Promise<unknown> | unknown;
|
|
402
|
+
}
|
|
403
|
+
interface HelixTool<TSchema extends HelixSchema = HelixSchema> {
|
|
404
|
+
/** In-process invocation: validate input, run handler with the caller's ctx. */
|
|
405
|
+
(input: InferSchemaOutput<TSchema, unknown>): Promise<unknown>;
|
|
406
|
+
readonly kind: typeof TOOL_DEFINITION_KIND;
|
|
407
|
+
readonly name: string;
|
|
408
|
+
readonly description: string;
|
|
409
|
+
readonly inputSchema: TSchema;
|
|
410
|
+
readonly needsApproval?: DefineToolConfig<TSchema>["needsApproval"];
|
|
411
|
+
/** Validate + execute with an explicit ctx (used by the agent runtime). */
|
|
412
|
+
readonly execute: (input: unknown, ctx: PlatformContext) => Promise<unknown>;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Type-erased view of a tool definition — what agent definitions accept.
|
|
416
|
+
* (HelixTool<TSchema> is invariant in its schema because of the callable's
|
|
417
|
+
* input position; this structural view is what `tools: [...]` is typed as.)
|
|
418
|
+
*/
|
|
419
|
+
interface HelixToolLike {
|
|
420
|
+
readonly kind: typeof TOOL_DEFINITION_KIND;
|
|
421
|
+
readonly name: string;
|
|
422
|
+
readonly description: string;
|
|
423
|
+
readonly inputSchema: HelixSchema;
|
|
424
|
+
readonly needsApproval?: boolean | ((input: never) => boolean | Promise<boolean>);
|
|
425
|
+
readonly execute: (input: unknown, ctx: PlatformContext) => Promise<unknown>;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Define a tool an agent can call (or that your code can invoke in-process).
|
|
429
|
+
*/
|
|
430
|
+
declare function defineTool<TSchema extends HelixSchema>(config: DefineToolConfig<TSchema>): HelixTool<TSchema>;
|
|
431
|
+
/** Structural check for defineTool output — see TOOL_DEFINITION_KIND. */
|
|
432
|
+
declare function isToolDefinition(value: unknown): value is HelixTool;
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* `defineAgent` (helix-spec 14) — one file per agent under
|
|
436
|
+
* `functions/_agents/`, definitions in code, the file system as the source of
|
|
437
|
+
* truth.
|
|
438
|
+
*
|
|
439
|
+
* Like `defineSchedule`, the SDK owns the definition + runtime and the
|
|
440
|
+
* host (dev server, lambda router) owns discovery: importing the module
|
|
441
|
+
* registers the agent by name.
|
|
442
|
+
*
|
|
443
|
+
* v1 deviations from the spec, both enforced with clear errors:
|
|
444
|
+
* - `name` is required (filename defaulting needs build-time discovery, which
|
|
445
|
+
* arrives with the deploy-side scan);
|
|
446
|
+
* - `instructionsFile` resolution requires the host to record the agent
|
|
447
|
+
* file's directory (the dev server does; direct imports in tests should use
|
|
448
|
+
* inline `instructions`).
|
|
449
|
+
*/
|
|
450
|
+
declare const AGENT_DEFINITION_KIND = "helix-agent";
|
|
451
|
+
declare const agentConfigSchema: z.ZodObject<{
|
|
452
|
+
name: z.ZodString;
|
|
453
|
+
description: z.ZodString;
|
|
454
|
+
model: z.ZodString;
|
|
455
|
+
auth: z.ZodString;
|
|
456
|
+
fallbacks: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
457
|
+
model: z.ZodString;
|
|
458
|
+
auth: z.ZodString;
|
|
459
|
+
}, z.core.$strip>>>;
|
|
460
|
+
instructions: z.ZodOptional<z.ZodString>;
|
|
461
|
+
instructionsFile: z.ZodOptional<z.ZodString>;
|
|
462
|
+
tools: z.ZodOptional<z.ZodArray<z.ZodCustom<HelixToolLike, HelixToolLike>>>;
|
|
463
|
+
agents: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
464
|
+
memory: z.ZodOptional<z.ZodObject<{
|
|
465
|
+
maxSessionMessages: z.ZodOptional<z.ZodNumber>;
|
|
466
|
+
ttl: z.ZodOptional<z.ZodNumber>;
|
|
467
|
+
scope: z.ZodOptional<z.ZodEnum<{
|
|
468
|
+
user: "user";
|
|
469
|
+
project: "project";
|
|
470
|
+
}>>;
|
|
471
|
+
}, z.core.$strip>>;
|
|
472
|
+
limits: z.ZodOptional<z.ZodObject<{
|
|
473
|
+
maxIterations: z.ZodOptional<z.ZodNumber>;
|
|
474
|
+
maxToolCalls: z.ZodOptional<z.ZodNumber>;
|
|
475
|
+
}, z.core.$strip>>;
|
|
476
|
+
}, z.core.$strip>;
|
|
477
|
+
type AgentDefinitionConfig = z.input<typeof agentConfigSchema>;
|
|
478
|
+
interface AgentDefinition extends z.output<typeof agentConfigSchema> {
|
|
479
|
+
kind: typeof AGENT_DEFINITION_KIND;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Define an agent (default export of a file under `functions/_agents/`).
|
|
483
|
+
*/
|
|
484
|
+
declare function defineAgent(config: AgentDefinitionConfig): AgentDefinition;
|
|
485
|
+
/** Structural check for defineAgent output — see AGENT_DEFINITION_KIND. */
|
|
486
|
+
declare function isAgentDefinition(value: unknown): value is AgentDefinition;
|
|
487
|
+
|
|
488
|
+
export { AGENT_DEFINITION_KIND as A, setSdkConfig as B, type ConfigFileOptions as C, type DefineToolConfig as D, HELIX_CONFIG_ENV as H, type LoadedTrayConfig as L, type ProvisionedTrayConfig as P, type SdkRuntimeConfig as S, type TrayConfig as T, type UnprovisionedTrayConfig as U, type WatchErrorPhase as W, AI_SERVICES as a, type AgentDefinition as b, type AgentDefinitionConfig as c, type AgentSessionsConfig as d, type AiProviderEntry as e, type AiService as f, type HelixTool as g, type HelixToolLike as h, TOOL_DEFINITION_KIND as i, WORKSPACE_ID_REQUIRED_CODE as j, type WorkspaceIdRequiredError as k, agentSessionsSchema as l, aiProviderEntrySchema as m, defineAgent as n, defineTool as o, getSdkConfig as p, isAgentDefinition as q, isToolDefinition as r, loadConfig as s, loadedTrayConfigSchema as t, projectIdSchema as u, requireWorkspaceId as v, resolveConfigFile as w, resolveConfigOverride as x, workspaceIdSchema as y, type SdkConfigInput as z };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import * as h3 from 'h3';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export {
|
|
7
|
-
export { a as REGION_VALUES, R as Region, r as regionSchema } from './region-schema-COfWyGI9.js';
|
|
2
|
+
import { H as HelixSchema, F as FunctionHandler, I as InferSchemaOutput, D as DefineFunctionOptions, a as DefineScheduleConfig, S as ScheduleDefinition, P as PlatformContext } from './types-c1QXQC1s.js';
|
|
3
|
+
export { A as AgentApprovalDecision, b as AgentCallOptions, c as AgentClient, d as AgentPendingApproval, e as AgentResult, f as AgentSession, g as AgentSessionPage, h as AgentSessionPageOptions, i as AgentSessionSummary, j as AgentSessionsList, k as AgentStreamResult, l as AiEmbeddingModelInstance, m as AiImageModelInstance, n as AiLanguageModelInstance, o as AiSpeechModelInstance, p as AiTranscriptionModelInstance, B as BrokerAuthedClient, q as BrokerCallOptions, r as BrokerCallResult, C as CallFunctionAsync, s as DbCallParameters, t as DbClient, u as FileSystemClient, v as HelixAI, w as HelixAIProvider, x as HelixAgent, y as HelixCost, z as HelixResultMeta, E as HttpClient, K as KeyValueStore, L as Logger, G as S3SignOptions, J as S3SignResult, M as ScheduleContext, N as ScheduleHandler, O as ScheduleTrigger, Q as SqlBuilder, T as TrayContext, U as UnvalidatedInput } from './types-c1QXQC1s.js';
|
|
4
|
+
import { T as TrayConfig, L as LoadedTrayConfig, W as WatchErrorPhase } from './define-agent-B6KPsK4S.js';
|
|
5
|
+
export { A as AGENT_DEFINITION_KIND, a as AI_SERVICES, b as AgentDefinition, c as AgentDefinitionConfig, d as AgentSessionsConfig, e as AiProviderEntry, f as AiService, C as ConfigFileOptions, D as DefineToolConfig, H as HELIX_CONFIG_ENV, g as HelixTool, h as HelixToolLike, P as ProvisionedTrayConfig, S as SdkRuntimeConfig, i as TOOL_DEFINITION_KIND, U as UnprovisionedTrayConfig, j as WORKSPACE_ID_REQUIRED_CODE, k as WorkspaceIdRequiredError, l as agentSessionsSchema, m as aiProviderEntrySchema, n as defineAgent, o as defineTool, p as getSdkConfig, q as isAgentDefinition, r as isToolDefinition, s as loadConfig, t as loadedTrayConfigSchema, u as projectIdSchema, v as requireWorkspaceId, w as resolveConfigFile, x as resolveConfigOverride, y as workspaceIdSchema } from './define-agent-B6KPsK4S.js';
|
|
6
|
+
export { a as REGION_VALUES, R as Region, r as region, b as regionSchema } from './region-schema-DAE9PT3S.js';
|
|
8
7
|
import { StopCondition, ToolSet } from 'ai';
|
|
9
8
|
export { EmbedManyResult, EmbedResult, EmbeddingModel, FinishReason, GenerateImageResult, GenerateObjectResult, GenerateTextResult, ImageModel, LanguageModel, LanguageModelUsage, ModelMessage, Output, PrepareStepFunction, SpeechModel, SpeechResult, StopCondition, StreamObjectResult, StreamTextResult, TextStreamPart, ToolChoice, ToolSet, TranscriptionModel, TranscriptionResult, UIMessage, convertToModelMessages, cosineSimilarity, dynamicTool, hasToolCall, jsonSchema, smoothStream, stepCountIs, tool, zodSchema } from 'ai';
|
|
10
9
|
import 'ky';
|
|
11
10
|
import '@ai-sdk/provider';
|
|
11
|
+
import 'zod';
|
|
12
|
+
import 'zod/v3';
|
|
12
13
|
|
|
13
|
-
declare function defineFunction<TInput extends
|
|
14
|
+
declare function defineFunction<TInput extends HelixSchema | undefined = undefined, TOutput extends HelixSchema | undefined = undefined>(handler: FunctionHandler<InferSchemaOutput<TInput>>, schemaOrOptions?: HelixSchema | DefineFunctionOptions<TInput, TOutput>): h3.EventHandler<h3.EventHandlerRequest, Promise<unknown>>;
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Discriminant for objects produced by defineSchedule. A plain string (not a
|
|
@@ -146,4 +147,4 @@ declare function createConfigService(options: CreateConfigServiceOptions): Promi
|
|
|
146
147
|
/** Helix stop condition: total tool executions across all steps. */
|
|
147
148
|
declare function totalToolCallsIs(max: number): StopCondition<ToolSet>;
|
|
148
149
|
|
|
149
|
-
export { type ConfigService, type CreateConfigServiceOptions, DefineFunctionOptions, DefineScheduleConfig, FunctionHandler, LoadedTrayConfig, PlatformContext, type RunWithinAppSpanArgs, SCHEDULE_DEFINITION_KIND, ScheduleConfigError, ScheduleDefinition, TrayConfig, WatchErrorPhase, createConfigService, defineConfig, defineFunction, defineSchedule, getContext, isScheduleDefinition, runWithinAppSpan, totalToolCallsIs };
|
|
150
|
+
export { type ConfigService, type CreateConfigServiceOptions, DefineFunctionOptions, DefineScheduleConfig, FunctionHandler, HelixSchema, LoadedTrayConfig, PlatformContext, type RunWithinAppSpanArgs, SCHEDULE_DEFINITION_KIND, ScheduleConfigError, ScheduleDefinition, TrayConfig, WatchErrorPhase, createConfigService, defineConfig, defineFunction, defineSchedule, getContext, isScheduleDefinition, runWithinAppSpan, totalToolCallsIs };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{A as
|
|
2
|
-
`)}function
|
|
1
|
+
import{$ as Re,A as me,B as pe,C as ge,D as he,E as ye,F as Ce,G as Se,H as ve,I as k,J as I,K as z,L as J,M as C,N as xe,O as Ee,P as Q,Q as we,R as _e,S as ke,Z as Ie,_ as be,ca as Ae,da as X,ea as Te,f as P,fa as He,g as _,ga as Pe,h as F,ha as Fe,i as y,j as O,k as D,l as L,m as j,n as de,o as W,p as N,q as K,r as $,s as V,w as B,x as G,y as le,z as fe}from"./chunk-TYQ5RKIZ.js";import{a as M,b as ce}from"./chunk-WUCX7RZO.js";import{d as w,r as U,s as q}from"./chunk-LKZKDHYO.js";import{randomUUID as qe}from"crypto";import{SpanStatusCode as re,SpanKind as Ke}from"@opentelemetry/api";import{defineEventHandler as $e,getMethod as Ve,getRequestURL as Be,getHeaders as ne,getHeader as x}from"h3";import{readBody as Oe,getQuery as De,getRouterParams as Le}from"h3";async function Y(e,t){let r=await je(e),n=De(e),o=Le(e)??{},s={...n,...r,...o};return t?Me(s,t):s}async function je(e){try{let t=await Oe(e);return t&&typeof t=="object"?t:(t!=null&&t!==""&&console.warn("[helix-sdk] Request body present but not a JSON object \u2014 ignored"),{})}catch(t){if(t instanceof Error&&"statusCode"in t&&t.statusCode===400){let n=new Error("Malformed request body");throw n.statusCode=400,n.data={message:"Request body is not valid JSON"},n}let r=e.method?.toUpperCase();if(r==="GET"||r==="HEAD"||r==="DELETE")return{};throw t}}function Me(e,t){let r=t.safeParse(e);if(!r.success){let n=new Error("Input validation failed");throw n.statusCode=400,n.data=r.error.flatten(),n}return r.data}var S=class extends Error{statusCode;constructor(t,r){super(r),this.statusCode=t,this.name="HttpError"}};function Z(e){return t=>{e.node.res.statusCode=t}}function ee(){return(e,t)=>{throw new S(e,t)}}function te(e,t){let{statusCode:r,message:n}=We(t.detail);return e.node.res.statusCode=r,{error:n,statusCode:r}}function We(e){switch(e.kind){case"unknown_alias":return{statusCode:400,message:"Unknown authentication alias"};case"input_validation_failed":return{statusCode:400,message:"Input validation failed"};case"output_validation_failed":return{statusCode:500,message:"Internal server error"};case"config_load_failed":return{statusCode:500,message:"Configuration error"};case"broker_error":return{statusCode:502,message:"Broker error"};case"unsupported_body_type":return{statusCode:400,message:"Unsupported request body type"};case"unsupported_scheme":return{statusCode:400,message:"Unsupported URL scheme"};case"missing_execution_credentials":return{statusCode:401,message:"Missing execution credentials"};case"missing_tray_token":return{statusCode:500,message:"Missing Tray token"};case"db_call_failed":return{statusCode:502,message:e.message};case"db_query_failed":return{statusCode:502,message:`Database query failed: ${e.message}`};case"db_invalid_parameters":return{statusCode:400,message:e.message};case"kv_key_invalid":return{statusCode:400,message:e.message};case"kv_value_invalid":return{statusCode:400,message:e.message};case"kv_value_too_large":return{statusCode:400,message:e.message};case"kv_ttl_invalid":return{statusCode:400,message:e.message};case"kv_not_available":return{statusCode:501,message:"Key-value store is not available in this environment"};case"kv_call_failed":return{statusCode:502,message:"Key-value store request failed"};case"kv_requires_provisioning":return{statusCode:500,message:"Internal server error"};case"files_path_invalid":return{statusCode:400,message:e.message};case"files_value_invalid":return{statusCode:400,message:e.message};case"files_value_too_large":return{statusCode:400,message:e.message};case"files_not_available":return{statusCode:501,message:"File storage is not available in this environment"};case"files_call_failed":return{statusCode:502,message:"File storage request failed"};case"files_requires_provisioning":return{statusCode:500,message:"Internal server error"};case"call_function_path_invalid":return{statusCode:400,message:e.message};case"call_function_call_failed":return{statusCode:502,message:"Async function call failed"};case"call_function_requires_provisioning":return{statusCode:500,message:"Internal server error"};case"call_function_not_available":return{statusCode:501,message:"callFunctionAsync is not available in this environment"};case"call_function_missing_execution_jwt":return{statusCode:401,message:"Missing execution credentials"};case"ai_unsupported_service":case"ai_provider_misconfigured":case"ai_model_id_required":case"ai_model_instance_required":case"ai_provider_not_configured":case"ai_foreign_model_rejected":case"agent_sessions_failed":return{statusCode:500,message:e.kind==="ai_unsupported_service"?`AI service not supported for alias "${e.alias}"`:e.kind==="ai_provider_misconfigured"?`AI provider misconfigured for alias "${e.alias}"`:"Internal server error"};default:return{statusCode:500,message:`Unhandled error kind: ${e.kind}`}}}var Ne=["authorization","x-tray-token","set-cookie","x-kong-request-id","traceparent","x-real-ip","x-tray-user-email","x-tray-user-name","cookie"];function Ue(e){return e.toLowerCase().includes("tray_lid")}function b(e){let t={};for(let[r,n]of Object.entries(e))if(!Ne.includes(r.toLowerCase())){if(r.toLowerCase()==="cookie"&&n){let o=n.split(";").map(s=>s.trim()).filter(s=>{let u=s.split("=")[0].trim();return!Ue(u)}).join("; ");o&&(t[r]=o);continue}t[r]=n}return t}function Ge(e,t){let{inputSchema:r,outputSchema:n}=Ze(t),o=e;return $e(async s=>{let u=w(),{executionId:a,userId:i,userEmail:p,userName:c,deploymentId:l}=et(u,s),m=u.mode==="lambda"?u.parentExecutionId??null:null,f=Date.now(),d=new Date().toISOString(),g=Ve(s),h=Be(s).pathname,ie=N(),T=W(),ae=`${g} ${h}`;O();let H={hasDb:!1,hasExternal:!1,hasAuth:!1,hasAi:!1,hasError:!1};return ze(()=>_.run(H,()=>P.run(a,async()=>{let v=await Je(s,r);if(!v.ok)return{response:v.response,errored:!1,errorMessage:null};let ue=rt(s,v.input,ie,T,g,h,a,l,i,p,c,m);return Qe(o,ue,n,s,T,a,l,{method:g,path:h,rawInput:v.input})})),{executionId:a,deploymentId:l,routeOrJob:ae,startedAt:d,startMs:f,userId:i,flags:H})})}async function ze(e,t){let r=!1,n=null;try{let o=await e();return r=o.errored,n=o.errorMessage,o.response}finally{j({...t,errored:r,errorMessage:n}),await D()}}async function Je(e,t){try{return{ok:!0,input:await Y(e,t)}}catch(r){let n=tt(e,r);if(n)return{ok:!1,response:n};throw r}}async function Qe(e,t,r,n,o,s,u,a){return L.startActiveSpan("function",{root:!0,kind:Ke.SERVER,attributes:{method:a.method,route:a.path,executionId:s,...u?{deploymentId:u}:{}}},async i=>{t.traceId=i.spanContext().traceId;let p=b(ne(n));y(i,"input",a.rawInput),y(i,"request",{method:a.method,path:a.path,headers:p,body:a.rawInput});let c=!1,l=null,m,f;try{let d=await M.run(t,()=>e(t));if(m=d,d==null)n.node.res.statusCode=204,f="";else if(d instanceof Response)f=d;else if(r){let g=r.safeParse(d);if(!g.success){let h=Object.keys(g.error.flatten().fieldErrors);throw o.error("Output validation failed",{fields:h,executionId:s}),U.outputValidationFailed(h)}f=g.data}else f=d}catch(d){c=!0,l=d instanceof Error?d.message:String(d),F("hasError"),f=Xe(d,n,o,s)}finally{Ye(i,n,{errored:c,errorMessage:l,handlerResult:m,response:f})}return{response:f,errored:c,errorMessage:l}})}function Xe(e,t,r,n){if(e instanceof S)return t.node.res.statusCode=e.statusCode,{error:e.message,statusCode:e.statusCode};if(q(e))return te(t,e);r.error("Unhandled error in handler",{error:e instanceof Error?e.message:String(e),executionId:n}),t.node.res.statusCode=500;let o=process.env.NODE_ENV==="development";return{error:o&&e instanceof Error?e.message:"Internal server error",statusCode:500,...o&&e instanceof Error&&e.stack?{stack:e.stack}:{}}}function Ye(e,t,r){e.setAttribute("statusCode",t.node.res.statusCode),!r.errored&&r.handlerResult!==void 0&&y(e,"output",r.handlerResult),y(e,"response",r.response);let n=_.getStore();e.setAttribute("hasAuth",n?.hasAuth??!1),e.setAttribute("hasAi",n?.hasAi??!1),e.setAttribute("hasExternal",n?.hasExternal??!1),e.setAttribute("hasDb",n?.hasDb??!1),e.setAttribute("status",r.errored?"error":"success");let o=r.errored||(n?.hasError??!1);e.setStatus({code:o?re.ERROR:re.OK,...r.errorMessage?{message:r.errorMessage}:{}}),e.end()}function Ze(e){if(!e)return{inputSchema:void 0,outputSchema:void 0};if(typeof e.safeParse=="function")return{inputSchema:e,outputSchema:void 0};if(typeof e=="object"&&("input"in e||"output"in e)){let t=e;return{inputSchema:t.input,outputSchema:t.output}}return{inputSchema:e,outputSchema:void 0}}function et(e,t){let r=e.mode==="lambda",n=(r?e.executionId:x(t,"x-tray-execution-id"))??qe(),o=(r?e.userId:x(t,"x-tray-user-id"))||null,s=(r?e.userEmail:x(t,"x-tray-user-email"))||null,u=(r?e.userName:x(t,"x-tray-user-name"))||null,a=r?e.deploymentId??null:null;return{executionId:n,userId:o,userEmail:s,userName:u,deploymentId:a}}function tt(e,t){if(!(t instanceof Error)||!("statusCode"in t)||!("data"in t))return null;let r=t.statusCode,n=t.data;e.node.res.statusCode=r;let o=n&&typeof n=="object"&&"fieldErrors"in n?n.fieldErrors:void 0;return{error:"Input validation failed",statusCode:r,...o?{fields:Object.keys(o)}:{}}}function rt(e,t,r,n,o,s,u,a,i,p,c,l){return{input:t,method:o,path:s,headers:b(ne(e)),http:K(),db:m=>$(m),kv:()=>V(),files:()=>B(),callFunctionAsync:G(),ai:Q(),agent:m=>X(m),log:n,config:r,status:Z(e),error:ee(),state:{},request:e,executionId:u,deploymentId:a,userId:i,parentExecutionId:l,identity:i!==null?{user:{id:i,email:p,name:c}}:null,traceId:""}}function nt(e){return e}import{existsSync as ot,watch as st,writeSync as it}from"fs";import{basename as at,dirname as ut,join as dt,resolve as E}from"path";import{watchConfig as ct}from"c12";function lt(e,t){let r=e instanceof Error?e.message:String(e);it(2,`[helix-watch] ${t.phase} error: ${r}
|
|
2
|
+
`)}function R(){return{kind:"unprovisioned",name:"",authentications:{},config:{},region:"us1"}}var ft=/^(?:helix|tray)\.config\.(?:m|c)?[jt]s$/,oe=new Set;function se(e,t){return I(e,{configFile:t})!==void 0}async function mt(e,t,r){if(se(e.cwd,t))try{return{current:await C(e.cwd,{configFile:t}),initialLoadSucceeded:!0}}catch(n){return r(n,{phase:"reload"}),{current:R(),initialLoadSucceeded:!1}}if(e.watch){let n=t!==void 0?E(e.cwd,t):E(e.cwd);oe.has(n)||(process.stderr.write(t!==void 0?`warning: config file ${E(e.cwd,t)} not found; tray running with default config
|
|
3
3
|
`:`warning: no helix.config.ts found at ${e.cwd}; tray running with default config \u2014 create one via \`helix init\`
|
|
4
|
-
`),oe.add(n))}return{current:
|
|
4
|
+
`),oe.add(n))}return{current:R(),initialLoadSucceeded:!1}}var A=class{constructor(t,r,n,o){this.cwd=t;this.configFile=r;this.onError=n;this.emit=o}cwd;configFile;onError;emit;stopped=!1;directoryWatcher=null;c12Unwatch=null;c12AttachPromise=null;updateChain=Promise.resolve();start(t){t?this.attachC12Watcher():this.attachCreationWatcher()}watcherReady(){return this.c12AttachPromise===null?Promise.resolve():this.c12AttachPromise.catch(()=>{})}async stop(){this.stopped=!0,this.directoryWatcher&&(this.directoryWatcher.close(),this.directoryWatcher=null),this.c12AttachPromise&&await this.c12AttachPromise.catch(t=>this.onError(t,{phase:"attach"})),this.c12Unwatch&&(await this.c12Unwatch(),this.c12Unwatch=null)}attachC12Watcher(){this.c12AttachPromise===null&&(this.c12AttachPromise=ct({...z(this.cwd,{configFile:this.configFile}),onUpdate:({newConfig:t})=>{this.stopped||(this.updateChain=this.updateChain.then(async()=>{if(this.stopped)return;let r;try{r=J(t.config,this.cwd)}catch(n){this.onError(n,{phase:"validation"});return}try{this.emit(r)}catch(n){this.onError(n,{phase:"reload"})}}))}}).then(async t=>{if(this.stopped){t.unwatch();return}this.c12Unwatch=t.unwatch;let{watch:r}=await import("chokidar"),n=r(this.cwd,{persistent:!1,depth:0});try{await new Promise((o,s)=>{n.once("ready",o),n.once("error",s)})}finally{await n.close()}}).catch(t=>{this.onError(t,{phase:"attach"})}))}attachCreationWatcher(){let t=this.configFile!==void 0?E(this.cwd,this.configFile):void 0,r=t!==void 0?ut(t):this.cwd;try{this.directoryWatcher=st(r,{persistent:!1},(n,o)=>{if(this.stopped||!o)return;let s=o.toString();if(t!==void 0){if(s!==at(t))return}else if(!ft.test(s))return;ot(dt(r,s))&&(this.updateChain=this.updateChain.then(async()=>{if(this.stopped)return;let u;try{u=await C(this.cwd,{configFile:this.configFile})}catch(i){this.onError(i,{phase:"reload"});return}if(this.stopped)return;this.emit(u);let a=this.directoryWatcher;a&&(this.directoryWatcher=null,a.close()),this.attachC12Watcher()}))}),this.directoryWatcher.on("error",n=>{this.onError(n,{phase:"attach"})})}catch(n){this.onError(n,{phase:"attach"})}}};async function pt(e){let t=e.onError??lt,r=new Set,n=k(e.configFile),o=await mt(e,n,t),s=o.current;function u(i){s=i;for(let p of[...r])try{p(i)}catch(c){t(c,{phase:"reload"})}}let a=new A(e.cwd,n,t,u);return e.watch&&a.start(o.initialLoadSucceeded),{get(){return s},async reload(){if(!se(e.cwd,n)){let i=R();return u(i),i}try{let i=await C(e.cwd,{configFile:n});return u(i),i}catch(i){return t(i,{phase:"reload"}),s}},subscribe(i){return r.add(i),()=>{r.delete(i)}},async stop(){r.clear(),await a.stop()},ready(){return a.watcherReady()}}}import{tool as ur,dynamicTool as dr,jsonSchema as cr,zodSchema as lr,stepCountIs as fr,hasToolCall as mr,convertToModelMessages as pr,cosineSimilarity as gr,smoothStream as hr,Output as yr}from"ai";export{Ie as AGENT_DEFINITION_KIND,ye as AI_SERVICES,ve as HELIX_CONFIG_ENV,yr as Output,le as REGION_VALUES,Te as SCHEDULE_DEFINITION_KIND,He as ScheduleConfigError,we as TOOL_DEFINITION_KIND,xe as WORKSPACE_ID_REQUIRED_CODE,he as agentSessionsSchema,Ce as aiProviderEntrySchema,pr as convertToModelMessages,gr as cosineSimilarity,pt as createConfigService,be as defineAgent,nt as defineConfig,Ge as defineFunction,Pe as defineSchedule,_e as defineTool,dr as dynamicTool,ce as getContext,w as getSdkConfig,mr as hasToolCall,Re as isAgentDefinition,Fe as isScheduleDefinition,ke as isToolDefinition,cr as jsonSchema,C as loadConfig,Se as loadedTrayConfigSchema,pe as projectIdSchema,me as region,fe as regionSchema,Ee as requireWorkspaceId,I as resolveConfigFile,k as resolveConfigOverride,de as runWithinAppSpan,hr as smoothStream,fr as stepCountIs,ur as tool,Ae as totalToolCallsIs,ge as workspaceIdSchema,lr as zodSchema};
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { L as LoadedTrayConfig, b as AgentDefinition } from '../define-agent-
|
|
2
|
-
export { z as SdkConfigInput, B as setSdkConfig } from '../define-agent-
|
|
3
|
-
import { j as AgentSessionsList, b as AgentCallOptions, e as AgentResult } from '../types-
|
|
4
|
-
export {
|
|
1
|
+
import { L as LoadedTrayConfig, b as AgentDefinition } from '../define-agent-B6KPsK4S.js';
|
|
2
|
+
export { z as SdkConfigInput, B as setSdkConfig } from '../define-agent-B6KPsK4S.js';
|
|
3
|
+
import { j as AgentSessionsList, b as AgentCallOptions, e as AgentResult } from '../types-c1QXQC1s.js';
|
|
4
|
+
export { R as SessionExpiredError, V as clearAgentSessions } from '../types-c1QXQC1s.js';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import 'h3';
|
|
7
7
|
import 'ky';
|