managed-deepagents 0.10.0-dev.6 → 0.10.0-dev.8
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 +100 -58
- package/dist/channels/github/connections.d.ts.map +1 -1
- package/dist/channels/github/connections.js +2 -2
- package/dist/channels/github/connections.js.map +1 -1
- package/dist/channels/github/index.d.ts +1 -1
- package/dist/channels/github/index.d.ts.map +1 -1
- package/dist/channels/github/index.js +52 -93
- package/dist/channels/github/index.js.map +1 -1
- package/dist/channels/github/schema.d.ts.map +1 -1
- package/dist/channels/github/schema.js +1 -3
- package/dist/channels/github/schema.js.map +1 -1
- package/dist/channels/github/types.d.ts +38 -10
- package/dist/channels/github/types.d.ts.map +1 -1
- package/dist/channels/http/forward.d.ts +13 -0
- package/dist/channels/http/forward.d.ts.map +1 -0
- package/dist/channels/http/forward.js +128 -0
- package/dist/channels/http/forward.js.map +1 -0
- package/dist/channels/http/http.d.ts.map +1 -1
- package/dist/channels/http/http.js +94 -95
- package/dist/channels/http/http.js.map +1 -1
- package/dist/channels/http/index.d.ts +1 -1
- package/dist/channels/http/index.d.ts.map +1 -1
- package/dist/channels/http/index.js +9 -0
- package/dist/channels/http/index.js.map +1 -1
- package/dist/channels/http/ingress.d.ts +26 -11
- package/dist/channels/http/ingress.d.ts.map +1 -1
- package/dist/channels/http/ingress.js +19 -34
- package/dist/channels/http/ingress.js.map +1 -1
- package/dist/channels/http/provider.d.ts +83 -0
- package/dist/channels/http/provider.d.ts.map +1 -0
- package/dist/channels/http/provider.js +176 -0
- package/dist/channels/http/provider.js.map +1 -0
- package/dist/channels/http/studio.d.ts +7 -5
- package/dist/channels/http/studio.d.ts.map +1 -1
- package/dist/channels/http/studio.js +12 -12
- package/dist/channels/http/studio.js.map +1 -1
- package/dist/channels/http/types.d.ts +53 -15
- package/dist/channels/http/types.d.ts.map +1 -1
- package/dist/channels/linear/connections.d.ts.map +1 -1
- package/dist/channels/linear/connections.js +2 -2
- package/dist/channels/linear/connections.js.map +1 -1
- package/dist/channels/linear/graphql.d.ts +5 -17
- package/dist/channels/linear/graphql.d.ts.map +1 -1
- package/dist/channels/linear/graphql.js +55 -57
- package/dist/channels/linear/graphql.js.map +1 -1
- package/dist/channels/linear/index.d.ts +1 -1
- package/dist/channels/linear/index.d.ts.map +1 -1
- package/dist/channels/linear/index.js +162 -160
- package/dist/channels/linear/index.js.map +1 -1
- package/dist/channels/linear/schema.d.ts +173 -144
- package/dist/channels/linear/schema.d.ts.map +1 -1
- package/dist/channels/linear/schema.js +45 -12
- package/dist/channels/linear/schema.js.map +1 -1
- package/dist/channels/linear/types.d.ts +42 -21
- package/dist/channels/linear/types.d.ts.map +1 -1
- 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/run-input.d.ts +3 -9
- package/dist/channels/run-input.d.ts.map +1 -1
- package/dist/channels/run-input.js +7 -17
- package/dist/channels/run-input.js.map +1 -1
- package/dist/channels/trigger/client.js +7 -3
- package/dist/channels/trigger/client.js.map +1 -1
- package/dist/channels/trigger/http.d.ts.map +1 -1
- package/dist/channels/trigger/http.js +6 -3
- package/dist/channels/trigger/http.js.map +1 -1
- package/dist/channels/trigger/tracing-project.d.ts +16 -0
- package/dist/channels/trigger/tracing-project.d.ts.map +1 -0
- package/dist/channels/trigger/tracing-project.js +54 -0
- package/dist/channels/trigger/tracing-project.js.map +1 -0
- package/dist/channels/trigger/types.d.ts +6 -0
- package/dist/channels/trigger/types.d.ts.map +1 -1
- package/dist/channels/trigger/types.js.map +1 -1
- package/dist/connections.d.ts +6 -0
- package/dist/connections.d.ts.map +1 -1
- package/dist/connections.js +27 -0
- package/dist/connections.js.map +1 -1
- package/dist/connectors/mcp/index.d.ts.map +1 -1
- package/dist/connectors/mcp/index.js +52 -2
- package/dist/connectors/mcp/index.js.map +1 -1
- package/dist/credential-gate.d.ts.map +1 -1
- package/dist/credential-gate.js +13 -3
- package/dist/credential-gate.js.map +1 -1
- package/dist/identity/options.d.ts +0 -9
- package/dist/identity/options.d.ts.map +1 -1
- package/dist/identity/options.js +1 -6
- package/dist/identity/options.js.map +1 -1
- package/dist/identity/types.d.ts +0 -6
- package/dist/identity/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/ingress/runs.d.ts +2 -4
- package/dist/ingress/runs.d.ts.map +1 -1
- package/dist/ingress/runs.js +5 -6
- package/dist/ingress/runs.js.map +1 -1
- package/dist/runtime/auth.d.ts +0 -9
- package/dist/runtime/auth.d.ts.map +1 -1
- package/dist/runtime/auth.js +2 -55
- package/dist/runtime/auth.js.map +1 -1
- package/dist/runtime/schedule-auth.d.ts +1 -1
- package/dist/runtime/schedule-auth.d.ts.map +1 -1
- package/dist/runtime/schedule-auth.js +12 -4
- package/dist/runtime/schedule-auth.js.map +1 -1
- package/dist/runtime-schedules.js +6 -6
- package/dist/runtime-schedules.js.map +1 -1
- package/package.json +7 -7
|
@@ -12,22 +12,10 @@ const GRAPH_NAMESPACE = "6ba7b821-9dad-11d1-80b4-00c04fd430c8";
|
|
|
12
12
|
* deployment's name or the thread's assistant is unknown. The LangSmith UI is
|
|
13
13
|
* the one `mda deploy` recorded for the deployment's environment
|
|
14
14
|
* (`MDA_LANGSMITH_URL`); without it there is nothing to link to.
|
|
15
|
-
*
|
|
16
|
-
* A platform that serves its own Studio for the deployment, such as the local
|
|
17
|
-
* stack, names it in `MDA_STUDIO_URL`; the link then opens that Studio on the
|
|
18
|
-
* thread.
|
|
19
15
|
*/
|
|
20
16
|
export function studioUrl(run, env = process.env) {
|
|
21
17
|
const threadId = run?.threadId;
|
|
22
18
|
const thread = threadId && UUID_PATTERN.test(threadId) ? threadId : undefined;
|
|
23
|
-
const standalone = parseHttpUrl(env.MDA_STUDIO_URL);
|
|
24
|
-
if (standalone) {
|
|
25
|
-
if (thread) {
|
|
26
|
-
standalone.searchParams.set("threadId", thread);
|
|
27
|
-
standalone.searchParams.set("mode", "chat");
|
|
28
|
-
}
|
|
29
|
-
return standalone.href;
|
|
30
|
-
}
|
|
31
19
|
const workspace = env.LANGSMITH_TENANT_ID?.trim() ?? "";
|
|
32
20
|
const deployment = env[DEPLOYMENT_ID_ENV]?.trim() ?? "";
|
|
33
21
|
if (!UUID_PATTERN.test(workspace) || !UUID_PATTERN.test(deployment))
|
|
@@ -49,6 +37,18 @@ export function studioUrl(run, env = process.env) {
|
|
|
49
37
|
});
|
|
50
38
|
return `${origin}/o/${workspace}/a/${encodeURIComponent(name)}/studio/thread?${query}`;
|
|
51
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* What a channel tells the conversation when its thread waits on a decision,
|
|
42
|
+
* with a link to the thread in Studio, where the decision is made. `again`
|
|
43
|
+
* says how to continue once it is made, such as "comment again".
|
|
44
|
+
*/
|
|
45
|
+
export function interruptedNotice(reason, run, again) {
|
|
46
|
+
const url = studioUrl(run);
|
|
47
|
+
const studio = url ? `[LangSmith Studio](${url})` : "LangSmith Studio";
|
|
48
|
+
return reason === "stopped"
|
|
49
|
+
? `I need a decision before I continue. Review the pending step in ${studio}.`
|
|
50
|
+
: `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}.`;
|
|
51
|
+
}
|
|
52
52
|
/**
|
|
53
53
|
* Studio opens an assistant by its ID. Channels start runs by graph ID, whose
|
|
54
54
|
* default assistant the Agent Server derives from it.
|
|
@@ -1 +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,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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"}
|
|
@@ -19,6 +19,13 @@ export interface HttpChannelInboundMessage {
|
|
|
19
19
|
*/
|
|
20
20
|
deliveryKey?: string;
|
|
21
21
|
}
|
|
22
|
+
/** The thread a `cancel` result stops, and who to tell. */
|
|
23
|
+
export interface HttpChannelCancelMessage {
|
|
24
|
+
userId: string;
|
|
25
|
+
threadId: string;
|
|
26
|
+
/** Where to report the stop. */
|
|
27
|
+
target: JsonValue;
|
|
28
|
+
}
|
|
22
29
|
export type HttpChannelParseResult = {
|
|
23
30
|
type: "message";
|
|
24
31
|
message: HttpChannelInboundMessage;
|
|
@@ -28,14 +35,15 @@ export type HttpChannelParseResult = {
|
|
|
28
35
|
} | {
|
|
29
36
|
type: "ignore";
|
|
30
37
|
response?: Response;
|
|
38
|
+
/** The provider's event, when it is parsed only to be forwarded. */
|
|
39
|
+
rawEvent?: JsonValue;
|
|
31
40
|
} | {
|
|
32
41
|
/**
|
|
33
42
|
* Stop the work on the message's thread: MDA cancels its queued and
|
|
34
|
-
* running runs, keeping their progress, then calls `onCancelled`.
|
|
35
|
-
* message needs no `content`.
|
|
43
|
+
* running runs, keeping their progress, then calls `onCancelled`.
|
|
36
44
|
*/
|
|
37
45
|
type: "cancel";
|
|
38
|
-
message:
|
|
46
|
+
message: HttpChannelCancelMessage;
|
|
39
47
|
rawEvent?: JsonValue;
|
|
40
48
|
response?: Response;
|
|
41
49
|
};
|
|
@@ -61,6 +69,11 @@ export interface HttpChannelAdapter {
|
|
|
61
69
|
* either way.
|
|
62
70
|
*/
|
|
63
71
|
multitaskStrategy?: MultitaskStrategy;
|
|
72
|
+
/**
|
|
73
|
+
* Why `onInterrupted` is called; by default only `"waiting"`. Add `"stopped"` to
|
|
74
|
+
* also hear when the run a delivery started stops on interrupts.
|
|
75
|
+
*/
|
|
76
|
+
interruptedReasons?: readonly HttpInterruptedReason[];
|
|
64
77
|
verify(context: HttpChannelRequest): boolean | Promise<boolean>;
|
|
65
78
|
/** Decode the verified request body in the provider's format. */
|
|
66
79
|
parse(context: HttpChannelRequest): HttpChannelParseResult | Promise<HttpChannelParseResult>;
|
|
@@ -69,16 +82,20 @@ export interface HttpChannelAdapter {
|
|
|
69
82
|
/**
|
|
70
83
|
* What a message without `content` starts a run with, asked only once the
|
|
71
84
|
* thread takes a new turn, never while it waits on an interrupt. `null` or
|
|
72
|
-
* `undefined` starts nothing.
|
|
73
|
-
* came in, which never reaches the run.
|
|
85
|
+
* `undefined` starts nothing.
|
|
74
86
|
*/
|
|
75
|
-
input?(message: HttpChannelInboundMessage, rawEvent: JsonValue | undefined
|
|
87
|
+
input?(message: HttpChannelInboundMessage, rawEvent: JsonValue | undefined): ChannelRunResult | null | undefined | Promise<ChannelRunResult | null | undefined>;
|
|
76
88
|
/**
|
|
77
|
-
* The thread waits on a decision
|
|
78
|
-
*
|
|
79
|
-
*
|
|
89
|
+
* The thread waits on a decision. Tell the sender where to make it (Studio
|
|
90
|
+
* resumes interrupts). Failures are logged. `reason` says why:
|
|
91
|
+
*
|
|
92
|
+
* - `"waiting"`: a message arrived while the thread waits, so MDA started
|
|
93
|
+
* no run.
|
|
94
|
+
* - `"stopped"`: the run this delivery started just stopped on interrupts.
|
|
95
|
+
*
|
|
96
|
+
* It is called only for the reasons in `interruptedReasons`.
|
|
80
97
|
*/
|
|
81
|
-
|
|
98
|
+
onInterrupted?(target: JsonValue, run: HttpChannelRunInfo, reason: HttpInterruptedReason): Promise<void>;
|
|
82
99
|
/**
|
|
83
100
|
* A verified message reached its thread, before MDA starts or queues
|
|
84
101
|
* anything for it, and whatever it then does. For providers that
|
|
@@ -86,6 +103,19 @@ export interface HttpChannelAdapter {
|
|
|
86
103
|
* logged.
|
|
87
104
|
*/
|
|
88
105
|
onDelivered?(target: JsonValue, run: HttpChannelRunInfo): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Send a verified delivery on to other services, besides acting on it here.
|
|
108
|
+
* Called for every verified delivery, after `parse`, with the delivery as
|
|
109
|
+
* the provider sent it: its raw body and its headers, signature included,
|
|
110
|
+
* minus the ones the platform in front of the deployment adds. Return a
|
|
111
|
+
* request to send, such as `new Request(url, request)`, several, or nothing.
|
|
112
|
+
*
|
|
113
|
+
* MDA sends them in the background, at most 10, each within 10 seconds and
|
|
114
|
+
* without following redirects; failures are logged. The provider's answer
|
|
115
|
+
* never waits for them, so delivery is best effort: a receiver should
|
|
116
|
+
* dedupe by the provider's delivery ID.
|
|
117
|
+
*/
|
|
118
|
+
forward?(request: Request, delivery: HttpForwardContext): HttpForwardResult | Promise<HttpForwardResult>;
|
|
89
119
|
/**
|
|
90
120
|
* MDA cancelled the thread's runs for a `cancel` result; `cancelled` says
|
|
91
121
|
* how many were active. Runs in the background; failures are logged.
|
|
@@ -101,14 +131,22 @@ export interface HttpChannelRunInfo {
|
|
|
101
131
|
assistantId?: string;
|
|
102
132
|
/** The provider event of the delivery the notice is about, when parsed. */
|
|
103
133
|
rawEvent?: JsonValue;
|
|
104
|
-
/**
|
|
105
|
-
* For `onPaused`: the delivery's own run just stopped on interrupts, rather
|
|
106
|
-
* than the message arriving while the thread already waited.
|
|
107
|
-
*/
|
|
108
|
-
stopped?: true;
|
|
109
134
|
}
|
|
135
|
+
/** Why `onInterrupted` is called; see {@link HttpChannelAdapter.onInterrupted}. */
|
|
136
|
+
export type HttpInterruptedReason = "waiting" | "stopped";
|
|
110
137
|
export interface HttpChannelRequest {
|
|
111
138
|
request: Request;
|
|
112
139
|
rawBody: Uint8Array;
|
|
113
140
|
}
|
|
141
|
+
/** What `forward` learns about a delivery besides the request. */
|
|
142
|
+
export interface HttpForwardContext {
|
|
143
|
+
/** What `parse` decided. */
|
|
144
|
+
result: "message" | "ignore" | "cancel";
|
|
145
|
+
/** The provider's event `parse` returned, if any. */
|
|
146
|
+
rawEvent?: JsonValue;
|
|
147
|
+
/** The thread the delivery is for, unless it is ignored. */
|
|
148
|
+
threadId?: string;
|
|
149
|
+
}
|
|
150
|
+
/** The requests `forward` sends a delivery on as. */
|
|
151
|
+
export type HttpForwardResult = Request | readonly Request[] | null | undefined;
|
|
114
152
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/channels/http/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,MAAM,WAAW,yBAAyB;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,4EAA4E;IAC5E,QAAQ,EAAE,MAAM,CAAC;IACjB,sEAAsE;IACtE,MAAM,EAAE,SAAS,CAAC;IAClB;;;OAGG;IACH,OAAO,CAAC,EAAE,cAAc,CAA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AED,qDAAqD;AACrD,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,SAAS,OAAO,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connections.d.ts","sourceRoot":"","sources":["../../../src/channels/linear/connections.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"connections.d.ts","sourceRoot":"","sources":["../../../src/channels/linear/connections.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,iBAAiB,qBAAqB,CAAC;AAEpD;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,MAAM,EACpB,MAAM,CAAC,EAAE,MAAM,GACd,MAAM,CAER"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { appConnectionSlug } from "../http/provider.js";
|
|
1
2
|
/**
|
|
2
3
|
* Reserved agent connection for the deployment's Linear app: reading it
|
|
3
4
|
* returns the app's access token, which Agent Auth renews.
|
|
@@ -8,7 +9,6 @@ export const LINEAR_TOKEN_SLUG = "mda/linear-token";
|
|
|
8
9
|
* beside it (`webhook-secret`) when `suffix` is given.
|
|
9
10
|
*/
|
|
10
11
|
export function linearAppConnectionSlug(deploymentId, suffix) {
|
|
11
|
-
|
|
12
|
-
return suffix ? `${slug}/${suffix}` : slug;
|
|
12
|
+
return appConnectionSlug("linear", deploymentId, suffix);
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=connections.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connections.js","sourceRoot":"","sources":["../../../src/channels/linear/connections.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAEpD;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CACrC,YAAoB,EACpB,MAAe;IAEf,
|
|
1
|
+
{"version":3,"file":"connections.js","sourceRoot":"","sources":["../../../src/channels/linear/connections.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAEpD;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CACrC,YAAoB,EACpB,MAAe;IAEf,OAAO,iBAAiB,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
/** Linear refused a request for exceeding its rate limit. */
|
|
2
3
|
export declare class LinearRateLimitError extends Error {
|
|
3
4
|
constructor();
|
|
@@ -7,19 +8,14 @@ export declare function resetLinearToken(): void;
|
|
|
7
8
|
/**
|
|
8
9
|
* Run a GraphQL operation as the app. `query` is a constant; everything that
|
|
9
10
|
* varies goes in `variables`. A rejected token is read again once. Returns
|
|
10
|
-
* the response's `data`.
|
|
11
|
+
* the response's `data`, checked against `schema`.
|
|
11
12
|
*/
|
|
12
|
-
export declare function linearRequest<T>(query: string, variables
|
|
13
|
+
export declare function linearRequest<T>(query: string, variables: Record<string, unknown>, schema: z.ZodType<T>): Promise<T>;
|
|
13
14
|
/** The Linear user the app acts as. */
|
|
14
15
|
export type LinearAppUser = {
|
|
15
16
|
id: string;
|
|
16
17
|
displayName: string;
|
|
17
18
|
};
|
|
18
|
-
/**
|
|
19
|
-
* The Linear user the app acts as, read once per process: its own comments
|
|
20
|
-
* and changes are ignored, and a comment mentioning its `displayName` starts
|
|
21
|
-
* an agent session.
|
|
22
|
-
*/
|
|
23
19
|
export declare function linearAppUser(): Promise<LinearAppUser>;
|
|
24
20
|
/** Forget the cached app user; for tests. */
|
|
25
21
|
export declare function resetLinearAppUser(): void;
|
|
@@ -41,23 +37,15 @@ export declare function commentInAgentSession(commentId: string): Promise<boolea
|
|
|
41
37
|
export type LinearActivityContent = {
|
|
42
38
|
type: "thought" | "response" | "error" | "elicitation";
|
|
43
39
|
body: string;
|
|
44
|
-
} | {
|
|
45
|
-
type: "action";
|
|
46
|
-
action: string;
|
|
47
|
-
parameter: string;
|
|
48
|
-
result?: string;
|
|
49
40
|
};
|
|
50
41
|
/**
|
|
51
|
-
* Post an activity to an agent session as the app. `ephemeral`
|
|
52
|
-
*
|
|
53
|
-
* options to choose from.
|
|
42
|
+
* Post an activity to an agent session as the app. An `ephemeral` thought is
|
|
43
|
+
* replaced by the next activity.
|
|
54
44
|
*/
|
|
55
45
|
export declare function createLinearActivity(input: {
|
|
56
46
|
agentSessionId: string;
|
|
57
47
|
content: LinearActivityContent;
|
|
58
48
|
ephemeral?: boolean;
|
|
59
|
-
signal?: "select" | "auth";
|
|
60
|
-
signalMetadata?: Record<string, unknown>;
|
|
61
49
|
}): Promise<{
|
|
62
50
|
id: string;
|
|
63
51
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../../src/channels/linear/graphql.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../../src/channels/linear/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAiCxB,6DAA6D;AAC7D,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,cAGC;CACF;AAQD,8CAA8C;AAC9C,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC;AAWD;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,CAAC,EACnC,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,CAAC,CA4BZ;AAoBD,uCAAuC;AACvC,MAAM,MAAM,aAAa,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC;AAahE,wBAAgB,aAAa,IAAI,OAAO,CAAC,aAAa,CAAC,CAEtD;AAED,6CAA6C;AAC7C,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AAYD;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,EAAE;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAKxC;AAWD,8DAA8D;AAC9D,wBAAsB,qBAAqB,CACzC,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC,CAOlB;AAED,6CAA6C;AAC7C,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,SAAS,GAAG,UAAU,GAAG,OAAO,GAAG,aAAa,CAAC;IACvD,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAYF;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,KAAK,EAAE;IAChD,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,qBAAqB,CAAC;IAC/B,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,GAAG,OAAO,CAAC;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC,CAS1B;AASD,2EAA2E;AAC3E,wBAAsB,mBAAmB,CACvC,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACnC,OAAO,CAAC,IAAI,CAAC,CAMf"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
import { connections } from "../../connections.js";
|
|
3
|
+
import { CachedRead } from "../http/provider.js";
|
|
4
|
+
import { nonblankStringSchema } from "../message-schema.js";
|
|
2
5
|
import { LINEAR_TOKEN_SLUG } from "./connections.js";
|
|
3
6
|
const LINEAR_GRAPHQL_URL = "https://api.linear.app/graphql";
|
|
4
7
|
const LINEAR_API_TIMEOUT_MS = 10_000;
|
|
@@ -6,7 +9,11 @@ const LINEAR_API_TIMEOUT_MS = 10_000;
|
|
|
6
9
|
const LINEAR_RESPONSE_MAX_CHARS = 1_000_000;
|
|
7
10
|
/** How long the app token read from Agent Auth is reused. */
|
|
8
11
|
const TOKEN_TTL_MS = 5 * 60_000;
|
|
9
|
-
|
|
12
|
+
/**
|
|
13
|
+
* How long the app's user is reused. It changes only when the app is
|
|
14
|
+
* installed anew, which a long-lived process should notice too.
|
|
15
|
+
*/
|
|
16
|
+
const APP_USER_TTL_MS = 60 * 60_000;
|
|
10
17
|
/**
|
|
11
18
|
* Where GraphQL requests go: Linear's API, or under `mda dev`
|
|
12
19
|
* (`MDA_LOCAL_DEV=1`) the stand-in `MDA_LINEAR_API_URL` names, so local
|
|
@@ -29,23 +36,10 @@ export class LinearRateLimitError extends Error {
|
|
|
29
36
|
}
|
|
30
37
|
}
|
|
31
38
|
/** The app's access token, read from Agent Auth at most every few minutes. */
|
|
32
|
-
|
|
33
|
-
if (appToken && appToken.expiresAt > Date.now())
|
|
34
|
-
return appToken.value;
|
|
35
|
-
const entry = {
|
|
36
|
-
value: connections.resolveDeploymentSecret(LINEAR_TOKEN_SLUG),
|
|
37
|
-
expiresAt: Date.now() + TOKEN_TTL_MS,
|
|
38
|
-
};
|
|
39
|
-
entry.value.catch(() => {
|
|
40
|
-
if (appToken === entry)
|
|
41
|
-
appToken = undefined;
|
|
42
|
-
});
|
|
43
|
-
appToken = entry;
|
|
44
|
-
return entry.value;
|
|
45
|
-
}
|
|
39
|
+
const appToken = new CachedRead(() => connections.resolveDeploymentSecret(LINEAR_TOKEN_SLUG), () => TOKEN_TTL_MS);
|
|
46
40
|
/** Forget the cached app token; for tests. */
|
|
47
41
|
export function resetLinearToken() {
|
|
48
|
-
appToken
|
|
42
|
+
appToken.reset();
|
|
49
43
|
}
|
|
50
44
|
function errorCodes(body) {
|
|
51
45
|
return (body.errors ?? []).flatMap((error) => typeof error.extensions?.code === "string" ? [error.extensions.code] : []);
|
|
@@ -53,13 +47,13 @@ function errorCodes(body) {
|
|
|
53
47
|
/**
|
|
54
48
|
* Run a GraphQL operation as the app. `query` is a constant; everything that
|
|
55
49
|
* varies goes in `variables`. A rejected token is read again once. Returns
|
|
56
|
-
* the response's `data`.
|
|
50
|
+
* the response's `data`, checked against `schema`.
|
|
57
51
|
*/
|
|
58
|
-
export async function linearRequest(query, variables
|
|
52
|
+
export async function linearRequest(query, variables, schema) {
|
|
59
53
|
const send = async () => fetch(graphqlUrl(), {
|
|
60
54
|
method: "POST",
|
|
61
55
|
headers: {
|
|
62
|
-
Authorization: `Bearer ${await
|
|
56
|
+
Authorization: `Bearer ${await appToken.get()}`,
|
|
63
57
|
"Content-Type": "application/json",
|
|
64
58
|
},
|
|
65
59
|
body: JSON.stringify({ query, variables }),
|
|
@@ -69,7 +63,7 @@ export async function linearRequest(query, variables = {}) {
|
|
|
69
63
|
let body = await readBody(response);
|
|
70
64
|
if (response.status === 401 ||
|
|
71
65
|
errorCodes(body).includes("AUTHENTICATION_ERROR")) {
|
|
72
|
-
appToken
|
|
66
|
+
appToken.reset();
|
|
73
67
|
response = await send();
|
|
74
68
|
body = await readBody(response);
|
|
75
69
|
}
|
|
@@ -77,7 +71,10 @@ export async function linearRequest(query, variables = {}) {
|
|
|
77
71
|
throw new LinearRateLimitError();
|
|
78
72
|
if (!response.ok || body.errors?.length || body.data === undefined)
|
|
79
73
|
throw new Error(`Linear refused the request (HTTP ${response.status})`);
|
|
80
|
-
|
|
74
|
+
const data = schema.safeParse(body.data);
|
|
75
|
+
if (!data.success)
|
|
76
|
+
throw new Error("Linear answered in an unexpected shape");
|
|
77
|
+
return data.data;
|
|
81
78
|
}
|
|
82
79
|
async function readBody(response) {
|
|
83
80
|
const text = await response.text();
|
|
@@ -94,76 +91,77 @@ async function readBody(response) {
|
|
|
94
91
|
}
|
|
95
92
|
}
|
|
96
93
|
const VIEWER_QUERY = "query MdaLinearViewer { viewer { id displayName } }";
|
|
97
|
-
|
|
94
|
+
const viewerSchema = z.object({
|
|
95
|
+
viewer: z.object({ id: nonblankStringSchema, displayName: z.string() }),
|
|
96
|
+
});
|
|
98
97
|
/**
|
|
99
|
-
* The Linear user the app acts as, read
|
|
100
|
-
*
|
|
101
|
-
*
|
|
98
|
+
* The Linear user the app acts as, read at most hourly: its own comments and
|
|
99
|
+
* changes are ignored, and a comment mentioning its `displayName` starts an
|
|
100
|
+
* agent session.
|
|
102
101
|
*/
|
|
102
|
+
const appUser = new CachedRead(async () => (await linearRequest(VIEWER_QUERY, {}, viewerSchema)).viewer, () => APP_USER_TTL_MS);
|
|
103
103
|
export function linearAppUser() {
|
|
104
|
-
appUser
|
|
105
|
-
if (typeof viewer?.id !== "string" ||
|
|
106
|
-
!viewer.id ||
|
|
107
|
-
typeof viewer.displayName !== "string")
|
|
108
|
-
throw new Error("Linear did not report the app's user");
|
|
109
|
-
return { id: viewer.id, displayName: viewer.displayName };
|
|
110
|
-
});
|
|
111
|
-
appUser.catch(() => {
|
|
112
|
-
appUser = undefined;
|
|
113
|
-
});
|
|
114
|
-
return appUser;
|
|
104
|
+
return appUser.get();
|
|
115
105
|
}
|
|
116
106
|
/** Forget the cached app user; for tests. */
|
|
117
107
|
export function resetLinearAppUser() {
|
|
118
|
-
appUser
|
|
108
|
+
appUser.reset();
|
|
119
109
|
}
|
|
120
110
|
const COMMENT_CREATE_MUTATION = `mutation MdaLinearCommentCreate($input: CommentCreateInput!) {
|
|
121
111
|
commentCreate(input: $input) { success comment { id url } }
|
|
122
112
|
}`;
|
|
113
|
+
const commentCreateSchema = z.object({
|
|
114
|
+
commentCreate: z.object({
|
|
115
|
+
success: z.literal(true),
|
|
116
|
+
comment: z.object({ id: nonblankStringSchema, url: z.string().nullish() }),
|
|
117
|
+
}),
|
|
118
|
+
});
|
|
123
119
|
/**
|
|
124
120
|
* Comment on an issue as the app, threaded under `parentId` when given.
|
|
125
121
|
* Returns the comment's id and URL.
|
|
126
122
|
*/
|
|
127
123
|
export async function createLinearComment(input) {
|
|
128
|
-
const
|
|
129
|
-
const comment = data.commentCreate?.comment;
|
|
130
|
-
if (!data.commentCreate?.success || !comment?.id)
|
|
131
|
-
throw new Error("Linear did not create the comment");
|
|
124
|
+
const { comment } = (await linearRequest(COMMENT_CREATE_MUTATION, { input }, commentCreateSchema)).commentCreate;
|
|
132
125
|
return { id: comment.id, ...(comment.url && { url: comment.url }) };
|
|
133
126
|
}
|
|
134
127
|
const COMMENT_SESSION_QUERY = `query MdaLinearCommentSession($id: String!) {
|
|
135
128
|
comment(id: $id) { agentSession { id } }
|
|
136
129
|
}`;
|
|
130
|
+
const commentSessionSchema = z.object({
|
|
131
|
+
comment: z
|
|
132
|
+
.object({ agentSession: z.object({ id: nonblankStringSchema }).nullable() })
|
|
133
|
+
.nullable(),
|
|
134
|
+
});
|
|
137
135
|
/** Whether a comment belongs to an agent session's thread. */
|
|
138
136
|
export async function commentInAgentSession(commentId) {
|
|
139
|
-
const
|
|
140
|
-
return Boolean(
|
|
137
|
+
const { comment } = await linearRequest(COMMENT_SESSION_QUERY, { id: commentId }, commentSessionSchema);
|
|
138
|
+
return Boolean(comment?.agentSession);
|
|
141
139
|
}
|
|
142
140
|
const ACTIVITY_CREATE_MUTATION = `mutation MdaLinearActivityCreate($input: AgentActivityCreateInput!) {
|
|
143
141
|
agentActivityCreate(input: $input) { success agentActivity { id } }
|
|
144
142
|
}`;
|
|
143
|
+
const activityCreateSchema = z.object({
|
|
144
|
+
agentActivityCreate: z.object({
|
|
145
|
+
success: z.literal(true),
|
|
146
|
+
agentActivity: z.object({ id: nonblankStringSchema }),
|
|
147
|
+
}),
|
|
148
|
+
});
|
|
145
149
|
/**
|
|
146
|
-
* Post an activity to an agent session as the app. `ephemeral`
|
|
147
|
-
*
|
|
148
|
-
* options to choose from.
|
|
150
|
+
* Post an activity to an agent session as the app. An `ephemeral` thought is
|
|
151
|
+
* replaced by the next activity.
|
|
149
152
|
*/
|
|
150
153
|
export async function createLinearActivity(input) {
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
if (!data.agentActivityCreate?.success || !activity?.id)
|
|
154
|
-
throw new Error("Linear did not create the activity");
|
|
155
|
-
return { id: activity.id };
|
|
154
|
+
const { agentActivity } = (await linearRequest(ACTIVITY_CREATE_MUTATION, { input }, activityCreateSchema)).agentActivityCreate;
|
|
155
|
+
return { id: agentActivity.id };
|
|
156
156
|
}
|
|
157
157
|
const SESSION_UPDATE_MUTATION = `mutation MdaLinearSessionUpdate($id: String!, $input: AgentSessionUpdateInput!) {
|
|
158
158
|
agentSessionUpdate(id: $id, input: $input) { success }
|
|
159
159
|
}`;
|
|
160
|
+
const sessionUpdateSchema = z.object({
|
|
161
|
+
agentSessionUpdate: z.object({ success: z.literal(true) }),
|
|
162
|
+
});
|
|
160
163
|
/** Link an agent session to a page about it, such as its Studio thread. */
|
|
161
164
|
export async function addLinearSessionUrl(agentSessionId, link) {
|
|
162
|
-
|
|
163
|
-
id: agentSessionId,
|
|
164
|
-
input: { addedExternalUrls: [link] },
|
|
165
|
-
});
|
|
166
|
-
if (!data.agentSessionUpdate?.success)
|
|
167
|
-
throw new Error("Linear did not update the session");
|
|
165
|
+
await linearRequest(SESSION_UPDATE_MUTATION, { id: agentSessionId, input: { addedExternalUrls: [link] } }, sessionUpdateSchema);
|
|
168
166
|
}
|
|
169
167
|
//# sourceMappingURL=graphql.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.js","sourceRoot":"","sources":["../../../src/channels/linear/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,MAAM,kBAAkB,GAAG,gCAAgC,CAAC;AAC5D,MAAM,qBAAqB,GAAG,M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,CAAC;AAED,MAAM,uBAAuB,GAAG;;EAE9B,CAAC;AACH,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,kBAAkB,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;CAC3D,CAAC,CAAC;AAEH,2EAA2E;AAC3E,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,cAAsB,EACtB,IAAoC;IAEpC,MAAM,aAAa,CACjB,uBAAuB,EACvB,EAAE,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,EAAE,iBAAiB,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,EAC5D,mBAAmB,CACpB,CAAC;AACJ,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type HttpChannel } from "../http/index.js";
|
|
2
2
|
import type { LinearChannelOptions } from "./types.js";
|
|
3
|
-
export type { LinearAppOptions, LinearChannelOptions,
|
|
3
|
+
export type { LinearAppOptions, LinearChannelOptions, LinearChannelThread, LinearEvent, LinearEventCallback, LinearEventKey, LinearEventResult, LinearPayloadFor, } from "./types.js";
|
|
4
4
|
export { LinearRateLimitError } from "./graphql.js";
|
|
5
5
|
/** Adapt verified Linear webhooks into HTTP channel messages or skips. */
|
|
6
6
|
export declare function linearChannel(options?: LinearChannelOptions): HttpChannel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/channels/linear/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,WAAW,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/channels/linear/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,WAAW,EAOjB,MAAM,kBAAkB,CAAC;AAkC1B,OAAO,KAAK,EAEV,oBAAoB,EAIrB,MAAM,YAAY,CAAC;AAGpB,YAAY,EACV,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAyBpD,0EAA0E;AAC1E,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,WAAW,CAoE7E;AA+CD,mDAAmD;AACnD,wBAAgB,wBAAwB,IAAI,IAAI,CAE/C"}
|