terse-sdk 0.9.20 → 0.9.21
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/dist/durableExecution.d.ts +0 -15
- package/dist/durableExecution.d.ts.map +1 -1
- package/dist/durableExecution.js +49 -31
- package/dist/durableExecution.js.map +1 -1
- package/dist/execution.d.ts +0 -5
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +22 -15
- package/dist/execution.js.map +1 -1
- package/dist/hmac.d.ts +0 -7
- package/dist/hmac.d.ts.map +1 -1
- package/dist/hmac.js +66 -57
- package/dist/hmac.js.map +1 -1
- package/dist/index.d.ts +0 -197
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +873 -642
- package/dist/index.js.map +1 -1
- package/dist/inputRequest.d.ts +0 -55
- package/dist/inputRequest.d.ts.map +1 -1
- package/dist/inputRequest.js +239 -160
- package/dist/inputRequest.js.map +1 -1
- package/dist/poll.d.ts +0 -8
- package/dist/poll.d.ts.map +1 -1
- package/dist/poll.js +33 -24
- package/dist/poll.js.map +1 -1
- package/dist/types.d.ts +0 -51
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +88 -12
- package/dist/types.js.map +1 -1
- package/package.json +4 -10
|
@@ -1,16 +1 @@
|
|
|
1
|
-
import type { StepStartedEvent } from "little-durable";
|
|
2
|
-
type CanonicalInput = StepStartedEvent["input"];
|
|
3
|
-
export type DurableStepParams<Input extends CanonicalInput, Output> = {
|
|
4
|
-
readonly name: string;
|
|
5
|
-
readonly input: Input;
|
|
6
|
-
readonly run: (input: Input) => Output | Promise<Output>;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Runtime target for the `step(call())` source transform. The envelope lets a
|
|
10
|
-
* normal JavaScript `void` result cross a journal that intentionally stores
|
|
11
|
-
* JSON only; every non-undefined result is still validated by the journal.
|
|
12
|
-
*/
|
|
13
|
-
export declare function __runDurableStep<Input extends CanonicalInput, Output>({ name, input, run }: DurableStepParams<Input, Output>): Promise<Output>;
|
|
14
|
-
export declare function runSdkStep<Input extends CanonicalInput, Output>(params: DurableStepParams<Input, Output>): Promise<Output>;
|
|
15
|
-
export {};
|
|
16
1
|
//# sourceMappingURL=durableExecution.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durableExecution.d.ts","sourceRoot":"","sources":["../src/durableExecution.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"durableExecution.d.ts","sourceRoot":"","sources":["../src/durableExecution.ts"],"names":[],"mappings":""}
|
package/dist/durableExecution.js
CHANGED
|
@@ -1,32 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// LEGACY-JOBS: Commented out while Terse is actors-only. Uncomment to restore; see the note in src/index.ts.
|
|
3
|
+
// import { step as durableStep, getExecutionPhase } from "little-durable"
|
|
4
|
+
// import type { StepCompletedEvent, StepStartedEvent } from "little-durable"
|
|
5
|
+
//
|
|
6
|
+
// import { DurableOnlyError } from "./execution.js"
|
|
7
|
+
//
|
|
8
|
+
// type CanonicalInput = StepStartedEvent["input"]
|
|
9
|
+
// type CanonicalOutput = StepCompletedEvent["output"]
|
|
10
|
+
//
|
|
11
|
+
// export type DurableStepParams<Input extends CanonicalInput, Output> = {
|
|
12
|
+
// readonly name: string
|
|
13
|
+
// readonly input: Input
|
|
14
|
+
// readonly run: (input: Input) => Output | Promise<Output>
|
|
15
|
+
// }
|
|
16
|
+
//
|
|
17
|
+
// type StoredStepOutput = { readonly type: "value"; readonly value: CanonicalOutput } | { readonly type: "undefined" }
|
|
18
|
+
//
|
|
19
|
+
// /**
|
|
20
|
+
// * Runtime target for the `step(call())` source transform. The envelope lets a
|
|
21
|
+
// * normal JavaScript `void` result cross a journal that intentionally stores
|
|
22
|
+
// * JSON only; every non-undefined result is still validated by the journal.
|
|
23
|
+
// */
|
|
24
|
+
// export async function __runDurableStep<Input extends CanonicalInput, Output>({ name, input, run }: DurableStepParams<Input, Output>): Promise<Output> {
|
|
25
|
+
// assertWorkflowPhase("step()")
|
|
26
|
+
//
|
|
27
|
+
// const stored = await durableStep<Input, StoredStepOutput>({
|
|
28
|
+
// name,
|
|
29
|
+
// input,
|
|
30
|
+
// run: async stepInput => {
|
|
31
|
+
// const value = await run(stepInput)
|
|
32
|
+
// if (value === undefined) return { type: "undefined" }
|
|
33
|
+
// return { type: "value", value: value as CanonicalOutput }
|
|
34
|
+
// }
|
|
35
|
+
// })
|
|
36
|
+
//
|
|
37
|
+
// return (stored.type === "undefined" ? undefined : stored.value) as Output
|
|
38
|
+
// }
|
|
39
|
+
//
|
|
40
|
+
// export async function runSdkStep<Input extends CanonicalInput, Output>(params: DurableStepParams<Input, Output>): Promise<Output> {
|
|
41
|
+
// if (getExecutionPhase() !== "workflow") return params.run(params.input)
|
|
42
|
+
// return __runDurableStep(params)
|
|
43
|
+
// }
|
|
44
|
+
//
|
|
45
|
+
// function assertWorkflowPhase(name: string): void {
|
|
46
|
+
// if (getExecutionPhase() !== "workflow") {
|
|
47
|
+
// throw new DurableOnlyError(`${name} is only available in durable jobs. Add \`durable: true\` to this job.`)
|
|
48
|
+
// }
|
|
49
|
+
// }
|
|
32
50
|
//# sourceMappingURL=durableExecution.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durableExecution.js","sourceRoot":"","sources":["../src/durableExecution.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"durableExecution.js","sourceRoot":"","sources":["../src/durableExecution.ts"],"names":[],"mappings":";AAAA,6GAA6G;AAC7G,0EAA0E;AAC1E,6EAA6E;AAC7E,EAAE;AACF,oDAAoD;AACpD,EAAE;AACF,kDAAkD;AAClD,sDAAsD;AACtD,EAAE;AACF,0EAA0E;AAC1E,4BAA4B;AAC5B,4BAA4B;AAC5B,+DAA+D;AAC/D,IAAI;AACJ,EAAE;AACF,uHAAuH;AACvH,EAAE;AACF,MAAM;AACN,iFAAiF;AACjF,+EAA+E;AAC/E,8EAA8E;AAC9E,MAAM;AACN,0JAA0J;AAC1J,oCAAoC;AACpC,EAAE;AACF,kEAAkE;AAClE,gBAAgB;AAChB,iBAAiB;AACjB,oCAAoC;AACpC,iDAAiD;AACjD,oEAAoE;AACpE,wEAAwE;AACxE,YAAY;AACZ,SAAS;AACT,EAAE;AACF,gFAAgF;AAChF,IAAI;AACJ,EAAE;AACF,sIAAsI;AACtI,8EAA8E;AAC9E,sCAAsC;AACtC,IAAI;AACJ,EAAE;AACF,qDAAqD;AACrD,gDAAgD;AAChD,sHAAsH;AACtH,QAAQ;AACR,IAAI"}
|
package/dist/execution.d.ts
CHANGED
package/dist/execution.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution.d.ts","sourceRoot":"","sources":["../src/execution.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"execution.d.ts","sourceRoot":"","sources":["../src/execution.ts"],"names":[],"mappings":""}
|
package/dist/execution.js
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// LEGACY-JOBS: Commented out while Terse is actors-only. Uncomment to restore; see the note in src/index.ts.
|
|
3
|
+
// import { getExecutionPhase } from "little-durable"
|
|
4
|
+
//
|
|
5
|
+
// declare const process: { env: Record<string, string | undefined> }
|
|
6
|
+
//
|
|
7
|
+
// export class DurableOnlyError extends Error {
|
|
8
|
+
// constructor(message: string) {
|
|
9
|
+
// super(message)
|
|
10
|
+
// this.name = "DurableOnlyError"
|
|
11
|
+
// }
|
|
12
|
+
// }
|
|
13
|
+
//
|
|
14
|
+
// export function isDurableExecution(): boolean {
|
|
15
|
+
// return getExecutionPhase() !== undefined
|
|
16
|
+
// }
|
|
17
|
+
//
|
|
18
|
+
// // Local test runs (`terse test`) execute in the developer's own process; only cloud
|
|
19
|
+
// // sandboxes set TERSE_RUN_ID. Primitives that suspend in production branch on this.
|
|
20
|
+
// export function isLocalTestRun(): boolean {
|
|
21
|
+
// return !process.env.TERSE_RUN_ID
|
|
22
|
+
// }
|
|
16
23
|
//# sourceMappingURL=execution.js.map
|
package/dist/execution.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution.js","sourceRoot":"","sources":["../src/execution.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"execution.js","sourceRoot":"","sources":["../src/execution.ts"],"names":[],"mappings":";AAAA,6GAA6G;AAC7G,qDAAqD;AACrD,EAAE;AACF,qEAAqE;AACrE,EAAE;AACF,gDAAgD;AAChD,qCAAqC;AACrC,yBAAyB;AACzB,yCAAyC;AACzC,QAAQ;AACR,IAAI;AACJ,EAAE;AACF,kDAAkD;AAClD,+CAA+C;AAC/C,IAAI;AACJ,EAAE;AACF,uFAAuF;AACvF,uFAAuF;AACvF,8CAA8C;AAC9C,uCAAuC;AACvC,IAAI"}
|
package/dist/hmac.d.ts
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
/** Compute the HMAC-SHA256 of a challenge token using the signing secret. */
|
|
2
|
-
export declare function computeChallengeSignature(signingSecret: string, challengeToken: string): Promise<string>;
|
|
3
|
-
/**
|
|
4
|
-
* Verify an incoming Terse request signature. Throws if invalid or missing.
|
|
5
|
-
* Useful both internally and as a public export for custom middleware.
|
|
6
|
-
*/
|
|
7
|
-
export declare function verifyIncomingRequest(signingSecret: string, headers: Record<string, string | string[] | undefined>, rawBody: string): Promise<void>;
|
|
8
1
|
//# sourceMappingURL=hmac.d.ts.map
|
package/dist/hmac.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmac.d.ts","sourceRoot":"","sources":["../src/hmac.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hmac.d.ts","sourceRoot":"","sources":["../src/hmac.ts"],"names":[],"mappings":""}
|
package/dist/hmac.js
CHANGED
|
@@ -1,58 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
async function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
//
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// LEGACY-JOBS: Commented out while Terse is actors-only. Uncomment to restore; see the note in src/index.ts.
|
|
3
|
+
// import { TERSE_SIGNATURE_HEADER, TERSE_SIGNATURE_VERSION, TERSE_TIMESTAMP_HEADER } from "terse-types"
|
|
4
|
+
//
|
|
5
|
+
// const MAX_TIMESTAMP_AGE_SECONDS = 300
|
|
6
|
+
//
|
|
7
|
+
// async function computeRequestSignature(signingSecret: string, timestamp: number, body: string): Promise<string> {
|
|
8
|
+
// const baseString = `${TERSE_SIGNATURE_VERSION}:${timestamp}:${body}`
|
|
9
|
+
// return `${TERSE_SIGNATURE_VERSION}=${await hmacSha256Hex(signingSecret, baseString)}`
|
|
10
|
+
// }
|
|
11
|
+
//
|
|
12
|
+
// async function verifyRequestSignature(signingSecret: string, signature: string, timestamp: number, body: string): Promise<boolean> {
|
|
13
|
+
// const expected = await computeRequestSignature(signingSecret, timestamp, body)
|
|
14
|
+
// return timingSafeEqualHex(signature, expected)
|
|
15
|
+
// }
|
|
16
|
+
//
|
|
17
|
+
// /** Compute the HMAC-SHA256 of a challenge token using the signing secret. */
|
|
18
|
+
// export async function computeChallengeSignature(signingSecret: string, challengeToken: string): Promise<string> {
|
|
19
|
+
// return hmacSha256Hex(signingSecret, challengeToken)
|
|
20
|
+
// }
|
|
21
|
+
//
|
|
22
|
+
// /**
|
|
23
|
+
// * Verify an incoming Terse request signature. Throws if invalid or missing.
|
|
24
|
+
// * Useful both internally and as a public export for custom middleware.
|
|
25
|
+
// */
|
|
26
|
+
// export async function verifyIncomingRequest(signingSecret: string, headers: Record<string, string | string[] | undefined>, rawBody: string): Promise<void> {
|
|
27
|
+
// const signature = headers[TERSE_SIGNATURE_HEADER]
|
|
28
|
+
// const timestampStr = headers[TERSE_TIMESTAMP_HEADER]
|
|
29
|
+
// if (typeof signature !== "string" || typeof timestampStr !== "string") {
|
|
30
|
+
// const missing = [typeof signature !== "string" ? TERSE_SIGNATURE_HEADER : null, typeof timestampStr !== "string" ? TERSE_TIMESTAMP_HEADER : null].filter(Boolean)
|
|
31
|
+
// throw new Error(
|
|
32
|
+
// `Missing required headers: ${missing.join(", ")}.\n` +
|
|
33
|
+
// `Make sure requests to this endpoint are coming from Terse (not a browser or other client) ` +
|
|
34
|
+
// `and that your reverse proxy is forwarding all headers.`
|
|
35
|
+
// )
|
|
36
|
+
// }
|
|
37
|
+
// const timestamp = Number(timestampStr)
|
|
38
|
+
// if (Number.isNaN(timestamp)) {
|
|
39
|
+
// throw new Error(`"${TERSE_TIMESTAMP_HEADER}" header is not a valid number (got "${timestampStr}").`)
|
|
40
|
+
// }
|
|
41
|
+
// const age = Math.abs(Math.floor(Date.now() / 1000) - timestamp)
|
|
42
|
+
// if (age > MAX_TIMESTAMP_AGE_SECONDS) {
|
|
43
|
+
// throw new Error(`Request timestamp is ${age}s old (max allowed: ${MAX_TIMESTAMP_AGE_SECONDS}s). ` + `Check that your server's clock is in sync.`)
|
|
44
|
+
// }
|
|
45
|
+
// if (!(await verifyRequestSignature(signingSecret, signature, timestamp, rawBody))) {
|
|
46
|
+
// throw new Error(`Request signature does not match. ` + `Verify that TERSE_SIGNING_SECRET matches the value shown in the Terse dashboard.`)
|
|
47
|
+
// }
|
|
48
|
+
// }
|
|
49
|
+
//
|
|
50
|
+
// // HMAC-SHA256 (hex) via Web Crypto (globalThis.crypto.subtle) instead of
|
|
51
|
+
// // node:crypto, so this module stays Node-free and is importable from a workflow
|
|
52
|
+
// // body. SubtleCrypto is async-only, hence the Promise.
|
|
53
|
+
// async function hmacSha256Hex(signingSecret: string, message: string): Promise<string> {
|
|
54
|
+
// const encoder = new TextEncoder()
|
|
55
|
+
// const key = await globalThis.crypto.subtle.importKey("raw", encoder.encode(signingSecret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"])
|
|
56
|
+
// const signature = await globalThis.crypto.subtle.sign("HMAC", key, encoder.encode(message))
|
|
57
|
+
// return Array.from(new Uint8Array(signature), byte => byte.toString(16).padStart(2, "0")).join("")
|
|
58
|
+
// }
|
|
59
|
+
//
|
|
60
|
+
// // Constant-time comparison of two hex signatures (replaces crypto.timingSafeEqual).
|
|
61
|
+
// function timingSafeEqualHex(a: string, b: string): boolean {
|
|
62
|
+
// if (a.length !== b.length) return false
|
|
63
|
+
// let mismatch = 0
|
|
64
|
+
// for (let i = 0; i < a.length; i++) mismatch |= a.charCodeAt(i) ^ b.charCodeAt(i)
|
|
65
|
+
// return mismatch === 0
|
|
66
|
+
// }
|
|
58
67
|
//# sourceMappingURL=hmac.js.map
|
package/dist/hmac.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmac.js","sourceRoot":"","sources":["../src/hmac.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"hmac.js","sourceRoot":"","sources":["../src/hmac.ts"],"names":[],"mappings":";AAAA,6GAA6G;AAC7G,wGAAwG;AACxG,EAAE;AACF,wCAAwC;AACxC,EAAE;AACF,oHAAoH;AACpH,2EAA2E;AAC3E,4FAA4F;AAC5F,IAAI;AACJ,EAAE;AACF,uIAAuI;AACvI,qFAAqF;AACrF,qDAAqD;AACrD,IAAI;AACJ,EAAE;AACF,gFAAgF;AAChF,oHAAoH;AACpH,0DAA0D;AAC1D,IAAI;AACJ,EAAE;AACF,MAAM;AACN,+EAA+E;AAC/E,0EAA0E;AAC1E,MAAM;AACN,+JAA+J;AAC/J,wDAAwD;AACxD,2DAA2D;AAC3D,+EAA+E;AAC/E,4KAA4K;AAC5K,2BAA2B;AAC3B,qEAAqE;AACrE,iHAAiH;AACjH,2EAA2E;AAC3E,YAAY;AACZ,QAAQ;AACR,6CAA6C;AAC7C,qCAAqC;AACrC,+GAA+G;AAC/G,QAAQ;AACR,sEAAsE;AACtE,6CAA6C;AAC7C,4JAA4J;AAC5J,QAAQ;AACR,2FAA2F;AAC3F,qJAAqJ;AACrJ,QAAQ;AACR,IAAI;AACJ,EAAE;AACF,4EAA4E;AAC5E,mFAAmF;AACnF,0DAA0D;AAC1D,0FAA0F;AAC1F,wCAAwC;AACxC,qJAAqJ;AACrJ,kGAAkG;AAClG,wGAAwG;AACxG,IAAI;AACJ,EAAE;AACF,uFAAuF;AACvF,+DAA+D;AAC/D,8CAA8C;AAC9C,uBAAuB;AACvB,uFAAuF;AACvF,4BAA4B;AAC5B,IAAI"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,205 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" preserve="true" />
|
|
2
|
-
import type { WorkflowDefinition } from "little-durable";
|
|
3
|
-
import type { RunHistoryAction, WebhookJobChallengeResponse, WebhookJobTriggerResponse } from "terse-types";
|
|
4
|
-
import { serializedEventSchema } from "terse-types";
|
|
5
|
-
import type { Trigger as _RawTrigger } from "terse-types";
|
|
6
|
-
import { z } from "zod";
|
|
7
|
-
import { type InferEvents, type InferToolApprovals, type SDKTrigger, type StateAccessor, type StateDefinition, type TriggerLike, type TypedSkill, type TypedTrigger } from "./types.js";
|
|
8
|
-
export declare const TERSE_JOB_WEBHOOK_TRIGGER_PATH: string;
|
|
9
2
|
export { Actor, ActorInvocationError, Persisted, Ephemeral, Emittable, Interleave, Compute } from "./actor.js";
|
|
10
3
|
export type { ActorBroadcastOptions, ActorClass, ActorConnection, ActorSocket, ActorSocketMessage, ActorSocketState, ComputeOptions, ComputeRegion } from "./actor.js";
|
|
11
4
|
export { ActorProxy } from "./actorProxy.js";
|
|
12
5
|
export type { ActorProxyOptions, ProxyActor, SocketAuthorization, SocketGrant } from "./actorProxy.js";
|
|
13
|
-
export { DurableOnlyError } from "./execution.js";
|
|
14
|
-
export { __runDurableStep } from "./durableExecution.js";
|
|
15
|
-
export { __inputRequestHook, slack, waitForInput } from "./inputRequest.js";
|
|
16
|
-
export type { InputDelivery, InputMedia, InputOption, InputRespondent, InputResponse, InputTarget, SlackInputTarget, WaitForInputParams } from "./inputRequest.js";
|
|
17
|
-
export { isAgentApprovalHandlingClaimed } from "./context.js";
|
|
18
|
-
export type { TerseJobContext } from "./context.js";
|
|
19
|
-
export { pollUntil } from "./poll.js";
|
|
20
|
-
export type { PollUntilOptions } from "./poll.js";
|
|
21
6
|
export { SessionStreamError, openListenStream, openSessionStream } from "./sessionStream.js";
|
|
22
7
|
export type { ListenStreamHandle, OpenListenStreamOptions, OpenSessionStreamOptions, SessionStartedEvent, SessionStreamEvent, SessionStreamHandle } from "./sessionStream.js";
|
|
23
|
-
export { createSDKTrigger, registerEventTransform } from "./types.js";
|
|
24
|
-
export type { InferEvent, InferEvents, InferStructuredOutput, InferToolApproval, InferToolApprovals, SDKTrigger, StateAccessor, StateDefinition, ToolboxEntry, TriggerLike, TypedSkill, TypedTrigger } from "./types.js";
|
|
25
|
-
export { ApolloOutputConfig, AttioEventType, AttioInputConfig, AttioOutputConfig, ConfigInstance, ConfigType, DatadogConfig, GitHubConfig, GitHubEventType, GmailConfig, GmailDraftOutputConfig, GmailEventType, GmailOutputConfig, GoogleSearchConsoleOutputConfig, HeyReachEventType, HeyReachInputConfig, HiggsfieldOutputConfig, ImageEditConfig, LaunchDarklyConfig, LinearEventType, LinearInputConfig, LinearOutputConfig, MemoryConfig, MetaAdsOutputConfig, NotionConfig, PosthogConfig, ResendOutputConfig, SlackConfig, SlackEventType, SlackOutputConfig, SnowflakeOutputConfig, TimeTriggerConfig, WebConfig, WebMonitorConfig, WebhookInputConfig, WorkOSEventType, WorkOSInputConfig, WorkOSOutputConfig, debugTrigger, formatTriggerForAgent } from "terse-types";
|
|
26
|
-
export type Trigger = SDKTrigger<_RawTrigger>;
|
|
27
|
-
export { FrequencyUnit, IntegrationType } from "terse-types";
|
|
28
|
-
export { TIMEZONES } from "terse-types";
|
|
29
|
-
export type { Timezone } from "terse-types";
|
|
30
|
-
export type { SdkAgentRunOptionsPayload, SdkAgentRunRequestBody, SdkAgentRunResponseBody, SdkAgentStreamEvent, ToolInputByName, ToolOutputByName } from "terse-types";
|
|
31
|
-
export type { SlackAttachments, SlackBlocks, SlackFiles } from "terse-types";
|
|
32
|
-
export { RunHistoryAction, RunHistoryDecision, RunHistoryRecord, RunHistoryStatus, RunHistoryTrigger } from "terse-types";
|
|
33
|
-
type Action = RunHistoryAction;
|
|
34
|
-
export type CreateJobParameters<TTriggers extends readonly TypedTrigger<TriggerLike>[] = TypedTrigger<TriggerLike>[], TStates extends readonly StateDefinition[] = readonly StateDefinition[]> = {
|
|
35
|
-
name: string;
|
|
36
|
-
triggers: [...TTriggers];
|
|
37
|
-
states?: [...TStates];
|
|
38
|
-
filter?: (event: InferEvents<TTriggers>, state: StateAccessor<TStates>) => boolean | Promise<boolean>;
|
|
39
|
-
onTrigger: (event: InferEvents<TTriggers>, state: StateAccessor<TStates>) => Promise<void>;
|
|
40
|
-
remoteServerUrl?: string;
|
|
41
|
-
durable?: boolean;
|
|
42
|
-
};
|
|
43
|
-
export declare function createJob<TTriggers extends readonly TypedTrigger<TriggerLike>[], const TStates extends readonly StateDefinition[] = readonly []>(params: CreateJobParameters<TTriggers, TStates>): CreateJobParameters<TTriggers, TStates>;
|
|
44
|
-
type TerseWorkflowDefinition = WorkflowDefinition<typeof serializedEventSchema>;
|
|
45
|
-
export declare function fetchRegisteredJobs(): Map<string, CreateJobParameters>;
|
|
46
|
-
export declare function __defineTerseWorkflow(job: CreateJobParameters): TerseWorkflowDefinition;
|
|
47
|
-
export declare function __registerDurableWorkflow(workflow: TerseWorkflowDefinition): void;
|
|
48
|
-
export declare function __fetchRegisteredDurableWorkflow(name: string): TerseWorkflowDefinition | undefined;
|
|
49
|
-
export declare function __resetRegisteredTerseInstances(): void;
|
|
50
|
-
export declare function __buildJobStateAccessor<TStates extends readonly StateDefinition[]>(states: TStates): StateAccessor<TStates>;
|
|
51
|
-
export declare class Terse {
|
|
52
|
-
constructor();
|
|
53
|
-
/**
|
|
54
|
-
* Handle an incoming trigger request from the Terse backend.
|
|
55
|
-
* Wire this into your own HTTP route (Express, Hono, Next.js, etc.).
|
|
56
|
-
*
|
|
57
|
-
* Two-phase protocol: (1) POST with `{ type: "challenge", challenge: "<token>" }` verifies the
|
|
58
|
-
* HMAC signature and echoes the challenge with a signed response. (2) POST with
|
|
59
|
-
* `{ jobName, runId, event }` opens an SDK session stream, **awaits** `onTrigger` (so this
|
|
60
|
-
* method does not return until your job handler finishes), then closes the session stream.
|
|
61
|
-
*
|
|
62
|
-
* Both phases require `TERSE_SIGNING_SECRET` to verify request signatures.
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```ts
|
|
66
|
-
* // Express — use TERSE_JOB_WEBHOOK_TRIGGER_PATH so the path matches the backend.
|
|
67
|
-
* app.post(TERSE_JOB_WEBHOOK_TRIGGER_PATH, async (req, res) => {
|
|
68
|
-
* const result = await terse.handleTrigger(req.body, req.headers)
|
|
69
|
-
* res.json(result)
|
|
70
|
-
* })
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
handleTrigger(body: unknown, headers: Record<string, string | string[] | undefined>): Promise<WebhookJobChallengeResponse | WebhookJobTriggerResponse>;
|
|
74
|
-
}
|
|
75
|
-
export type ApprovalRequestInfo = {
|
|
76
|
-
stepId: string;
|
|
77
|
-
toolName: string;
|
|
78
|
-
arguments: string;
|
|
79
|
-
};
|
|
80
|
-
export declare class TerseAgent<TSkills extends readonly TypedSkill<string>[] = readonly TypedSkill<string>[]> {
|
|
81
|
-
readonly prompt: string;
|
|
82
|
-
readonly skills: TSkills;
|
|
83
|
-
readonly toolApprovals: InferToolApprovals<TSkills>[];
|
|
84
|
-
/**
|
|
85
|
-
* Optional callback invoked when the agent requires tool approval.
|
|
86
|
-
* Return `true` to approve, `false` to reject.
|
|
87
|
-
* If not set, approval events are yielded as ToolApprovalRequestedResult
|
|
88
|
-
* but no decision is submitted (the stream will hang waiting).
|
|
89
|
-
*/
|
|
90
|
-
onApprovalRequired?: (info: ApprovalRequestInfo) => Promise<boolean>;
|
|
91
|
-
private constructor();
|
|
92
|
-
static create<TSkills extends readonly TypedSkill<string>[]>(params: {
|
|
93
|
-
prompt: string;
|
|
94
|
-
skills: [...TSkills];
|
|
95
|
-
toolApprovals?: InferToolApprovals<TSkills>[];
|
|
96
|
-
}): TerseAgent<TSkills>;
|
|
97
|
-
static create(params: {
|
|
98
|
-
prompt: string;
|
|
99
|
-
}): TerseAgent<readonly []>;
|
|
100
|
-
run(userMessage: string, outputSchema?: z.ZodType): AsyncGenerator<TerseAgentResult>;
|
|
101
|
-
submitApprovalDecision(params: {
|
|
102
|
-
runId: string;
|
|
103
|
-
stepId: string;
|
|
104
|
-
approved: boolean;
|
|
105
|
-
}): Promise<void>;
|
|
106
|
-
runAndWait<OutputSchema extends z.ZodType>(userMessage: string, outputSchema: OutputSchema): Promise<z.infer<OutputSchema>>;
|
|
107
|
-
runAndWait(userMessage: string): Promise<string>;
|
|
108
|
-
private buildRequestBody;
|
|
109
|
-
private static fetchFinalOutput;
|
|
110
|
-
static executeTool<TOutput = unknown>(toolName: string, params?: Record<string, unknown>): Promise<TOutput>;
|
|
111
|
-
private static buildHeaders;
|
|
112
|
-
private consumeSseStream;
|
|
113
|
-
}
|
|
114
|
-
type GenerateTextParams<TSkills extends readonly TypedSkill<string>[] = readonly TypedSkill<string>[]> = {
|
|
115
|
-
prompt: string;
|
|
116
|
-
skills?: TSkills;
|
|
117
|
-
toolApprovals?: InferToolApprovals<TSkills>[];
|
|
118
|
-
};
|
|
119
|
-
type GenerateTextStructuredOutput<OutputSchema extends z.ZodType> = GenerateTextParams & {
|
|
120
|
-
outputSchema: OutputSchema;
|
|
121
|
-
};
|
|
122
|
-
export declare function generateText<OutputSchema extends z.ZodType>(params: GenerateTextStructuredOutput<OutputSchema>): Promise<z.infer<OutputSchema>>;
|
|
123
|
-
export declare function generateText(params: GenerateTextParams): Promise<string>;
|
|
124
|
-
export declare function jobStep<I extends z.ZodType, O>(opts: {
|
|
125
|
-
input: z.infer<I>;
|
|
126
|
-
inputSchema: I;
|
|
127
|
-
outputSchema?: z.ZodType<O>;
|
|
128
|
-
run: (input: z.infer<I>) => Promise<O>;
|
|
129
|
-
}): Promise<O>;
|
|
130
|
-
export declare function jobStep<O>(opts: {
|
|
131
|
-
outputSchema?: z.ZodType<O>;
|
|
132
|
-
run: () => Promise<O>;
|
|
133
|
-
}): Promise<O>;
|
|
134
|
-
/**
|
|
135
|
-
* Runs the wrapped call as a journaled durable step: `step(client.method(args))`.
|
|
136
|
-
* Terse rewrites the call to an inline durable closure before loading the job,
|
|
137
|
-
* so `step()` must wrap the call directly, and its arguments and resolved value
|
|
138
|
-
* must be serializable. Only available in durable jobs.
|
|
139
|
-
*/
|
|
140
|
-
export declare function step<T>(promise: Promise<T>): Promise<T>;
|
|
141
|
-
/**
|
|
142
|
-
* Replay-safe logging for durable jobs: `await log("processed", count)`.
|
|
143
|
-
* In workflow code the call is a journaled step, so the line prints exactly
|
|
144
|
-
* once instead of once per replay like a bare `console.log` outside a step
|
|
145
|
-
* would. Arguments cross the step boundary, so they must be serializable.
|
|
146
|
-
* Inside step bodies and non-durable jobs it simply forwards to `console.log`.
|
|
147
|
-
*/
|
|
148
|
-
export declare function log(...args: unknown[]): Promise<void>;
|
|
149
|
-
export declare function sleep(duration: string | number | Date): Promise<void>;
|
|
150
|
-
export declare enum EventType {
|
|
151
|
-
TEXT = "text",
|
|
152
|
-
FINAL_OUTPUT = "final_output",
|
|
153
|
-
TOOL_CALL_PARAMS = "tool_call_params",
|
|
154
|
-
TOOL_CALL_STARTED = "tool_call_started",
|
|
155
|
-
TOOL_CALL_COMPLETED = "tool_call_completed",
|
|
156
|
-
TOOL_APPROVAL_REQUESTED = "tool_approval_requested",
|
|
157
|
-
ACTION = "action"
|
|
158
|
-
}
|
|
159
|
-
export interface TerseAgentResult {
|
|
160
|
-
type: EventType;
|
|
161
|
-
}
|
|
162
|
-
export declare class TextResult implements TerseAgentResult {
|
|
163
|
-
type: EventType.TEXT;
|
|
164
|
-
text: string;
|
|
165
|
-
constructor(text: string);
|
|
166
|
-
}
|
|
167
|
-
export declare class FinalOutputResult implements TerseAgentResult {
|
|
168
|
-
type: EventType.FINAL_OUTPUT;
|
|
169
|
-
finalOutput: string;
|
|
170
|
-
constructor(finalOutput: string);
|
|
171
|
-
}
|
|
172
|
-
export declare class ToolCallParamsResult implements TerseAgentResult {
|
|
173
|
-
type: EventType.TOOL_CALL_PARAMS;
|
|
174
|
-
toolCallParams: string;
|
|
175
|
-
constructor(toolCallParams: string);
|
|
176
|
-
}
|
|
177
|
-
export declare class ToolCallStartedResult implements TerseAgentResult {
|
|
178
|
-
type: EventType.TOOL_CALL_STARTED;
|
|
179
|
-
toolCallStarted: string;
|
|
180
|
-
constructor(toolCallStarted: string);
|
|
181
|
-
}
|
|
182
|
-
export declare class ToolCallCompletedResult implements TerseAgentResult {
|
|
183
|
-
type: EventType.TOOL_CALL_COMPLETED;
|
|
184
|
-
toolCallCompleted: string;
|
|
185
|
-
constructor(toolCallCompleted: string);
|
|
186
|
-
}
|
|
187
|
-
export declare class ToolApprovalRequestedResult implements TerseAgentResult {
|
|
188
|
-
type: EventType.TOOL_APPROVAL_REQUESTED;
|
|
189
|
-
toolApprovalRequested: {
|
|
190
|
-
stepId: string;
|
|
191
|
-
toolName: string;
|
|
192
|
-
arguments: string;
|
|
193
|
-
};
|
|
194
|
-
constructor(toolApprovalRequested: {
|
|
195
|
-
stepId: string;
|
|
196
|
-
toolName: string;
|
|
197
|
-
arguments: string;
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
export declare class ActionResult implements TerseAgentResult {
|
|
201
|
-
type: EventType.ACTION;
|
|
202
|
-
action: Action;
|
|
203
|
-
constructor(action: Action);
|
|
204
|
-
}
|
|
205
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAC9G,YAAY,EAAE,qBAAqB,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAEtK,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAEtG,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAC5F,YAAY,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA"}
|