experimental-ash 0.18.0 → 0.18.2
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 +43 -2
- package/dist/docs/public/channels/README.md +75 -9
- package/dist/docs/public/schedules.md +13 -4
- package/dist/src/channel/adapter-context.d.ts +4 -0
- package/dist/src/channel/adapter-context.js +6 -0
- package/dist/src/channel/adapter.d.ts +10 -10
- package/dist/src/channel/cross-channel-receive.d.ts +1 -1
- package/dist/src/channel/cross-channel-receive.js +40 -0
- package/dist/src/channel/routes.d.ts +7 -0
- package/dist/src/channel/send.js +1 -1
- package/dist/src/channel/session.d.ts +47 -1
- package/dist/src/channel/session.js +46 -0
- package/dist/src/channel/types.d.ts +6 -5
- package/dist/src/chunks/client-CKsU8Li3.js +4 -0
- package/dist/src/chunks/{dev-authored-source-watcher-CG6kri3T.js → dev-authored-source-watcher-j7YWh2Gx.js} +1 -1
- package/dist/src/chunks/{host-CIU0NATc.js → host-DkTSR6YJ.js} +2 -2
- package/dist/src/chunks/{paths-CvbqpwTh.js → paths-Dwv0Eash.js} +22 -22
- package/dist/src/chunks/{prewarm-C_Vd0JR7.js → prewarm-CQYfka30.js} +1 -1
- package/dist/src/cli/commands/info.js +1 -1
- package/dist/src/cli/dev/repl.js +1 -1
- package/dist/src/cli/run.js +1 -1
- package/dist/src/client/client.js +2 -1
- package/dist/src/client/index.d.ts +3 -0
- package/dist/src/client/index.js +1 -0
- package/dist/src/client/message-reducer-types.d.ts +130 -0
- package/dist/src/client/message-reducer-types.js +1 -0
- package/dist/src/client/message-reducer.d.ts +14 -0
- package/dist/src/client/message-reducer.js +462 -0
- package/dist/src/client/open-stream.js +2 -4
- package/dist/src/client/reducer.d.ts +63 -0
- package/dist/src/client/reducer.js +1 -0
- package/dist/src/client/session.js +3 -5
- package/dist/src/client/url.d.ts +8 -0
- package/dist/src/client/url.js +34 -0
- package/dist/src/compiler/module-map.js +12 -0
- package/dist/src/evals/cli/eval.js +1 -1
- package/dist/src/execution/sandbox/bindings/vercel.d.ts +2 -2
- package/dist/src/execution/sandbox/bindings/vercel.js +1 -34
- package/dist/src/execution/workflow-entry.js +35 -31
- package/dist/src/execution/workflow-steps.d.ts +16 -0
- package/dist/src/execution/workflow-steps.js +32 -4
- package/dist/src/harness/attachment-staging.js +2 -1
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/public/channels/slack/api.d.ts +13 -8
- package/dist/src/public/channels/slack/api.js +31 -17
- package/dist/src/public/channels/slack/index.d.ts +2 -2
- package/dist/src/public/channels/slack/index.js +1 -0
- package/dist/src/public/channels/slack/interactions.js +3 -3
- package/dist/src/public/channels/slack/slackChannel.d.ts +5 -3
- package/dist/src/public/channels/slack/slackChannel.js +26 -15
- package/dist/src/public/channels/twilio/api.d.ts +9 -0
- package/dist/src/public/channels/twilio/api.js +11 -0
- package/dist/src/public/channels/twilio/index.d.ts +1 -1
- package/dist/src/public/channels/twilio/index.js +1 -1
- package/dist/src/public/channels/twilio/twilioChannel.d.ts +2 -0
- package/dist/src/public/channels/twilio/twilioChannel.js +8 -11
- package/dist/src/public/definitions/defineChannel.d.ts +9 -1
- package/dist/src/public/definitions/defineChannel.js +7 -11
- package/dist/src/public/definitions/sandbox.d.ts +2 -3
- package/dist/src/public/sandbox/backends/vercel.d.ts +4 -4
- package/dist/src/public/sandbox/backends/vercel.js +2 -2
- package/dist/src/public/sandbox/index.d.ts +1 -1
- package/dist/src/public/sandbox/vercel-sandbox.d.ts +3 -28
- package/dist/src/react/index.d.ts +3 -0
- package/dist/src/react/index.js +3 -0
- package/dist/src/react/use-ash-agent.d.ts +79 -0
- package/dist/src/react/use-ash-agent.js +330 -0
- package/dist/src/runtime/types.d.ts +1 -2
- package/dist/src/shared/sandbox-backend.d.ts +4 -4
- package/dist/src/shared/sandbox-definition.d.ts +6 -6
- package/package.json +15 -2
- package/dist/src/chunks/client-BeZ_W7vl.js +0 -4
|
@@ -6,6 +6,15 @@
|
|
|
6
6
|
* required or exposed through Ash public APIs.
|
|
7
7
|
*/
|
|
8
8
|
import { type TwilioAuthToken } from "#public/channels/twilio/verify.js";
|
|
9
|
+
/**
|
|
10
|
+
* Builds the Twilio channel-local continuation token
|
|
11
|
+
* (`<from>:<to>`). Route `send()` namespaces this with the channel
|
|
12
|
+
* name before handing it to the runtime (`twilio:<from>:<to>`), so
|
|
13
|
+
* Twilio routes should pass the raw channel-local form returned
|
|
14
|
+
* here. `to` may be empty for proactive sessions that don't yet know
|
|
15
|
+
* the Twilio sender number.
|
|
16
|
+
*/
|
|
17
|
+
export declare function twilioContinuationToken(from: string, to: string | undefined): string;
|
|
9
18
|
/** Twilio Account SID, materialized directly or from an async secret provider. */
|
|
10
19
|
export type TwilioAccountSid = string | (() => string | Promise<string>);
|
|
11
20
|
/** Fetch implementation override used by tests or non-standard runtimes. */
|
|
@@ -6,6 +6,17 @@
|
|
|
6
6
|
* required or exposed through Ash public APIs.
|
|
7
7
|
*/
|
|
8
8
|
import { resolveTwilioAuthToken } from "#public/channels/twilio/verify.js";
|
|
9
|
+
/**
|
|
10
|
+
* Builds the Twilio channel-local continuation token
|
|
11
|
+
* (`<from>:<to>`). Route `send()` namespaces this with the channel
|
|
12
|
+
* name before handing it to the runtime (`twilio:<from>:<to>`), so
|
|
13
|
+
* Twilio routes should pass the raw channel-local form returned
|
|
14
|
+
* here. `to` may be empty for proactive sessions that don't yet know
|
|
15
|
+
* the Twilio sender number.
|
|
16
|
+
*/
|
|
17
|
+
export function twilioContinuationToken(from, to) {
|
|
18
|
+
return `${from}:${to ?? ""}`;
|
|
19
|
+
}
|
|
9
20
|
/** Resolves a Twilio Account SID, falling back to `TWILIO_ACCOUNT_SID`. */
|
|
10
21
|
export async function resolveTwilioAccountSid(accountSid) {
|
|
11
22
|
const source = accountSid ?? process.env.TWILIO_ACCOUNT_SID;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { twilioChannel, type TwilioAllowFrom, type TwilioChannel, type TwilioChannelConfig, type TwilioChannelCredentials, type TwilioChannelEvents, type TwilioChannelState, type TwilioContext, type TwilioEventContext, type TwilioHandle, type TwilioInboundResult, type TwilioInboundResultOrPromise, type TwilioMessagingConfig, type TwilioReceiveArgs, type TwilioSendMessageOptions, type TwilioVoiceConfig, type TwilioVoiceResult, type TwilioVoiceResultOrPromise, } from "#public/channels/twilio/twilioChannel.js";
|
|
2
|
-
export { callTwilioApi, resolveTwilioAccountSid, sendTwilioMessage, updateTwilioCall, type TwilioAccountSid, type TwilioApiOptions, type TwilioApiResponse, type TwilioCredentials, type TwilioFetch, type TwilioSendMessageInput, type TwilioUpdateCallInput, } from "#public/channels/twilio/api.js";
|
|
2
|
+
export { callTwilioApi, resolveTwilioAccountSid, sendTwilioMessage, twilioContinuationToken, updateTwilioCall, type TwilioAccountSid, type TwilioApiOptions, type TwilioApiResponse, type TwilioCredentials, type TwilioFetch, type TwilioSendMessageInput, type TwilioUpdateCallInput, } from "#public/channels/twilio/api.js";
|
|
3
3
|
export type { TwilioInboundContext, TwilioTextMessage, TwilioVoiceCall, TwilioVoiceTranscription, } from "#public/channels/twilio/inbound.js";
|
|
4
4
|
export { emptyTwilioResponse, escapeXml, gatherSpeechTwilioResponse, sayTwilioResponse, twimlResponse, type TwilioGatherTwimlOptions, } from "#public/channels/twilio/twiml.js";
|
|
5
5
|
export { buildTwilioSignatureBase, resolveTwilioAuthToken, signTwilioRequest, verifyTwilioRequest, type TwilioAuthToken, type TwilioVerifiedRequest, type TwilioVerifyOptions, type TwilioWebhookUrl, } from "#public/channels/twilio/verify.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { twilioChannel, } from "#public/channels/twilio/twilioChannel.js";
|
|
2
|
-
export { callTwilioApi, resolveTwilioAccountSid, sendTwilioMessage, updateTwilioCall, } from "#public/channels/twilio/api.js";
|
|
2
|
+
export { callTwilioApi, resolveTwilioAccountSid, sendTwilioMessage, twilioContinuationToken, updateTwilioCall, } from "#public/channels/twilio/api.js";
|
|
3
3
|
export { emptyTwilioResponse, escapeXml, gatherSpeechTwilioResponse, sayTwilioResponse, twimlResponse, } from "#public/channels/twilio/twiml.js";
|
|
4
4
|
export { buildTwilioSignatureBase, resolveTwilioAuthToken, signTwilioRequest, verifyTwilioRequest, } from "#public/channels/twilio/verify.js";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TypedReceiveRoute } from "#channel/receive-args.js";
|
|
2
|
+
import type { SessionHandle } from "#channel/session.js";
|
|
2
3
|
import type { SessionAuthContext } from "#channel/types.js";
|
|
3
4
|
import type { HandleMessageStreamEvent } from "#protocol/message.js";
|
|
4
5
|
import { type TwilioApiOptions, type TwilioApiResponse, type TwilioCredentials } from "#public/channels/twilio/api.js";
|
|
@@ -16,6 +17,7 @@ export interface TwilioContext {
|
|
|
16
17
|
}
|
|
17
18
|
/** Event-handler Twilio context, including mutable per-phone channel state. */
|
|
18
19
|
export interface TwilioEventContext extends TwilioContext {
|
|
20
|
+
readonly session: SessionHandle;
|
|
19
21
|
state: TwilioChannelState;
|
|
20
22
|
}
|
|
21
23
|
/** JSON-serializable state for the phone-number conversation. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createLogger } from "#internal/logging.js";
|
|
2
|
-
import { callTwilioApi, sendTwilioMessage, updateTwilioCall, } from "#public/channels/twilio/api.js";
|
|
2
|
+
import { callTwilioApi, sendTwilioMessage, twilioContinuationToken, updateTwilioCall, } from "#public/channels/twilio/api.js";
|
|
3
3
|
import { defaultEvents, defaultOnText, defaultOnVoice, defaultOnVoiceTranscription, } from "#public/channels/twilio/defaults.js";
|
|
4
4
|
import { parseTwilioTextMessage, parseTwilioVoiceCall, parseTwilioVoiceTranscription, prependTwilioContext, } from "#public/channels/twilio/inbound.js";
|
|
5
5
|
import { emptyTwilioResponse, gatherSpeechTwilioResponse, sayTwilioResponse, } from "#public/channels/twilio/twiml.js";
|
|
@@ -22,8 +22,8 @@ export function twilioChannel(config) {
|
|
|
22
22
|
lastCallSid: null,
|
|
23
23
|
lastMessageSid: null,
|
|
24
24
|
},
|
|
25
|
-
context(state) {
|
|
26
|
-
return rebuildTwilioContext(state, config);
|
|
25
|
+
context(state, session) {
|
|
26
|
+
return rebuildTwilioContext(state, session, config);
|
|
27
27
|
},
|
|
28
28
|
routes: [
|
|
29
29
|
POST(routes.messages, async (req, { send, waitUntil }) => {
|
|
@@ -96,10 +96,9 @@ export function twilioChannel(config) {
|
|
|
96
96
|
throw new Error("twilioChannel().receive requires args.phoneNumber.");
|
|
97
97
|
}
|
|
98
98
|
const from = readString(input.args.from) ?? config.messaging?.from ?? null;
|
|
99
|
-
const continuationToken = encodeTwilioContinuationToken(phoneNumber, from);
|
|
100
99
|
return send(input.message, {
|
|
101
100
|
auth: input.auth,
|
|
102
|
-
continuationToken,
|
|
101
|
+
continuationToken: twilioContinuationToken(phoneNumber, from ?? undefined),
|
|
103
102
|
state: {
|
|
104
103
|
from: phoneNumber,
|
|
105
104
|
lastCallSid: null,
|
|
@@ -111,8 +110,9 @@ export function twilioChannel(config) {
|
|
|
111
110
|
events: mergedEvents,
|
|
112
111
|
});
|
|
113
112
|
}
|
|
114
|
-
function rebuildTwilioContext(state, config) {
|
|
113
|
+
function rebuildTwilioContext(state, session, config) {
|
|
115
114
|
return {
|
|
115
|
+
session,
|
|
116
116
|
state,
|
|
117
117
|
twilio: buildTwilioHandle({
|
|
118
118
|
callSid: state.lastCallSid ?? undefined,
|
|
@@ -218,7 +218,7 @@ async function dispatchText(input) {
|
|
|
218
218
|
try {
|
|
219
219
|
await input.send(turnMessage, {
|
|
220
220
|
auth: result.auth,
|
|
221
|
-
continuationToken:
|
|
221
|
+
continuationToken: twilioContinuationToken(message.from, message.to),
|
|
222
222
|
state: {
|
|
223
223
|
from: message.from,
|
|
224
224
|
lastCallSid: null,
|
|
@@ -278,7 +278,7 @@ async function dispatchVoiceTranscription(input) {
|
|
|
278
278
|
try {
|
|
279
279
|
await input.send(turnMessage, {
|
|
280
280
|
auth: result.auth,
|
|
281
|
-
continuationToken:
|
|
281
|
+
continuationToken: twilioContinuationToken(transcription.from, transcription.to),
|
|
282
282
|
state: {
|
|
283
283
|
from: transcription.from,
|
|
284
284
|
lastCallSid: transcription.callSid ?? null,
|
|
@@ -297,9 +297,6 @@ async function isAllowed(from, allowFrom) {
|
|
|
297
297
|
return true;
|
|
298
298
|
return typeof resolved === "string" ? resolved === from : resolved.includes(from);
|
|
299
299
|
}
|
|
300
|
-
function encodeTwilioContinuationToken(from, to) {
|
|
301
|
-
return `${from}:${to ?? ""}`;
|
|
302
|
-
}
|
|
303
300
|
async function buildActionUrl(request, config, route) {
|
|
304
301
|
const base = typeof config.publicBaseUrl === "function"
|
|
305
302
|
? await config.publicBaseUrl(request)
|
|
@@ -33,7 +33,15 @@ export interface ChannelEvents<TCtx = void> {
|
|
|
33
33
|
}
|
|
34
34
|
export interface ChannelConfig<TState = undefined, TCtx = void> {
|
|
35
35
|
readonly state?: TState;
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Builds the per-step channel context handed to `events` and
|
|
38
|
+
* `deliver`. Receives the live {@link SessionHandle} so factories
|
|
39
|
+
* that need to wire late-bound callbacks (e.g. Slack's auto-anchor
|
|
40
|
+
* `onAnchor` calling `session.setContinuationToken(...)`) can close
|
|
41
|
+
* over it. State mutations made inside the returned context flow
|
|
42
|
+
* back through `adapter.state` automatically.
|
|
43
|
+
*/
|
|
44
|
+
context?(state: NonNullable<TState>, session: SessionHandle): TCtx;
|
|
37
45
|
readonly routes: readonly RouteDefinition<TState>[];
|
|
38
46
|
receive?(input: {
|
|
39
47
|
readonly message: string;
|
|
@@ -48,26 +48,21 @@ function buildAdapter(config) {
|
|
|
48
48
|
if (!hasBehavior && !hasEventHandlers && !hasFetchFile) {
|
|
49
49
|
return { kind: config.kindHint ?? HTTP_ADAPTER_KIND };
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
const adapter = {
|
|
52
52
|
kind: config.kindHint ?? "defineChannel",
|
|
53
53
|
state: hasState ? { ...config.state } : {},
|
|
54
54
|
fetchFile: config.fetchFile,
|
|
55
55
|
createAdapterContext(base) {
|
|
56
56
|
const state = base.state;
|
|
57
|
-
const
|
|
57
|
+
const session = base.session;
|
|
58
|
+
const channelCtx = hasContext
|
|
59
|
+
? config.context(state, session)
|
|
60
|
+
: {};
|
|
58
61
|
return {
|
|
59
62
|
...channelCtx,
|
|
60
63
|
state,
|
|
61
64
|
ctx: base.ctx,
|
|
62
|
-
session
|
|
63
|
-
id: "",
|
|
64
|
-
continuationToken: "",
|
|
65
|
-
auth: null,
|
|
66
|
-
initiatorAuth: null,
|
|
67
|
-
setContinuationToken(_token) {
|
|
68
|
-
// TODO: wire to runtime
|
|
69
|
-
},
|
|
70
|
-
},
|
|
65
|
+
session,
|
|
71
66
|
};
|
|
72
67
|
},
|
|
73
68
|
deliver(payload) {
|
|
@@ -75,4 +70,5 @@ function buildAdapter(config) {
|
|
|
75
70
|
},
|
|
76
71
|
...eventHandlers,
|
|
77
72
|
};
|
|
73
|
+
return adapter;
|
|
78
74
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { Optional } from "#shared/optional.js";
|
|
2
|
-
import type { SandboxSession } from "#shared/sandbox-session.js";
|
|
3
2
|
import type { SandboxDefinition as SharedSandboxDefinition } from "#shared/sandbox-definition.js";
|
|
4
3
|
export type { SandboxCommandOptions, SandboxCommandResult, SandboxReadTextFileOptions, SandboxSession, SandboxWriteTextFileOptions, } from "#shared/sandbox-session.js";
|
|
5
4
|
export type { SandboxBootstrapUseFn, SandboxSessionUseFn, SandboxBootstrapContext, SandboxSessionContext, } from "#shared/sandbox-definition.js";
|
|
6
|
-
export type SandboxDefinition<
|
|
5
|
+
export type SandboxDefinition<BO = Record<string, never>, SO = Record<string, never>> = Optional<SharedSandboxDefinition<BO, SO>, "backend">;
|
|
7
6
|
/**
|
|
8
7
|
* Defines a sandbox configuration.
|
|
9
8
|
*/
|
|
10
|
-
export declare function defineSandbox<
|
|
9
|
+
export declare function defineSandbox<BO = Record<string, never>, SO = Record<string, never>>(definition: SandboxDefinition<BO, SO>): SandboxDefinition<BO, SO>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { SandboxBackend } from "#public/definitions/sandbox-backend.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { VercelSandboxBootstrapUseOptions, VercelSandboxSessionUseOptions } from "#public/sandbox/vercel-sandbox.js";
|
|
3
3
|
/**
|
|
4
4
|
* Constructs the built-in Vercel sandbox backend.
|
|
5
5
|
*
|
|
6
6
|
* `bootstrap({ use })` applies its options to the template via
|
|
7
7
|
* `sandbox.update(...)`; those settings persist into the snapshot.
|
|
8
|
-
* `onSession({ use })` applies its options to the live session via
|
|
9
|
-
* `
|
|
8
|
+
* `onSession({ use })` applies its options to the live session via the
|
|
9
|
+
* SDK's `update` under the hood.
|
|
10
10
|
*/
|
|
11
|
-
export declare function vercelBackend(): SandboxBackend<
|
|
11
|
+
export declare function vercelBackend(): SandboxBackend<VercelSandboxBootstrapUseOptions, VercelSandboxSessionUseOptions>;
|
|
@@ -4,8 +4,8 @@ import { createVercelSandboxBackend } from "#execution/sandbox/bindings/vercel.j
|
|
|
4
4
|
*
|
|
5
5
|
* `bootstrap({ use })` applies its options to the template via
|
|
6
6
|
* `sandbox.update(...)`; those settings persist into the snapshot.
|
|
7
|
-
* `onSession({ use })` applies its options to the live session via
|
|
8
|
-
* `
|
|
7
|
+
* `onSession({ use })` applies its options to the live session via the
|
|
8
|
+
* SDK's `update` under the hood.
|
|
9
9
|
*/
|
|
10
10
|
export function vercelBackend() {
|
|
11
11
|
return createVercelSandboxBackend();
|
|
@@ -9,4 +9,4 @@ export { SandboxTemplateNotProvisionedError } from "#public/definitions/sandbox-
|
|
|
9
9
|
export { defaultBackend } from "#public/sandbox/backends/default.js";
|
|
10
10
|
export { localBackend } from "#public/sandbox/backends/local.js";
|
|
11
11
|
export { vercelBackend } from "#public/sandbox/backends/vercel.js";
|
|
12
|
-
export type {
|
|
12
|
+
export type { VercelSandboxBootstrapUseOptions, VercelSandboxSessionUseOptions, } from "#public/sandbox/vercel-sandbox.js";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { SandboxUpdateParams } from "#compiled/@vercel/sandbox/index.js";
|
|
2
|
-
import type { SandboxSession } from "#public/definitions/sandbox.js";
|
|
3
2
|
/**
|
|
4
3
|
* Options accepted by the Vercel backend's `bootstrap({ use })` hook.
|
|
5
4
|
* Aliases the Vercel SDK's `SandboxUpdateParams` because bootstrap
|
|
@@ -14,32 +13,8 @@ import type { SandboxSession } from "#public/definitions/sandbox.js";
|
|
|
14
13
|
*/
|
|
15
14
|
export type VercelSandboxBootstrapUseOptions = SandboxUpdateParams;
|
|
16
15
|
/**
|
|
17
|
-
* Options accepted by the Vercel backend's `onSession({ use })` hook
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* is available to authors.
|
|
16
|
+
* Options accepted by the Vercel backend's `onSession({ use })` hook.
|
|
17
|
+
* Aliases the Vercel SDK's `SandboxUpdateParams`; passed values are
|
|
18
|
+
* applied to the live session via the SDK's `update` under the hood.
|
|
21
19
|
*/
|
|
22
20
|
export type VercelSandboxSessionUseOptions = SandboxUpdateParams;
|
|
23
|
-
/**
|
|
24
|
-
* Ash-owned session type returned by the Vercel backend's
|
|
25
|
-
* `onSession({ use })` hook. Extends the narrow
|
|
26
|
-
* {@link SandboxSession} with Vercel-specific capabilities that only
|
|
27
|
-
* make sense on a live session sandbox (not a bootstrap template).
|
|
28
|
-
*/
|
|
29
|
-
export interface VercelSandbox extends SandboxSession {
|
|
30
|
-
readonly name: string;
|
|
31
|
-
readonly persistent: boolean;
|
|
32
|
-
readonly status: string;
|
|
33
|
-
readonly networkPolicy: SandboxUpdateParams["networkPolicy"];
|
|
34
|
-
readonly tags: Record<string, string> | undefined;
|
|
35
|
-
update(params: VercelSandboxSessionUseOptions): Promise<void>;
|
|
36
|
-
stop(opts?: {
|
|
37
|
-
blocking?: boolean;
|
|
38
|
-
}): Promise<void>;
|
|
39
|
-
snapshot(opts?: {
|
|
40
|
-
expiration?: number;
|
|
41
|
-
}): Promise<{
|
|
42
|
-
snapshotId: string;
|
|
43
|
-
}>;
|
|
44
|
-
domain(port: number): string;
|
|
45
|
-
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { useAshAgent, type UseAshAgentHelpers, type UseAshAgentOptions, type UseAshAgentSnapshot, type UseAshAgentStatus, } from "#react/use-ash-agent.js";
|
|
2
|
+
export { type AshAgentReducer, type AshAgentReducerEvent, type ClientInputRespondedEvent, type ClientMessageFailedEvent, type ClientMessageSubmittedEvent, } from "#client/reducer.js";
|
|
3
|
+
export { defaultMessageReducer, type AshMessageData, type AshDynamicToolPart, type AshMessageInputRequest, type AshMessage, type AshMessageMetadata, type AshMessagePart, type AshMessageToolMetadata, } from "#client/message-reducer.js";
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { AshAgentReducer } from "#client/reducer.js";
|
|
2
|
+
import type { ClientSession } from "#client/session.js";
|
|
3
|
+
import { type AshMessageData } from "#client/message-reducer.js";
|
|
4
|
+
import type { HandleMessageStreamEvent } from "#protocol/message.js";
|
|
5
|
+
import type { ClientAuth, HeadersValue, SendMessageOptions, SendTurnInput, SessionState } from "#client/types.js";
|
|
6
|
+
export type UseAshAgentStatus = "error" | "ready" | "streaming" | "submitted";
|
|
7
|
+
/**
|
|
8
|
+
* Current projected state for an Ash agent session.
|
|
9
|
+
*/
|
|
10
|
+
export interface UseAshAgentSnapshot<TData> {
|
|
11
|
+
readonly data: TData;
|
|
12
|
+
readonly error: Error | undefined;
|
|
13
|
+
readonly events: readonly HandleMessageStreamEvent[];
|
|
14
|
+
readonly session: SessionState;
|
|
15
|
+
readonly status: UseAshAgentStatus;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Lifecycle callbacks invoked while `useAshAgent` processes a turn.
|
|
19
|
+
*/
|
|
20
|
+
export interface UseAshAgentCallbacks<TData> {
|
|
21
|
+
readonly onError?: (error: Error) => void;
|
|
22
|
+
readonly onEvent?: (event: HandleMessageStreamEvent) => void;
|
|
23
|
+
readonly onFinish?: (snapshot: UseAshAgentSnapshot<TData>) => void;
|
|
24
|
+
readonly onSessionChange?: (session: SessionState) => void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Snapshot plus commands returned by `useAshAgent`.
|
|
28
|
+
*/
|
|
29
|
+
export interface UseAshAgentHelpers<TData> extends UseAshAgentSnapshot<TData> {
|
|
30
|
+
readonly reset: () => void;
|
|
31
|
+
readonly send: (input: SendTurnInput, options?: SendMessageOptions) => Promise<void>;
|
|
32
|
+
readonly sendMessage: (message: string, options?: SendMessageOptions) => Promise<void>;
|
|
33
|
+
readonly stop: () => void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Configuration for creating or binding a React Ash agent session.
|
|
37
|
+
*
|
|
38
|
+
* Session configuration is read when the hook creates its internal store. To
|
|
39
|
+
* point the hook at a different host, reducer, or session, remount the
|
|
40
|
+
* component that calls the hook. Lifecycle callbacks are updated on every
|
|
41
|
+
* render.
|
|
42
|
+
*
|
|
43
|
+
* For credentials or headers that must change without remounting, pass function
|
|
44
|
+
* values to `auth` or `headers`; the underlying client resolves those before
|
|
45
|
+
* each HTTP request.
|
|
46
|
+
*/
|
|
47
|
+
export interface UseAshAgentOptions<TData> extends UseAshAgentCallbacks<TData> {
|
|
48
|
+
readonly auth?: ClientAuth;
|
|
49
|
+
readonly headers?: HeadersValue;
|
|
50
|
+
/**
|
|
51
|
+
* Base URL used for Ash client requests.
|
|
52
|
+
*
|
|
53
|
+
* By default, requests target same-origin Ash routes such as `/ash/v1/...`.
|
|
54
|
+
* Pass a same-origin prefix such as `/api` to use an app-owned proxy, or an
|
|
55
|
+
* absolute origin to talk to an Ash server directly.
|
|
56
|
+
*
|
|
57
|
+
* @default ""
|
|
58
|
+
*/
|
|
59
|
+
readonly host?: string;
|
|
60
|
+
readonly initialEvents?: readonly HandleMessageStreamEvent[];
|
|
61
|
+
readonly initialSession?: SessionState;
|
|
62
|
+
readonly maxReconnectAttempts?: number;
|
|
63
|
+
/**
|
|
64
|
+
* Project submitted user messages before Ash confirms them with a
|
|
65
|
+
* `message.received` stream event.
|
|
66
|
+
*
|
|
67
|
+
* Optimistic events are reducer-facing projection events only. They are not
|
|
68
|
+
* exposed through `events`, which remains the authoritative Ash stream.
|
|
69
|
+
*
|
|
70
|
+
* @default true
|
|
71
|
+
*/
|
|
72
|
+
readonly optimistic?: boolean;
|
|
73
|
+
readonly reducer?: AshAgentReducer<TData>;
|
|
74
|
+
readonly session?: ClientSession;
|
|
75
|
+
}
|
|
76
|
+
export declare function useAshAgent(options?: UseAshAgentOptions<AshMessageData>): UseAshAgentHelpers<AshMessageData>;
|
|
77
|
+
export declare function useAshAgent<TData>(options: UseAshAgentOptions<TData> & {
|
|
78
|
+
readonly reducer: AshAgentReducer<TData>;
|
|
79
|
+
}): UseAshAgentHelpers<TData>;
|