@zapier/zapier-sdk 0.76.1 → 0.77.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +7 -7
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +5 -0
- package/dist/experimental.cjs +55 -60
- package/dist/experimental.d.mts +8 -8
- package/dist/experimental.d.ts +6 -6
- package/dist/experimental.mjs +55 -60
- package/dist/{index-Dlf9DlnJ.d.mts → index-BZShISEr.d.mts} +45 -44
- package/dist/{index-Dlf9DlnJ.d.ts → index-BZShISEr.d.ts} +45 -44
- package/dist/index.cjs +37 -31
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.mjs +37 -31
- package/dist/plugins/codeSubstrate/triggerWorkflow/index.d.ts +3 -9
- package/dist/plugins/codeSubstrate/triggerWorkflow/index.d.ts.map +1 -1
- package/dist/plugins/codeSubstrate/triggerWorkflow/index.js +17 -29
- package/dist/plugins/codeSubstrate/triggerWorkflow/schemas.d.ts +3 -3
- package/dist/plugins/codeSubstrate/triggerWorkflow/schemas.d.ts.map +1 -1
- package/dist/plugins/codeSubstrate/triggerWorkflow/schemas.js +4 -9
- package/dist/plugins/eventEmission/builders.js +2 -1
- package/dist/plugins/eventEmission/utils.d.ts +0 -43
- package/dist/plugins/eventEmission/utils.d.ts.map +1 -1
- package/dist/plugins/eventEmission/utils.js +0 -76
- package/dist/utils/agent.d.ts +44 -0
- package/dist/utils/agent.d.ts.map +1 -0
- package/dist/utils/agent.js +76 -0
- package/package.json +1 -1
|
@@ -12,41 +12,29 @@ export const triggerWorkflowPlugin = definePlugin((sdk) => createPluginMethod(sd
|
|
|
12
12
|
outputSchema: TriggerWorkflowResponseSchema,
|
|
13
13
|
resolvers: { workflow: workflowIdResolver },
|
|
14
14
|
handler: async ({ sdk, options }) => {
|
|
15
|
-
// Two-step: get the workflow's trigger_url
|
|
16
|
-
//
|
|
17
|
-
// auth header — the URL itself embeds a secret token. Custom
|
|
18
|
-
// fetch (e.g. tests) flows through sdk.context.options.fetch.
|
|
15
|
+
// Two-step: get the workflow's trigger_url, then fire it. Both go
|
|
16
|
+
// through the authenticated api client.
|
|
19
17
|
const rawWorkflow = await sdk.context.api.get(`/durableworkflowzaps/api/v0/workflows/${encodeURIComponent(options.workflow)}`, {
|
|
20
18
|
authRequired: true,
|
|
21
19
|
resource: { type: "workflow", id: options.workflow },
|
|
22
20
|
});
|
|
23
21
|
const workflow = TriggerWorkflowLookupResponseSchema.parse(rawWorkflow);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
});
|
|
32
|
-
const text = await response.text().catch(() => "");
|
|
33
|
-
let body = text;
|
|
34
|
-
if (text) {
|
|
35
|
-
try {
|
|
36
|
-
body = JSON.parse(text);
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
body = text;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (!response.ok) {
|
|
43
|
-
throw new ZapierApiError(`Trigger failed: ${response.status} ${response.statusText}: ${text || "(empty body)"}`, { statusCode: response.status, response: body });
|
|
22
|
+
// trigger_url is an absolute URL. Take only the token (its last path
|
|
23
|
+
// segment) and rebuild the gateway path so the call routes through the
|
|
24
|
+
// authenticated proxy, the same as every other call here.
|
|
25
|
+
const segments = new URL(workflow.trigger_url).pathname.split("/");
|
|
26
|
+
const triggerToken = segments[segments.length - 1];
|
|
27
|
+
if (!triggerToken) {
|
|
28
|
+
throw new ZapierApiError(`Workflow ${options.workflow} returned a malformed trigger_url`, { statusCode: 0, response: workflow.trigger_url });
|
|
44
29
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
30
|
+
// Fire the trigger through the authenticated api client and return its
|
|
31
|
+
// response directly, the same as every other code-substrate method.
|
|
32
|
+
// api.post throws the SDK's typed errors on non-2xx.
|
|
33
|
+
const raw = await sdk.context.api.post(`/durableworkflowzaps/api/v0/workflows/trigger/${encodeURIComponent(triggerToken)}`, options.input, {
|
|
34
|
+
authRequired: true,
|
|
35
|
+
resource: { type: "workflow", id: options.workflow },
|
|
36
|
+
});
|
|
37
|
+
const data = TriggerWorkflowResponseSchema.parse(raw);
|
|
50
38
|
return { data };
|
|
51
39
|
},
|
|
52
40
|
}));
|
|
@@ -8,9 +8,9 @@ export declare const TriggerWorkflowOptionsSchema: z.ZodObject<{
|
|
|
8
8
|
}, z.core.$strip>;
|
|
9
9
|
export type TriggerWorkflowOptions = z.infer<typeof TriggerWorkflowOptionsSchema>;
|
|
10
10
|
export declare const TriggerWorkflowResponseSchema: z.ZodObject<{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
id: z.ZodString;
|
|
12
|
+
workflow_id: z.ZodString;
|
|
13
|
+
created_at: z.ZodString;
|
|
14
14
|
}, z.core.$strip>;
|
|
15
15
|
export type TriggerWorkflowResponse = z.infer<typeof TriggerWorkflowResponseSchema>;
|
|
16
16
|
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../../src/plugins/codeSubstrate/triggerWorkflow/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,eAAO,MAAM,mCAAmC;;iBAIhC,CAAC;AAEjB,eAAO,MAAM,4BAA4B;;;iBAYtC,CAAC;AAEJ,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAC1C,OAAO,4BAA4B,CACpC,CAAC;AAEF,eAAO,MAAM,6BAA6B;;;;
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../../src/plugins/codeSubstrate/triggerWorkflow/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,eAAO,MAAM,mCAAmC;;iBAIhC,CAAC;AAEjB,eAAO,MAAM,4BAA4B;;;iBAYtC,CAAC;AAEJ,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAC1C,OAAO,4BAA4B,CACpC,CAAC;AAEF,eAAO,MAAM,6BAA6B;;;;iBAIxC,CAAC;AAEH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAC3C,OAAO,6BAA6B,CACrC,CAAC"}
|
|
@@ -18,14 +18,9 @@ export const TriggerWorkflowOptionsSchema = z
|
|
|
18
18
|
.optional()
|
|
19
19
|
.describe("JSON payload delivered as the trigger body. Sent as `application/json`; omit to fire with an empty body."),
|
|
20
20
|
})
|
|
21
|
-
.describe("Look up a workflow's trigger URL and fire it manually
|
|
21
|
+
.describe("Look up a workflow's trigger URL and fire it manually, as the authenticated account.");
|
|
22
22
|
export const TriggerWorkflowResponseSchema = z.object({
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
.int()
|
|
27
|
-
.describe("HTTP status returned by the trigger endpoint"),
|
|
28
|
-
body: z
|
|
29
|
-
.unknown()
|
|
30
|
-
.describe("Response body from the trigger endpoint. Parsed as JSON when the response body parses, otherwise returned as the raw response text."),
|
|
23
|
+
id: z.string().describe("Trigger ID (UUID)"),
|
|
24
|
+
workflow_id: z.string().describe("The workflow that was triggered (UUID)"),
|
|
25
|
+
created_at: z.string().describe("When the trigger was received (ISO-8601)"),
|
|
31
26
|
});
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* Provides builder functions that auto-populate common fields and ensure
|
|
5
5
|
* schema compliance for all event types.
|
|
6
6
|
*/
|
|
7
|
-
import { generateEventId, getCurrentTimestamp, getReleaseId, getOsInfo, getPlatformVersions, getMemoryUsage, getCpuTime, isCi, getCiPlatform, getTtyContext,
|
|
7
|
+
import { generateEventId, getCurrentTimestamp, getReleaseId, getOsInfo, getPlatformVersions, getMemoryUsage, getCpuTime, isCi, getCiPlatform, getTtyContext, } from "./utils";
|
|
8
8
|
import { SDK_VERSION } from "../../sdk-version";
|
|
9
|
+
import { getAgent } from "../../utils/agent";
|
|
9
10
|
// Create base event with auto-populated common fields
|
|
10
11
|
// Kept for backward compatibility but can be replaced with direct construction
|
|
11
12
|
export function createBaseEvent(context = {}) {
|
|
@@ -53,47 +53,4 @@ export declare function getTtyContext(): {
|
|
|
53
53
|
stdin_is_tty: boolean | null;
|
|
54
54
|
stdout_is_tty: boolean | null;
|
|
55
55
|
};
|
|
56
|
-
/**
|
|
57
|
-
* Detects which AI coding agent is executing the current process by inspecting
|
|
58
|
-
* well-known environment variables set by each agent's runtime.
|
|
59
|
-
*
|
|
60
|
-
* Claude Code
|
|
61
|
-
* CLAUDECODE — set to "1" in all subprocesses spawned by Claude Code
|
|
62
|
-
* https://code.claude.com/docs/en/env-vars
|
|
63
|
-
*
|
|
64
|
-
* GitHub Copilot
|
|
65
|
-
* COPILOT_AGENT — set to "1" in VS Code agent terminal sessions
|
|
66
|
-
* https://github.com/microsoft/vscode/pull/316267
|
|
67
|
-
*
|
|
68
|
-
* Cursor
|
|
69
|
-
* CURSOR_AGENT — set to "1" by Cursor when executing terminal commands
|
|
70
|
-
* https://cursor.com/docs/agent/tools/terminal
|
|
71
|
-
*
|
|
72
|
-
* Codex CLI
|
|
73
|
-
* CODEX_SANDBOX — set to "seatbelt" (macOS) or a non-empty string (Linux/Windows)
|
|
74
|
-
* https://github.com/openai/codex/blob/main/codex-rs/core/src/spawn.rs
|
|
75
|
-
*
|
|
76
|
-
* Gemini CLI
|
|
77
|
-
* GEMINI_CLI — set to "1" in subprocesses spawned by Gemini CLI's shell tool
|
|
78
|
-
* https://github.com/google-gemini/gemini-cli/blob/main/packages/core/src/services/shellExecutionService.ts
|
|
79
|
-
*
|
|
80
|
-
* Augment
|
|
81
|
-
* AUGMENT_AGENT — set to "1" when Auggie executes shell commands via its launch-process tool
|
|
82
|
-
* https://docs.augmentcode.com/cli/reference
|
|
83
|
-
*
|
|
84
|
-
* Cline
|
|
85
|
-
* CLINE_ACTIVE — set to "true" when Cline is executing terminal commands
|
|
86
|
-
* https://github.com/cline/cline/pull/5367
|
|
87
|
-
*
|
|
88
|
-
* OpenCode
|
|
89
|
-
* OPENCODE_CLIENT — client identifier set by OpenCode (defaults to "cli")
|
|
90
|
-
* https://anomalyco-opencode.mintlify.app/cli/overview#environment-variables
|
|
91
|
-
*
|
|
92
|
-
* Returns null if no known agent is detected or process is unavailable.
|
|
93
|
-
*
|
|
94
|
-
* Never throws: try/catch guards against exotic environments (e.g. a Proxy on
|
|
95
|
-
* globalThis.process) where property access could unexpectedly fail. Event
|
|
96
|
-
* emission must never cascade into a thrown exception.
|
|
97
|
-
*/
|
|
98
|
-
export declare function getAgent(): string | null;
|
|
99
56
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/plugins/eventEmission/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAiBH;;GAEG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI;IAC3B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAaA;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAQnE;AAED;;GAEG;AACH,wBAAgB,IAAI,IAAI,OAAO,CAa9B;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,MAAM,GAAG,IAAI,CAgB7C;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,MAAM,GAAG,IAAI,CAM9C;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,MAAM,GAAG,IAAI,CAM1C;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,IAAI;IAC/B,YAAY,EAAE,OAAO,GAAG,IAAI,CAAC;IAC7B,aAAa,EAAE,OAAO,GAAG,IAAI,CAAC;CAC/B,CAWA
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/plugins/eventEmission/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAiBH;;GAEG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI;IAC3B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAaA;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAQnE;AAED;;GAEG;AACH,wBAAgB,IAAI,IAAI,OAAO,CAa9B;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,MAAM,GAAG,IAAI,CAgB7C;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,MAAM,GAAG,IAAI,CAM9C;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,MAAM,GAAG,IAAI,CAM1C;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,IAAI;IAC/B,YAAY,EAAE,OAAO,GAAG,IAAI,CAAC;IAC7B,aAAa,EAAE,OAAO,GAAG,IAAI,CAAC;CAC/B,CAWA"}
|
|
@@ -140,79 +140,3 @@ export function getTtyContext() {
|
|
|
140
140
|
return { stdin_is_tty: null, stdout_is_tty: null };
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
|
-
// Matches "1" or "true" (case-insensitive).
|
|
144
|
-
const isTruthy = (value) => {
|
|
145
|
-
const lower = value.toLowerCase();
|
|
146
|
-
return lower === "1" || lower === "true";
|
|
147
|
-
};
|
|
148
|
-
// Any non-empty string — for vars whose value is meaningful rather than boolean.
|
|
149
|
-
const isNonEmpty = (value) => value !== "";
|
|
150
|
-
const agentDetectors = [
|
|
151
|
-
{ name: "claude-code", key: "CLAUDECODE", predicate: isTruthy },
|
|
152
|
-
{ name: "github-copilot", key: "COPILOT_AGENT", predicate: isTruthy },
|
|
153
|
-
{ name: "cursor", key: "CURSOR_AGENT", predicate: isTruthy },
|
|
154
|
-
{ name: "codex", key: "CODEX_SANDBOX", predicate: isNonEmpty },
|
|
155
|
-
{ name: "gemini-cli", key: "GEMINI_CLI", predicate: isTruthy },
|
|
156
|
-
{ name: "augment", key: "AUGMENT_AGENT", predicate: isTruthy },
|
|
157
|
-
{ name: "cline", key: "CLINE_ACTIVE", predicate: isTruthy },
|
|
158
|
-
{ name: "opencode", key: "OPENCODE_CLIENT", predicate: isNonEmpty },
|
|
159
|
-
];
|
|
160
|
-
/**
|
|
161
|
-
* Detects which AI coding agent is executing the current process by inspecting
|
|
162
|
-
* well-known environment variables set by each agent's runtime.
|
|
163
|
-
*
|
|
164
|
-
* Claude Code
|
|
165
|
-
* CLAUDECODE — set to "1" in all subprocesses spawned by Claude Code
|
|
166
|
-
* https://code.claude.com/docs/en/env-vars
|
|
167
|
-
*
|
|
168
|
-
* GitHub Copilot
|
|
169
|
-
* COPILOT_AGENT — set to "1" in VS Code agent terminal sessions
|
|
170
|
-
* https://github.com/microsoft/vscode/pull/316267
|
|
171
|
-
*
|
|
172
|
-
* Cursor
|
|
173
|
-
* CURSOR_AGENT — set to "1" by Cursor when executing terminal commands
|
|
174
|
-
* https://cursor.com/docs/agent/tools/terminal
|
|
175
|
-
*
|
|
176
|
-
* Codex CLI
|
|
177
|
-
* CODEX_SANDBOX — set to "seatbelt" (macOS) or a non-empty string (Linux/Windows)
|
|
178
|
-
* https://github.com/openai/codex/blob/main/codex-rs/core/src/spawn.rs
|
|
179
|
-
*
|
|
180
|
-
* Gemini CLI
|
|
181
|
-
* GEMINI_CLI — set to "1" in subprocesses spawned by Gemini CLI's shell tool
|
|
182
|
-
* https://github.com/google-gemini/gemini-cli/blob/main/packages/core/src/services/shellExecutionService.ts
|
|
183
|
-
*
|
|
184
|
-
* Augment
|
|
185
|
-
* AUGMENT_AGENT — set to "1" when Auggie executes shell commands via its launch-process tool
|
|
186
|
-
* https://docs.augmentcode.com/cli/reference
|
|
187
|
-
*
|
|
188
|
-
* Cline
|
|
189
|
-
* CLINE_ACTIVE — set to "true" when Cline is executing terminal commands
|
|
190
|
-
* https://github.com/cline/cline/pull/5367
|
|
191
|
-
*
|
|
192
|
-
* OpenCode
|
|
193
|
-
* OPENCODE_CLIENT — client identifier set by OpenCode (defaults to "cli")
|
|
194
|
-
* https://anomalyco-opencode.mintlify.app/cli/overview#environment-variables
|
|
195
|
-
*
|
|
196
|
-
* Returns null if no known agent is detected or process is unavailable.
|
|
197
|
-
*
|
|
198
|
-
* Never throws: try/catch guards against exotic environments (e.g. a Proxy on
|
|
199
|
-
* globalThis.process) where property access could unexpectedly fail. Event
|
|
200
|
-
* emission must never cascade into a thrown exception.
|
|
201
|
-
*/
|
|
202
|
-
export function getAgent() {
|
|
203
|
-
try {
|
|
204
|
-
const env = globalThis.process?.env;
|
|
205
|
-
if (!env)
|
|
206
|
-
return null;
|
|
207
|
-
for (const detector of agentDetectors) {
|
|
208
|
-
const value = env[detector.key];
|
|
209
|
-
if (value !== undefined && detector.predicate(value)) {
|
|
210
|
-
return detector.name;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
return null;
|
|
214
|
-
}
|
|
215
|
-
catch {
|
|
216
|
-
return null;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects which AI coding agent is executing the current process by inspecting
|
|
3
|
+
* well-known environment variables set by each agent's runtime.
|
|
4
|
+
*
|
|
5
|
+
* Claude Code
|
|
6
|
+
* CLAUDECODE — set to "1" in all subprocesses spawned by Claude Code
|
|
7
|
+
* https://code.claude.com/docs/en/env-vars
|
|
8
|
+
*
|
|
9
|
+
* GitHub Copilot
|
|
10
|
+
* COPILOT_AGENT — set to "1" in VS Code agent terminal sessions
|
|
11
|
+
* https://github.com/microsoft/vscode/pull/316267
|
|
12
|
+
*
|
|
13
|
+
* Cursor
|
|
14
|
+
* CURSOR_AGENT — set to "1" by Cursor when executing terminal commands
|
|
15
|
+
* https://cursor.com/docs/agent/tools/terminal
|
|
16
|
+
*
|
|
17
|
+
* Codex CLI
|
|
18
|
+
* CODEX_SANDBOX — set to "seatbelt" (macOS) or a non-empty string (Linux/Windows)
|
|
19
|
+
* https://github.com/openai/codex/blob/main/codex-rs/core/src/spawn.rs
|
|
20
|
+
*
|
|
21
|
+
* Gemini CLI
|
|
22
|
+
* GEMINI_CLI — set to "1" in subprocesses spawned by Gemini CLI's shell tool
|
|
23
|
+
* https://github.com/google-gemini/gemini-cli/blob/main/packages/core/src/services/shellExecutionService.ts
|
|
24
|
+
*
|
|
25
|
+
* Augment
|
|
26
|
+
* AUGMENT_AGENT — set to "1" when Auggie executes shell commands via its launch-process tool
|
|
27
|
+
* https://docs.augmentcode.com/cli/reference
|
|
28
|
+
*
|
|
29
|
+
* Cline
|
|
30
|
+
* CLINE_ACTIVE — set to "true" when Cline is executing terminal commands
|
|
31
|
+
* https://github.com/cline/cline/pull/5367
|
|
32
|
+
*
|
|
33
|
+
* OpenCode
|
|
34
|
+
* OPENCODE_CLIENT — client identifier set by OpenCode (defaults to "cli")
|
|
35
|
+
* https://anomalyco-opencode.mintlify.app/cli/overview#environment-variables
|
|
36
|
+
*
|
|
37
|
+
* Returns null if no known agent is detected or process is unavailable.
|
|
38
|
+
*
|
|
39
|
+
* Never throws: try/catch guards against exotic environments (e.g. a Proxy on
|
|
40
|
+
* globalThis.process) where property access could unexpectedly fail. Event
|
|
41
|
+
* emission must never cascade into a thrown exception.
|
|
42
|
+
*/
|
|
43
|
+
export declare function getAgent(): string | null;
|
|
44
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/utils/agent.ts"],"names":[],"mappings":"AA0BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,QAAQ,IAAI,MAAM,GAAG,IAAI,CAgBxC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Matches "1" or "true" (case-insensitive).
|
|
2
|
+
const isTruthy = (value) => {
|
|
3
|
+
const lower = value.toLowerCase();
|
|
4
|
+
return lower === "1" || lower === "true";
|
|
5
|
+
};
|
|
6
|
+
// Any non-empty string — for vars whose value is meaningful rather than boolean.
|
|
7
|
+
const isNonEmpty = (value) => value !== "";
|
|
8
|
+
const agentDetectors = [
|
|
9
|
+
{ name: "claude-code", key: "CLAUDECODE", predicate: isTruthy },
|
|
10
|
+
{ name: "github-copilot", key: "COPILOT_AGENT", predicate: isTruthy },
|
|
11
|
+
{ name: "cursor", key: "CURSOR_AGENT", predicate: isTruthy },
|
|
12
|
+
{ name: "codex", key: "CODEX_SANDBOX", predicate: isNonEmpty },
|
|
13
|
+
{ name: "gemini-cli", key: "GEMINI_CLI", predicate: isTruthy },
|
|
14
|
+
{ name: "augment", key: "AUGMENT_AGENT", predicate: isTruthy },
|
|
15
|
+
{ name: "cline", key: "CLINE_ACTIVE", predicate: isTruthy },
|
|
16
|
+
{ name: "opencode", key: "OPENCODE_CLIENT", predicate: isNonEmpty },
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* Detects which AI coding agent is executing the current process by inspecting
|
|
20
|
+
* well-known environment variables set by each agent's runtime.
|
|
21
|
+
*
|
|
22
|
+
* Claude Code
|
|
23
|
+
* CLAUDECODE — set to "1" in all subprocesses spawned by Claude Code
|
|
24
|
+
* https://code.claude.com/docs/en/env-vars
|
|
25
|
+
*
|
|
26
|
+
* GitHub Copilot
|
|
27
|
+
* COPILOT_AGENT — set to "1" in VS Code agent terminal sessions
|
|
28
|
+
* https://github.com/microsoft/vscode/pull/316267
|
|
29
|
+
*
|
|
30
|
+
* Cursor
|
|
31
|
+
* CURSOR_AGENT — set to "1" by Cursor when executing terminal commands
|
|
32
|
+
* https://cursor.com/docs/agent/tools/terminal
|
|
33
|
+
*
|
|
34
|
+
* Codex CLI
|
|
35
|
+
* CODEX_SANDBOX — set to "seatbelt" (macOS) or a non-empty string (Linux/Windows)
|
|
36
|
+
* https://github.com/openai/codex/blob/main/codex-rs/core/src/spawn.rs
|
|
37
|
+
*
|
|
38
|
+
* Gemini CLI
|
|
39
|
+
* GEMINI_CLI — set to "1" in subprocesses spawned by Gemini CLI's shell tool
|
|
40
|
+
* https://github.com/google-gemini/gemini-cli/blob/main/packages/core/src/services/shellExecutionService.ts
|
|
41
|
+
*
|
|
42
|
+
* Augment
|
|
43
|
+
* AUGMENT_AGENT — set to "1" when Auggie executes shell commands via its launch-process tool
|
|
44
|
+
* https://docs.augmentcode.com/cli/reference
|
|
45
|
+
*
|
|
46
|
+
* Cline
|
|
47
|
+
* CLINE_ACTIVE — set to "true" when Cline is executing terminal commands
|
|
48
|
+
* https://github.com/cline/cline/pull/5367
|
|
49
|
+
*
|
|
50
|
+
* OpenCode
|
|
51
|
+
* OPENCODE_CLIENT — client identifier set by OpenCode (defaults to "cli")
|
|
52
|
+
* https://anomalyco-opencode.mintlify.app/cli/overview#environment-variables
|
|
53
|
+
*
|
|
54
|
+
* Returns null if no known agent is detected or process is unavailable.
|
|
55
|
+
*
|
|
56
|
+
* Never throws: try/catch guards against exotic environments (e.g. a Proxy on
|
|
57
|
+
* globalThis.process) where property access could unexpectedly fail. Event
|
|
58
|
+
* emission must never cascade into a thrown exception.
|
|
59
|
+
*/
|
|
60
|
+
export function getAgent() {
|
|
61
|
+
try {
|
|
62
|
+
const env = globalThis.process?.env;
|
|
63
|
+
if (!env)
|
|
64
|
+
return null;
|
|
65
|
+
for (const detector of agentDetectors) {
|
|
66
|
+
const value = env[detector.key];
|
|
67
|
+
if (value !== undefined && detector.predicate(value)) {
|
|
68
|
+
return detector.name;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|