@letsping/sdk 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,80 +0,0 @@
1
- import { StateGraph, START } from "@langchain/langgraph";
2
- import { LetsPing } from "@letsping/sdk";
3
- import { LetsPingCheckpointer } from "@letsping/sdk/integrations/langgraph";
4
-
5
- type DemoState = {
6
- thread_id: string;
7
- step: "START" | "NEEDS_APPROVAL" | "DONE";
8
- amount: number;
9
- };
10
-
11
- const lp = new LetsPing(process.env.LETSPING_API_KEY!);
12
- const checkpointer = new LetsPingCheckpointer(lp);
13
-
14
- // Chain the methods directly off the instantiation
15
- const builder = new StateGraph<DemoState>({
16
- channels: {
17
- thread_id: null,
18
- step: null,
19
- amount: null,
20
- },
21
- })
22
- .addNode("charge_step", async (state: DemoState): Promise<DemoState> => {
23
- // On the first pass, ask LetsPing for approval and park state.
24
- if (state.step === "START") {
25
- const decision = await lp.defer({
26
- service: "demo-agent",
27
- action: "payments:charge",
28
- priority: "high",
29
- payload: { amount: state.amount },
30
- // Persist enough context so the webhook can resume the same thread.
31
- state_snapshot: {
32
- thread_id: state.thread_id,
33
- input: state,
34
- },
35
- });
36
-
37
- console.log("Queued LetsPing request id:", decision.id);
38
-
39
- return {
40
- ...state,
41
- step: "NEEDS_APPROVAL",
42
- };
43
- }
44
-
45
- // After approval + webhook resume, the graph will be invoked again
46
- if (state.step === "NEEDS_APPROVAL") {
47
- console.log("Approval received. Performing final charge for:", state.amount);
48
- return {
49
- ...state,
50
- step: "DONE",
51
- };
52
- }
53
-
54
- return state;
55
- })
56
- // Notice we are chaining addEdge directly after addNode
57
- .addEdge(START, "charge_step");
58
-
59
- export const demoGraph = builder.compile({ checkpointer });
60
-
61
- if (require.main === module) {
62
- (async () => {
63
- const threadId = `demo-${Date.now()}`;
64
- console.log("Starting demo thread:", threadId);
65
-
66
- await demoGraph.invoke(
67
- {
68
- thread_id: threadId,
69
- step: "START",
70
- amount: 500,
71
- },
72
- { configurable: { thread_id: threadId } },
73
- );
74
-
75
- console.log("Demo graph invoked. Wait for LetsPing approval, then webhook will resume.");
76
- })().catch((e) => {
77
- console.error(e);
78
- process.exit(1);
79
- });
80
- }