experimental-ash 0.22.2 → 0.24.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 +36 -0
- package/dist/docs/internals/hooks.md +13 -16
- package/dist/docs/internals/message-runtime.md +1 -1
- package/dist/docs/public/auth-and-route-protection.md +3 -3
- package/dist/docs/public/faqs.md +67 -0
- package/dist/docs/public/meta.json +1 -0
- package/dist/docs/public/schedules.md +11 -0
- package/dist/docs/public/session-context.md +46 -89
- package/dist/docs/public/skills.md +13 -0
- package/dist/docs/public/subagents.md +12 -6
- package/dist/docs/public/tools.md +9 -13
- package/dist/docs/public/typescript-api.md +4 -4
- package/dist/src/channel/types.d.ts +10 -12
- package/dist/src/chunks/{client-CKsU8Li3.js → client-nshDsWNF.js} +1 -1
- package/dist/src/chunks/{dev-authored-source-watcher-BLzYWh05.js → dev-authored-source-watcher-B4PaZGUr.js} +1 -1
- package/dist/src/chunks/host-DsW72Q-w.js +65 -0
- package/dist/src/chunks/paths-OknjaYR8.js +89 -0
- package/dist/src/chunks/prewarm-B4YblQ5m.js +6 -0
- package/dist/src/cli/commands/info.js +1 -1
- package/dist/src/cli/dev/repl.js +2 -2
- package/dist/src/cli/run.js +1 -1
- package/dist/src/client/session.js +8 -0
- package/dist/src/client/types.d.ts +12 -1
- package/dist/src/compiled/.vendor-stamp.json +3 -3
- package/dist/src/compiled/@workflow/core/_ms.d.ts +4 -0
- package/dist/src/compiled/@workflow/core/_workflow-serde.d.ts +5 -0
- package/dist/src/compiled/@workflow/core/_workflow-utils.d.ts +8 -0
- package/dist/src/compiled/@workflow/core/_workflow-world.d.ts +59 -0
- package/dist/src/compiled/@workflow/core/capabilities.d.ts +45 -0
- package/dist/src/compiled/@workflow/core/capture-stack.d.ts +16 -0
- package/dist/src/compiled/@workflow/core/class-serialization.d.ts +31 -0
- package/dist/src/compiled/@workflow/core/classify-error.d.ts +20 -0
- package/dist/src/compiled/@workflow/core/context-errors.d.ts +27 -0
- package/dist/src/compiled/@workflow/core/context-violation-error.d.ts +97 -0
- package/dist/src/compiled/@workflow/core/create-hook.d.ts +179 -0
- package/dist/src/compiled/@workflow/core/define-hook.d.ts +68 -0
- package/dist/src/compiled/@workflow/core/describe-error.d.ts +70 -0
- package/dist/src/compiled/@workflow/core/encryption.d.ts +51 -0
- package/dist/src/compiled/@workflow/core/events-consumer.d.ts +64 -0
- package/dist/src/compiled/@workflow/core/flushable-stream.d.ts +82 -0
- package/dist/src/compiled/@workflow/core/global.d.ts +48 -0
- package/dist/src/compiled/@workflow/core/index.d.ts +19 -38
- package/dist/src/compiled/@workflow/core/index.js +2 -2
- package/dist/src/compiled/@workflow/core/log-format.d.ts +25 -0
- package/dist/src/compiled/@workflow/core/logger.d.ts +29 -0
- package/dist/src/compiled/@workflow/core/package.json +1 -1
- package/dist/src/compiled/@workflow/core/private.d.ts +59 -10
- package/dist/src/compiled/@workflow/core/runtime/constants.d.ts +51 -0
- package/dist/src/compiled/@workflow/core/runtime/get-port-lazy.d.ts +10 -0
- package/dist/src/compiled/@workflow/core/runtime/get-world-lazy.d.ts +32 -0
- package/dist/src/compiled/@workflow/core/runtime/helpers.d.ts +97 -0
- package/dist/src/compiled/@workflow/core/runtime/replay-budget.d.ts +98 -0
- package/dist/src/compiled/@workflow/core/runtime/resume-hook.d.ts +77 -0
- package/dist/src/compiled/@workflow/core/runtime/run.d.ts +134 -0
- package/dist/src/compiled/@workflow/core/runtime/runs.d.ts +50 -0
- package/dist/src/compiled/@workflow/core/runtime/start.d.ts +59 -0
- package/dist/src/compiled/@workflow/core/runtime/step-executor.d.ts +40 -0
- package/dist/src/compiled/@workflow/core/runtime/step-handler.d.ts +2 -0
- package/dist/src/compiled/@workflow/core/runtime/suspension-handler.d.ts +42 -0
- package/dist/src/compiled/@workflow/core/runtime/world-init.d.ts +75 -0
- package/dist/src/compiled/@workflow/core/runtime/world.d.ts +32 -0
- package/dist/src/compiled/@workflow/core/runtime.d.ts +22 -67
- package/dist/src/compiled/@workflow/core/runtime.js +27 -27
- package/dist/src/compiled/@workflow/core/schemas.d.ts +15 -0
- package/dist/src/compiled/@workflow/core/serialization/client.d.ts +17 -0
- package/dist/src/compiled/@workflow/core/serialization/codec-devalue.d.ts +14 -0
- package/dist/src/compiled/@workflow/core/serialization/codec.d.ts +90 -0
- package/dist/src/compiled/@workflow/core/serialization/encryption.d.ts +32 -0
- package/dist/src/compiled/@workflow/core/serialization/errors.d.ts +21 -0
- package/dist/src/compiled/@workflow/core/serialization/format.d.ts +60 -0
- package/dist/src/compiled/@workflow/core/serialization/index.d.ts +18 -0
- package/dist/src/compiled/@workflow/core/serialization/reducers/class.d.ts +11 -0
- package/dist/src/compiled/@workflow/core/serialization/reducers/common.d.ts +16 -0
- package/dist/src/compiled/@workflow/core/serialization/reducers/step-function.d.ts +35 -0
- package/dist/src/compiled/@workflow/core/serialization/step.d.ts +17 -0
- package/dist/src/compiled/@workflow/core/serialization/types.d.ts +215 -0
- package/dist/src/compiled/@workflow/core/serialization/workflow.d.ts +29 -0
- package/dist/src/compiled/@workflow/core/serialization-format.d.ts +171 -0
- package/dist/src/compiled/@workflow/core/serialization.d.ts +337 -0
- package/dist/src/compiled/@workflow/core/sleep.d.ts +33 -0
- package/dist/src/compiled/@workflow/core/source-map.d.ts +10 -0
- package/dist/src/compiled/@workflow/core/step/context-storage.d.ts +13 -0
- package/dist/src/compiled/@workflow/core/step/get-closure-vars.d.ts +9 -0
- package/dist/src/compiled/@workflow/core/step/get-step-metadata.d.ts +42 -0
- package/dist/src/compiled/@workflow/core/step/get-workflow-metadata.d.ts +7 -0
- package/dist/src/compiled/@workflow/core/step/writable-stream.d.ts +22 -0
- package/dist/src/compiled/@workflow/core/step.d.ts +4 -0
- package/dist/src/compiled/@workflow/core/symbols.d.ts +36 -0
- package/dist/src/compiled/@workflow/core/telemetry/semantic-conventions.d.ts +283 -0
- package/dist/src/compiled/@workflow/core/telemetry.d.ts +53 -0
- package/dist/src/compiled/@workflow/core/types.d.ts +14 -0
- package/dist/src/compiled/@workflow/core/util.d.ts +40 -0
- package/dist/src/compiled/@workflow/core/version.d.ts +2 -0
- package/dist/src/compiled/@workflow/core/vm/index.d.ts +17 -0
- package/dist/src/compiled/@workflow/core/vm/uint8array-base64.d.ts +21 -0
- package/dist/src/compiled/@workflow/core/vm/uuid.d.ts +10 -0
- package/dist/src/compiled/@workflow/core/workflow/abort-controller.d.ts +65 -0
- package/dist/src/compiled/@workflow/core/workflow/create-hook.d.ts +7 -0
- package/dist/src/compiled/@workflow/core/workflow/define-hook.d.ts +10 -0
- package/dist/src/compiled/@workflow/core/workflow/get-workflow-metadata.d.ts +32 -0
- package/dist/src/compiled/@workflow/core/workflow/hook.d.ts +4 -0
- package/dist/src/compiled/@workflow/core/workflow/index.d.ts +11 -0
- package/dist/src/compiled/@workflow/core/workflow/sleep.d.ts +4 -0
- package/dist/src/compiled/@workflow/core/workflow/world-init-stub.d.ts +15 -0
- package/dist/src/compiled/@workflow/core/workflow/writable-stream.d.ts +3 -0
- package/dist/src/compiled/@workflow/core/workflow.d.ts +1 -38
- package/dist/src/compiled/@workflow/core/workflow.js +1 -1
- package/dist/src/compiled/@workflow/errors/error-codes.d.ts +5 -1
- package/dist/src/compiled/@workflow/errors/index.d.ts +15 -1
- package/dist/src/compiled/@workflow/errors/index.js +1 -1
- package/dist/src/compiled/@workflow/errors/package.json +1 -1
- package/dist/src/compiled/_chunks/workflow/{context-errors-zbKocOyk.js → context-errors-Bbvvp-li.js} +2 -2
- package/dist/src/compiled/_chunks/workflow/{dist-0iNBqPYp.js → dist-C7wPwOI9.js} +2 -2
- package/dist/src/compiled/_chunks/workflow/{dist-D774SUM4.js → dist-C_oiE-l7.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/resume-hook-C3VWUPii.js +12 -0
- package/dist/src/compiled/_chunks/workflow/sleep-QTkC1VFe.js +1 -0
- package/dist/src/compiled/_chunks/workflow/{symbols-D-4tVV8x.js → symbols-QezhMuLg.js} +1 -1
- package/dist/src/evals/cli/eval.js +1 -1
- package/dist/src/execution/await-authorization-orchestrator.d.ts +2 -1
- package/dist/src/execution/await-authorization-orchestrator.js +4 -0
- package/dist/src/execution/connection-auth-steps.d.ts +4 -0
- package/dist/src/execution/connection-auth-steps.js +9 -11
- package/dist/src/execution/node-step.d.ts +4 -5
- package/dist/src/execution/subagent-adapter.d.ts +0 -27
- package/dist/src/execution/subagent-adapter.js +2 -66
- package/dist/src/execution/subagent-hitl-proxy.d.ts +2 -2
- package/dist/src/execution/subagent-hitl-proxy.js +2 -2
- package/dist/src/execution/task-mode.d.ts +3 -3
- package/dist/src/execution/task-mode.js +3 -3
- package/dist/src/execution/turn-workflow.d.ts +41 -0
- package/dist/src/execution/turn-workflow.js +96 -0
- package/dist/src/execution/workflow-entry.js +77 -87
- package/dist/src/execution/workflow-errors.d.ts +14 -0
- package/dist/src/execution/workflow-errors.js +54 -0
- package/dist/src/execution/workflow-runtime.d.ts +34 -3
- package/dist/src/execution/workflow-runtime.js +52 -10
- package/dist/src/execution/workflow-steps.d.ts +27 -2
- package/dist/src/execution/workflow-steps.js +31 -26
- package/dist/src/harness/instrumentation-config.js +14 -7
- package/dist/src/harness/messages.d.ts +7 -7
- package/dist/src/harness/messages.js +4 -4
- package/dist/src/harness/runtime-actions.d.ts +4 -4
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/workflow-bundle/workflow-builders.d.ts +1 -1
- package/dist/src/internal/workflow-bundle/workflow-builders.js +20 -8
- package/dist/src/internal/workflow-bundle/workflow-transformer.d.ts +13 -0
- package/dist/src/internal/workflow-bundle/workflow-transformer.js +10 -4
- package/dist/src/protocol/message.d.ts +6 -1
- package/dist/src/public/channels/ash.js +50 -3
- package/dist/src/public/context/index.d.ts +4 -7
- package/dist/src/public/context/index.js +4 -5
- package/dist/src/public/definitions/state.d.ts +33 -0
- package/dist/src/public/definitions/state.js +34 -0
- package/dist/src/public/next/index.d.ts +7 -0
- package/dist/src/public/next/index.js +2 -0
- package/dist/src/public/next/vercel-json.d.ts +1 -0
- package/dist/src/public/next/vercel-json.js +1 -0
- package/dist/src/react/index.d.ts +1 -1
- package/dist/src/react/use-ash-agent.d.ts +8 -0
- package/dist/src/react/use-ash-agent.js +26 -4
- package/dist/src/services/dev-client.d.ts +4 -1
- package/dist/src/services/dev-client.js +1 -0
- package/package.json +4 -4
- package/dist/src/chunks/host-DREC8e8Z.js +0 -65
- package/dist/src/chunks/paths-C6sp4T2U.js +0 -88
- package/dist/src/chunks/prewarm-hz8p2jlZ.js +0 -6
- package/dist/src/compiled/_chunks/workflow/resume-hook-CL8Ed91K.js +0 -12
- package/dist/src/compiled/_chunks/workflow/sleep-Dn3i9nxI.js +0 -1
- package/dist/src/execution/continuous-entry.d.ts +0 -59
- package/dist/src/execution/continuous-entry.js +0 -487
- package/dist/src/execution/continuous-runtime.d.ts +0 -17
- package/dist/src/execution/continuous-runtime.js +0 -123
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed handle returned by {@link defineState}. Provides read and
|
|
3
|
+
* update operations over a named context slot.
|
|
4
|
+
*
|
|
5
|
+
* All operations require an active Ash context (ALS scope) and throw
|
|
6
|
+
* when called outside one.
|
|
7
|
+
*/
|
|
8
|
+
export interface StateHandle<T> {
|
|
9
|
+
/** Read the current value. Returns `initial()` on first access within a context. */
|
|
10
|
+
get(): T;
|
|
11
|
+
/** Update the value with a function that receives the current value. */
|
|
12
|
+
update(fn: (current: T) => T): void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Creates a typed, named state slot backed by a durable `ContextKey`.
|
|
16
|
+
*
|
|
17
|
+
* All operations require an active Ash context — calling `get()` or
|
|
18
|
+
* `update()` outside of tools, hooks, or other framework-managed
|
|
19
|
+
* code throws.
|
|
20
|
+
*
|
|
21
|
+
* State is durable: values survive across workflow step boundaries.
|
|
22
|
+
* To reset per-turn, use `update(() => freshValue)` in a lifecycle
|
|
23
|
+
* hook.
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* const budget = defineState("my-agent.budget", () => ({ count: 0, cap: 25 }));
|
|
27
|
+
*
|
|
28
|
+
* // In a tool or hook:
|
|
29
|
+
* budget.update((s) => ({ ...s, count: s.count + 1 }));
|
|
30
|
+
* const current = budget.get();
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function defineState<T>(name: string, initial: () => T): StateHandle<T>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ContextKey } from "#context/key.js";
|
|
2
|
+
import { loadContext } from "#context/container.js";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a typed, named state slot backed by a durable `ContextKey`.
|
|
5
|
+
*
|
|
6
|
+
* All operations require an active Ash context — calling `get()` or
|
|
7
|
+
* `update()` outside of tools, hooks, or other framework-managed
|
|
8
|
+
* code throws.
|
|
9
|
+
*
|
|
10
|
+
* State is durable: values survive across workflow step boundaries.
|
|
11
|
+
* To reset per-turn, use `update(() => freshValue)` in a lifecycle
|
|
12
|
+
* hook.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* const budget = defineState("my-agent.budget", () => ({ count: 0, cap: 25 }));
|
|
16
|
+
*
|
|
17
|
+
* // In a tool or hook:
|
|
18
|
+
* budget.update((s) => ({ ...s, count: s.count + 1 }));
|
|
19
|
+
* const current = budget.get();
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function defineState(name, initial) {
|
|
23
|
+
const key = new ContextKey(name);
|
|
24
|
+
return {
|
|
25
|
+
get() {
|
|
26
|
+
return loadContext().ensure(key, initial);
|
|
27
|
+
},
|
|
28
|
+
update(fn) {
|
|
29
|
+
const ctx = loadContext();
|
|
30
|
+
const current = ctx.ensure(key, initial);
|
|
31
|
+
ctx.set(key, fn(current));
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -45,6 +45,13 @@ export interface WithAshOptions {
|
|
|
45
45
|
* absolute. Defaults to the Next.js app root.
|
|
46
46
|
*/
|
|
47
47
|
readonly ashRoot?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Build command for the generated Ash Vercel service. Defaults to `ash build`.
|
|
50
|
+
*
|
|
51
|
+
* Use this when the Ash service needs project-specific prework before the
|
|
52
|
+
* framework build, without changing the Next.js service build command.
|
|
53
|
+
*/
|
|
54
|
+
readonly ashBuildCommand?: string;
|
|
48
55
|
/**
|
|
49
56
|
* Set to `false` to skip creating or updating `vercel.json`.
|
|
50
57
|
*
|
|
@@ -9,6 +9,7 @@ import { ensureAshVercelJson } from "./vercel-json.js";
|
|
|
9
9
|
export const ASH_NEXT_SERVICE_PREFIX = "/_ash_internal/ash";
|
|
10
10
|
const ASH_NEXT_PRODUCTION_ORIGIN_ENV = "ASH_NEXT_PRODUCTION_ORIGIN";
|
|
11
11
|
const ASH_NEXT_PRODUCTION_PORT_ENV = "ASH_NEXT_PRODUCTION_PORT";
|
|
12
|
+
const DEFAULT_ASH_BUILD_COMMAND = "ash build";
|
|
12
13
|
const DEFAULT_ASH_NEXT_PRODUCTION_PORT = 4274;
|
|
13
14
|
const ASH_PROXY_REWRITE_SOURCES = [`${ASH_ROUTE_PREFIX}/:path+`];
|
|
14
15
|
function resolveApplicationRoot(appPath) {
|
|
@@ -129,6 +130,7 @@ export function withAsh(configOrFunction, options = {}) {
|
|
|
129
130
|
const configuredVercel = shouldConfigureVercelJson
|
|
130
131
|
? await ensureAshVercelJson({
|
|
131
132
|
appRoot,
|
|
133
|
+
ashBuildCommand: options.ashBuildCommand ?? DEFAULT_ASH_BUILD_COMMAND,
|
|
132
134
|
nextRoot,
|
|
133
135
|
servicePrefix: servicePrefixInput,
|
|
134
136
|
})
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { useAshAgent, type UseAshAgentHelpers, type UseAshAgentOptions, type UseAshAgentSnapshot, type UseAshAgentStatus, } from "#react/use-ash-agent.js";
|
|
1
|
+
export { useAshAgent, type PrepareSend, type UseAshAgentHelpers, type UseAshAgentOptions, type UseAshAgentSnapshot, type UseAshAgentStatus, } from "#react/use-ash-agent.js";
|
|
2
2
|
export { type AshAgentReducer, type AshAgentReducerEvent, type ClientInputRespondedEvent, type ClientMessageFailedEvent, type ClientMessageSubmittedEvent, } from "#client/reducer.js";
|
|
3
3
|
export { defaultMessageReducer, type AshMessageData, type AshDynamicToolPart, type AshMessageInputRequest, type AshMessage, type AshMessageMetadata, type AshMessagePart, type AshMessageToolMetadata, } from "#client/message-reducer.js";
|
|
@@ -4,6 +4,13 @@ import { type AshMessageData } from "#client/message-reducer.js";
|
|
|
4
4
|
import type { HandleMessageStreamEvent } from "#protocol/message.js";
|
|
5
5
|
import type { ClientAuth, HeadersValue, SendMessageOptions, SendTurnInput, SessionState } from "#client/types.js";
|
|
6
6
|
export type UseAshAgentStatus = "error" | "ready" | "streaming" | "submitted";
|
|
7
|
+
/**
|
|
8
|
+
* Prepares one outbound turn immediately before the client sends it.
|
|
9
|
+
*
|
|
10
|
+
* Use this to attach fresh, one-turn client state such as page context via
|
|
11
|
+
* `clientContext`.
|
|
12
|
+
*/
|
|
13
|
+
export type PrepareSend = (input: SendTurnInput) => SendTurnInput | Promise<SendTurnInput>;
|
|
7
14
|
/**
|
|
8
15
|
* Current projected state for an Ash agent session.
|
|
9
16
|
*/
|
|
@@ -22,6 +29,7 @@ export interface UseAshAgentCallbacks<TData> {
|
|
|
22
29
|
readonly onEvent?: (event: HandleMessageStreamEvent) => void;
|
|
23
30
|
readonly onFinish?: (snapshot: UseAshAgentSnapshot<TData>) => void;
|
|
24
31
|
readonly onSessionChange?: (session: SessionState) => void;
|
|
32
|
+
readonly prepareSend?: PrepareSend;
|
|
25
33
|
}
|
|
26
34
|
/**
|
|
27
35
|
* Snapshot plus commands returned by `useAshAgent`.
|
|
@@ -26,6 +26,7 @@ export function useAshAgent(options = {}) {
|
|
|
26
26
|
onEvent: options.onEvent,
|
|
27
27
|
onFinish: options.onFinish,
|
|
28
28
|
onSessionChange: options.onSessionChange,
|
|
29
|
+
prepareSend: options.prepareSend,
|
|
29
30
|
});
|
|
30
31
|
const subscribe = useCallback((onStoreChange) => store.subscribe(onStoreChange), [store]);
|
|
31
32
|
const snapshot = useSyncExternalStore(subscribe, () => store.snapshot, () => store.snapshot);
|
|
@@ -102,11 +103,16 @@ class UseAshAgentStore {
|
|
|
102
103
|
this.#abortController = abortController;
|
|
103
104
|
this.#error = undefined;
|
|
104
105
|
this.#status = "submitted";
|
|
105
|
-
this.#projectOptimisticMessage(input);
|
|
106
|
-
this.#projectInputResponses(input);
|
|
107
106
|
this.#publish();
|
|
108
107
|
try {
|
|
109
|
-
const
|
|
108
|
+
const preparedInput = (await this.#callbacks.prepareSend?.(input)) ?? input;
|
|
109
|
+
if (!this.#isCurrentOperation(operationId)) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
this.#projectOptimisticMessage(preparedInput);
|
|
113
|
+
this.#projectInputResponses(preparedInput);
|
|
114
|
+
this.#publish();
|
|
115
|
+
const response = await this.#session.send(preparedInput, {
|
|
110
116
|
...options,
|
|
111
117
|
signal: createAbortSignal(options?.signal, abortController.signal),
|
|
112
118
|
});
|
|
@@ -195,7 +201,7 @@ class UseAshAgentStore {
|
|
|
195
201
|
const pending = {
|
|
196
202
|
createdAt: Date.now(),
|
|
197
203
|
id,
|
|
198
|
-
message: input.message,
|
|
204
|
+
message: summarizeUserContent(input.message),
|
|
199
205
|
};
|
|
200
206
|
this.#pendingMessageSubmission = pending;
|
|
201
207
|
this.#appendProjectionEvent({
|
|
@@ -312,6 +318,22 @@ function createSubmissionId() {
|
|
|
312
318
|
function createAbortSignal(first, second) {
|
|
313
319
|
return first ? AbortSignal.any([first, second]) : second;
|
|
314
320
|
}
|
|
321
|
+
function summarizeUserContent(message) {
|
|
322
|
+
if (typeof message === "string") {
|
|
323
|
+
return message;
|
|
324
|
+
}
|
|
325
|
+
const parts = [];
|
|
326
|
+
for (const part of message) {
|
|
327
|
+
if (part.type === "text") {
|
|
328
|
+
parts.push(part.text);
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
if (part.type === "file") {
|
|
332
|
+
parts.push(part.filename ? `[file: ${part.filename}]` : "[file]");
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return parts.join("\n");
|
|
336
|
+
}
|
|
315
337
|
function isAbortError(error) {
|
|
316
338
|
return error instanceof Error && error.name === "AbortError";
|
|
317
339
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import type { UserContent } from "ai";
|
|
1
2
|
import { type SessionState } from "#client/index.js";
|
|
2
3
|
import type { HandleMessageStreamEvent } from "#protocol/message.js";
|
|
3
4
|
import type { InputResponse } from "#runtime/input/types.js";
|
|
5
|
+
import type { JsonObject } from "#shared/json.js";
|
|
4
6
|
export type { DevelopmentRequestHeaders } from "#services/dev-client/request-headers.js";
|
|
5
7
|
export { extractCompletedMessage } from "#services/dev-client/stream.js";
|
|
6
8
|
/**
|
|
@@ -41,8 +43,9 @@ export interface DevelopmentMessageClient {
|
|
|
41
43
|
* Sends one turn payload through the active development session.
|
|
42
44
|
*/
|
|
43
45
|
send(input: {
|
|
46
|
+
readonly clientContext?: string | readonly string[] | JsonObject;
|
|
44
47
|
readonly inputResponses?: readonly InputResponse[];
|
|
45
|
-
readonly message?: string;
|
|
48
|
+
readonly message?: string | UserContent;
|
|
46
49
|
onEvent?(event: HandleMessageStreamEvent): void;
|
|
47
50
|
onResponseStart?(response: {
|
|
48
51
|
sessionId?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "experimental-ash",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"bin": {
|
|
5
5
|
"ash": "./bin/ash.js",
|
|
6
6
|
"experimental-ash": "./bin/ash.js"
|
|
@@ -174,9 +174,9 @@
|
|
|
174
174
|
"@types/react-test-renderer": "19.1.0",
|
|
175
175
|
"@vercel/oidc": "3.4.0",
|
|
176
176
|
"@vercel/sandbox": "2.0.0-beta.14",
|
|
177
|
-
"@workflow/core": "5.0.0-beta.
|
|
178
|
-
"@workflow/errors": "5.0.0-beta.
|
|
179
|
-
"@workflow/world-local": "5.0.0-beta.
|
|
177
|
+
"@workflow/core": "5.0.0-beta.7",
|
|
178
|
+
"@workflow/errors": "5.0.0-beta.4",
|
|
179
|
+
"@workflow/world-local": "5.0.0-beta.6",
|
|
180
180
|
"ai": "7.0.0-canary.144",
|
|
181
181
|
"autoevals": "0.0.132",
|
|
182
182
|
"chat": "4.28.1",
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import{n as e}from"./chunk-8L7ocgPr.js";import{C as t,T as n,i as r,r as i,w as a}from"./paths-C6sp4T2U.js";import{a as o,i as s,n as c,r as l}from"./authored-module-loader-XcFLnl49.js";import{a as u,i as d,n as f,o as p,r as m,t as h}from"./package-DmsQgn4v.js";import{g,m as ee,p as te}from"./types-MZUhN0Zy.js";import{a as ne,c as re,n as ie,o as ae,r as oe,t as se}from"./prewarm-hz8p2jlZ.js";import{builtinModules as ce}from"node:module";import{dirname as _,extname as le,isAbsolute as ue,join as v,relative as y,resolve as b,sep as de}from"node:path";import{cp as x,mkdir as S,readFile as C,readdir as w,realpath as fe,rename as T,rm as E,symlink as pe,writeFile as D}from"node:fs/promises";import{randomUUID as me}from"node:crypto";import{existsSync as he,readFileSync as ge}from"node:fs";import{fileURLToPath as _e}from"node:url";import{Buffer as ve}from"node:buffer";import{build as ye,copyPublicAssets as be,createDevServer as xe,createNitro as Se,prepare as Ce,prerender as we}from"nitro/builder";const Te=`ash-cache.json`;async function Ee(e){let t=await De(e),n=h().version;t!==null&&t===n||await E(e,{force:!0,recursive:!0})}async function O(e){await S(e,{recursive:!0}),await D(v(e,Te),`${JSON.stringify({ashVersion:h().version},null,2)}\n`)}async function De(e){try{let t=JSON.parse(await C(v(e,Te),`utf8`));return typeof t.ashVersion==`string`?t.ashVersion:null}catch(e){return e instanceof Error&&`code`in e&&e.code,null}}const Oe=new Set([`__builtin_response_array_buffer`,`__builtin_response_json`,`__builtin_response_text`]);async function ke(e){if(e.mode===!1)return{code:e.source,workflowManifest:{}};let t=await Ae(e.filename,e.source),n=Me(t);if(n.length===0)return{code:e.source,workflowManifest:{}};let r=e.moduleSpecifier??`./${qe(e.filename)}`,i={},a=[],o=[],s=!1;for(let t of n){if(t.directive===`use step`){let n=Je(r,t.name);i.steps??={};let c=i.steps[e.filename]??={};if(c[t.name]={stepId:n},e.mode===`workflow`){let e=t.exportPrefix.length>0?`export `:``;a.push({end:t.rangeEnd,start:t.rangeStart,text:`${e}var ${t.name} = globalThis[Symbol.for("WORKFLOW_USE_STEP")](${JSON.stringify(n)});`})}else a.push({end:t.directiveEnd,start:t.directiveStart,text:``}),e.mode===`step`?(s=!0,o.push(`registerStepFunction(${JSON.stringify(n)}, ${t.name});`)):o.push(`${t.name}.stepId = ${JSON.stringify(n)};`);continue}let n=`workflow//${r}//${t.name}`;i.workflows??={};let c=i.workflows[e.filename]??={};c[t.name]={workflowId:n},e.mode===`workflow`?(a.push({end:t.directiveEnd,start:t.directiveStart,text:``}),o.push(`${t.name}.workflowId = ${JSON.stringify(n)};`),o.push(`globalThis.__private_workflows.set(${JSON.stringify(n)}, ${t.name});`)):(a.push({end:t.directiveEnd,start:t.directiveStart,text:`throw new Error(${JSON.stringify(`You attempted to execute workflow ${t.name} function directly. To start a workflow, use start(${t.name}) from workflow/api`)});`}),o.push(`${t.name}.workflowId = ${JSON.stringify(n)};`))}let c=`/**__internal_workflows${JSON.stringify(i)}*/;`,l=n.some(e=>e.directive===`use workflow`);if(e.mode===`workflow`&&!l)return{code:`${c}\n${je(e.source,t,n,r)}`,workflowManifest:i};let u=Le(e.source,a),d=e.mode===`workflow`?await Re(e.filename,u):u;return{code:`${s?`import { registerStepFunction } from "workflow/internal/private";\n${c}\n`:`${c}\n`}${d}${o.length>0?`\n${o.join(`
|
|
2
|
-
`)}\n`:``}`,workflowManifest:i}}async function Ae(e,t){let{parseAst:n}=await o();return n(t,{astType:`ts`,lang:Ke(e),range:!0,sourceType:`module`},e)}function je(e,t,n,r){let i=ze(e,t),a=n.filter(e=>e.directive===`use step`).map(e=>{let t=e.exportPrefix.length>0?`export `:``,n=Je(r,e.name);return`${t}var ${e.name} = globalThis[Symbol.for("WORKFLOW_USE_STEP")](${JSON.stringify(n)});`}),o=[...i,...a];return o.length>0?`${o.join(`
|
|
3
|
-
`)}\n`:``}function Me(e){let t=[];for(let n of e.body??[]){let e=Ne(n);if(e===null)continue;let r=e.fn,i=r.id?.name,a=Fe(r.body);if(r.async!==!0||i===void 0||a===void 0)continue;let o=Ie(a[0]);o!==null&&t.push({directive:o.value,directiveEnd:o.end,directiveStart:o.start,exportPrefix:e.exported?`export `:``,name:i,rangeEnd:e.end,rangeStart:e.start})}return t}function Ne(e){return e.type===`FunctionDeclaration`?Pe(e,!1,e):e.type!==`ExportNamedDeclaration`||e.declaration?.type!==`FunctionDeclaration`?null:Pe(e.declaration,!0,e)}function Pe(e,t,n){return e.start===void 0||e.end===void 0||n.start===void 0||n.end===void 0?null:{end:n.end,exported:t,fn:e,start:n.start}}function Fe(e){return e===void 0||Array.isArray(e)?e:e.body}function Ie(e){let t=e?.directive??(e?.type===`ExpressionStatement`&&e.expression?.type===`Literal`?e.expression.value:void 0);return t!==`use workflow`&&t!==`use step`||e?.start===void 0||e.end===void 0?null:{end:e.end,start:e.start,value:t}}function Le(e,t){let n=``,r=0;for(let i of[...t].sort((e,t)=>e.start-t.start))n+=e.slice(r,i.start),n+=i.text,r=i.end;return n+e.slice(r)}async function Re(e,t){let n=await Ae(e,t),r=Ue(n),i=[];for(let e of n.body??[]){if(e.type!==`ImportDeclaration`||e.start===void 0||e.end===void 0)continue;let n=He(e);n.length>0&&n.every(e=>!r.has(e))&&i.push({end:Ge(t,e.end),start:e.start,text:``})}return i.length>0?Le(t,i):t}function ze(e,t){let n=[];for(let r of t.body??[])r.type===`ExportNamedDeclaration`&&r.declaration?.type===`VariableDeclaration`&&r.declaration.kind===`const`&&r.start!==void 0&&r.end!==void 0&&(r.declaration.declarations??[]).every(Be)&&n.push(e.slice(r.start,r.end).trim());return n}function Be(e){return Ve(e.init)}function Ve(e){return e==null?!1:e.type===`Literal`?e.value===null||typeof e.value==`boolean`||typeof e.value==`number`||typeof e.value==`string`:e.type===`TSAsExpression`||e.type===`TSSatisfiesExpression`||e.type===`TSNonNullExpression`||e.type===`TSTypeAssertion`?Ve(e.expression):e.type===`UnaryExpression`&&e.argument?.type===`Literal`?typeof e.argument.value==`number`:!1}function He(e){return e.importKind===`type`?[]:(e.specifiers??[]).filter(e=>e.importKind!==`type`).map(e=>e.local?.name).filter(e=>e!==void 0)}function Ue(e){let t=new Set;return k(e,e=>{e.type===`Identifier`&&typeof e.name==`string`&&t.add(e.name)}),t}function k(e,t){if(!(e.type===`ImportDeclaration`||e.type?.startsWith(`TS`))){t(e);for(let n of Object.values(e))if(Array.isArray(n))for(let e of n)We(e)&&k(e,t);else We(n)&&k(n,t)}}function We(e){return typeof e==`object`&&!!e&&typeof e.type==`string`}function Ge(e,t){let n=t;for(;n<e.length&&(e[n]===` `||e[n]===` `);)n+=1;return e[n]===`\r`&&e[n+1]===`
|
|
4
|
-
`?n+2:e[n]===`
|
|
5
|
-
`?n+1:n}function Ke(e){return e.endsWith(`.tsx`)?`tsx`:e.endsWith(`.jsx`)?`jsx`:/\.[cm]?ts$/.test(e)?`ts`:`js`}function qe(e){return e.replace(/\.(?:[cm]?[jt]sx?)$/,``)}function Je(e,t){return Oe.has(t)?t:`step//${e}//${t}`}const Ye={type:`queue/v2beta`,topic:`__wkf_workflow_*`,consumer:`default`,retryAfterSeconds:5,initialDelaySeconds:0},A=new Map,Xe=new Map;async function j(e,t,n,r,i){let a=i??process.cwd(),{moduleSpecifier:o}=$e(r===void 0?ue(e)?e:v(a,e):r,a);return ke({filename:e,mode:n,moduleSpecifier:o,source:t})}function Ze(e){return{hasSerde:e.includes(`workflow.serde`)||e.includes(`@serde`)||e.includes(`workflowSerde`)||e.includes(`__workflow_serde`),hasUseStep:/["']use step["']/.test(e),hasUseWorkflow:/["']use workflow["']/.test(e)}}function Qe(e,t){let n=P(e),r=!n&&rt(e,t);if(n||r){let n=M(e);if(n!==null){let i=nt(t).has(n.name);if(!(r||i))return{importPath:F(e,t),isPackage:!1};let a=et(e,n);return a?{importPath:`${n.name}${a}`,isPackage:!0}:ot(e,n)?{importPath:n.name,isPackage:!0}:{importPath:F(e,t),isPackage:!1}}}return{importPath:F(e,t),isPackage:!1}}function $e(e,t){let n=P(e),r=!n&&rt(e,t);if(!n&&!r)return{moduleSpecifier:void 0};let i=M(e);if(i===null)return{moduleSpecifier:void 0};let a=et(e,i);return{moduleSpecifier:a?`${i.name}${a}@${i.version}`:`${i.name}@${i.version}`}}function M(e){let t=_(e),n=[];for(;t!==_(t);){let e=A.get(t);if(e!==void 0){for(let t of n)A.set(t,e);return e}n.push(t);let r=v(t,`package.json`);if(he(r))try{let e=JSON.parse(ge(r,`utf8`));if(typeof e.name==`string`&&typeof e.version==`string`){let r={dir:t,exports:e.exports,main:e.main,module:e.module,name:e.name,version:e.version};A.set(t,r);for(let e of n)A.set(e,r);return r}}catch{}t=_(t)}for(let e of n)A.set(e,null);return null}function et(e,t){if(t.exports===null||typeof t.exports!=`object`||Array.isArray(t.exports))return``;let n=e.replace(/\\/g,`/`),r=t.dir.replace(/\\/g,`/`),i=n.startsWith(`${r}/`)?`./${n.substring(r.length+1)}`:null;if(i===null)return``;for(let[e,n]of Object.entries(t.exports)){let t=N(n);if(t!==null&&tt(t)===i)return e===`.`?``:e.substring(1)}return``}function N(e){if(typeof e==`string`)return e;if(Array.isArray(e)){for(let t of e){let e=N(t);if(e!==null)return e}return null}if(typeof e==`object`&&e)for(let t of[`workflow`,`default`,`require`,`import`,`node`]){let n=e[t],r=N(n);if(r!==null)return r}return null}function tt(e){return e.startsWith(`./`)?e:`./${e}`}function P(e){return e.split(de).join(`/`).includes(`/node_modules/`)}function nt(e){let t=Xe.get(e);if(t!==void 0)return t;let n=new Set,r=v(e,`package.json`);if(he(r))try{let e=JSON.parse(ge(r,`utf8`));for(let t of[`dependencies`,`devDependencies`,`peerDependencies`,`optionalDependencies`]){let r=e[t];if(typeof r==`object`&&r&&!Array.isArray(r))for(let e of Object.keys(r))n.add(e)}}catch{}return Xe.set(e,n),n}function rt(e,t){if(P(e))return!1;let n=M(e);return n===null||b(n.dir)===b(t)?!1:nt(t).has(n.name)}function F(e,t){let n=t.replace(/\\/g,`/`),r=e.replace(/\\/g,`/`),i=r.startsWith(`${n}/`)?r.substring(n.length+1):y(t,e).replace(/\\/g,`/`);return i.startsWith(`.`)||(i=`./${i}`),i}function it(e){if(typeof e==`string`||Array.isArray(e))return!0;if(typeof e!=`object`||!e)return!1;let t=Object.keys(e);return t.length>0&&t.every(e=>!e.startsWith(`.`))?!0:`.`in e}function at(e){let t=e.replace(/\\/g,`/`);return t.startsWith(`./`)?t.substring(2):t.startsWith(`/`)?t.substring(1):t}function ot(e,t){let n=e.replace(/\\/g,`/`),r=t.dir.replace(/\\/g,`/`);if(!n.startsWith(`${r}/`))return!1;let i=n.substring(r.length+1);if(t.exports!==void 0){let e;if(t.exports!==null&&typeof t.exports==`object`&&`.`in t.exports)e=t.exports[`.`];else if(it(t.exports))e=t.exports;else return!1;let n=N(e);return n!==null&&at(n)===i}return[t.module,t.main,`index.js`,`index.mjs`,`index.cjs`,`index.ts`,`index.mts`,`index.cts`].flatMap(e=>typeof e==`string`?[at(e)]:[]).includes(i)}const st=`\0ash-workflow-entry`,ct=new Set([`server-only`,`client-only`,`next/dist/compiled/server-only`,`next/dist/compiled/client-only`]);new Set([...ce,...ce.map(e=>`node:${e}`)]);const lt=new Set([`.ts`,`.tsx`,`.mts`,`.cts`,`.js`,`.jsx`,`.mjs`,`.cjs`]),ut=new Set([`node_modules`,`.git`,`.next`,`.nuxt`,`.output`,`.vercel`,`.workflow-data`,`.workflow-vitest`,`.well-known`,`.svelte-kit`,`.turbo`,`.cache`,`.yarn`,`.pnpm-store`]);async function dt(e){let t=[];async function n(e){let r;try{r=await w(e,{withFileTypes:!0})}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}for(let i of r){if(i.isDirectory()){ut.has(i.name)||await n(v(e,i.name));continue}if(!i.isFile())continue;let r=i.name.match(/\.[^.]+$/)?.[0];r!==void 0&<.has(r)&&t.push(v(e,i.name))}}return await n(e),t}function ft(e,t){let{importPath:n,isPackage:r}=Qe(e,t);return r?`import ${JSON.stringify(n)};`:`import ${JSON.stringify(xt(t,e))};`}function pt(e){return{name:`ash-workflow-virtual-entry`,resolveId(e){if(e===`\0ash-workflow-entry`)return{id:e}},load(t){if(t===`\0ash-workflow-entry`)return{code:e,moduleSideEffects:!0,moduleType:`js`}}}}function mt(){return{name:`ash-workflow-pseudo-packages`,resolveId(e){if(ct.has(e))return{id:`\0ash-workflow-pseudo-package:${e}`}},load(e){if(e.startsWith(`\0ash-workflow-pseudo-package:`))return{code:``,moduleType:`js`}}}}function ht(e,t={}){return{name:`ash-package-imports`,resolveId(n){let r=n.match(/^#compiled\/(.+)$/)?.[1];if(r!==void 0)return t.workflowCondition===!0&&r===`@workflow/core/index.js`?I([v(e,`src`,`internal`,`workflow-bundle`,`workflow-core-shim.ts`),v(e,`dist`,`src`,`internal`,`workflow-bundle`,`workflow-core-shim.js`)]):I([v(e,`.generated`,`compiled`,r),v(e,`dist`,`src`,`compiled`,r)]);let i=n.match(/^#(.+)\.js$/)?.[1];if(i!==void 0)return I([`.ts`,`.tsx`,`.mts`,`.cts`,`.js`,`.jsx`,`.mjs`,`.cjs`].flatMap(t=>[v(e,`src`,`${i}${t}`),v(e,`dist`,`src`,`${i}${t}`)]))}}}function gt(e){let t=new Set(e.sideEffectFiles?.map(e=>e.replaceAll(`\\`,`/`))??[]);return{name:`ash-workflow-transform`,async load(n){if(!Tt(n))return;let r=await C(n,`utf8`),i=await j(wt(e.workingDir,n),r.replace(/require\(\s*(['"])server-only\1\s*\)/g,`void 0`).replace(/require\(\s*(['"])client-only\1\s*\)/g,`void 0`),e.mode??`workflow`,n,e.projectRoot);return Ct(e.manifest,i.workflowManifest),{code:i.code,map:null,moduleSideEffects:t.has(n.replaceAll(`\\`,`/`))||void 0}}}}async function _t(e){let t=`// biome-ignore-all lint: generated file
|
|
6
|
-
/* eslint-disable */
|
|
7
|
-
import { workflowEntrypoint } from 'workflow/runtime';
|
|
8
|
-
|
|
9
|
-
const workflowCode = \`${(e.code.endsWith(`
|
|
10
|
-
`)?e.code:`${e.code}\n`).replace(/[\\`$]/g,`\\$&`)}\`;
|
|
11
|
-
|
|
12
|
-
export const POST = workflowEntrypoint(workflowCode);`;if(!e.bundleFinalOutput){await St(e.outfile,t);return}let n=s(await l({cwd:e.workingDir,input:st,external:e=>e===`@aws-sdk/credential-provider-web-identity`,platform:`node`,plugins:[pt(t)],write:!1,output:{comments:!1,format:e.format,sourcemap:!1}}),`final workflow bundle for "${e.outfile}"`);await St(e.outfile,n.code)}function vt(e){let t={};for(let[n,r]of Object.entries(e??{})){t[n]={};for(let[e,i]of Object.entries(r))t[n][e]={stepId:i.stepId}}return t}function yt(e){let t={};for(let[n,r]of Object.entries(e??{})){t[n]={};for(let[e,i]of Object.entries(r))t[n][e]={graph:{edges:[],nodes:[]},workflowId:i.workflowId}}return t}function bt(e){let t={};for(let[n,r]of Object.entries(e??{})){t[n]={};for(let[e,i]of Object.entries(r))t[n][e]={classId:i.classId}}return t}function xt(e,t){let n=y(e,t).replaceAll(`\\`,`/`);return n.startsWith(`./`)||n.startsWith(`../`)?n:`./${n}`}function I(e){for(let t of e)if(he(t))return{id:b(t)}}async function St(e,t){await S(_(e),{recursive:!0});let n=`${e}.${process.pid}.${Date.now()}.tmp`;await D(n,t),await T(n,e)}function Ct(e,t){e.steps=L(e.steps,t.steps),e.workflows=L(e.workflows,t.workflows),e.classes=L(e.classes,t.classes)}function L(e,t){if(t===void 0)return e;let n={...e};for(let[e,r]of Object.entries(t))n[e]={...n[e],...r};return n}function wt(e,t){let n=t.replaceAll(`\\`,`/`),r=y(e.replaceAll(`\\`,`/`),n).replaceAll(`\\`,`/`);return r.startsWith(`../`)&&(r=r.split(`/`).filter(e=>e!==`..`).join(`/`)),r}function Tt(e){return/\.(?:[cm]?[jt]sx?)$/.test(e)}async function R(e,t){let n=`${e}.tmp-${process.pid}-${Date.now().toString(36)}`;await D(n,t),await Et(n,e)}async function Et(e,t){if(process.platform!==`win32`){await T(e,t);return}for(let n=0;n<10;n+=1)try{await T(e,t);return}catch(e){if(!(e instanceof Error&&`code`in e&&(e.code===`EPERM`||e.code===`EACCES`||e.code===`EBUSY`))||n===9)throw e;await new Promise(e=>setTimeout(e,10*(n+1)))}}async function Dt(e){let t=[...e.discoveredEntries.discoveredSteps].sort(),n=new Set(t),r=[...e.discoveredEntries.discoveredSerdeFiles].sort().filter(e=>!n.has(e)),i=await kt({projectRoot:e.projectRoot,stepFiles:t,serdeOnlyFiles:r,workingDir:e.workingDir}),a=_(e.outfile),o=[`// Generated by Ash. Do not edit by hand.`,...Ot({builtinsImportSpecifier:e.builtinsPath===void 0?`workflow/internal/builtins`:z({outfileDirectory:a,preferAbsoluteFileImports:e.preferAbsoluteFileImports??!1,targetPath:e.builtinsPath}),outfileDirectory:a,preferAbsoluteFileImports:e.preferAbsoluteFileImports??!1,serdeOnlyFiles:r,stepFiles:t}),`export const __steps_registered = true;`,``].join(`
|
|
13
|
-
`);return await S(a,{recursive:!0}),await Nt(e.outfile)!==o&&await D(e.outfile,o),i}function Ot(e){return[e.builtinsImportSpecifier,...e.stepFiles.map(t=>z({outfileDirectory:e.outfileDirectory,preferAbsoluteFileImports:e.preferAbsoluteFileImports,targetPath:t})),...e.serdeOnlyFiles.map(t=>z({outfileDirectory:e.outfileDirectory,preferAbsoluteFileImports:e.preferAbsoluteFileImports,targetPath:t}))].map(e=>`import ${JSON.stringify(e)};`)}function z(e){return e.preferAbsoluteFileImports?t(e.targetPath):Mt(e.outfileDirectory,e.targetPath)}async function kt(e){let t={},n=[...e.stepFiles,...e.serdeOnlyFiles];for(let r of n){let n=await C(r,`utf8`);At(t,(await j(jt(e.workingDir,r),n,`step`,r,e.projectRoot)).workflowManifest)}return t}function At(e,t){e.steps=B(e.steps,t.steps),e.workflows=B(e.workflows,t.workflows),e.classes=B(e.classes,t.classes)}function B(e,t){if(t===void 0)return e;let n={...e};for(let[e,r]of Object.entries(t))n[e]={...n[e],...r};return n}function jt(e,t){let n=t.replaceAll(`\\`,`/`),r=y(e.replaceAll(`\\`,`/`),n).replaceAll(`\\`,`/`);return r.startsWith(`../`)&&(r=r.split(`/`).filter(e=>e!==`..`).join(`/`)),r}function Mt(e,t){let n=y(e,t).replaceAll(`\\`,`/`);return n.startsWith(`.`)?n:`./${n}`}async function Nt(e){try{return await C(e,`utf8`)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return null;throw e}}const Pt=`index.__ash_service_route_prefix.mjs`,Ft=[`ash/`,`.well-known/workflow/`];function V(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function It(e){return Ft.some(t=>e.startsWith(t))}function Lt(e,t){return e.filter(Rt).map(e=>Bt(e,t))}function Rt(e){if(!V(e)||`handle`in e)return!0;let t=typeof e.src==`string`?e.src:``,n=typeof e.dest==`string`?e.dest:``;return H(t)||H(n)}function H(e){return e.includes(`/ash/v1`)||e.includes(`/.well-known/workflow/`)}function zt(e){return e.includes(`/ash/v1`)}function Bt(e,t){if(!V(e)||`handle`in e||typeof e.src!=`string`)return e;let n=zt(e.src)||typeof e.dest==`string`&&zt(e.dest),r={...e,src:Vt(e.src,t)};return n&&(r.dest=`/ash/__server`),r}function Vt(e,t){if(t===void 0||t===`/`||!H(e)||e.includes(t))return e;let n=t.endsWith(`/`)?t.slice(0,-1):t,r=n.replaceAll(`/`,`\\/`);return e.includes(r)?e:e.startsWith(`^(?:/`)?`^(?:${n}${e.slice(4)}`:e.startsWith(`^/`)?`^${n}${e.slice(1)}`:e.startsWith(`/`)?`${n}${e}`:e}async function Ht(e,t){let n=v(e,`.vc-config.json`),r=v(e,Pt),i=JSON.parse(await C(n,`utf8`)),a=V(i)?i:{};await D(r,Ut(t)),await D(n,`${JSON.stringify({...a,handler:Pt},null,2)}\n`)}function Ut(e){return`
|
|
14
|
-
import { Server } from "node:http";
|
|
15
|
-
|
|
16
|
-
const SERVICE_PREFIX = ${JSON.stringify(Wt(e))};
|
|
17
|
-
const PATCH_SYMBOL = Symbol.for("ash.service.route-prefix-strip.patch");
|
|
18
|
-
|
|
19
|
-
function stripServiceRoutePrefix(requestUrl) {
|
|
20
|
-
if (typeof requestUrl !== "string" || requestUrl === "*") {
|
|
21
|
-
return requestUrl;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const queryIndex = requestUrl.indexOf("?");
|
|
25
|
-
const rawPath = queryIndex === -1 ? requestUrl : requestUrl.slice(0, queryIndex);
|
|
26
|
-
const query = queryIndex === -1 ? "" : requestUrl.slice(queryIndex);
|
|
27
|
-
const path = rawPath.startsWith("/") ? rawPath : \`/\${rawPath}\`;
|
|
28
|
-
|
|
29
|
-
if (path === SERVICE_PREFIX) {
|
|
30
|
-
return \`/\${query}\`;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (path.startsWith(\`\${SERVICE_PREFIX}/\`)) {
|
|
34
|
-
return path.slice(SERVICE_PREFIX.length) + query;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return path + query;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (!globalThis[PATCH_SYMBOL]) {
|
|
41
|
-
globalThis[PATCH_SYMBOL] = true;
|
|
42
|
-
const originalEmit = Server.prototype.emit;
|
|
43
|
-
Server.prototype.emit = function patchedEmit(event, request, ...args) {
|
|
44
|
-
if (event === "request" && request && typeof request.url === "string") {
|
|
45
|
-
request.url = stripServiceRoutePrefix(request.url);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return originalEmit.call(this, event, request, ...args);
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const originalModule = await import("./index.mjs");
|
|
53
|
-
const entrypoint = originalModule?.default ?? originalModule;
|
|
54
|
-
|
|
55
|
-
export default entrypoint;
|
|
56
|
-
`.trimStart()}function Wt(e){let t=(e.startsWith(`/`)?e:`/${e}`).replace(/\/+$/,``);return t.length===0?`/`:t}const Gt=[`@mongodb-js/zstd`,`node-liblzma`],Kt=[`@chat-adapter/slack`,`chat`];function qt(e){let t={};return Jt(e)&&Object.assign(t,e),t.NODE_OPTIONS=`--experimental-require-module`,t}function Jt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}async function Yt(e){await E(e,{force:!0,recursive:!0}),await S(e,{recursive:!0})}async function Xt(e){try{return await fe(e.sourcePath)}catch{return await fe(e.fallbackPath)}}async function Zt(e){let t=await Xt({fallbackPath:e.fallbackPath,sourcePath:e.sourcePath});await Yt(e.targetPath),await x(t,e.targetPath,{dereference:!0,recursive:!0})}async function Qt(e,t={}){let n=v(e,`functions`),r=await $t(n);r!==null&&(t.servicePrefix!==void 0&&await Ht(r,t.servicePrefix),await en(n,r)),await nn(n,n),await rn(e,t.servicePrefix)}async function $t(e){let t=v(e,`__server.func`),n=v(e,`ash/__server.func`),r;try{r=await fe(t)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return null;throw e}let i=`${n}.ash-staging`;return await S(_(n),{recursive:!0}),await E(i,{force:!0,recursive:!0}),await x(r,i,{dereference:!0,recursive:!0}),await E(n,{force:!0,recursive:!0}),await T(i,n),n}async function en(e,t,n=e){let r;try{r=await w(e,{withFileTypes:!0})}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}await Promise.all(r.map(async r=>{let i=v(e,r.name),a=U(y(n,i));if(r.isSymbolicLink()){r.name.endsWith(`.func`)&&It(a)&&await tn(i,t);return}r.isDirectory()&&!r.name.endsWith(`.func`)&&await en(i,t,n)}))}async function tn(e,t){await E(e,{force:!0,recursive:!0}),await pe(U(y(_(e),t)),e,`dir`)}async function nn(e,t){let n;try{n=await w(t,{withFileTypes:!0})}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}await Promise.all(n.map(async n=>{let r=v(t,n.name),i=U(y(e,r));if(n.name.endsWith(`.func`)){It(i)||await E(r,{force:!0,recursive:!0});return}n.isDirectory()&&await nn(e,r)}))}async function rn(e,t){let n=v(e,`config.json`),r;try{r=JSON.parse(await C(n,`utf8`))}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}!Jt(r)||!Array.isArray(r.routes)||(r.routes=Lt(r.routes,t),await D(n,`${JSON.stringify(r,null,2)}\n`))}function U(e){return e.replaceAll(`\\`,`/`)}function an(e){let t=y(e.fromDirectoryPath,e.toFilePath).replaceAll(`\\`,`/`);return t.startsWith(`.`)?t:`./${t}`}function on(e){return[`import nitroHandler from ${JSON.stringify(e.delegateImportPath)};`,``,`function invokeNitroHandler(request, context) {`,` if (typeof nitroHandler === "function") {`,` return nitroHandler(request, context);`,` }`,``,` if (nitroHandler !== null && typeof nitroHandler === "object" && "fetch" in nitroHandler) {`,` const fetch = nitroHandler.fetch;`,` if (typeof fetch === "function") {`,` return fetch.call(nitroHandler, request, context);`,` }`,` }`,``,` throw new TypeError("Expected Nitro handler to export a function or an object with fetch(request, context).");`,`}`,``,`const workflowRoutePath = ${JSON.stringify(e.workflowRoutePath)};`,``,`function rewriteRequestToWorkflowRoute(request) {`,` const sourceUrl = new URL(request.url);`,` const routedUrl = new URL(workflowRoutePath, sourceUrl);`,` routedUrl.search = sourceUrl.search;`,` return new Request(routedUrl, request);`,`}`,``,`export default {`,` fetch(request, context) {`,` return invokeNitroHandler(rewriteRequestToWorkflowRoute(request), context);`,` },`,`};`,``].join(`
|
|
57
|
-
`)}async function sn(e){try{let t=JSON.parse(await C(v(e,`.vc-config.json`),`utf8`));if(typeof t.handler==`string`&&t.handler.length>0)return t.handler}catch{}return`index.mjs`}async function cn(e){let t=await sn(e.functionDirectoryPath),n=v(e.functionDirectoryPath,t),r=_(n),i=le(t),a=v(r,`__ash_nitro_handler__${i.length>0?i:`.mjs`}`),o=an({fromDirectoryPath:r,toFilePath:a});await T(n,a),await D(n,on({delegateImportPath:o,workflowRoutePath:e.workflowRoutePath}))}const ln=new Map;var un=class{#e;#t;config;#n=new WeakMap;constructor(e){this.config={buildTarget:`standalone`,dirs:[m(`src/execution`)],externalPackages:[...Gt,...Kt],projectRoot:e.appRoot,watch:e.watch,workingDir:e.rootDir},this.#e=e.compiledArtifactsBootstrapPath,this.#t=e.outDir}async build(e={}){let t=(ln.get(this.#t)??Promise.resolve()).then(()=>this.#r(e));ln.set(this.#t,t.catch(()=>{})),await t}async#r(e){await Ee(this.#t);let t=await this.#i();if(t.length===0)throw Error(`Expected the execution workflow source file under "${m(`src/execution`)}".`);let n=await this.findTsConfigPath();await S(this.#t,{recursive:!0});let r=await this.discoverEntries(t,this.#t,n),i=v(this.#t,`workflows.mjs`),{manifest:a}=await this.createWorkflowsBundle({discoveredEntries:r,keepInterimBundleContext:!1,outfile:i,bundleFinalOutput:!1,format:`esm`,inputFiles:t,tsconfigPath:n}),o=v(this.#t,`steps.mjs`),s=await Dt({builtinsPath:u(`workflow/internal/builtins`),discoveredEntries:r,outfile:o,preferAbsoluteFileImports:!0,projectRoot:this.config.projectRoot??this.config.workingDir,workingDir:this.config.workingDir}),c=e.nitroStepOutfile;c!==void 0&&c!==o&&await Dt({builtinsPath:u(`workflow/internal/builtins`),discoveredEntries:r,outfile:c,preferAbsoluteFileImports:!0,projectRoot:this.config.projectRoot??this.config.workingDir,workingDir:this.config.workingDir}),await dn(i,o),await fn(i),await pn(i);let l=e.nitroWorkflowOutfile;l!==void 0&&l!==i&&(await S(_(l),{recursive:!0}),await xn(i,l),c!==void 0&&(await dn(l,c),await fn(l),await pn(l))),await this.createManifest({workflowBundlePath:v(this.#t,`workflows.mjs`),manifestDir:this.#t,manifest:{steps:{...s.steps,...a.steps},workflows:{...s.workflows,...a.workflows},classes:{...s.classes,...a.classes}}}),await O(this.#t)}get transformProjectRoot(){return this.config.projectRoot??this.config.workingDir}async findTsConfigPath(){let e=this.config.workingDir;for(;;){for(let t of[`tsconfig.json`,`jsconfig.json`]){let n=v(e,t);try{return await C(n),n}catch(e){if(!(e instanceof Error&&`code`in e&&e.code===`ENOENT`))throw e}}let t=_(e);if(t===e)return;e=t}}async getInputFiles(){let e=this.config.dirs.map(e=>b(this.config.workingDir,e));return(await Promise.all(e.map(e=>dt(e)))).flat()}async discoverEntries(e,t,n){let r=this.#n.get(e);if(r!==void 0)return r;let i={discoveredSerdeFiles:[],discoveredSteps:[],discoveredWorkflows:[]};for(let t of e){let e=Ze(await C(t,`utf8`));e.hasUseStep&&i.discoveredSteps.push(t),e.hasUseWorkflow&&i.discoveredWorkflows.push(t),e.hasSerde&&i.discoveredSerdeFiles.push(t)}return this.#n.set(e,i),i}async createWorkflowsBundle({bundleFinalOutput:e=!0,discoveredEntries:t,format:n=`cjs`,inputFiles:r,keepInterimBundleContext:i=this.config.watch,outfile:a,tsconfigPath:o}){let c=t??await this.discoverEntries(r,_(a),o),u=[...c.discoveredWorkflows].sort(),d=new Set(u),f=[...c.discoveredSerdeFiles].sort().filter(e=>!d.has(e)),p={},m=[...u.map(e=>ft(e,this.config.workingDir)),...f.map(e=>ft(e,this.config.workingDir))].join(`
|
|
58
|
-
`);return await _t({bundleFinalOutput:e,code:s(await l({cwd:this.config.workingDir,input:st,platform:`neutral`,plugins:[pt(m),mt(),ht(this.config.workingDir,{workflowCondition:!0}),gt({manifest:p,projectRoot:this.transformProjectRoot,sideEffectFiles:[...u,...f],workingDir:this.config.workingDir})],resolve:{conditionNames:[`ash-source`,`workflow`,`node`,`import`,`default`],extensions:[`.ts`,`.tsx`,`.mts`,`.cts`,`.js`,`.jsx`,`.mjs`,`.cjs`],mainFields:[`module`,`main`]},tsconfig:o??!1,write:!1,output:{banner:`globalThis.__private_workflows = new Map();`,codeSplitting:!1,comments:!1,format:`cjs`,sourcemap:`inline`}}),`intermediate workflow bundle for "${a}"`).code,format:n,outfile:a,workingDir:this.config.workingDir}),i?{bundleFinal:async t=>{await _t({bundleFinalOutput:e,code:t,format:n,outfile:a,workingDir:this.config.workingDir})},interimBundleCtx:void 0,manifest:p}:{manifest:p}}async createManifest({manifest:e,manifestDir:t}){let n={version:`1.0.0`,steps:vt(e.steps),workflows:yt(e.workflows),classes:bt(e.classes)},r=JSON.stringify(n,null,2);return await S(t,{recursive:!0}),await D(v(t,`manifest.json`),r),r}async buildVercelOutput(e){await this.build();let t=v(this.#t,`vercel-build-output`,`functions`,`.well-known`,`workflow`,`v1`),n=v(t,`flow.func`),r=v(e.outputDir,`functions`,`.well-known`,`workflow`,`v1`),i=v(e.flowNitroOutputDir,`functions`,`__server.func`),a=v(e.flowNitroOutputDir,`functions`,`.well-known`,`workflow`,`v1`,`flow.func`),o=v(r,`flow.func`),s=v(r,`step.func`),c=v(r,`webhook`,`[token].func`);await Zt({fallbackPath:i,sourcePath:a,targetPath:n}),await Promise.all([this.#a(n,{experimentalTriggers:Array.from([Ye]),maxDuration:`max`,runtime:e.runtime??null,shouldAddHelpers:!1}),x(v(this.#t,`manifest.json`),v(t,`manifest.json`))]),await cn({functionDirectoryPath:n,workflowRoutePath:`/.well-known/workflow/v1/flow`}),await Promise.all([E(o,{force:!0,recursive:!0}),E(s,{force:!0,recursive:!0}),E(c,{force:!0,recursive:!0})]),await S(r,{recursive:!0}),await Promise.all([x(n,o,{recursive:!0}),x(v(t,`manifest.json`),v(r,`manifest.json`))])}async#i(){return[...await this.getInputFiles(),this.#e]}async#a(e,t){let n=v(e,`.vc-config.json`),r=await this.#o(n),i={...r};i.environment=qt(r.environment),t.runtime!==null&&(i.runtime=t.runtime),t.maxDuration!==void 0&&(i.maxDuration=t.maxDuration),t.shouldAddHelpers!==void 0&&(i.shouldAddHelpers=t.shouldAddHelpers),t.shouldAddSourcemapSupport!==void 0&&(i.shouldAddSourcemapSupport=t.shouldAddSourcemapSupport),t.experimentalTriggers!==void 0&&(i.experimentalTriggers=[...t.experimentalTriggers]),await D(n,`${JSON.stringify(i,null,2)}\n`)}async#o(e){try{let t=JSON.parse(await C(e,`utf8`));if(typeof t==`object`&&t)return t}catch{}return{}}};async function dn(e,t){let n=await yn(e);if(n===null||n.includes(`__ashWorkflowStepsRegistered`))return;let r=vn(_(e),t),i=[`import { __steps_registered as __ashWorkflowStepsRegistered } from ${JSON.stringify(r)};`,`void __ashWorkflowStepsRegistered;`,``].join(`
|
|
59
|
-
`),a=n.match(/^import\s.+?;\n/m);if(a===null||a.index===void 0){await R(e,`${i}${n}`);return}let o=a.index+a[0].length;await R(e,`${n.slice(0,o)}${i}${n.slice(o)}`)}async function fn(e){let t=await yn(e);if(t===null)return;let n=t;for(let e of[`workflow`,`workflow/api`,`workflow/internal/builtins`,`workflow/internal/private`,`workflow/runtime`]){let t=_n(u(e));n=gn(n,e,t)}n!==t&&await R(e,n)}async function pn(e){let t=await yn(e);if(t===null)return;let n=t.indexOf(`const workflowCode = `),r=t.lastIndexOf(`;
|
|
60
|
-
|
|
61
|
-
export const POST = workflowEntrypoint(workflowCode);`);if(n===-1||r===-1||r<=n)return;let i=n+21,a=t.slice(i,r);if(!a.trimStart().startsWith("`"))return;let o=hn(a,e),s=`${t.slice(0,i)}${mn(o)}${t.slice(r)}`;s!==t&&await R(e,s)}function mn(e){let t=ve.from(e,`utf8`).toString(`base64`).match(/.{1,16384}/g)??[``];return`Buffer.from(${JSON.stringify(t)}.join(""), "base64").toString("utf8")`}function hn(e,t){let n=e.trim();if(!n.startsWith("`")||!n.endsWith("`"))throw Error(`Expected generated workflow code literal in "${t}" to be a template.`);let r=n.slice(1,-1),i=``;for(let e=0;e<r.length;e+=1){let t=r[e];if(t!==`\\`){i+=t;continue}let n=r[e+1];if(n===`\\`||n==="`"||n===`$`){i+=n,e+=1;continue}i+=t}return i}function gn(e,t,n){return e.replaceAll(JSON.stringify(t),JSON.stringify(n)).replaceAll(`'${t}'`,JSON.stringify(n))}function _n(e){return t(e)}function vn(e,t){let n=y(e,t).replaceAll(`\\`,`/`);return n.startsWith(`.`)?n:`./${n}`}async function yn(e){try{return await C(e,`utf8`)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return null;throw e}}async function bn(e){try{return await C(e)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return null;throw e}}async function xn(e,t){let n=await C(e),r=await bn(t);r!==null&&r.equals(n)||await R(t,n)}const Sn=`\0ash-pruned-local-sandbox-backend`,Cn=/[/\\]bindings[/\\]local\.js$/;function wn(){return{name:`ash-hosted-sandbox-backend-prune`,load(e){return e===Sn?[`export function createLocalSandboxBackend() {`,` throw new Error("The local sandbox backend is pruned from hosted server bundles.");`,`}`,``].join(`
|
|
62
|
-
`):null},resolveId(e){return Cn.test(e)?Sn:null}}}const Tn=`${g}/runs`,En=`${g}/runs/:runId`,Dn=`${g}/runs/:runId/steps`,On=`${g}/runs/:runId/events`;function kn(e){return e===`all`||e===`app`}function An(e){return W(e)}function W(e){return e===`all`||e===`flow`}function G(e,t){let r=`#ash-route-handler/${t.method??`ALL`} ${t.route}`,i=n(t.handlerPath);e.options.handlers.push({handler:r,method:t.method,route:t.route}),e.options.virtual[r]=[`import handler from ${i};`,`export default handler;`].join(`
|
|
63
|
-
`)}function K(e){return v(e.options.buildDir,`workflow`)}function jn(e,t){let n=y(e,t).replaceAll(`\\`,`/`);return n.startsWith(`.`)?n:`./${n}`}async function Mn(e,t){let n=v(K(e),`${t.bundleName}-handler.mjs`),r=_(n),i=jn(r,t.bundlePath),a=(t.directHandlers??[]).map(e=>{let t=jn(r,e.bundlePath);return{importSpecifier:t,isOwnBundle:t===i,queuePrefix:e.queuePrefix}});await S(r,{recursive:!0}),await D(n,Nn({bundlePath:i,directHandlers:a,runtimeImportSpecifier:t.runtimeImportSpecifier})),e.options.handlers.push({handler:n,route:t.route})}function Nn(e){let t=[`// Generated by Ash. Do not edit by hand.`,`import { POST } from ${JSON.stringify(e.bundlePath)};`];if(e.directHandlers.length>0&&e.runtimeImportSpecifier!==void 0){let n=0,r=e.directHandlers.map(e=>{if(e.isOwnBundle)return{...e,binding:`POST`};let t=`__ashWorkflowDirectHandler${n}`;return n+=1,{...e,binding:t}});for(let e of r)e.isOwnBundle||t.push(`import { POST as ${e.binding} } from ${JSON.stringify(e.importSpecifier)};`);t.push(`import { getWorld as __ashGetWorkflowWorld } from ${JSON.stringify(e.runtimeImportSpecifier)};`,``,`try {`,` const __ashWorkflowWorld = await __ashGetWorkflowWorld();`,` if (typeof __ashWorkflowWorld?.registerHandler === "function") {`);for(let e of r)t.push(` __ashWorkflowWorld.registerHandler(${JSON.stringify(e.queuePrefix)}, ${e.binding});`);t.push(` }`,`} catch (err) {`,` console.warn("[ash] Failed to register direct workflow queue handlers:", err);`,`}`)}return t.push(``,`export default async ({ req }) => {`,` return await POST(req);`,`};`,``),t.join(`
|
|
64
|
-
`)}function Pn(e,t){let r=`#ash-route${t.route}`,i=n(t.modulePath);e.options.handlers.push({handler:r,method:t.method,route:t.route}),e.options.virtual[r]=[`import { ${t.handlerExport} } from ${i};`,`export default async (event) => ${t.handlerExport}(${t.args}, event.req);`].join(`
|
|
65
|
-
`)}async function Fn(e,n,r){if(An(r.surface)){let t=f(),i=new un({appRoot:n.appRoot,compiledArtifactsBootstrapPath:n.compiledArtifacts.bootstrapPath,outDir:n.workflowBuildDir,rootDir:t,watch:e.options.dev}),a=Promise.resolve(),o=async()=>{await i.build({nitroStepOutfile:W(r.surface)?v(K(e),`steps.mjs`):void 0,nitroWorkflowOutfile:e.options.dev&&W(r.surface)?v(K(e),`workflows.mjs`):void 0})},s=async()=>{let e=a.then(o);a=e.catch(()=>{}),await e},c=!0;await s(),e.hooks.hook(`build:before`,async()=>{if(c){c=!1;return}await s()}),e.options.dev&&e.hooks.hook(`dev:reload`,async()=>{await s()})}let i=re({appRoot:n.appRoot,dev:e.options.dev});kn(r.surface)&&(G(e,{handlerPath:d(`src/internal/nitro/routes/index.ts`),method:`GET`,route:`/`}),G(e,{handlerPath:d(`src/internal/nitro/routes/health.ts`),method:`GET`,route:te}),Pn(e,{args:JSON.stringify({appRoot:i.appRoot}),handlerExport:`handleAgentInfoRequest`,method:`GET`,modulePath:d(`src/internal/nitro/routes/info.ts`),route:ee}),G(e,{handlerPath:d(`src/internal/nitro/routes/workflow-runs.ts`),method:`GET`,route:Tn}),G(e,{handlerPath:d(`src/internal/nitro/routes/workflow-run.ts`),method:`GET`,route:En}),G(e,{handlerPath:d(`src/internal/nitro/routes/workflow-run-steps.ts`),method:`GET`,route:Dn}),G(e,{handlerPath:d(`src/internal/nitro/routes/workflow-run-events.ts`),method:`GET`,route:On}),ae(e,{artifactsConfig:i,registrations:ne(n)}));let a=K(e),o=W(r.surface)?e.options.dev?v(a,`workflows.mjs`):v(n.workflowBuildDir,`workflows.mjs`):void 0,s=e.options.dev&&o!==void 0?[{bundlePath:o,queuePrefix:`__wkf_workflow_`}]:[],c=s.length>0?t(u(`workflow/runtime`)):void 0;o&&await Mn(e,{bundleName:`workflows`,bundlePath:o,directHandlers:s,route:`/.well-known/workflow/v1/flow`,runtimeImportSpecifier:c}),e.routing.sync()}function In(){return`${g}/cron/${me()}`}function Ln(e){e.options.vercel!==void 0&&(e.options.vercel.cronHandlerRoute=In())}function Rn(e){return{plugins:[c(),...e]}}function zn(e){e.hooks.hook(`rollup:before`,(e,t)=>{Array.isArray(t.plugins)&&t.plugins.unshift({name:`ash:nitro-routing-import-specifiers`,transform(e,t){if(t!==`#nitro/virtual/routing`&&t!==`#nitro/virtual/routing-meta`)return null;let n=a(e);return n===e?null:{code:n,map:null}}})})}const Bn=`@alinea/generated.@appsignal/nodejs.@aws-sdk/client-s3.@aws-sdk/s3-presigned-post.@blockfrost/blockfrost-js.@highlight-run/node.@huggingface/transformers.@jpg-store/lucid-cardano.@libsql/client.@mikro-orm/core.@mikro-orm/knex.@node-rs/argon2.@node-rs/bcrypt.@prisma/client.@react-pdf/renderer.@sentry/profiling-node.@sparticuz/chromium.@sparticuz/chromium-min.@statsig/statsig-node-core.@swc/core.@xenova/transformers.@zenstackhq/runtime.argon2.autoprefixer.aws-crt.bcrypt.better-sqlite3.canvas.chromadb-default-embed.config.cpu-features.cypress.dd-trace.eslint.express.firebase-admin.htmlrewriter.import-in-the-middle.isolated-vm.jest.jsdom.keyv.libsql.mdx-bundler.mongodb.mongoose.newrelic.next-mdx-remote.next-seo.node-cron.node-pty.node-web-audio-api.onnxruntime-node.oslo.pg.pino.pino-pretty.pino-roll.playwright.playwright-core.postcss.prettier.prisma.puppeteer.puppeteer-core.ravendb.require-in-the-middle.rimraf.sharp.shiki.sqlite3.thread-stream.ts-morph.ts-node.typescript.vscode-oniguruma.webpack.websocket.zeromq`.split(`.`);function Vn(e){if(e)return{config:{version:3,framework:{version:h().version}}}}const Hn=[`workflow`,`workflow/api`,`workflow/errors`,`workflow/internal/builtins`,`workflow/internal/private`,`workflow/runtime`],Un=Symbol(`ash.workflow-transform-patched`),Wn=[`@napi-rs/keyring`];function Gn(){let e={};for(let t of Hn)e[t]=u(t);return e}function Kn(e){if(!e&&process.env.VERCEL)return`vercel`}function qn(e){return e===`all`||e===`app`}function Jn(e){return e===`all`||e===`flow`}function Yn(e){return Jn(e)}function Xn(e,t){return e.options.dev?v(e.options.buildDir,`workflow`,`steps.mjs`):v(t.workflowBuildDir,`steps.mjs`)}function Zn(e){let t=e.compileResult.manifest.config.build;return[...new Set([...Wn,...Bn,...t?.externalDependencies??[]])].filter(e=>e!==p)}function q(e){return e.replaceAll(`\\`,`/`)}function Qn(e){let t=e.indexOf(`?`),n=e.indexOf(`#`),r=t===-1?n:n===-1?t:Math.min(t,n);return r===-1?e:e.slice(0,r)}function $n(e){return e.startsWith(`/@fs/`)?e.slice(4):e}function J(e,t){return t.startsWith(`file://`)?q($n(Qn(_e(t)))):ue(t)?q($n(Qn(t))):q($n(Qn(b(e,t))))}function er(e,t){let n=q(e);return n.startsWith(t)||n.includes(`/.ash/workflow-cache/`)}function tr(e){let t=q(e);return process.platform===`win32`?t.toLowerCase():t}function nr(e){let t=/^\s*import\s+(?:.+?\s+from\s+)?["']([^"']+)["'];?\s*$/gm,n=[];for(let r of e.matchAll(t)){let e=r[1];e!==void 0&&n.push(e)}return n}function rr(e,t,n){return t.startsWith(`workflow`)?u(t):t.startsWith(`.`)||t.startsWith(`/`)||t.startsWith(`file://`)?J(n===void 0?e:_(J(e,n)),t):null}async function ir(e,t){let n=await C(e,`utf8`),r=new Set;for(let i of nr(n)){let n=rr(t,i,e);n!==null&&r.add(tr(n))}return r}async function ar(e,t){if(e.options.noExternals===!0)return;let n;try{n=await ir(t,e.options.rootDir)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}let r=Array.isArray(e.options.noExternals)?[...e.options.noExternals]:[];e.options.noExternals=[...new Set([...r,...n])]}function or(e,t){let n=q(e).replace(/\/$/,``),r=q(t),i=n.toLowerCase(),a=r.toLowerCase();if(a.startsWith(`${i}/`))return r.slice(n.length+1);if(a===i)return`.`;let o=y(n,r).replaceAll(`\\`,`/`);if(o.startsWith(`../`)&&(o=o.split(`/`).filter(e=>e!==`..`).join(`/`)),o.includes(`:`)||o.startsWith(`/`)){let e=r.split(`/`).pop();return e===void 0||e.length===0?`unknown.ts`:e}return o}function sr(e,t){let n=[t,v(e.options.buildDir,`workflow`)].map(t=>J(e.options.rootDir,t));e.hooks.hook(`rollup:before`,(t,r)=>{Array.isArray(r.plugins)&&r.plugins.unshift({name:`ash:workflow-module-side-effects`,resolveId(t,r){let i=rr(e.options.rootDir,t,r)??J(e.options.rootDir,t);return n.some(e=>er(i,e))?{id:i,moduleSideEffects:`no-treeshake`}:null}})})}function cr(e,t){let n=null,r=async()=>(n===null&&(n=await ir(t.stepEntrypointPath,e.options.rootDir)),n);e.hooks.hook(`build:before`,()=>{n=null}),e.options.dev&&e.hooks.hook(`dev:reload`,()=>{n=null}),e.hooks.hook(`rollup:before`,(t,n)=>{Array.isArray(n.plugins)&&n.plugins.unshift({name:`ash:workflow-step-module-side-effects`,async resolveId(t,n){let i=rr(e.options.rootDir,t,n);return i===null||!(await r()).has(tr(i))?null:{id:i,moduleSideEffects:`no-treeshake`}}})})}function lr(e,t){let n=null,r=async()=>(n===null&&(n=await ir(t.stepEntrypointPath,e.options.rootDir)),n);e.hooks.hook(`build:before`,()=>{n=null}),e.options.dev&&e.hooks.hook(`dev:reload`,()=>{n=null}),e.hooks.hook(`rollup:before`,(t,n)=>{Array.isArray(n.plugins)&&n.plugins.unshift({async transform(t,n){let i=await r(),a=J(e.options.rootDir,n);return i.has(tr(a))?{code:(await j(or(e.options.rootDir,a),t,`step`,a,e.options.rootDir)).code,map:null}:null},name:`ash:workflow-step-transform`})})}function ur(e,t){let n=q(t);e.hooks.hook(`rollup:before`,(e,t)=>{Array.isArray(t.plugins)&&t.plugins.unshift({name:`ash:instrumentation-module-side-effects`,resolveId(e){return q(e)===n?{id:e,moduleSideEffects:`no-treeshake`}:null}})})}function dr(e,t){let n=q(t);e.hooks.hook(`rollup:before`,(e,t)=>{if(Array.isArray(t.plugins))for(let e of t.plugins){if(typeof e!=`object`||!e)continue;let t=e;if(t.name!==`workflow:transform`||t[Un]===!0||typeof t.transform!=`function`)continue;let r=t.transform;t.transform=function(e,t,...i){return er(t,n)?null:r.call(this,e,t,...i)},t[Un]=!0}})}async function Y(e,t,n={}){let r=n.surface??`all`,a=(!t||n.schedules===!0)&&qn(r)&&e.scheduleRegistrations.length>0,o=Kn(t),s=o===`vercel`?wn():null,c=s===null?[]:[s],l=Rn(c),u=Rn(c),f=Zn(e),p=i(e.appRoot,r),h=e.compiledArtifacts.instrumentationPluginPath===void 0?[e.compiledArtifacts.bootstrapPath]:[e.compiledArtifacts.instrumentationPluginPath,e.compiledArtifacts.bootstrapPath];await Ee(p);let g=await Se({_cli:{command:t?`dev`:`build`},buildDir:p,dev:t,logLevel:t?1:void 0,output:n.outputDir===void 0?void 0:{dir:n.outputDir},preset:o,plugins:h,publicAssets:[],scanDirs:Yn(r)?[m(`src/execution`)]:void 0,rolldownConfig:l,rollupConfig:u,rootDir:e.appRoot,serverDir:!1,traceDeps:f,vercel:Vn(o===`vercel`&&qn(r))},t?{watch:!0}:void 0);if(await O(p),zn(g),Jn(r)){let t=Gn();for(let[e,n]of Object.entries(t))g.options.alias[e]=n;sr(g,e.workflowBuildDir),dr(g,e.workflowBuildDir)}if(Yn(r)){let t=Xn(g,e);cr(g,{stepEntrypointPath:t}),lr(g,{stepEntrypointPath:t})}if(e.compiledArtifacts.instrumentationSourcePath!==void 0&&ur(g,e.compiledArtifacts.instrumentationSourcePath),t&&Jn(r)){let t=e.workflowBuildDir,n=new Set([q(v(t,`workflows.mjs`))]);g.hooks.hook(`rollup:before`,(e,t)=>{let r=t.external;t.external=(e,...t)=>{if(n.has(q(e)))return!0;if(typeof r==`function`)return r(e,...t)}})}return a&&(Ln(g),oe(g,{artifactsConfig:re({appRoot:e.appRoot,dev:g.options.dev}),dispatchModulePath:d(`src/internal/nitro/routes/schedule-task.ts`),registrations:e.scheduleRegistrations})),await Fn(g,e,{surface:r}),Yn(r)&&await ar(g,Xn(g,e)),g}function fr(e){if(typeof e!=`string`||e.length===0)return`unknown`;let t=e.toLowerCase();return t===`slack`||t.includes(`slack`)?`slack`:t===`http`?`http`:t.includes(`webhook`)?`webhook`:`unknown`}function pr(e){let{manifest:t}=e;return{kind:`vercel-ash-agent-summary`,schemaVersion:2,generatorVersion:e.generatorVersion??h().version,agent:{name:t.config.name,description:t.config.description,modelId:t.config.model.id},instructions:t.instructions?gr(t.instructions):null,schedules:t.schedules.map(_r),tools:t.tools.map(vr),skills:t.skills.map(yr),connections:t.connections.map(br),channels:t.channels.filter(hr).map(xr),sandbox:t.sandbox===null?null:{logicalPath:t.sandbox.logicalPath},subagents:t.subagents.map(Sr),diagnostics:{errors:t.diagnosticsSummary.errors,warnings:t.diagnosticsSummary.warnings}}}async function mr(e){let t=pr({generatorVersion:e.generatorVersion,manifest:e.manifest}),n=v(e.appRoot,`.ash/agent-summary.json`);return await S(_(n),{recursive:!0}),await D(n,`${JSON.stringify(t,null,2)}\n`),n}function hr(e){return e.kind===`channel`}function gr(e){return{logicalPath:e.logicalPath,sourceKind:e.sourceKind,markdown:e.markdown}}function _r(e){return{name:e.name,cron:e.cron,logicalPath:e.logicalPath}}function vr(e){return{name:e.name,description:e.description,logicalPath:e.logicalPath}}function yr(e){return{name:e.name,description:e.description,logicalPath:e.logicalPath,sourceKind:e.sourceKind}}function br(e){let t={name:e.connectionName,description:e.description,url:e.url,logicalPath:e.logicalPath,type:`mcp`};return e.vercelConnect===void 0?t:{...t,vercelConnect:{connector:e.vercelConnect.connector}}}function xr(e){let t={name:e.name,method:e.method,urlPath:e.urlPath,type:fr(e.adapterKind),logicalPath:e.logicalPath};return e.adapterKind===void 0?t:{...t,adapterKind:e.adapterKind}}function Sr(e){return{name:e.name,description:e.description,logicalPath:e.logicalPath}}function Cr(){let e=process.env.VERCEL?.trim(),t=process.env.VERCEL_DEPLOYMENT_ID?.trim();return typeof e==`string`&&e.length>0&&typeof t==`string`&&t.length>0}async function wr(e){return Cr()?(await se(e),!0):!1}function Tr(e){return e.replace(/[\\/]+$/,``)}function X(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Er(e,t){return typeof t!=`string`||t.trim().length===0?null:b(e,t)}function Dr(e){if(!X(e.config)||!X(e.config.experimentalServices))return;let t=!1,n;for(let r of Object.values(e.config.experimentalServices)){if(!X(r))continue;if(r.framework===`nextjs`){t=!0;continue}if(r.framework!==`ash`)continue;let i=Er(e.configRoot,r.entrypoint),a=typeof r.routePrefix==`string`?r.routePrefix.trim():``;i===e.appRoot&&a.length>0&&a!==`/`&&(n=a)}return t?n:void 0}async function Or(e){let t=e;for(;;){try{let n=v(t,`vercel.json`),r=JSON.parse(await C(n,`utf8`)),i=Dr({appRoot:e,configRoot:t,config:r});if(i!==void 0)return i}catch(e){if(!(e instanceof Error&&`code`in e&&e.code===`ENOENT`))throw e}let n=_(t);if(n===t)return;t=n}}async function kr(e){try{return JSON.parse(await C(v(e,`functions`,`__server.func`,`.vc-config.json`),`utf8`)).runtime}catch{return}}async function Ar(e){let t=new un({appRoot:e.appRoot,compiledArtifactsBootstrapPath:e.compiledArtifactsBootstrapPath,outDir:e.workflowBuildDir,rootDir:f(),watch:!1}),n=await kr(e.outputDir);await t.buildVercelOutput({flowNitroOutputDir:e.flowNitroOutputDir,outputDir:e.outputDir,runtime:n})}async function jr(e){let t=Tr(e.options.output.dir);return await Ee(t),await Ce(e),await be(e),await we(e),await ye(e),await O(t),t}async function Mr(e,t){let n=await Y(e,!1,{outputDir:r(e.appRoot,t),surface:t});try{return await jr(n)}finally{await n.close()}}async function Nr(e){let t=await ie(e);if(!process.env.VERCEL){let e=await Y(t,!1);try{let n=await jr(e);return await mr({manifest:t.compileResult.manifest,appRoot:t.appRoot}),n}finally{await e.close()}}let n=await Y(t,!1,{surface:`app`});try{let e=await jr(n);await wr({appRoot:t.appRoot,log(e){console.log(e)}});let r=await Mr(t,`flow`);await Ar({appRoot:t.appRoot,compiledArtifactsBootstrapPath:t.compiledArtifacts.bootstrapPath,flowNitroOutputDir:r,outputDir:e,workflowBuildDir:t.workflowBuildDir});let i=await Or(t.appRoot);return i!==void 0&&await Qt(e,{servicePrefix:i}),await mr({manifest:t.compileResult.manifest,appRoot:t.appRoot}),e}finally{await n.close()}}const Z=65535,Q=`WORKFLOW_LOCAL_BASE_URL`,$=`PORT`,Pr=new Set([`[::]`,`::`,`0.0.0.0`]);function Fr(e){let t=new URL(e);return Pr.has(t.hostname)?(t.hostname=`127.0.0.1`,t.toString()):e}function Ir(e){return e instanceof Error&&`code`in e&&e.code===`EADDRINUSE`}function Lr(e){let t=typeof e==`string`?Number(e):e??3e3;if(!Number.isInteger(t)||t<0||t>Z)throw Error(`Invalid development server port "${String(e)}". Expected an integer between 0 and ${Z}.`);return t}function Rr(){let e=process.env[$];if(e===void 0||e.trim()===``)return;let t=Number(e);if(!Number.isInteger(t)||t<0||t>Z)throw Error(`Invalid ${$} environment variable "${e}". Expected an integer between 0 and ${Z}.`);return t}function zr(e){let t=Lr(e.port);if(t===0||!e.retryOnAddressInUse)return[t];let n=[];for(let e=0;e<10;e+=1){let r=t+e;if(r>65535)break;n.push(r)}return n}function Br(e){let t=process.env[Q],n=process.env[$],r=new URL(Fr(e));return process.env[Q]=r.origin,r.port&&(process.env[$]=r.port),()=>{t===void 0?delete process.env[Q]:process.env[Q]=t,n===void 0?delete process.env[$]:process.env[$]=n}}function Vr(e){let t=()=>{};return e.once(`error`,t),()=>{e.off(`error`,t)}}function Hr(e){let t=e.upgrade.bind(e);e.upgrade=async(e,n,r)=>{let i=Vr(n);try{await t(e,n,r)}catch{n.destroyed||n.destroy()}finally{i()}}}async function Ur(e){let t=zr({port:e.port,retryOnAddressInUse:e.retryOnAddressInUse}),n;for(let r of t){let t=e.devServer.listen({hostname:e.host,port:r,silent:!0});try{return await t.ready(),t}catch(r){if(n=r,await t.close().catch(()=>{}),!Ir(r)||!e.retryOnAddressInUse)throw r}}throw Error(`Failed to start Nitro dev server after ${t.length} attempts. Tried ports ${t.join(`, `)}.`,{cause:n})}async function Wr(e,t={}){let n=t.schedules===!0,r=await ie(e);await se({appRoot:r.appRoot,log:e=>console.log(e)});let i=await Y(r,!0,{schedules:n}),a=xe(i);Hr(a);let o=t.host??i.options.devServer.hostname,s=t.port??Rr(),c=s??i.options.devServer.port,l=s===void 0,u;try{let e=await Ur({devServer:a,host:o,port:c,retryOnAddressInUse:l});if(!e.url)throw Error(`Nitro dev server did not expose a URL.`);u=Br(e.url),await Ce(i),await ye(i);let{startAuthoredSourceWatcher:t}=await import(`./dev-authored-source-watcher-BLzYWh05.js`),s=await t({nitro:i,preparedHost:r,schedulesEnabled:n}),d=u;if(d===void 0)throw Error(`Workflow local queue environment was not initialized.`);return{async close(){try{await s.close(),await a.close(),await i.close()}finally{d()}},url:Fr(e.url)}}catch(e){throw u?.(),await a.close().catch(()=>{}),await i.close().catch(()=>{}),e}}var Gr=e({buildHost:()=>Kr,startHost:()=>qr});async function Kr(e){return await Nr(e)}async function qr(e,t={}){return await Wr(e,t)}export{qr as n,Gr as t};
|