@thecorporation/corp-tools 0.1.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/dist/index.js ADDED
@@ -0,0 +1,1626 @@
1
+ // src/api-client.ts
2
+ var SessionExpiredError = class extends Error {
3
+ constructor() {
4
+ super("Your API key is no longer valid. Run 'corp setup' to re-authenticate.");
5
+ this.name = "SessionExpiredError";
6
+ }
7
+ };
8
+ async function provisionWorkspace(apiUrl, name) {
9
+ const url = `${apiUrl.replace(/\/+$/, "")}/v1/workspaces/provision`;
10
+ const body = {};
11
+ if (name) body.name = name;
12
+ const resp = await fetch(url, {
13
+ method: "POST",
14
+ headers: { "Content-Type": "application/json" },
15
+ body: JSON.stringify(body)
16
+ });
17
+ if (!resp.ok) throw new Error(`Provision failed: ${resp.status} ${resp.statusText}`);
18
+ return resp.json();
19
+ }
20
+ var CorpAPIClient = class {
21
+ apiUrl;
22
+ apiKey;
23
+ workspaceId;
24
+ constructor(apiUrl, apiKey, workspaceId) {
25
+ this.apiUrl = apiUrl.replace(/\/+$/, "");
26
+ this.apiKey = apiKey;
27
+ this.workspaceId = workspaceId;
28
+ }
29
+ headers() {
30
+ return {
31
+ Authorization: `Bearer ${this.apiKey}`,
32
+ "Content-Type": "application/json",
33
+ Accept: "application/json"
34
+ };
35
+ }
36
+ async request(method, path, body, params) {
37
+ let url = `${this.apiUrl}${path}`;
38
+ if (params) {
39
+ const qs = new URLSearchParams(params).toString();
40
+ if (qs) url += `?${qs}`;
41
+ }
42
+ const opts = { method, headers: this.headers() };
43
+ if (body !== void 0) opts.body = JSON.stringify(body);
44
+ return fetch(url, opts);
45
+ }
46
+ async get(path, params) {
47
+ const resp = await this.request("GET", path, void 0, params);
48
+ if (resp.status === 401) throw new SessionExpiredError();
49
+ if (!resp.ok) throw new Error(`${resp.status} ${resp.statusText}`);
50
+ return resp.json();
51
+ }
52
+ async post(path, body) {
53
+ const resp = await this.request("POST", path, body);
54
+ if (resp.status === 401) throw new SessionExpiredError();
55
+ if (!resp.ok) throw new Error(`${resp.status} ${resp.statusText}`);
56
+ return resp.json();
57
+ }
58
+ async patch(path, body) {
59
+ const resp = await this.request("PATCH", path, body);
60
+ if (resp.status === 401) throw new SessionExpiredError();
61
+ if (!resp.ok) throw new Error(`${resp.status} ${resp.statusText}`);
62
+ return resp.json();
63
+ }
64
+ async del(path) {
65
+ const resp = await this.request("DELETE", path);
66
+ if (resp.status === 401) throw new SessionExpiredError();
67
+ if (!resp.ok) throw new Error(`${resp.status} ${resp.statusText}`);
68
+ }
69
+ // --- Workspace ---
70
+ getStatus() {
71
+ return this.get(`/v1/workspaces/${this.workspaceId}/status`);
72
+ }
73
+ // --- Obligations ---
74
+ getObligations(tier) {
75
+ const params = {};
76
+ if (tier) params.tier = tier;
77
+ return this.get("/v1/obligations/summary", params);
78
+ }
79
+ // --- Digests ---
80
+ listDigests() {
81
+ return this.get("/v1/digests");
82
+ }
83
+ triggerDigest() {
84
+ return this.post("/v1/digests/trigger");
85
+ }
86
+ getDigest(key) {
87
+ return this.get(`/v1/digests/${key}`);
88
+ }
89
+ // --- Entities ---
90
+ listEntities() {
91
+ return this.get(`/v1/workspaces/${this.workspaceId}/entities`);
92
+ }
93
+ // --- Contacts ---
94
+ listContacts() {
95
+ return this.get(`/v1/workspaces/${this.workspaceId}/contacts`);
96
+ }
97
+ getContact(id) {
98
+ return this.get(`/v1/contacts/${id}`);
99
+ }
100
+ getContactProfile(id) {
101
+ return this.get(`/v1/contacts/${id}/profile`);
102
+ }
103
+ createContact(data) {
104
+ return this.post(`/v1/workspaces/${this.workspaceId}/contacts`, data);
105
+ }
106
+ updateContact(id, data) {
107
+ return this.patch(`/v1/contacts/${id}`, data);
108
+ }
109
+ getNotificationPrefs(contactId) {
110
+ return this.get(`/v1/contacts/${contactId}/notification-prefs`);
111
+ }
112
+ updateNotificationPrefs(contactId, prefs) {
113
+ return this.patch(`/v1/contacts/${contactId}/notification-prefs`, prefs);
114
+ }
115
+ // --- Cap Table ---
116
+ getCapTable(entityId) {
117
+ return this.get(`/v1/entities/${entityId}/cap-table`);
118
+ }
119
+ getSafeNotes(entityId) {
120
+ return this.get(`/v1/entities/${entityId}/safe-notes`);
121
+ }
122
+ getShareTransfers(entityId) {
123
+ return this.get(`/v1/entities/${entityId}/share-transfers`);
124
+ }
125
+ getValuations(entityId) {
126
+ return this.get(`/v1/entities/${entityId}/valuations`);
127
+ }
128
+ getCurrent409a(entityId) {
129
+ return this.get(`/v1/entities/${entityId}/current-409a`);
130
+ }
131
+ issueEquity(data) {
132
+ return this.post("/v1/equity/grants", data);
133
+ }
134
+ issueSafe(data) {
135
+ return this.post("/v1/safe-notes", data);
136
+ }
137
+ transferShares(data) {
138
+ return this.post("/v1/share-transfers", data);
139
+ }
140
+ calculateDistribution(data) {
141
+ return this.post("/v1/distributions", data);
142
+ }
143
+ // --- Governance ---
144
+ listGovernanceBodies(entityId) {
145
+ return this.get(`/v1/entities/${entityId}/governance-bodies`);
146
+ }
147
+ getGovernanceSeats(bodyId) {
148
+ return this.get(`/v1/governance-bodies/${bodyId}/seats`);
149
+ }
150
+ listMeetings(bodyId) {
151
+ return this.get(`/v1/governance-bodies/${bodyId}/meetings`);
152
+ }
153
+ getMeetingResolutions(meetingId) {
154
+ return this.get(`/v1/meetings/${meetingId}/resolutions`);
155
+ }
156
+ conveneMeeting(data) {
157
+ return this.post("/v1/meetings", data);
158
+ }
159
+ castVote(meetingId, itemId, data) {
160
+ return this.post(`/v1/meetings/${meetingId}/agenda-items/${itemId}/vote`, data);
161
+ }
162
+ // --- Documents ---
163
+ getEntityDocuments(entityId) {
164
+ return this.get(`/v1/formations/${entityId}/documents`);
165
+ }
166
+ generateContract(data) {
167
+ return this.post("/v1/contracts", data);
168
+ }
169
+ getSigningLink(documentId) {
170
+ return {
171
+ document_id: documentId,
172
+ signing_url: `https://humans.thecorporation.ai/sign/${documentId}`
173
+ };
174
+ }
175
+ // --- Finance ---
176
+ createInvoice(data) {
177
+ return this.post("/v1/invoices", data);
178
+ }
179
+ runPayroll(data) {
180
+ return this.post("/v1/payroll/runs", data);
181
+ }
182
+ submitPayment(data) {
183
+ return this.post("/v1/payments", data);
184
+ }
185
+ openBankAccount(data) {
186
+ return this.post("/v1/bank-accounts", data);
187
+ }
188
+ classifyContractor(data) {
189
+ return this.post("/v1/contractors/classify", data);
190
+ }
191
+ reconcileLedger(data) {
192
+ return this.post("/v1/ledger/reconcile", data);
193
+ }
194
+ // --- Tax ---
195
+ fileTaxDocument(data) {
196
+ return this.post("/v1/tax/filings", data);
197
+ }
198
+ trackDeadline(data) {
199
+ return this.post("/v1/deadlines", data);
200
+ }
201
+ // --- Billing ---
202
+ getBillingStatus() {
203
+ return this.get("/v1/billing/status", { workspace_id: this.workspaceId });
204
+ }
205
+ getBillingPlans() {
206
+ return this.get("/v1/billing/plans").then((data) => {
207
+ if (typeof data === "object" && data !== null && "plans" in data) {
208
+ return data.plans;
209
+ }
210
+ return data;
211
+ });
212
+ }
213
+ createBillingPortal() {
214
+ return this.post("/v1/billing/portal", { workspace_id: this.workspaceId });
215
+ }
216
+ createBillingCheckout(tier, entityId) {
217
+ const body = { tier };
218
+ if (entityId) body.entity_id = entityId;
219
+ return this.post("/v1/billing/checkout", body);
220
+ }
221
+ // --- Formations ---
222
+ getFormation(id) {
223
+ return this.get(`/v1/formations/${id}`);
224
+ }
225
+ getFormationDocuments(id) {
226
+ return this.get(`/v1/formations/${id}/documents`);
227
+ }
228
+ createFormation(data) {
229
+ return this.post("/v1/formations", data);
230
+ }
231
+ // --- Human obligations ---
232
+ getHumanObligations() {
233
+ return this.get(`/v1/workspaces/${this.workspaceId}/human-obligations`);
234
+ }
235
+ getSignerToken(obligationId) {
236
+ return this.post(`/v1/human-obligations/${obligationId}/signer-token`);
237
+ }
238
+ // --- Demo ---
239
+ seedDemo(name) {
240
+ return this.post("/v1/demo/seed", { name, workspace_id: this.workspaceId });
241
+ }
242
+ // --- Entities writes ---
243
+ convertEntity(entityId, data) {
244
+ return this.post(`/v1/entities/${entityId}/convert`, data);
245
+ }
246
+ dissolveEntity(entityId, data) {
247
+ return this.post(`/v1/entities/${entityId}/dissolve`, data);
248
+ }
249
+ // --- Agents ---
250
+ listAgents() {
251
+ return this.get("/v1/agents");
252
+ }
253
+ getAgent(id) {
254
+ return this.get(`/v1/agents/${id}`);
255
+ }
256
+ createAgent(data) {
257
+ return this.post("/v1/agents", data);
258
+ }
259
+ updateAgent(id, data) {
260
+ return this.patch(`/v1/agents/${id}`, data);
261
+ }
262
+ deleteAgent(id) {
263
+ return this.del(`/v1/agents/${id}`);
264
+ }
265
+ sendAgentMessage(id, body) {
266
+ return this.post(`/v1/agents/${id}/messages`, { body });
267
+ }
268
+ listAgentExecutions(id) {
269
+ return this.get(`/v1/agents/${id}/executions`);
270
+ }
271
+ getAgentUsage(id) {
272
+ return this.get(`/v1/agents/${id}/usage`);
273
+ }
274
+ addAgentSkill(id, data) {
275
+ return this.post(`/v1/agents/${id}/skills`, data);
276
+ }
277
+ listSupportedModels() {
278
+ return this.get("/v1/models");
279
+ }
280
+ // --- Approvals ---
281
+ listPendingApprovals() {
282
+ return this.get("/v1/approvals/pending");
283
+ }
284
+ respondApproval(id, decision, message = "") {
285
+ return this.patch(`/v1/approvals/${id}`, { decision, message });
286
+ }
287
+ // --- API Keys ---
288
+ listApiKeys() {
289
+ return this.get("/v1/api-keys", { workspace_id: this.workspaceId });
290
+ }
291
+ // --- Obligations ---
292
+ assignObligation(obligationId, contactId) {
293
+ return this.patch(`/v1/obligations/${obligationId}/assign`, { contact_id: contactId });
294
+ }
295
+ // --- Config ---
296
+ getConfig() {
297
+ return this.get("/v1/config");
298
+ }
299
+ // --- Link/Claim ---
300
+ async createLink() {
301
+ const resp = await this.request("POST", "/v1/workspaces/link");
302
+ if (!resp.ok) throw new Error(`${resp.status} ${resp.statusText}`);
303
+ return resp.json();
304
+ }
305
+ };
306
+
307
+ // src/tools.ts
308
+ import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
309
+ import { join } from "path";
310
+
311
+ // src/tool-defs.generated.ts
312
+ var GENERATED_TOOL_DEFINITIONS = [
313
+ {
314
+ "type": "function",
315
+ "function": {
316
+ "name": "get_workspace_status",
317
+ "description": "Get workspace status summary",
318
+ "parameters": {
319
+ "type": "object",
320
+ "properties": {},
321
+ "required": []
322
+ }
323
+ }
324
+ },
325
+ {
326
+ "type": "function",
327
+ "function": {
328
+ "name": "list_entities",
329
+ "description": "List all entities in the workspace",
330
+ "parameters": {
331
+ "type": "object",
332
+ "properties": {},
333
+ "required": []
334
+ }
335
+ }
336
+ },
337
+ {
338
+ "type": "function",
339
+ "function": {
340
+ "name": "get_cap_table",
341
+ "description": "Get cap table for an entity",
342
+ "parameters": {
343
+ "type": "object",
344
+ "properties": {
345
+ "entity_id": {
346
+ "type": "string"
347
+ }
348
+ },
349
+ "required": [
350
+ "entity_id"
351
+ ]
352
+ }
353
+ }
354
+ },
355
+ {
356
+ "type": "function",
357
+ "function": {
358
+ "name": "list_documents",
359
+ "description": "List documents for an entity",
360
+ "parameters": {
361
+ "type": "object",
362
+ "properties": {
363
+ "entity_id": {
364
+ "type": "string"
365
+ }
366
+ },
367
+ "required": [
368
+ "entity_id"
369
+ ]
370
+ }
371
+ }
372
+ },
373
+ {
374
+ "type": "function",
375
+ "function": {
376
+ "name": "list_safe_notes",
377
+ "description": "List SAFE notes for an entity",
378
+ "parameters": {
379
+ "type": "object",
380
+ "properties": {
381
+ "entity_id": {
382
+ "type": "string"
383
+ }
384
+ },
385
+ "required": [
386
+ "entity_id"
387
+ ]
388
+ }
389
+ }
390
+ },
391
+ {
392
+ "type": "function",
393
+ "function": {
394
+ "name": "list_agents",
395
+ "description": "List all agents in the workspace",
396
+ "parameters": {
397
+ "type": "object",
398
+ "properties": {},
399
+ "required": []
400
+ }
401
+ }
402
+ },
403
+ {
404
+ "type": "function",
405
+ "function": {
406
+ "name": "list_obligations",
407
+ "description": "List obligations with urgency tiers",
408
+ "parameters": {
409
+ "type": "object",
410
+ "properties": {
411
+ "tier": {
412
+ "type": "string"
413
+ }
414
+ },
415
+ "required": []
416
+ }
417
+ }
418
+ },
419
+ {
420
+ "type": "function",
421
+ "function": {
422
+ "name": "get_billing_status",
423
+ "description": "Get billing status and plans",
424
+ "parameters": {
425
+ "type": "object",
426
+ "properties": {},
427
+ "required": []
428
+ }
429
+ }
430
+ },
431
+ {
432
+ "type": "function",
433
+ "function": {
434
+ "name": "form_entity",
435
+ "description": "Form a new business entity (LLC or corporation)",
436
+ "parameters": {
437
+ "type": "object",
438
+ "properties": {
439
+ "entity_type": {
440
+ "type": "string",
441
+ "enum": [
442
+ "llc",
443
+ "corporation"
444
+ ]
445
+ },
446
+ "entity_name": {
447
+ "type": "string"
448
+ },
449
+ "jurisdiction": {
450
+ "type": "string"
451
+ },
452
+ "members": {
453
+ "type": "array",
454
+ "items": {
455
+ "type": "object",
456
+ "properties": {
457
+ "name": {
458
+ "type": "string"
459
+ },
460
+ "investor_type": {
461
+ "type": "string",
462
+ "enum": [
463
+ "natural_person",
464
+ "agent",
465
+ "entity"
466
+ ]
467
+ },
468
+ "email": {
469
+ "type": "string"
470
+ },
471
+ "agent_id": {
472
+ "type": "string"
473
+ },
474
+ "entity_id": {
475
+ "type": "string"
476
+ },
477
+ "ownership_pct": {
478
+ "type": "number"
479
+ },
480
+ "membership_units": {
481
+ "type": "integer"
482
+ },
483
+ "share_count": {
484
+ "type": "integer"
485
+ },
486
+ "share_class": {
487
+ "type": "string"
488
+ },
489
+ "role": {
490
+ "type": "string"
491
+ }
492
+ },
493
+ "required": [
494
+ "name",
495
+ "investor_type"
496
+ ]
497
+ }
498
+ }
499
+ },
500
+ "required": [
501
+ "entity_type",
502
+ "entity_name",
503
+ "jurisdiction",
504
+ "members"
505
+ ]
506
+ }
507
+ }
508
+ },
509
+ {
510
+ "type": "function",
511
+ "function": {
512
+ "name": "issue_equity",
513
+ "description": "Issue an equity grant",
514
+ "parameters": {
515
+ "type": "object",
516
+ "properties": {
517
+ "entity_id": {
518
+ "type": "string"
519
+ },
520
+ "grant_type": {
521
+ "type": "string"
522
+ },
523
+ "shares": {
524
+ "type": "integer"
525
+ },
526
+ "recipient_name": {
527
+ "type": "string"
528
+ },
529
+ "vesting_schedule": {
530
+ "type": "string"
531
+ }
532
+ },
533
+ "required": [
534
+ "entity_id",
535
+ "grant_type",
536
+ "shares",
537
+ "recipient_name"
538
+ ]
539
+ }
540
+ }
541
+ },
542
+ {
543
+ "type": "function",
544
+ "function": {
545
+ "name": "issue_safe",
546
+ "description": "Issue a SAFE note",
547
+ "parameters": {
548
+ "type": "object",
549
+ "properties": {
550
+ "entity_id": {
551
+ "type": "string"
552
+ },
553
+ "investor_name": {
554
+ "type": "string"
555
+ },
556
+ "principal_amount_cents": {
557
+ "type": "integer"
558
+ },
559
+ "safe_type": {
560
+ "type": "string"
561
+ },
562
+ "valuation_cap_cents": {
563
+ "type": "integer"
564
+ }
565
+ },
566
+ "required": [
567
+ "entity_id",
568
+ "investor_name",
569
+ "principal_amount_cents",
570
+ "safe_type",
571
+ "valuation_cap_cents"
572
+ ]
573
+ }
574
+ }
575
+ },
576
+ {
577
+ "type": "function",
578
+ "function": {
579
+ "name": "transfer_shares",
580
+ "description": "Transfer shares between holders",
581
+ "parameters": {
582
+ "type": "object",
583
+ "properties": {
584
+ "entity_id": {
585
+ "type": "string"
586
+ },
587
+ "share_class_id": {
588
+ "type": "string"
589
+ },
590
+ "from_holder": {
591
+ "type": "string"
592
+ },
593
+ "to_holder": {
594
+ "type": "string"
595
+ },
596
+ "transfer_type": {
597
+ "type": "string"
598
+ },
599
+ "shares": {
600
+ "type": "integer"
601
+ }
602
+ },
603
+ "required": [
604
+ "entity_id",
605
+ "from_holder",
606
+ "to_holder",
607
+ "shares"
608
+ ]
609
+ }
610
+ }
611
+ },
612
+ {
613
+ "type": "function",
614
+ "function": {
615
+ "name": "calculate_distribution",
616
+ "description": "Calculate a distribution",
617
+ "parameters": {
618
+ "type": "object",
619
+ "properties": {
620
+ "entity_id": {
621
+ "type": "string"
622
+ },
623
+ "total_amount_cents": {
624
+ "type": "integer"
625
+ },
626
+ "distribution_type": {
627
+ "type": "string"
628
+ }
629
+ },
630
+ "required": [
631
+ "entity_id",
632
+ "total_amount_cents"
633
+ ]
634
+ }
635
+ }
636
+ },
637
+ {
638
+ "type": "function",
639
+ "function": {
640
+ "name": "create_invoice",
641
+ "description": "Create an invoice",
642
+ "parameters": {
643
+ "type": "object",
644
+ "properties": {
645
+ "entity_id": {
646
+ "type": "string"
647
+ },
648
+ "customer_name": {
649
+ "type": "string"
650
+ },
651
+ "amount_cents": {
652
+ "type": "integer"
653
+ },
654
+ "description": {
655
+ "type": "string"
656
+ },
657
+ "due_date": {
658
+ "type": "string"
659
+ }
660
+ },
661
+ "required": [
662
+ "entity_id",
663
+ "customer_name",
664
+ "amount_cents",
665
+ "due_date"
666
+ ]
667
+ }
668
+ }
669
+ },
670
+ {
671
+ "type": "function",
672
+ "function": {
673
+ "name": "run_payroll",
674
+ "description": "Run payroll",
675
+ "parameters": {
676
+ "type": "object",
677
+ "properties": {
678
+ "entity_id": {
679
+ "type": "string"
680
+ },
681
+ "pay_period_start": {
682
+ "type": "string"
683
+ },
684
+ "pay_period_end": {
685
+ "type": "string"
686
+ }
687
+ },
688
+ "required": [
689
+ "entity_id",
690
+ "pay_period_start",
691
+ "pay_period_end"
692
+ ]
693
+ }
694
+ }
695
+ },
696
+ {
697
+ "type": "function",
698
+ "function": {
699
+ "name": "submit_payment",
700
+ "description": "Submit a payment",
701
+ "parameters": {
702
+ "type": "object",
703
+ "properties": {
704
+ "entity_id": {
705
+ "type": "string"
706
+ },
707
+ "amount_cents": {
708
+ "type": "integer"
709
+ },
710
+ "recipient": {
711
+ "type": "string"
712
+ },
713
+ "description": {
714
+ "type": "string"
715
+ }
716
+ },
717
+ "required": [
718
+ "entity_id",
719
+ "amount_cents",
720
+ "recipient"
721
+ ]
722
+ }
723
+ }
724
+ },
725
+ {
726
+ "type": "function",
727
+ "function": {
728
+ "name": "open_bank_account",
729
+ "description": "Open a business bank account",
730
+ "parameters": {
731
+ "type": "object",
732
+ "properties": {
733
+ "entity_id": {
734
+ "type": "string"
735
+ },
736
+ "institution_name": {
737
+ "type": "string"
738
+ }
739
+ },
740
+ "required": [
741
+ "entity_id"
742
+ ]
743
+ }
744
+ }
745
+ },
746
+ {
747
+ "type": "function",
748
+ "function": {
749
+ "name": "generate_contract",
750
+ "description": "Generate a contract from a template",
751
+ "parameters": {
752
+ "type": "object",
753
+ "properties": {
754
+ "entity_id": {
755
+ "type": "string"
756
+ },
757
+ "template_type": {
758
+ "type": "string"
759
+ },
760
+ "parameters": {
761
+ "type": "object"
762
+ }
763
+ },
764
+ "required": [
765
+ "entity_id",
766
+ "template_type"
767
+ ]
768
+ }
769
+ }
770
+ },
771
+ {
772
+ "type": "function",
773
+ "function": {
774
+ "name": "file_tax_document",
775
+ "description": "File a tax document",
776
+ "parameters": {
777
+ "type": "object",
778
+ "properties": {
779
+ "entity_id": {
780
+ "type": "string"
781
+ },
782
+ "document_type": {
783
+ "type": "string"
784
+ },
785
+ "tax_year": {
786
+ "type": "integer"
787
+ }
788
+ },
789
+ "required": [
790
+ "entity_id",
791
+ "document_type",
792
+ "tax_year"
793
+ ]
794
+ }
795
+ }
796
+ },
797
+ {
798
+ "type": "function",
799
+ "function": {
800
+ "name": "track_deadline",
801
+ "description": "Track a compliance deadline",
802
+ "parameters": {
803
+ "type": "object",
804
+ "properties": {
805
+ "entity_id": {
806
+ "type": "string"
807
+ },
808
+ "deadline_type": {
809
+ "type": "string"
810
+ },
811
+ "due_date": {
812
+ "type": "string"
813
+ },
814
+ "description": {
815
+ "type": "string"
816
+ },
817
+ "recurrence": {
818
+ "type": "string"
819
+ }
820
+ },
821
+ "required": [
822
+ "entity_id",
823
+ "deadline_type",
824
+ "due_date",
825
+ "description"
826
+ ]
827
+ }
828
+ }
829
+ },
830
+ {
831
+ "type": "function",
832
+ "function": {
833
+ "name": "classify_contractor",
834
+ "description": "Classify contractor risk",
835
+ "parameters": {
836
+ "type": "object",
837
+ "properties": {
838
+ "entity_id": {
839
+ "type": "string"
840
+ },
841
+ "contractor_name": {
842
+ "type": "string"
843
+ },
844
+ "state": {
845
+ "type": "string"
846
+ },
847
+ "hours_per_week": {
848
+ "type": "integer"
849
+ },
850
+ "exclusive_client": {
851
+ "type": "boolean"
852
+ },
853
+ "duration_months": {
854
+ "type": "integer"
855
+ },
856
+ "provides_tools": {
857
+ "type": "boolean"
858
+ }
859
+ },
860
+ "required": [
861
+ "entity_id",
862
+ "contractor_name",
863
+ "state",
864
+ "hours_per_week"
865
+ ]
866
+ }
867
+ }
868
+ },
869
+ {
870
+ "type": "function",
871
+ "function": {
872
+ "name": "reconcile_ledger",
873
+ "description": "Reconcile an entity's ledger",
874
+ "parameters": {
875
+ "type": "object",
876
+ "properties": {
877
+ "entity_id": {
878
+ "type": "string"
879
+ },
880
+ "start_date": {
881
+ "type": "string"
882
+ },
883
+ "end_date": {
884
+ "type": "string"
885
+ }
886
+ },
887
+ "required": [
888
+ "entity_id",
889
+ "start_date",
890
+ "end_date"
891
+ ]
892
+ }
893
+ }
894
+ },
895
+ {
896
+ "type": "function",
897
+ "function": {
898
+ "name": "convene_meeting",
899
+ "description": "Convene a governance meeting",
900
+ "parameters": {
901
+ "type": "object",
902
+ "properties": {
903
+ "meeting_type": {
904
+ "type": "string"
905
+ },
906
+ "title": {
907
+ "type": "string"
908
+ },
909
+ "agenda_item_titles": {
910
+ "type": "array",
911
+ "items": {
912
+ "type": "string"
913
+ }
914
+ },
915
+ "entity_id": {
916
+ "type": "string"
917
+ },
918
+ "governance_body_id": {
919
+ "type": "string"
920
+ },
921
+ "scheduled_date": {
922
+ "type": "string"
923
+ }
924
+ },
925
+ "required": [
926
+ "entity_id",
927
+ "governance_body_id",
928
+ "meeting_type",
929
+ "title",
930
+ "scheduled_date"
931
+ ]
932
+ }
933
+ }
934
+ },
935
+ {
936
+ "type": "function",
937
+ "function": {
938
+ "name": "cast_vote",
939
+ "description": "Cast a vote on an agenda item",
940
+ "parameters": {
941
+ "type": "object",
942
+ "properties": {
943
+ "meeting_id": {
944
+ "type": "string"
945
+ },
946
+ "agenda_item_id": {
947
+ "type": "string"
948
+ },
949
+ "voter_id": {
950
+ "type": "string"
951
+ },
952
+ "vote": {
953
+ "type": "string",
954
+ "description": "for, against, abstain, or recusal"
955
+ }
956
+ },
957
+ "required": [
958
+ "meeting_id",
959
+ "agenda_item_id",
960
+ "voter_id",
961
+ "vote"
962
+ ]
963
+ }
964
+ }
965
+ },
966
+ {
967
+ "type": "function",
968
+ "function": {
969
+ "name": "schedule_meeting",
970
+ "description": "Schedule a board or member meeting",
971
+ "parameters": {
972
+ "type": "object",
973
+ "properties": {
974
+ "body_id": {
975
+ "type": "string"
976
+ },
977
+ "meeting_type": {
978
+ "type": "string"
979
+ },
980
+ "title": {
981
+ "type": "string"
982
+ },
983
+ "proposed_date": {
984
+ "type": "string"
985
+ },
986
+ "agenda_items": {
987
+ "type": "array",
988
+ "items": {
989
+ "type": "string"
990
+ }
991
+ }
992
+ },
993
+ "required": [
994
+ "body_id",
995
+ "meeting_type",
996
+ "title",
997
+ "proposed_date"
998
+ ]
999
+ }
1000
+ }
1001
+ },
1002
+ {
1003
+ "type": "function",
1004
+ "function": {
1005
+ "name": "get_signer_link",
1006
+ "description": "Generate a signing link for a human obligation",
1007
+ "parameters": {
1008
+ "type": "object",
1009
+ "properties": {
1010
+ "obligation_id": {
1011
+ "type": "string"
1012
+ }
1013
+ },
1014
+ "required": [
1015
+ "obligation_id"
1016
+ ]
1017
+ }
1018
+ }
1019
+ },
1020
+ {
1021
+ "type": "function",
1022
+ "function": {
1023
+ "name": "get_document_link",
1024
+ "description": "Get a download link for a document",
1025
+ "parameters": {
1026
+ "type": "object",
1027
+ "properties": {
1028
+ "document_id": {
1029
+ "type": "string"
1030
+ }
1031
+ },
1032
+ "required": [
1033
+ "document_id"
1034
+ ]
1035
+ }
1036
+ }
1037
+ },
1038
+ {
1039
+ "type": "function",
1040
+ "function": {
1041
+ "name": "convert_entity",
1042
+ "description": "Convert entity type",
1043
+ "parameters": {
1044
+ "type": "object",
1045
+ "properties": {
1046
+ "entity_id": {
1047
+ "type": "string"
1048
+ },
1049
+ "new_entity_type": {
1050
+ "type": "string"
1051
+ },
1052
+ "new_jurisdiction": {
1053
+ "type": "string"
1054
+ }
1055
+ },
1056
+ "required": [
1057
+ "entity_id",
1058
+ "new_entity_type"
1059
+ ]
1060
+ }
1061
+ }
1062
+ },
1063
+ {
1064
+ "type": "function",
1065
+ "function": {
1066
+ "name": "dissolve_entity",
1067
+ "description": "Dissolve an entity",
1068
+ "parameters": {
1069
+ "type": "object",
1070
+ "properties": {
1071
+ "entity_id": {
1072
+ "type": "string"
1073
+ },
1074
+ "reason": {
1075
+ "type": "string"
1076
+ },
1077
+ "effective_date": {
1078
+ "type": "string"
1079
+ }
1080
+ },
1081
+ "required": [
1082
+ "entity_id",
1083
+ "reason"
1084
+ ]
1085
+ }
1086
+ }
1087
+ },
1088
+ {
1089
+ "type": "function",
1090
+ "function": {
1091
+ "name": "add_agent_skill",
1092
+ "description": "Add a skill to an agent",
1093
+ "parameters": {
1094
+ "type": "object",
1095
+ "properties": {
1096
+ "agent_id": {
1097
+ "type": "string"
1098
+ },
1099
+ "skill_name": {
1100
+ "type": "string"
1101
+ },
1102
+ "description": {
1103
+ "type": "string"
1104
+ },
1105
+ "instructions": {
1106
+ "type": "string"
1107
+ }
1108
+ },
1109
+ "required": [
1110
+ "agent_id",
1111
+ "skill_name",
1112
+ "description"
1113
+ ]
1114
+ }
1115
+ }
1116
+ },
1117
+ {
1118
+ "type": "function",
1119
+ "function": {
1120
+ "name": "get_checklist",
1121
+ "description": "Get the user's onboarding checklist",
1122
+ "parameters": {
1123
+ "type": "object",
1124
+ "properties": {},
1125
+ "required": []
1126
+ }
1127
+ }
1128
+ },
1129
+ {
1130
+ "type": "function",
1131
+ "function": {
1132
+ "name": "update_checklist",
1133
+ "description": "Update the user's onboarding checklist",
1134
+ "parameters": {
1135
+ "type": "object",
1136
+ "properties": {
1137
+ "checklist": {
1138
+ "type": "string"
1139
+ }
1140
+ },
1141
+ "required": [
1142
+ "checklist"
1143
+ ]
1144
+ }
1145
+ }
1146
+ },
1147
+ {
1148
+ "type": "function",
1149
+ "function": {
1150
+ "name": "get_signing_link",
1151
+ "description": "Get a signing link for a document",
1152
+ "parameters": {
1153
+ "type": "object",
1154
+ "properties": {
1155
+ "document_id": {
1156
+ "type": "string"
1157
+ }
1158
+ },
1159
+ "required": [
1160
+ "document_id"
1161
+ ]
1162
+ }
1163
+ }
1164
+ },
1165
+ {
1166
+ "type": "function",
1167
+ "function": {
1168
+ "name": "create_agent",
1169
+ "description": "Create a new agent",
1170
+ "parameters": {
1171
+ "type": "object",
1172
+ "properties": {
1173
+ "name": {
1174
+ "type": "string"
1175
+ },
1176
+ "system_prompt": {
1177
+ "type": "string"
1178
+ },
1179
+ "model": {
1180
+ "type": "string"
1181
+ }
1182
+ },
1183
+ "required": [
1184
+ "name",
1185
+ "system_prompt"
1186
+ ]
1187
+ }
1188
+ }
1189
+ },
1190
+ {
1191
+ "type": "function",
1192
+ "function": {
1193
+ "name": "send_agent_message",
1194
+ "description": "Send a message to an agent",
1195
+ "parameters": {
1196
+ "type": "object",
1197
+ "properties": {
1198
+ "agent_id": {
1199
+ "type": "string"
1200
+ },
1201
+ "body": {
1202
+ "type": "string"
1203
+ }
1204
+ },
1205
+ "required": [
1206
+ "agent_id",
1207
+ "body"
1208
+ ]
1209
+ }
1210
+ }
1211
+ },
1212
+ {
1213
+ "type": "function",
1214
+ "function": {
1215
+ "name": "update_agent",
1216
+ "description": "Update an agent",
1217
+ "parameters": {
1218
+ "type": "object",
1219
+ "properties": {
1220
+ "agent_id": {
1221
+ "type": "string"
1222
+ },
1223
+ "status": {
1224
+ "type": "string"
1225
+ }
1226
+ },
1227
+ "required": [
1228
+ "agent_id"
1229
+ ]
1230
+ }
1231
+ }
1232
+ }
1233
+ ];
1234
+
1235
+ // src/tools.ts
1236
+ var TOOL_HANDLERS = {
1237
+ get_workspace_status: async (_args, client) => client.getStatus(),
1238
+ list_obligations: async (args, client) => client.getObligations(args.tier),
1239
+ list_entities: async (_args, client) => client.listEntities(),
1240
+ get_cap_table: async (args, client) => client.getCapTable(args.entity_id),
1241
+ list_documents: async (args, client) => client.getEntityDocuments(args.entity_id),
1242
+ list_safe_notes: async (args, client) => client.getSafeNotes(args.entity_id),
1243
+ list_agents: async (_args, client) => client.listAgents(),
1244
+ get_billing_status: async (_args, client) => {
1245
+ const [status, plans] = await Promise.all([client.getBillingStatus(), client.getBillingPlans()]);
1246
+ return { status, plans };
1247
+ },
1248
+ form_entity: async (args, client, ctx) => {
1249
+ const entityType = args.entity_type;
1250
+ let jurisdiction = args.jurisdiction || "";
1251
+ if (!jurisdiction || jurisdiction.length === 2) {
1252
+ jurisdiction = entityType === "llc" ? "US-WY" : "US-DE";
1253
+ }
1254
+ const members = args.members ?? [];
1255
+ if (!members.length) return { error: "Members are required." };
1256
+ for (const m of members) {
1257
+ if (!m.investor_type) m.investor_type = "natural_person";
1258
+ if (typeof m.ownership_pct === "number" && m.ownership_pct > 1) {
1259
+ m.ownership_pct = m.ownership_pct / 100;
1260
+ }
1261
+ }
1262
+ const result = await client.createFormation({
1263
+ entity_type: entityType,
1264
+ legal_name: args.entity_name,
1265
+ jurisdiction,
1266
+ members,
1267
+ workspace_id: client.workspaceId
1268
+ });
1269
+ const entityId = result.entity_id;
1270
+ if (entityId && ctx.onEntityFormed) {
1271
+ ctx.onEntityFormed(entityId);
1272
+ }
1273
+ return result;
1274
+ },
1275
+ issue_equity: async (args, client) => client.issueEquity(args),
1276
+ issue_safe: async (args, client) => client.issueSafe(args),
1277
+ create_invoice: async (args, client) => {
1278
+ if (!("amount_cents" in args) && Array.isArray(args.line_items)) {
1279
+ args.amount_cents = args.line_items.reduce((sum, item) => sum + (item.amount_cents ?? 0), 0);
1280
+ }
1281
+ if (!("amount_cents" in args)) args.amount_cents = 0;
1282
+ return client.createInvoice(args);
1283
+ },
1284
+ run_payroll: async (args, client) => client.runPayroll(args),
1285
+ submit_payment: async (args, client) => client.submitPayment(args),
1286
+ open_bank_account: async (args, client) => {
1287
+ const body = { entity_id: args.entity_id };
1288
+ if (args.institution_name) body.institution_name = args.institution_name;
1289
+ return client.openBankAccount(body);
1290
+ },
1291
+ generate_contract: async (args, client) => client.generateContract(args),
1292
+ file_tax_document: async (args, client) => client.fileTaxDocument(args),
1293
+ get_signer_link: async (args, client) => {
1294
+ const result = await client.getSignerToken(args.obligation_id);
1295
+ const token = result.token ?? "";
1296
+ const obligationId = args.obligation_id;
1297
+ const humansBase = client.apiUrl.replace("://api.", "://humans.");
1298
+ return {
1299
+ signer_url: `${humansBase}/human/${obligationId}?token=${token}`,
1300
+ obligation_id: obligationId,
1301
+ expires_in_seconds: result.expires_in ?? 900,
1302
+ message: "Share this link with the signer. Link expires in 15 minutes."
1303
+ };
1304
+ },
1305
+ schedule_meeting: async (args, client) => {
1306
+ const body = {
1307
+ body_id: args.body_id,
1308
+ meeting_type: args.meeting_type,
1309
+ title: args.title,
1310
+ proposed_date: args.proposed_date
1311
+ };
1312
+ if (args.agenda_items) body.agenda_item_titles = args.agenda_items;
1313
+ return client.conveneMeeting(body);
1314
+ },
1315
+ cast_vote: async (args, client) => client.castVote(args.meeting_id, args.agenda_item_id, {
1316
+ voter_id: args.voter_id,
1317
+ vote_value: args.vote
1318
+ }),
1319
+ update_checklist: async (args, _client, ctx) => {
1320
+ const path = join(ctx.dataDir, "checklist.md");
1321
+ mkdirSync(ctx.dataDir, { recursive: true });
1322
+ writeFileSync(path, args.checklist);
1323
+ return { status: "updated", checklist: args.checklist };
1324
+ },
1325
+ get_checklist: async (_args, _client, ctx) => {
1326
+ const path = join(ctx.dataDir, "checklist.md");
1327
+ if (existsSync(path)) return { checklist: readFileSync(path, "utf-8") };
1328
+ return { checklist: null, message: "No checklist yet." };
1329
+ },
1330
+ get_document_link: async (args, client) => {
1331
+ const docId = args.document_id;
1332
+ try {
1333
+ const resp = await fetch(`${client.apiUrl}/v1/documents/${docId}/request-copy`, {
1334
+ method: "POST",
1335
+ headers: { Authorization: `Bearer ${client.apiKey}`, "Content-Type": "application/json" },
1336
+ body: JSON.stringify({ email: "owner@workspace" })
1337
+ });
1338
+ if (!resp.ok) throw new Error("request-copy failed");
1339
+ const result = await resp.json();
1340
+ let downloadUrl = result.download_url ?? "";
1341
+ if (downloadUrl.startsWith("/")) downloadUrl = client.apiUrl + downloadUrl;
1342
+ return { document_id: docId, download_url: downloadUrl, expires_in: "24 hours" };
1343
+ } catch {
1344
+ return {
1345
+ document_id: docId,
1346
+ download_url: `${client.apiUrl}/v1/documents/${docId}/pdf`,
1347
+ note: "Use your API key to authenticate the download."
1348
+ };
1349
+ }
1350
+ },
1351
+ get_signing_link: async (args, client) => client.getSigningLink(args.document_id),
1352
+ convert_entity: async (args, client) => client.convertEntity(args.entity_id, args),
1353
+ dissolve_entity: async (args, client) => client.dissolveEntity(args.entity_id, args),
1354
+ transfer_shares: async (args, client) => client.transferShares(args),
1355
+ calculate_distribution: async (args, client) => client.calculateDistribution(args),
1356
+ classify_contractor: async (args, client) => client.classifyContractor(args),
1357
+ reconcile_ledger: async (args, client) => client.reconcileLedger(args),
1358
+ track_deadline: async (args, client) => client.trackDeadline(args),
1359
+ convene_meeting: async (args, client) => client.conveneMeeting(args),
1360
+ create_agent: async (args, client) => client.createAgent(args),
1361
+ send_agent_message: async (args, client) => client.sendAgentMessage(args.agent_id, args.body),
1362
+ update_agent: async (args, client) => client.updateAgent(args.agent_id, args),
1363
+ add_agent_skill: async (args, client) => client.addAgentSkill(args.agent_id, args)
1364
+ };
1365
+ var TOOL_DEFINITIONS = GENERATED_TOOL_DEFINITIONS;
1366
+ var READ_ONLY_TOOLS = /* @__PURE__ */ new Set([
1367
+ "get_workspace_status",
1368
+ "list_entities",
1369
+ "get_cap_table",
1370
+ "list_documents",
1371
+ "list_safe_notes",
1372
+ "list_agents",
1373
+ "get_checklist",
1374
+ "get_document_link",
1375
+ "get_signing_link",
1376
+ "list_obligations",
1377
+ "get_billing_status"
1378
+ ]);
1379
+ function isWriteTool(name) {
1380
+ return !READ_ONLY_TOOLS.has(name);
1381
+ }
1382
+ async function executeTool(name, args, client, ctx) {
1383
+ const handler = TOOL_HANDLERS[name];
1384
+ if (!handler) return JSON.stringify({ error: `Unknown tool: ${name}` });
1385
+ try {
1386
+ const result = await handler(args, client, ctx);
1387
+ return JSON.stringify(result, null, 0);
1388
+ } catch (err) {
1389
+ return JSON.stringify({ error: String(err) });
1390
+ }
1391
+ }
1392
+
1393
+ // src/tool-descriptions.ts
1394
+ function centsToUsd(cents) {
1395
+ return "$" + (cents / 100).toLocaleString("en-US", { minimumFractionDigits: 0, maximumFractionDigits: 0 });
1396
+ }
1397
+ function describeToolCall(name, args) {
1398
+ const a = { ...args };
1399
+ for (const k of ["amount_cents", "principal_amount_cents", "total_amount_cents", "valuation_cap_cents"]) {
1400
+ if (k in a) {
1401
+ try {
1402
+ a._amount = centsToUsd(Number(a[k]));
1403
+ } catch {
1404
+ a._amount = String(a[k]);
1405
+ }
1406
+ }
1407
+ }
1408
+ a._amount ??= "?";
1409
+ a.institution_name ??= "Mercury";
1410
+ a.payment_method ??= "ach";
1411
+ const fmts = {
1412
+ form_entity: 'Form a new {entity_type} named "{entity_name}" in {jurisdiction}',
1413
+ convert_entity: "Convert entity to {new_entity_type}",
1414
+ dissolve_entity: "Dissolve entity \u2014 {dissolution_reason}",
1415
+ issue_equity: "Issue {shares} {grant_type} shares to {recipient_name}",
1416
+ transfer_shares: "Transfer {shares} shares to {to_recipient_name}",
1417
+ issue_safe: "Issue SAFE note to {investor_name} for {_amount}",
1418
+ calculate_distribution: "Calculate {distribution_type} distribution of {_amount}",
1419
+ create_invoice: "Create invoice for {customer_name} \u2014 {_amount}",
1420
+ run_payroll: "Run payroll for {pay_period_start} to {pay_period_end}",
1421
+ submit_payment: "Submit {_amount} payment to {recipient} via {payment_method}",
1422
+ open_bank_account: "Open bank account at {institution_name}",
1423
+ reconcile_ledger: "Reconcile ledger from {start_date} to {end_date}",
1424
+ generate_contract: "Generate {template_type} contract for {counterparty_name}",
1425
+ file_tax_document: "File {document_type} for tax year {tax_year}",
1426
+ track_deadline: "Track {deadline_type} deadline \u2014 {description}",
1427
+ classify_contractor: "Classify contractor {contractor_name} in {state}",
1428
+ convene_meeting: "Convene {meeting_type} meeting",
1429
+ cast_vote: "Cast {vote} vote",
1430
+ schedule_meeting: "Schedule {meeting_type} meeting: {title}",
1431
+ update_checklist: "Update workspace checklist",
1432
+ create_agent: 'Create agent "{name}"',
1433
+ send_agent_message: "Send message to agent",
1434
+ update_agent: "Update agent configuration",
1435
+ add_agent_skill: 'Add skill "{skill_name}" to agent'
1436
+ };
1437
+ const fmt = fmts[name];
1438
+ if (fmt) {
1439
+ try {
1440
+ return fmt.replace(/\{(\w+)\}/g, (_, k) => String(a[k] ?? "?"));
1441
+ } catch {
1442
+ }
1443
+ }
1444
+ return name.replace(/_/g, " ");
1445
+ }
1446
+
1447
+ // src/system-prompt.ts
1448
+ var SYSTEM_PROMPT_BASE = `You are a corporate governance assistant for TheCorporation, an agentic corporate governance platform.
1449
+
1450
+ ## Context
1451
+ {context}
1452
+
1453
+ ## Capabilities
1454
+ You can perform the full range of corporate operations:
1455
+
1456
+ **Read operations:**
1457
+ - View workspace status, entities, cap tables, documents
1458
+ - List SAFE notes, equity grants, agents
1459
+ - Check deadlines and compliance status
1460
+
1461
+ **Write operations:**
1462
+ - Form new LLCs and corporations in any US jurisdiction
1463
+ - Issue equity (common, preferred, options, units)
1464
+ - Issue SAFE notes to investors
1465
+ - Transfer shares between holders
1466
+ - Convert entities (LLC <> Corporation)
1467
+ - Create invoices, run payroll, submit payments
1468
+ - Open bank accounts, reconcile ledgers
1469
+ - Generate contracts (NDAs, employment offers, consulting agreements)
1470
+ - File tax documents (1099-NEC, K-1, 941, W-2, estimated tax)
1471
+ - Generate signing links for documents (human-only signing)
1472
+ - Track compliance deadlines
1473
+ - Classify contractor risk (employee vs 1099)
1474
+ - Convene governance meetings and cast votes
1475
+ - Dissolve entities with full wind-down workflow
1476
+
1477
+ ## Rules
1478
+ - All monetary values are in integer cents ($1,000 = 100000).
1479
+ - Be concise and helpful.
1480
+ - **You MUST confirm with the user before calling ANY write tool.** Describe what you are about to do and wait for explicit approval. Never execute tools speculatively or "on behalf of" the user without their go-ahead.
1481
+ - Don't ask for info available in platform config \u2014 use the correct values automatically.
1482
+ - If only one option exists for a field, use it without asking.
1483
+ - Don't make up data \u2014 only present what the tools return.
1484
+ - If a tool returns an error, explain it simply without exposing raw error details.
1485
+ - NEVER create an agent to answer a question you can answer yourself. You are the assistant \u2014 answer questions directly using your knowledge and the read tools.
1486
+
1487
+ ## Agent Rules
1488
+ - Agents are for **delegating recurring corporate operations tasks** that the user explicitly requests \u2014 e.g. "process incoming invoices", "monitor compliance deadlines", "handle payroll every two weeks".
1489
+ - Agents are NOT for research, answering questions, or one-off lookups. If the user asks a question, YOU answer it.
1490
+ - NEVER proactively suggest or create an agent unless the user specifically asks for one.
1491
+ - Agent tools require a paid plan.
1492
+
1493
+ ## Entity Formation Rules
1494
+ - When forming an entity, you MUST ask about all founding members and their ownership allocations BEFORE calling the form_entity tool.
1495
+ - For LLCs, ownership percentages must total 100%.
1496
+
1497
+ ## Document Signing Rules
1498
+ - You CANNOT sign documents on behalf of users. Signing is a human action.
1499
+ - Use \`get_signing_link\` to generate a signing URL for a document.
1500
+ - Present the signing link so users can open it and sign themselves.
1501
+ - NEVER attempt to sign, execute, or complete signature actions automatically.
1502
+ - The \`get_signing_link\` tool does NOT sign anything \u2014 it only returns a URL.
1503
+
1504
+ ## User Journey
1505
+ After completing any action, ALWAYS present the logical next step(s) as a
1506
+ numbered list. The user should never wonder "what now?" \u2014 guide them forward.
1507
+
1508
+ After entity formation:
1509
+ 1. The \`form_entity\` response includes a \`documents\` array with document IDs. These documents are created immediately \u2014 they are NEVER "still being generated" or delayed.
1510
+ 2. Immediately call \`get_signing_link\` for each document ID in the response to get signing URLs.
1511
+ 3. Present the signing links to the user right away. Do NOT tell the user to "check back later" or that documents are "being prepared" \u2014 they already exist.
1512
+ 4. Then: "Documents signed! Next: apply for an EIN, open a bank account, or issue equity."
1513
+
1514
+ After document generation:
1515
+ 1. Present signing links immediately \u2014 don't wait for the user to ask.
1516
+ 2. Use the document IDs from the tool response \u2014 do NOT call \`list_documents\` to re-fetch them.
1517
+
1518
+ After signing:
1519
+ 1. "Documents are signed! Next: file for EIN, open a bank account, or add team members."
1520
+
1521
+ After equity issuance:
1522
+ 1. "Equity issued! Next: generate the stock certificate for signing, or issue more grants."
1523
+
1524
+ General pattern:
1525
+ - Always end with 1-2 concrete next actions the user can take.
1526
+ - Phrase them as questions or suggestions: "Would you like to [next step]?"
1527
+ - If there are signing obligations, proactively generate and present the signing links.
1528
+ - Never just say "done" \u2014 always show what comes next.
1529
+
1530
+ After major actions, use update_checklist to track progress. Use markdown checkbox
1531
+ format (- [x] / - [ ]). Call get_checklist first to see current state, then
1532
+ update_checklist with checked-off items. This helps users see where they are.
1533
+
1534
+ {extra_sections}`;
1535
+ function formatConfigSection(cfgData) {
1536
+ const lines = [];
1537
+ const entityTypes = cfgData.entity_types;
1538
+ if (entityTypes?.length) {
1539
+ const vals = entityTypes.map((t) => `"${t.value}"`).join(", ");
1540
+ lines.push(`Entity types: ${vals}`);
1541
+ }
1542
+ const jurisdictions = cfgData.jurisdictions;
1543
+ if (jurisdictions) {
1544
+ for (const [etype, jurs] of Object.entries(jurisdictions)) {
1545
+ const jurVals = jurs.map((j) => `${j.label} (${j.value})`).join(", ");
1546
+ lines.push(`Jurisdictions for ${etype}: ${jurVals}`);
1547
+ }
1548
+ }
1549
+ const invTypes = cfgData.investor_types;
1550
+ if (invTypes?.length) {
1551
+ const vals = invTypes.map((t) => `"${t.value}"`).join(", ");
1552
+ lines.push(`Investor types: ${vals}`);
1553
+ }
1554
+ const workers = cfgData.worker_classifications;
1555
+ if (workers?.length) {
1556
+ const vals = workers.map((t) => `"${t.value}"`).join(", ");
1557
+ lines.push(`Worker classifications: ${vals}`);
1558
+ }
1559
+ const vesting = cfgData.vesting_schedules;
1560
+ if (vesting?.length) {
1561
+ const vals = vesting.map((t) => `${t.label} (${t.value})`).join(", ");
1562
+ lines.push(`Vesting schedules: ${vals}`);
1563
+ }
1564
+ const safeTypes = cfgData.safe_types;
1565
+ if (safeTypes?.length) {
1566
+ const vals = safeTypes.map((t) => `"${t.value}"`).join(", ");
1567
+ lines.push(`SAFE types: ${vals}`);
1568
+ }
1569
+ const compTypes = cfgData.compensation_types;
1570
+ if (compTypes?.length) {
1571
+ const vals = compTypes.map((t) => `${t.label} (${t.value})`).join(", ");
1572
+ lines.push(`Compensation types: ${vals}`);
1573
+ }
1574
+ const bodyTypes = cfgData.governance_body_types;
1575
+ if (bodyTypes?.length) {
1576
+ const vals = bodyTypes.map((t) => `"${t.value}"`).join(", ");
1577
+ lines.push(`Governance body types: ${vals}`);
1578
+ }
1579
+ const quorum = cfgData.quorum_rules;
1580
+ if (quorum?.length) {
1581
+ const vals = quorum.map((t) => `"${t.value}"`).join(", ");
1582
+ lines.push(`Quorum rules: ${vals}`);
1583
+ }
1584
+ const voting = cfgData.voting_methods;
1585
+ if (voting?.length) {
1586
+ const vals = voting.map((t) => `${t.label} (${t.value})`).join(", ");
1587
+ lines.push(`Voting methods: ${vals}`);
1588
+ }
1589
+ if (!lines.length) return "";
1590
+ const configYaml = lines.map((line) => `- ${line}`).join("\n");
1591
+ return "\n## Platform Configuration\nThe following are the ONLY valid values supported by this platform. Do not offer or accept values outside these lists.\n\n" + configYaml + "\n";
1592
+ }
1593
+
1594
+ // src/definitions.ts
1595
+ var TOOL_REGISTRY = {};
1596
+ for (const td of GENERATED_TOOL_DEFINITIONS) {
1597
+ TOOL_REGISTRY[td.function.name] = td.function;
1598
+ }
1599
+ var READ_ONLY_TOOLS2 = /* @__PURE__ */ new Set([
1600
+ "get_workspace_status",
1601
+ "list_entities",
1602
+ "get_cap_table",
1603
+ "list_documents",
1604
+ "list_safe_notes",
1605
+ "list_agents",
1606
+ "get_checklist",
1607
+ "get_document_link",
1608
+ "get_signing_link",
1609
+ "list_obligations",
1610
+ "get_billing_status"
1611
+ ]);
1612
+ export {
1613
+ CorpAPIClient,
1614
+ GENERATED_TOOL_DEFINITIONS,
1615
+ READ_ONLY_TOOLS2 as READ_ONLY_TOOLS,
1616
+ SYSTEM_PROMPT_BASE,
1617
+ SessionExpiredError,
1618
+ TOOL_DEFINITIONS,
1619
+ TOOL_REGISTRY,
1620
+ describeToolCall,
1621
+ executeTool,
1622
+ formatConfigSection,
1623
+ isWriteTool,
1624
+ provisionWorkspace
1625
+ };
1626
+ //# sourceMappingURL=index.js.map