managed-deepagents 0.9.6-dev.3 → 0.9.6-dev.30
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/README.md +1075 -37
- package/dist/agent-auth.d.ts +1 -1
- package/dist/agent-auth.d.ts.map +1 -1
- package/dist/agent-auth.js +36 -12
- package/dist/agent-auth.js.map +1 -1
- package/dist/browser.d.ts +37 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +31 -0
- package/dist/browser.js.map +1 -0
- package/dist/channels/actor.d.ts +57 -0
- package/dist/channels/actor.d.ts.map +1 -0
- package/dist/channels/actor.js +24 -0
- package/dist/channels/actor.js.map +1 -0
- package/dist/channels/assistant-text.d.ts +29 -0
- package/dist/channels/assistant-text.d.ts.map +1 -1
- package/dist/channels/assistant-text.js +81 -4
- package/dist/channels/assistant-text.js.map +1 -1
- package/dist/channels/binding.d.ts +20 -1
- package/dist/channels/binding.d.ts.map +1 -1
- package/dist/channels/binding.js +44 -11
- package/dist/channels/binding.js.map +1 -1
- package/dist/channels/delivery.d.ts +51 -0
- package/dist/channels/delivery.d.ts.map +1 -0
- package/dist/channels/delivery.js +424 -0
- package/dist/channels/delivery.js.map +1 -0
- package/dist/channels/github/app-setup.d.ts +32 -0
- package/dist/channels/github/app-setup.d.ts.map +1 -0
- package/dist/channels/github/app-setup.js +146 -0
- package/dist/channels/github/app-setup.js.map +1 -0
- package/dist/channels/github/connections.d.ts +11 -0
- package/dist/channels/github/connections.d.ts.map +1 -0
- package/dist/channels/github/connections.js +14 -0
- package/dist/channels/github/connections.js.map +1 -0
- package/dist/channels/github/index.d.ts +12 -0
- package/dist/channels/github/index.d.ts.map +1 -0
- package/dist/channels/github/index.js +266 -0
- package/dist/channels/github/index.js.map +1 -0
- package/dist/channels/github/mentions.d.ts +12 -0
- package/dist/channels/github/mentions.d.ts.map +1 -0
- package/dist/channels/github/mentions.js +185 -0
- package/dist/channels/github/mentions.js.map +1 -0
- package/dist/channels/github/schema.d.ts +4165 -0
- package/dist/channels/github/schema.d.ts.map +1 -0
- package/dist/channels/github/schema.js +221 -0
- package/dist/channels/github/schema.js.map +1 -0
- package/dist/channels/github/types.d.ts +170 -0
- package/dist/channels/github/types.d.ts.map +1 -0
- package/dist/channels/github/types.js +2 -0
- package/dist/channels/github/types.js.map +1 -0
- package/dist/channels/http/endpoint.d.ts +137 -0
- package/dist/channels/http/endpoint.d.ts.map +1 -0
- package/dist/channels/http/endpoint.js +286 -0
- package/dist/channels/http/endpoint.js.map +1 -0
- package/dist/channels/http/http.d.ts.map +1 -1
- package/dist/channels/http/http.js +439 -65
- package/dist/channels/http/http.js.map +1 -1
- package/dist/channels/http/index.d.ts +8 -1
- package/dist/channels/http/index.d.ts.map +1 -1
- package/dist/channels/http/index.js +35 -16
- package/dist/channels/http/index.js.map +1 -1
- package/dist/channels/http/ingress.d.ts +67 -5
- package/dist/channels/http/ingress.d.ts.map +1 -1
- package/dist/channels/http/ingress.js +155 -43
- package/dist/channels/http/ingress.js.map +1 -1
- package/dist/channels/http/provider.d.ts +125 -0
- package/dist/channels/http/provider.d.ts.map +1 -0
- package/dist/channels/http/provider.js +227 -0
- package/dist/channels/http/provider.js.map +1 -0
- package/dist/channels/http/studio.d.ts +24 -0
- package/dist/channels/http/studio.d.ts.map +1 -0
- package/dist/channels/http/studio.js +95 -0
- package/dist/channels/http/studio.js.map +1 -0
- package/dist/channels/http/threads.d.ts +7 -0
- package/dist/channels/http/threads.d.ts.map +1 -0
- package/dist/channels/http/threads.js +10 -0
- package/dist/channels/http/threads.js.map +1 -0
- package/dist/channels/http/types.d.ts +166 -2
- package/dist/channels/http/types.d.ts.map +1 -1
- package/dist/channels/linear/app-setup.d.ts +29 -0
- package/dist/channels/linear/app-setup.d.ts.map +1 -0
- package/dist/channels/linear/app-setup.js +102 -0
- package/dist/channels/linear/app-setup.js.map +1 -0
- package/dist/channels/linear/connections.d.ts +11 -0
- package/dist/channels/linear/connections.d.ts.map +1 -0
- package/dist/channels/linear/connections.js +14 -0
- package/dist/channels/linear/connections.js.map +1 -0
- package/dist/channels/linear/graphql.d.ts +57 -0
- package/dist/channels/linear/graphql.d.ts.map +1 -0
- package/dist/channels/linear/graphql.js +167 -0
- package/dist/channels/linear/graphql.js.map +1 -0
- package/dist/channels/linear/index.d.ts +13 -0
- package/dist/channels/linear/index.d.ts.map +1 -0
- package/dist/channels/linear/index.js +457 -0
- package/dist/channels/linear/index.js.map +1 -0
- package/dist/channels/linear/schema.d.ts +1050 -0
- package/dist/channels/linear/schema.d.ts.map +1 -0
- package/dist/channels/linear/schema.js +255 -0
- package/dist/channels/linear/schema.js.map +1 -0
- package/dist/channels/linear/types.d.ts +169 -0
- package/dist/channels/linear/types.d.ts.map +1 -0
- package/dist/channels/linear/types.js +2 -0
- package/dist/channels/linear/types.js.map +1 -0
- package/dist/channels/message-schema.d.ts +2 -0
- package/dist/channels/message-schema.d.ts.map +1 -1
- package/dist/channels/message-schema.js +4 -0
- package/dist/channels/message-schema.js.map +1 -1
- package/dist/channels/messaging-registry.d.ts +16 -0
- package/dist/channels/messaging-registry.d.ts.map +1 -1
- package/dist/channels/messaging-registry.js +29 -0
- package/dist/channels/messaging-registry.js.map +1 -1
- package/dist/channels/reserved-connections.d.ts +12 -0
- package/dist/channels/reserved-connections.d.ts.map +1 -0
- package/dist/channels/reserved-connections.js +55 -0
- package/dist/channels/reserved-connections.js.map +1 -0
- package/dist/channels/resolve-user-endpoint.d.ts +34 -0
- package/dist/channels/resolve-user-endpoint.d.ts.map +1 -0
- package/dist/channels/resolve-user-endpoint.js +51 -0
- package/dist/channels/resolve-user-endpoint.js.map +1 -0
- package/dist/channels/resolve-user.d.ts +95 -0
- package/dist/channels/resolve-user.d.ts.map +1 -0
- package/dist/channels/resolve-user.js +143 -0
- package/dist/channels/resolve-user.js.map +1 -0
- package/dist/channels/run-input.d.ts +88 -0
- package/dist/channels/run-input.d.ts.map +1 -0
- package/dist/channels/run-input.js +177 -0
- package/dist/channels/run-input.js.map +1 -0
- package/dist/channels/runtime.d.ts +5 -2
- package/dist/channels/runtime.d.ts.map +1 -1
- package/dist/channels/runtime.js +19 -10
- package/dist/channels/runtime.js.map +1 -1
- package/dist/channels/schedule-delivery.d.ts +2 -13
- package/dist/channels/schedule-delivery.d.ts.map +1 -1
- package/dist/channels/schedule-delivery.js +6 -73
- package/dist/channels/schedule-delivery.js.map +1 -1
- package/dist/channels/slack/api.d.ts +2 -0
- package/dist/channels/slack/api.d.ts.map +1 -1
- package/dist/channels/slack/api.js +6 -0
- package/dist/channels/slack/api.js.map +1 -1
- package/dist/channels/slack/connections.d.ts +6 -0
- package/dist/channels/slack/connections.d.ts.map +1 -0
- package/dist/channels/slack/connections.js +6 -0
- package/dist/channels/slack/connections.js.map +1 -0
- package/dist/channels/slack/events.d.ts +278 -0
- package/dist/channels/slack/events.d.ts.map +1 -0
- package/dist/channels/slack/events.js +235 -0
- package/dist/channels/slack/events.js.map +1 -0
- package/dist/channels/slack/files.d.ts.map +1 -1
- package/dist/channels/slack/files.js +2 -3
- package/dist/channels/slack/files.js.map +1 -1
- package/dist/channels/slack/index.d.ts +90 -2
- package/dist/channels/slack/index.d.ts.map +1 -1
- package/dist/channels/slack/index.js +188 -6
- package/dist/channels/slack/index.js.map +1 -1
- package/dist/channels/slack/message-content.d.ts.map +1 -1
- package/dist/channels/slack/message-content.js +23 -28
- package/dist/channels/slack/message-content.js.map +1 -1
- package/dist/channels/slack/status.d.ts +76 -0
- package/dist/channels/slack/status.d.ts.map +1 -0
- package/dist/channels/slack/status.js +427 -0
- package/dist/channels/slack/status.js.map +1 -0
- package/dist/channels/source-providers.js +1 -1
- package/dist/channels/source-providers.js.map +1 -1
- package/dist/channels/trigger/client.d.ts.map +1 -1
- package/dist/channels/trigger/client.js +9 -15
- package/dist/channels/trigger/client.js.map +1 -1
- package/dist/channels/trigger/conversation.d.ts +11 -0
- package/dist/channels/trigger/conversation.d.ts.map +1 -0
- package/dist/channels/trigger/conversation.js +72 -0
- package/dist/channels/trigger/conversation.js.map +1 -0
- package/dist/channels/trigger/http.d.ts +130 -4
- package/dist/channels/trigger/http.d.ts.map +1 -1
- package/dist/channels/trigger/http.js +408 -78
- package/dist/channels/trigger/http.js.map +1 -1
- package/dist/channels/trigger/identity-context.d.ts.map +1 -1
- package/dist/channels/trigger/identity-context.js +2 -5
- package/dist/channels/trigger/identity-context.js.map +1 -1
- package/dist/channels/trigger/ingress.d.ts +70 -1
- package/dist/channels/trigger/ingress.d.ts.map +1 -1
- package/dist/channels/trigger/ingress.js +135 -21
- package/dist/channels/trigger/ingress.js.map +1 -1
- package/dist/channels/trigger/transport.d.ts +10 -0
- package/dist/channels/trigger/transport.d.ts.map +1 -1
- package/dist/channels/trigger/transport.js +25 -9
- package/dist/channels/trigger/transport.js.map +1 -1
- package/dist/channels/trigger/types.d.ts +92 -3
- package/dist/channels/trigger/types.d.ts.map +1 -1
- package/dist/channels/trigger/types.js +37 -0
- package/dist/channels/trigger/types.js.map +1 -1
- package/dist/channels/types.d.ts +53 -4
- package/dist/channels/types.d.ts.map +1 -1
- package/dist/channels/types.js +2 -0
- package/dist/channels/types.js.map +1 -1
- package/dist/connections.d.ts +36 -12
- package/dist/connections.d.ts.map +1 -1
- package/dist/connections.js +125 -30
- package/dist/connections.js.map +1 -1
- package/dist/connectors/mcp/langsmith-url.d.ts.map +1 -1
- package/dist/connectors/mcp/langsmith-url.js +0 -1
- package/dist/connectors/mcp/langsmith-url.js.map +1 -1
- package/dist/credential-gate.d.ts +2 -0
- package/dist/credential-gate.d.ts.map +1 -1
- package/dist/credential-gate.js +37 -3
- package/dist/credential-gate.js.map +1 -1
- package/dist/define-deep-agent.d.ts +2 -2
- package/dist/define-deep-agent.d.ts.map +1 -1
- package/dist/define-deep-agent.js +53 -2
- package/dist/define-deep-agent.js.map +1 -1
- package/dist/identity/index.d.ts.map +1 -1
- package/dist/identity/index.js +3 -1
- package/dist/identity/index.js.map +1 -1
- package/dist/identity/loopback.d.ts +1 -1
- package/dist/identity/loopback.d.ts.map +1 -1
- package/dist/identity/loopback.js +3 -2
- package/dist/identity/loopback.js.map +1 -1
- package/dist/identity/options.d.ts +9 -0
- package/dist/identity/options.d.ts.map +1 -1
- package/dist/identity/options.js +1 -1
- package/dist/identity/options.js.map +1 -1
- package/dist/identity/slack/links.js +3 -2
- package/dist/identity/slack/links.js.map +1 -1
- package/dist/identity/types.d.ts +3 -0
- package/dist/identity/types.d.ts.map +1 -1
- package/dist/index.d.ts +19 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/ingress/loopback.d.ts +1 -0
- package/dist/ingress/loopback.d.ts.map +1 -1
- package/dist/ingress/loopback.js +7 -3
- package/dist/ingress/loopback.js.map +1 -1
- package/dist/ingress/runs.d.ts +74 -1
- package/dist/ingress/runs.d.ts.map +1 -1
- package/dist/ingress/runs.js +184 -9
- package/dist/ingress/runs.js.map +1 -1
- package/dist/managed-composition.d.ts +3 -0
- package/dist/managed-composition.d.ts.map +1 -1
- package/dist/managed-composition.js +29 -13
- package/dist/managed-composition.js.map +1 -1
- package/dist/namespaces.d.ts +25 -21
- package/dist/namespaces.d.ts.map +1 -1
- package/dist/namespaces.js +4 -29
- package/dist/namespaces.js.map +1 -1
- package/dist/runtime/async-subagents.d.ts +27 -0
- package/dist/runtime/async-subagents.d.ts.map +1 -0
- package/dist/runtime/async-subagents.js +139 -0
- package/dist/runtime/async-subagents.js.map +1 -0
- package/dist/runtime/auth.d.ts.map +1 -1
- package/dist/runtime/auth.js +177 -8
- package/dist/runtime/auth.js.map +1 -1
- package/dist/runtime/backend.d.ts +7 -0
- package/dist/runtime/backend.d.ts.map +1 -1
- package/dist/runtime/backend.js +32 -7
- package/dist/runtime/backend.js.map +1 -1
- package/dist/runtime/browser-facade.d.ts +10 -0
- package/dist/runtime/browser-facade.d.ts.map +1 -0
- package/dist/runtime/browser-facade.js +23 -0
- package/dist/runtime/browser-facade.js.map +1 -0
- package/dist/runtime/browser-langsmith.d.ts +143 -0
- package/dist/runtime/browser-langsmith.d.ts.map +1 -0
- package/dist/runtime/browser-langsmith.js +508 -0
- package/dist/runtime/browser-langsmith.js.map +1 -0
- package/dist/runtime/browser-recorder.py +831 -0
- package/dist/runtime/browser-selection.d.ts +10 -0
- package/dist/runtime/browser-selection.d.ts.map +1 -0
- package/dist/runtime/browser-selection.js +21 -0
- package/dist/runtime/browser-selection.js.map +1 -0
- package/dist/runtime/browser.d.ts +138 -0
- package/dist/runtime/browser.d.ts.map +1 -0
- package/dist/runtime/browser.js +802 -0
- package/dist/runtime/browser.js.map +1 -0
- package/dist/runtime/channel-icon.d.ts +22 -0
- package/dist/runtime/channel-icon.d.ts.map +1 -0
- package/dist/runtime/channel-icon.js +81 -0
- package/dist/runtime/channel-icon.js.map +1 -0
- package/dist/runtime/channel.d.ts +11 -0
- package/dist/runtime/channel.d.ts.map +1 -1
- package/dist/runtime/channel.js.map +1 -1
- package/dist/runtime/graph-build-timing.d.ts +30 -0
- package/dist/runtime/graph-build-timing.d.ts.map +1 -0
- package/dist/runtime/graph-build-timing.js +50 -0
- package/dist/runtime/graph-build-timing.js.map +1 -0
- package/dist/runtime/identity-http.d.ts +2 -0
- package/dist/runtime/identity-http.d.ts.map +1 -1
- package/dist/runtime/identity-http.js +38 -2
- package/dist/runtime/identity-http.js.map +1 -1
- package/dist/runtime/identity-runtime.d.ts +10 -0
- package/dist/runtime/identity-runtime.d.ts.map +1 -1
- package/dist/runtime/identity-runtime.js +22 -0
- package/dist/runtime/identity-runtime.js.map +1 -1
- package/dist/runtime/index.d.ts +38 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +97 -43
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/langsmith-env.d.ts +19 -0
- package/dist/runtime/langsmith-env.d.ts.map +1 -0
- package/dist/runtime/langsmith-env.js +38 -0
- package/dist/runtime/langsmith-env.js.map +1 -0
- package/dist/runtime/managed-thread.d.ts +61 -0
- package/dist/runtime/managed-thread.d.ts.map +1 -0
- package/dist/runtime/managed-thread.js +76 -0
- package/dist/runtime/managed-thread.js.map +1 -0
- package/dist/runtime/managed-tools.d.ts +10 -2
- package/dist/runtime/managed-tools.d.ts.map +1 -1
- package/dist/runtime/managed-tools.js +10 -8
- package/dist/runtime/managed-tools.js.map +1 -1
- package/dist/runtime/memory/policy.d.ts.map +1 -1
- package/dist/runtime/memory/policy.js +1 -3
- package/dist/runtime/memory/policy.js.map +1 -1
- package/dist/runtime/parent-run.d.ts +33 -0
- package/dist/runtime/parent-run.d.ts.map +1 -0
- package/dist/runtime/parent-run.js +114 -0
- package/dist/runtime/parent-run.js.map +1 -0
- package/dist/runtime/run-input.d.ts +14 -1
- package/dist/runtime/run-input.d.ts.map +1 -1
- package/dist/runtime/run-input.js +100 -7
- package/dist/runtime/run-input.js.map +1 -1
- package/dist/runtime/sandbox-manager.d.ts +18 -4
- package/dist/runtime/sandbox-manager.d.ts.map +1 -1
- package/dist/runtime/sandbox-manager.js +57 -20
- package/dist/runtime/sandbox-manager.js.map +1 -1
- package/dist/runtime/schedule-auth.d.ts +79 -0
- package/dist/runtime/schedule-auth.d.ts.map +1 -1
- package/dist/runtime/schedule-auth.js +165 -7
- package/dist/runtime/schedule-auth.js.map +1 -1
- package/dist/runtime/static-entry.d.ts.map +1 -1
- package/dist/runtime/static-entry.js +1 -0
- package/dist/runtime/static-entry.js.map +1 -1
- package/dist/runtime/thread-record.d.ts +88 -0
- package/dist/runtime/thread-record.d.ts.map +1 -0
- package/dist/runtime/thread-record.js +213 -0
- package/dist/runtime/thread-record.js.map +1 -0
- package/dist/runtime/types.d.ts +12 -1
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/runtime-schedules.d.ts +15 -0
- package/dist/runtime-schedules.d.ts.map +1 -1
- package/dist/runtime-schedules.js +83 -20
- package/dist/runtime-schedules.js.map +1 -1
- package/dist/sandbox.d.ts +0 -6
- package/dist/sandbox.d.ts.map +1 -1
- package/dist/sandbox.js +3 -7
- package/dist/sandbox.js.map +1 -1
- package/dist/schedule-channel.d.ts +5 -2
- package/dist/schedule-channel.d.ts.map +1 -1
- package/dist/schedule-channel.js +13 -12
- package/dist/schedule-channel.js.map +1 -1
- package/dist/telemetry/metadata.d.ts.map +1 -1
- package/dist/telemetry/metadata.js +4 -4
- package/dist/telemetry/metadata.js.map +1 -1
- package/dist/telemetry/otel/exporter.d.ts.map +1 -1
- package/dist/telemetry/otel/exporter.js +3 -3
- package/dist/telemetry/otel/exporter.js.map +1 -1
- package/dist/types.d.ts +19 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/values.d.ts +15 -0
- package/dist/values.d.ts.map +1 -0
- package/dist/values.js +31 -0
- package/dist/values.js.map +1 -0
- package/package.json +26 -12
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What webhook channels built on `httpChannel`, such as GitHub and Linear,
|
|
3
|
+
* share: their name, the events they subscribe to, the secrets they read from
|
|
4
|
+
* Agent Auth, signature checks, running an event's handler, and the hooks
|
|
5
|
+
* that hand their typed events to the user.
|
|
6
|
+
*/
|
|
7
|
+
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
8
|
+
import { isJsonValue } from "../message-schema.js";
|
|
9
|
+
import { immutableCopy } from "../runtime.js";
|
|
10
|
+
import { logger } from "../../runtime/log.js";
|
|
11
|
+
import { endpointHandler, isEventEndpoint, } from "./endpoint.js";
|
|
12
|
+
import { ConnectionNotFoundError, DEPLOYMENT_ID_ENV, connections, } from "../../connections.js";
|
|
13
|
+
/** The channel's name in the project, or its provider before it has one. */
|
|
14
|
+
export function channelName(channel) {
|
|
15
|
+
return channel.name ?? channel.kind;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Check a channel's `onEvent` keys. The types limit them, but a JavaScript
|
|
19
|
+
* caller or a cast gets no error, and a key nothing dispatches never runs.
|
|
20
|
+
*/
|
|
21
|
+
export function checkEventKeys(provider, handlers, supported) {
|
|
22
|
+
const unknown = Object.keys(handlers).filter((key) => !supported.has(key));
|
|
23
|
+
if (unknown.length)
|
|
24
|
+
throw new TypeError(`unsupported ${provider} event key ${unknown.sort().join(", ")}`);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A channel's `onEvent` with each endpoint, a URL or `Request`, replaced by
|
|
28
|
+
* the handler it stands for, so the channel calls handlers alone. A bad
|
|
29
|
+
* endpoint, or a value that is neither a handler nor an endpoint, throws when
|
|
30
|
+
* the channel is declared. The endpoint's handler is
|
|
31
|
+
* typed as the channel's own: `E` and `T` carry what it sends, and `fields`
|
|
32
|
+
* are the channel's own fields of `E` it sends beside key, delivery ID and
|
|
33
|
+
* payload, listed in one place per channel.
|
|
34
|
+
*/
|
|
35
|
+
export function resolveEndpoints(provider, onEvent, fields = []) {
|
|
36
|
+
return Object.fromEntries(Object.entries(onEvent ?? {}).map(([key, value]) => {
|
|
37
|
+
const label = `${provider} onEvent["${key}"]`;
|
|
38
|
+
if (isEventEndpoint(value))
|
|
39
|
+
return [key, endpointHandler(value, label, fields)];
|
|
40
|
+
if (value !== undefined && typeof value !== "function")
|
|
41
|
+
throw new TypeError(`${label} must be a function, a URL or a Request`);
|
|
42
|
+
return [key, value];
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
/** The thread of a delivery to the channel named `name`. */
|
|
46
|
+
export function eventThread(delivery, name) {
|
|
47
|
+
return { id: delivery.threadId, channel: { name } };
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The HTTP channel's `onFinish` for a provider channel: the channel's own
|
|
51
|
+
* notice first, such as a link to a pending decision, then the user's hook,
|
|
52
|
+
* for the deliveries whose event the channel parsed. A failing notice is
|
|
53
|
+
* logged and doesn't keep the user's hook from running.
|
|
54
|
+
*/
|
|
55
|
+
export function finishEvents(notice, onFinish, parse, thread) {
|
|
56
|
+
return async (target, delivery) => {
|
|
57
|
+
try {
|
|
58
|
+
await notice(target, delivery);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
logger.error(`channel finish notice failed (${logger.safeErrorLabel(error)})`);
|
|
62
|
+
}
|
|
63
|
+
const event = onFinish && (await parse(delivery.rawEvent));
|
|
64
|
+
if (event === undefined)
|
|
65
|
+
return;
|
|
66
|
+
await onFinish?.(event, thread(delivery), finishOf(delivery));
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** How a delivery finished, without the delivery's own fields. */
|
|
70
|
+
function finishOf(delivery) {
|
|
71
|
+
const { interrupts } = delivery;
|
|
72
|
+
switch (delivery.type) {
|
|
73
|
+
case "run":
|
|
74
|
+
return { type: "run", run: delivery.run, interrupts };
|
|
75
|
+
case "skipped":
|
|
76
|
+
return { type: "skipped", reason: delivery.reason, interrupts };
|
|
77
|
+
default:
|
|
78
|
+
return { type: "failed", reason: delivery.reason, interrupts };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The HTTP channel's `onReceived` for a provider channel's user hook, for the
|
|
83
|
+
* deliveries whose event the channel parsed.
|
|
84
|
+
*/
|
|
85
|
+
export function receiveEvents(onReceived, parse, name) {
|
|
86
|
+
if (!onReceived)
|
|
87
|
+
return undefined;
|
|
88
|
+
return async (_target, delivery) => {
|
|
89
|
+
const event = parse(delivery.rawEvent);
|
|
90
|
+
if (event === undefined)
|
|
91
|
+
return;
|
|
92
|
+
await onReceived(event, {
|
|
93
|
+
id: delivery.threadId,
|
|
94
|
+
channel: { name: name() },
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/** The events deploy subscribes the provider's webhook to: the handled ones. */
|
|
99
|
+
export function handledEventKeys(handlers) {
|
|
100
|
+
return Object.entries(handlers)
|
|
101
|
+
.filter(([, handler]) => handler !== undefined)
|
|
102
|
+
.map(([key]) => key)
|
|
103
|
+
.sort();
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The connection `mda deploy` stores for the provider's app, or one of the
|
|
107
|
+
* values stored beside it, such as `webhook-secret`, when `suffix` is given.
|
|
108
|
+
*/
|
|
109
|
+
export function appConnectionSlug(provider, deploymentId, suffix) {
|
|
110
|
+
const slug = `mda/${provider}-app/${deploymentId}`;
|
|
111
|
+
return suffix ? `${slug}/${suffix}` : slug;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* A frozen copy of a parsed event, kept as the delivery's raw event so a
|
|
115
|
+
* handler that changes its argument can't change what MDA keeps.
|
|
116
|
+
*/
|
|
117
|
+
export function eventSnapshot(event, provider) {
|
|
118
|
+
if (!isJsonValue(event))
|
|
119
|
+
throw new TypeError(`invalid ${provider} event`);
|
|
120
|
+
return immutableCopy(event);
|
|
121
|
+
}
|
|
122
|
+
/** App options for deploy, without unset fields. */
|
|
123
|
+
export function definedFields(fields) {
|
|
124
|
+
const defined = {};
|
|
125
|
+
for (const [key, value] of Object.entries(fields))
|
|
126
|
+
if (value !== undefined)
|
|
127
|
+
defined[key] = value;
|
|
128
|
+
return defined;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Whether `signature`, a hex HMAC-SHA256 the caller checked the format of,
|
|
132
|
+
* signs `rawBody` with `secret`. Compared in constant time.
|
|
133
|
+
*/
|
|
134
|
+
export function verifyHmacSha256(secret, rawBody, signature) {
|
|
135
|
+
const expected = createHmac("sha256", secret).update(rawBody).digest();
|
|
136
|
+
const given = Buffer.from(signature, "hex");
|
|
137
|
+
return given.length === expected.length && timingSafeEqual(expected, given);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* A value read at most every `ttlMs(value)` milliseconds. Concurrent callers
|
|
141
|
+
* share the read in flight; a failed read is not kept, so the next call reads
|
|
142
|
+
* again.
|
|
143
|
+
*/
|
|
144
|
+
export class CachedRead {
|
|
145
|
+
read;
|
|
146
|
+
ttlMs;
|
|
147
|
+
#entry;
|
|
148
|
+
constructor(read, ttlMs) {
|
|
149
|
+
this.read = read;
|
|
150
|
+
this.ttlMs = ttlMs;
|
|
151
|
+
}
|
|
152
|
+
get() {
|
|
153
|
+
if (this.#entry && this.#entry.expiresAt > Date.now())
|
|
154
|
+
return this.#entry.value;
|
|
155
|
+
const entry = {
|
|
156
|
+
value: this.read().then((value) => {
|
|
157
|
+
entry.expiresAt = Date.now() + this.ttlMs(value);
|
|
158
|
+
return value;
|
|
159
|
+
}, (error) => {
|
|
160
|
+
if (this.#entry === entry)
|
|
161
|
+
this.#entry = undefined;
|
|
162
|
+
throw error;
|
|
163
|
+
}),
|
|
164
|
+
expiresAt: Number.POSITIVE_INFINITY,
|
|
165
|
+
};
|
|
166
|
+
this.#entry = entry;
|
|
167
|
+
return entry.value;
|
|
168
|
+
}
|
|
169
|
+
/** Read again on the next call. */
|
|
170
|
+
reset() {
|
|
171
|
+
this.#entry = undefined;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/** How long a value read from Agent Auth is reused before it is read again. */
|
|
175
|
+
const SECRET_TTL_MS = 5 * 60_000;
|
|
176
|
+
/** How long a missing value is remembered, so unsigned traffic can't hammer Agent Auth. */
|
|
177
|
+
const MISSING_SECRET_TTL_MS = 60_000;
|
|
178
|
+
const deploymentSecrets = new Map();
|
|
179
|
+
/**
|
|
180
|
+
* A value `mda deploy` stored for the deployment, such as a webhook secret:
|
|
181
|
+
* the `env` override when set, otherwise the agent secret Agent Auth keeps at
|
|
182
|
+
* `slug(deploymentId)`. Only a missing connection reads as `undefined`, and is
|
|
183
|
+
* logged as `label`; credential store failures propagate.
|
|
184
|
+
*/
|
|
185
|
+
export function readDeploymentSecret(env, slug, label) {
|
|
186
|
+
const override = process.env[env]?.trim();
|
|
187
|
+
if (override)
|
|
188
|
+
return Promise.resolve(override);
|
|
189
|
+
const deploymentId = process.env[DEPLOYMENT_ID_ENV]?.trim();
|
|
190
|
+
if (!deploymentId)
|
|
191
|
+
return Promise.resolve(undefined);
|
|
192
|
+
const key = slug(deploymentId);
|
|
193
|
+
let cached = deploymentSecrets.get(key);
|
|
194
|
+
if (!cached) {
|
|
195
|
+
cached = new CachedRead(() => connections.resolveDeploymentSecret(key).catch((error) => {
|
|
196
|
+
if (!(error instanceof ConnectionNotFoundError))
|
|
197
|
+
throw error;
|
|
198
|
+
logger.error(`${label} is not stored in Agent Auth`);
|
|
199
|
+
return undefined;
|
|
200
|
+
}), (value) => (value === undefined ? MISSING_SECRET_TTL_MS : SECRET_TTL_MS));
|
|
201
|
+
deploymentSecrets.set(key, cached);
|
|
202
|
+
}
|
|
203
|
+
return cached.get();
|
|
204
|
+
}
|
|
205
|
+
/** Forget values read from Agent Auth; for tests. */
|
|
206
|
+
export function resetDeploymentSecrets() {
|
|
207
|
+
deploymentSecrets.clear();
|
|
208
|
+
}
|
|
209
|
+
/** Run an event's handler. A throw is logged, not raised. */
|
|
210
|
+
export async function runEventHandler(provider, event, call) {
|
|
211
|
+
const receipt = JSON.stringify({
|
|
212
|
+
event: logger.logIdentifier(event.key),
|
|
213
|
+
deliveryId: logger.logIdentifier(event.deliveryId),
|
|
214
|
+
});
|
|
215
|
+
try {
|
|
216
|
+
const input = await call();
|
|
217
|
+
if (input === undefined || input === null)
|
|
218
|
+
return { type: "skipped" };
|
|
219
|
+
logger.info(`${provider} handler returned run input ${receipt}`);
|
|
220
|
+
return { type: "input", input };
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
logger.error(`${provider.toLowerCase()} callback failed ${receipt} (${logger.safeErrorLabel(error)})`);
|
|
224
|
+
return { type: "failed" };
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/channels/http/provider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG1D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,O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AK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QACtE,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,+BAA+B,OAAO,EAAE,CAAC,CAAC;QACjE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAClC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CACV,GAAG,QAAQ,CAAC,WAAW,EAAE,oBAAoB,OAAO,KAAK,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,GAAG,CACzF,CAAC;QACF,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAC5B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { HttpDelivery, HttpFinish } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* The thread in the deployment's Studio, or the deployment's page when the
|
|
4
|
+
* deployment's name or the thread's assistant is unknown. The LangSmith UI is
|
|
5
|
+
* the one `mda deploy` recorded for the deployment's environment
|
|
6
|
+
* (`MDA_LANGSMITH_URL`); without it there is nothing to link to.
|
|
7
|
+
*/
|
|
8
|
+
export declare function studioUrl(run: HttpDelivery | undefined, env?: NodeJS.ProcessEnv): string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* `waiting` when a finished delivery's message found the thread waiting on a
|
|
11
|
+
* decision. A run that stopped on interrupts posts its own `interrupted`
|
|
12
|
+
* notice as it ends (the paused notice), so a `run` delivery has none here.
|
|
13
|
+
* Undefined when nothing waits, or the delivery was a cancel or lost.
|
|
14
|
+
*/
|
|
15
|
+
export declare function pendingDecision(finish: HttpFinish): "waiting" | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* What a channel tells the conversation when its thread waits on a decision,
|
|
18
|
+
* with a link to the thread in Studio, where the decision is made: the run
|
|
19
|
+
* the delivery started stopped on interrupts (`interrupted`), or the message
|
|
20
|
+
* found the thread waiting (`waiting`). `again` says how to continue once it
|
|
21
|
+
* is made, such as "comment again".
|
|
22
|
+
*/
|
|
23
|
+
export declare function interruptedNotice(outcome: "interrupted" | "waiting", delivery: HttpDelivery, again: string): string;
|
|
24
|
+
//# sourceMappingURL=studio.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"studio.d.ts","sourceRoot":"","sources":["../../../src/channels/http/studio.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAS3D;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,GAAG,EAAE,YAAY,GAAG,SAAS,EAC7B,GAAG,oBAAc,GAChB,MAAM,GAAG,SAAS,CAsBpB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,GAAG,SAAS,GAAG,SAAS,CAKzE;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,aAAa,GAAG,SAAS,EAClC,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,MAAM,GACZ,MAAM,CAMR"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/** Links from channel notices into the deployment's LangSmith Studio. */
|
|
2
|
+
import { v5 as uuidv5 } from "uuid";
|
|
3
|
+
import { DEPLOYMENT_ID_ENV } from "../../connections.js";
|
|
4
|
+
import { managedDeploymentName } from "../../runtime/sandbox-manager.js";
|
|
5
|
+
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
6
|
+
const DEPLOYMENT_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
7
|
+
const GRAPH_ID_PATTERN = /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$/;
|
|
8
|
+
/** The namespace the Agent Server derives a graph's default assistant from. */
|
|
9
|
+
const GRAPH_NAMESPACE = "6ba7b821-9dad-11d1-80b4-00c04fd430c8";
|
|
10
|
+
/**
|
|
11
|
+
* The thread in the deployment's Studio, or the deployment's page when the
|
|
12
|
+
* deployment's name or the thread's assistant is unknown. The LangSmith UI is
|
|
13
|
+
* the one `mda deploy` recorded for the deployment's environment
|
|
14
|
+
* (`MDA_LANGSMITH_URL`); without it there is nothing to link to.
|
|
15
|
+
*/
|
|
16
|
+
export function studioUrl(run, env = process.env) {
|
|
17
|
+
const threadId = run?.threadId;
|
|
18
|
+
const thread = threadId && UUID_PATTERN.test(threadId) ? threadId : undefined;
|
|
19
|
+
const workspace = env.LANGSMITH_TENANT_ID?.trim() ?? "";
|
|
20
|
+
const deployment = env[DEPLOYMENT_ID_ENV]?.trim() ?? "";
|
|
21
|
+
if (!UUID_PATTERN.test(workspace) || !UUID_PATTERN.test(deployment))
|
|
22
|
+
return undefined;
|
|
23
|
+
const origin = parseHttpUrl(env.MDA_LANGSMITH_URL)?.origin;
|
|
24
|
+
if (!origin)
|
|
25
|
+
return undefined;
|
|
26
|
+
const name = managedDeploymentName(env);
|
|
27
|
+
const assistantId = assistantUuid(run?.assistantId);
|
|
28
|
+
if (!name || !DEPLOYMENT_NAME_PATTERN.test(name) || !thread || !assistantId)
|
|
29
|
+
return `${origin}/o/${workspace}/host/deployments/${deployment}`;
|
|
30
|
+
const query = new URLSearchParams({
|
|
31
|
+
organizationId: workspace,
|
|
32
|
+
render: "interact",
|
|
33
|
+
hostProjectId: deployment,
|
|
34
|
+
assistantId,
|
|
35
|
+
mode: "chat",
|
|
36
|
+
threadId: thread,
|
|
37
|
+
});
|
|
38
|
+
return `${origin}/o/${workspace}/a/${encodeURIComponent(name)}/studio/thread?${query}`;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* `waiting` when a finished delivery's message found the thread waiting on a
|
|
42
|
+
* decision. A run that stopped on interrupts posts its own `interrupted`
|
|
43
|
+
* notice as it ends (the paused notice), so a `run` delivery has none here.
|
|
44
|
+
* Undefined when nothing waits, or the delivery was a cancel or lost.
|
|
45
|
+
*/
|
|
46
|
+
export function pendingDecision(finish) {
|
|
47
|
+
if (!finish.interrupts.length)
|
|
48
|
+
return undefined;
|
|
49
|
+
return finish.type === "skipped" && finish.reason === "waiting"
|
|
50
|
+
? "waiting"
|
|
51
|
+
: undefined;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* What a channel tells the conversation when its thread waits on a decision,
|
|
55
|
+
* with a link to the thread in Studio, where the decision is made: the run
|
|
56
|
+
* the delivery started stopped on interrupts (`interrupted`), or the message
|
|
57
|
+
* found the thread waiting (`waiting`). `again` says how to continue once it
|
|
58
|
+
* is made, such as "comment again".
|
|
59
|
+
*/
|
|
60
|
+
export function interruptedNotice(outcome, delivery, again) {
|
|
61
|
+
const url = studioUrl(delivery);
|
|
62
|
+
const studio = url ? `[LangSmith Studio](${url})` : "LangSmith Studio";
|
|
63
|
+
return outcome === "interrupted"
|
|
64
|
+
? `I need a decision before I continue. Review the pending step in ${studio}.`
|
|
65
|
+
: `I'm waiting for a decision on an earlier step in this conversation, so I haven't read this yet. Review the pending step in ${studio}, then ${again}.`;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Studio opens an assistant by its ID. Channels start runs by graph ID, whose
|
|
69
|
+
* default assistant the Agent Server derives from it.
|
|
70
|
+
*/
|
|
71
|
+
function assistantUuid(assistant) {
|
|
72
|
+
if (!assistant)
|
|
73
|
+
return undefined;
|
|
74
|
+
if (UUID_PATTERN.test(assistant))
|
|
75
|
+
return assistant;
|
|
76
|
+
return GRAPH_ID_PATTERN.test(assistant)
|
|
77
|
+
? uuidv5(assistant, GRAPH_NAMESPACE)
|
|
78
|
+
: undefined;
|
|
79
|
+
}
|
|
80
|
+
function parseHttpUrl(value) {
|
|
81
|
+
if (!value?.trim())
|
|
82
|
+
return undefined;
|
|
83
|
+
try {
|
|
84
|
+
const url = new URL(value.trim());
|
|
85
|
+
return (url.protocol === "https:" || url.protocol === "http:") &&
|
|
86
|
+
!url.username &&
|
|
87
|
+
!url.password
|
|
88
|
+
? url
|
|
89
|
+
: undefined;
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=studio.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"studio.js","sourceRoot":"","sources":["../../../src/channels/http/studio.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAGzE,MAAM,YAAY,GAChB,iEAAiE,CAAC;AACpE,MAAM,uBAAuB,GAAG,oCAAoC,CAAC;AACrE,MAAM,gBAAgB,GAAG,qCAAqC,CAAC;AAC/D,+EAA+E;AAC/E,MAAM,eAAe,GAAG,sCAAsC,CAAC;AAE/D;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CACvB,GAA6B,EAC7B,GAAG,GAAG,OAAO,CAAC,GAAG;IAEjB,MAAM,QAAQ,GAAG,GAAG,EAAE,QAAQ,CAAC;IAC/B,MAAM,MAAM,GAAG,QAAQ,IAAI,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IAC9E,MAAM,SAAS,GAAG,GAAG,CAAC,mBAAmB,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACxD,MAAM,UAAU,GAAG,GAAG,CAAC,iBAAiB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACxD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC;QACjE,OAAO,SAAS,CAAC;IAC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vE,OAAO,OAAO,KAAK,aAAa;QAC9B,CAAC,CAAC,mEAAmE,MAAM,GAAG;QAC9E,CAAC,CAAC,8HAA8H,MAAM,UAAU,KAAK,GAAG,CAAC;AAC7J,CAAC;AAED;;;GAGG;AACH,SAAS,aAAa,CAAC,SAA6B;IAClD,IAAI,CAAC,SAAS;QAAE,OAAO,SAAS,CAAC;IACjC,IAAI,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC;QAAE,OAAO,SAAS,CAAC;IACnD,OAAO,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC;QACrC,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,eAAe,CAAC;QACpC,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,SAAS,YAAY,CAAC,KAAyB;IAC7C,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE;QAAE,OAAO,SAAS,CAAC;IACrC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;QAClC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,CAAC;YAC5D,CAAC,GAAG,CAAC,QAAQ;YACb,CAAC,GAAG,CAAC,QAAQ;YACb,CAAC,CAAC,GAAG;YACL,CAAC,CAAC,SAAS,CAAC;IAChB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The thread for one provider conversation, such as an issue or a chat: the
|
|
3
|
+
* same channel and key always give the same UUID, so each message continues
|
|
4
|
+
* the conversation. The Python runtime derives the same IDs.
|
|
5
|
+
*/
|
|
6
|
+
export declare function channelThreadId(channelName: string, key: string): string;
|
|
7
|
+
//# sourceMappingURL=threads.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"threads.d.ts","sourceRoot":"","sources":["../../../src/channels/http/threads.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAKxE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { v5 as uuidv5 } from "uuid";
|
|
2
|
+
/**
|
|
3
|
+
* The thread for one provider conversation, such as an issue or a chat: the
|
|
4
|
+
* same channel and key always give the same UUID, so each message continues
|
|
5
|
+
* the conversation. The Python runtime derives the same IDs.
|
|
6
|
+
*/
|
|
7
|
+
export function channelThreadId(channelName, key) {
|
|
8
|
+
return uuidv5(`mda-thread:v1:${JSON.stringify([channelName, key])}`, uuidv5.URL);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=threads.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"threads.js","sourceRoot":"","sources":["../../../src/channels/http/threads.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,WAAmB,EAAE,GAAW;IAC9D,OAAO,MAAM,CACX,iBAAiB,IAAI,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,EAAE,EACrD,MAAM,CAAC,GAAG,CACX,CAAC;AACJ,CAAC"}
|
|
@@ -1,21 +1,70 @@
|
|
|
1
|
+
import type { Interrupt } from "@langchain/langgraph-sdk";
|
|
2
|
+
import type { MultitaskStrategy } from "../../ingress/runs.js";
|
|
1
3
|
import type { MessageContent } from "@langchain/core/messages";
|
|
2
|
-
import type { ChannelMessage, JsonValue } from "../types.js";
|
|
4
|
+
import type { ChannelMessage, ChannelReply, JsonValue } from "../types.js";
|
|
5
|
+
import type { ChannelRunResult } from "../run-input.js";
|
|
6
|
+
import type { ChannelActor } from "../actor.js";
|
|
3
7
|
export interface HttpChannelInboundMessage {
|
|
4
8
|
userId: string;
|
|
9
|
+
/** See {@link channelThreadId} for one thread per provider conversation. */
|
|
5
10
|
threadId: string;
|
|
6
11
|
/** Provider destination, independent of the LangGraph thread UUID. */
|
|
7
12
|
target: JsonValue;
|
|
8
|
-
|
|
13
|
+
/**
|
|
14
|
+
* What a new run starts with. Without it, the adapter's `input` supplies it
|
|
15
|
+
* once MDA knows the thread takes a new turn.
|
|
16
|
+
*/
|
|
17
|
+
content?: MessageContent;
|
|
18
|
+
/**
|
|
19
|
+
* The provider's ID for this delivery. A thread runs each delivery once, so
|
|
20
|
+
* a redelivered event starts nothing.
|
|
21
|
+
*
|
|
22
|
+
* @experimental This may change in a minor release.
|
|
23
|
+
*/
|
|
24
|
+
deliveryKey?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Answer the provider before the adapter's `input` decides what the run
|
|
27
|
+
* starts with, and start it in the background: for input that may take
|
|
28
|
+
* longer than the provider waits, such as an event endpoint's. A failure
|
|
29
|
+
* then can't fail the delivery, so the provider doesn't redeliver it.
|
|
30
|
+
*
|
|
31
|
+
* @experimental This may change in a minor release.
|
|
32
|
+
*/
|
|
33
|
+
background?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The thread a `cancel` result stops, and who to tell.
|
|
37
|
+
*
|
|
38
|
+
* @experimental This may change in a minor release.
|
|
39
|
+
*/
|
|
40
|
+
export interface HttpChannelCancelMessage {
|
|
41
|
+
userId: string;
|
|
42
|
+
threadId: string;
|
|
43
|
+
/** Where to report the stop. */
|
|
44
|
+
target: JsonValue;
|
|
9
45
|
}
|
|
10
46
|
export type HttpChannelParseResult = {
|
|
11
47
|
type: "message";
|
|
12
48
|
message: HttpChannelInboundMessage;
|
|
13
49
|
/** Optional provider data exposed as runtime.channel.rawEvent. */
|
|
14
50
|
rawEvent?: JsonValue;
|
|
51
|
+
/** The verified sender, which `resolveUser` maps to one of your users. */
|
|
52
|
+
actor?: ChannelActor;
|
|
15
53
|
response?: Response;
|
|
16
54
|
} | {
|
|
17
55
|
type: "ignore";
|
|
18
56
|
response?: Response;
|
|
57
|
+
} | {
|
|
58
|
+
/**
|
|
59
|
+
* Stop the work on the message's thread: MDA cancels its queued and
|
|
60
|
+
* running runs, keeping their progress, then calls `onFinish`.
|
|
61
|
+
*
|
|
62
|
+
* @experimental This may change in a minor release.
|
|
63
|
+
*/
|
|
64
|
+
type: "cancel";
|
|
65
|
+
message: HttpChannelCancelMessage;
|
|
66
|
+
rawEvent?: JsonValue;
|
|
67
|
+
response?: Response;
|
|
19
68
|
};
|
|
20
69
|
/** MDA adds the verified reply target to the validated message. */
|
|
21
70
|
export type HttpChannelPostInput = ChannelMessage & {
|
|
@@ -29,11 +78,126 @@ export interface HttpPostedMessage {
|
|
|
29
78
|
}
|
|
30
79
|
export interface HttpChannelAdapter {
|
|
31
80
|
provider: string;
|
|
81
|
+
providerConfig?: Record<string, JsonValue>;
|
|
82
|
+
/**
|
|
83
|
+
* What a message that starts a turn does while its thread already runs:
|
|
84
|
+
* `enqueue` (the default) waits for the run and starts after it,
|
|
85
|
+
* `interrupt` cancels the run, keeping its progress, and starts at once,
|
|
86
|
+
* `rollback` cancels it and discards its progress, and `reject` starts
|
|
87
|
+
* nothing. Messages to a thread that waits on an interrupt start nothing
|
|
88
|
+
* either way.
|
|
89
|
+
*
|
|
90
|
+
* @experimental This may change in a minor release.
|
|
91
|
+
*/
|
|
92
|
+
multitaskStrategy?: MultitaskStrategy;
|
|
93
|
+
/**
|
|
94
|
+
* Whether the channel posts the run's final answer with `post`: `auto`
|
|
95
|
+
* (the default) or `none`, to leave replying to the agent; see
|
|
96
|
+
* {@link ChannelReply}.
|
|
97
|
+
*
|
|
98
|
+
* @experimental This may change in a minor release.
|
|
99
|
+
*/
|
|
100
|
+
reply?: ChannelReply;
|
|
32
101
|
verify(context: HttpChannelRequest): boolean | Promise<boolean>;
|
|
33
102
|
/** Decode the verified request body in the provider's format. */
|
|
34
103
|
parse(context: HttpChannelRequest): HttpChannelParseResult | Promise<HttpChannelParseResult>;
|
|
35
104
|
post?(input: HttpChannelPostInput): Promise<HttpPostedMessage>;
|
|
105
|
+
/**
|
|
106
|
+
* The run a message started failed: tell the sender instead of the default
|
|
107
|
+
* apology `post` sends. Called before `onFinish`.
|
|
108
|
+
*/
|
|
36
109
|
onError?(error: unknown, target: JsonValue): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* What a message without `content` starts a run with, asked only once the
|
|
112
|
+
* thread takes a new turn, never while it waits on an interrupt. `null` or
|
|
113
|
+
* `undefined` starts nothing.
|
|
114
|
+
*
|
|
115
|
+
* @experimental This may change in a minor release.
|
|
116
|
+
*/
|
|
117
|
+
input?(message: HttpChannelInboundMessage, rawEvent: JsonValue | undefined): ChannelRunResult | null | undefined | Promise<ChannelRunResult | null | undefined>;
|
|
118
|
+
/**
|
|
119
|
+
* A verified message reached its thread, before MDA starts or queues
|
|
120
|
+
* anything for it. For providers that expect a prompt acknowledgement.
|
|
121
|
+
* Each message that gets it later gets `onFinish`. Runs in the
|
|
122
|
+
* background; failures are logged.
|
|
123
|
+
*
|
|
124
|
+
* @experimental This may change in a minor release.
|
|
125
|
+
*/
|
|
126
|
+
onReceived?(target: JsonValue, delivery: HttpDelivery): Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* A message is done, once, with how: the run it started ended (`run`), it
|
|
129
|
+
* started none and why (`skipped`), or MDA couldn't start the run or lost
|
|
130
|
+
* track of it (`failed`); see {@link HttpFinish}. `interrupts` are what the
|
|
131
|
+
* thread waits on now, non-empty while a decision is pending, made in
|
|
132
|
+
* Studio. Called after `onReceived` and `onError`, in the background;
|
|
133
|
+
* failures are logged.
|
|
134
|
+
*
|
|
135
|
+
* It runs in the process that took the delivery, so a restart loses it,
|
|
136
|
+
* and a run Studio resumes has no delivery. Keep a reconciliation, or set
|
|
137
|
+
* the run's `webhook`, for anything that must not miss a run.
|
|
138
|
+
*
|
|
139
|
+
* @experimental This may change in a minor release.
|
|
140
|
+
*/
|
|
141
|
+
onFinish?(target: JsonValue, delivery: HttpFinishedDelivery): Promise<void>;
|
|
142
|
+
}
|
|
143
|
+
/** A delivery's thread, for notices and links into LangSmith Studio. */
|
|
144
|
+
export interface HttpDelivery {
|
|
145
|
+
threadId: string;
|
|
146
|
+
/** The assistant that runs on the thread, when known. */
|
|
147
|
+
assistantId?: string;
|
|
148
|
+
/** The provider event `parse` returned, if any. */
|
|
149
|
+
rawEvent?: JsonValue;
|
|
150
|
+
}
|
|
151
|
+
/** A delivery that is done; see {@link HttpChannelAdapter.onFinish}. */
|
|
152
|
+
export type HttpFinishedDelivery = HttpDelivery & HttpFinish;
|
|
153
|
+
/**
|
|
154
|
+
* How a delivery finished, to switch on by `type`. Each comes with
|
|
155
|
+
* `interrupts`, the thread's pending interrupts: what it waits on now.
|
|
156
|
+
*
|
|
157
|
+
* - `run`: the run it started ended; `run.status` says how.
|
|
158
|
+
* - `skipped`: it started no run; `reason` says why.
|
|
159
|
+
* - `failed`: MDA couldn't start its run after the provider got its answer,
|
|
160
|
+
* so nothing redelivers it (`start`); couldn't start it and answered the
|
|
161
|
+
* provider with an error, so it may redeliver it as a new delivery, which
|
|
162
|
+
* reports its own outcome (`retry`); or lost track of the run it started
|
|
163
|
+
* (`observe`), which may still answer. Only `start` is a final failure.
|
|
164
|
+
*/
|
|
165
|
+
export type HttpFinish = {
|
|
166
|
+
type: "run";
|
|
167
|
+
run: HttpFinishedRun;
|
|
168
|
+
interrupts: Interrupt[];
|
|
169
|
+
} | {
|
|
170
|
+
type: "skipped";
|
|
171
|
+
reason: HttpSkipReason;
|
|
172
|
+
interrupts: Interrupt[];
|
|
173
|
+
} | {
|
|
174
|
+
type: "failed";
|
|
175
|
+
reason: "start" | "retry" | "observe";
|
|
176
|
+
interrupts: Interrupt[];
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Why a delivery started no run:
|
|
180
|
+
*
|
|
181
|
+
* - `cancel`: it was a cancel, and MDA cancelled the thread's runs.
|
|
182
|
+
* - `waiting`: its thread waits on a decision; `interrupts` say on what.
|
|
183
|
+
* - `ignored`: its input started nothing, such as a handler that declined.
|
|
184
|
+
* - `duplicate`: a redelivery of a delivery the thread already took; that
|
|
185
|
+
* delivery's own `onFinish` reports its run.
|
|
186
|
+
* - `rejected`: its thread was busy, and the channel's `multitaskStrategy`
|
|
187
|
+
* is `reject`.
|
|
188
|
+
* - `dropped`: a cancel dropped it while it waited for its busy thread or
|
|
189
|
+
* for its input.
|
|
190
|
+
*/
|
|
191
|
+
export type HttpSkipReason = "cancel" | "waiting" | "ignored" | "duplicate" | "rejected" | "dropped";
|
|
192
|
+
/**
|
|
193
|
+
* How a LangGraph run ended: `interrupted` when it was cancelled, by a cancel
|
|
194
|
+
* or a newer message, or replaced by a newer message's `rollback`.
|
|
195
|
+
*/
|
|
196
|
+
export type HttpRunStatus = "success" | "error" | "timeout" | "interrupted";
|
|
197
|
+
/** A run a delivery started, and how it ended. */
|
|
198
|
+
export interface HttpFinishedRun {
|
|
199
|
+
id: string;
|
|
200
|
+
status: HttpRunStatus;
|
|
37
201
|
}
|
|
38
202
|
export interface HttpChannelRequest {
|
|
39
203
|
request: Request;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/channels/http/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/channels/http/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KA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CAC7E;AAED,wEAAwE;AACxE,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,yDAAyD;IACzD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mDAAmD;IACnD,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,wEAAwE;AACxE,MAAM,MAAM,oBAAoB,GAAG,YAAY,GAAG,UAAU,CAAC;AAE7D;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,GAAG,EAAE,eAAe,CAAC;IAAC,UAAU,EAAE,SAAS,EAAE,CAAA;CAAE,GAC9D;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,cAAc,CAAC;IAAC,UAAU,EAAE,SAAS,EAAE,CAAA;CAAE,GACpE;IACE,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;IACtC,UAAU,EAAE,SAAS,EAAE,CAAC;CACzB,CAAC;AAEN;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,cAAc,GACtB,QAAQ,GACR,SAAS,GACT,SAAS,GACT,WAAW,GACX,UAAU,GACV,SAAS,CAAC;AAEd;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,aAAa,CAAC;AAE5E,kDAAkD;AAClD,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,aAAa,CAAC;CACvB;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,UAAU,CAAC;CACrB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { LinearAppOptions } from "./types.js";
|
|
2
|
+
/** What `mda deploy` needs to set up the Linear app. */
|
|
3
|
+
export type LinearAppSetup = {
|
|
4
|
+
/** The handled event keys, such as `Issue.create`. */
|
|
5
|
+
events: string[];
|
|
6
|
+
/** Whether the app answers agent sessions. */
|
|
7
|
+
sessions: boolean;
|
|
8
|
+
/** The webhook resource types the app subscribes to. */
|
|
9
|
+
webhookResourceTypes: string[];
|
|
10
|
+
/** The OAuth scopes the install asks for. */
|
|
11
|
+
scopes: string[];
|
|
12
|
+
/** The most the install may be granted. */
|
|
13
|
+
allowedScopes: string[];
|
|
14
|
+
/** How the app looks; deploy names it after the agent when unset. */
|
|
15
|
+
app?: {
|
|
16
|
+
name?: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
icon?: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* The app the channel's handlers and options need. The CLI reads it from the
|
|
23
|
+
* channel's manifest instead of working it out; the Python runtime mirrors
|
|
24
|
+
* these rules in `linear_app_setup.py`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function linearAppSetup(handlers: object, app: LinearAppOptions | undefined, options: {
|
|
27
|
+
sessions: boolean;
|
|
28
|
+
}): LinearAppSetup;
|
|
29
|
+
//# sourceMappingURL=app-setup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-setup.d.ts","sourceRoot":"","sources":["../../../src/channels/linear/app-setup.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAkB,MAAM,YAAY,CAAC;AAqCnE,wDAAwD;AACxD,MAAM,MAAM,cAAc,GAAG;IAC3B,sDAAsD;IACtD,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,8CAA8C;IAC9C,QAAQ,EAAE,OAAO,CAAC;IAClB,wDAAwD;IACxD,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,6CAA6C;IAC7C,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,2CAA2C;IAC3C,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,qEAAqE;IACrE,GAAG,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC9D,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,gBAAgB,GAAG,SAAS,EACjC,OAAO,EAAE;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE,GAC7B,cAAc,CAkChB"}
|