@thecorporation/corp-tools 26.3.21 → 26.3.23
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.d.ts +40 -2
- package/dist/index.js +347 -16
- package/dist/index.js.map +1 -1
- package/package.json +9 -1
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ interface CorpConfig {
|
|
|
14
14
|
email: string;
|
|
15
15
|
};
|
|
16
16
|
active_entity_id: string;
|
|
17
|
+
data_dir: string;
|
|
17
18
|
active_entity_ids?: Record<string, string>;
|
|
18
19
|
last_references?: Record<string, string>;
|
|
19
20
|
[key: string]: unknown;
|
|
@@ -3212,7 +3213,7 @@ type DigestTriggerResponse = components["schemas"]["DigestTriggerResponse"];
|
|
|
3212
3213
|
type InvoiceResponse = components["schemas"]["InvoiceResponse"];
|
|
3213
3214
|
|
|
3214
3215
|
declare class SessionExpiredError extends Error {
|
|
3215
|
-
constructor();
|
|
3216
|
+
constructor(detail?: string);
|
|
3216
3217
|
}
|
|
3217
3218
|
declare function provisionWorkspace(apiUrl: string, name?: string): Promise<ApiRecord>;
|
|
3218
3219
|
declare class CorpAPIClient {
|
|
@@ -3288,6 +3289,13 @@ declare class CorpAPIClient {
|
|
|
3288
3289
|
computeResolution(meetingId: string, itemId: string, entityId: string, data: ApiRecord): Promise<ResolutionResponse>;
|
|
3289
3290
|
attachResolutionDocument(meetingId: string, resolutionId: string, data: ApiRecord): Promise<ResolutionResponse>;
|
|
3290
3291
|
writtenConsent(data: ApiRecord): Promise<WrittenConsentResponse>;
|
|
3292
|
+
getGovernanceMode(entityId: string): Promise<ApiRecord>;
|
|
3293
|
+
setGovernanceMode(data: ApiRecord): Promise<ApiRecord>;
|
|
3294
|
+
resignSeat(seatId: string, entityId: string): Promise<ApiRecord>;
|
|
3295
|
+
createGovernanceIncident(data: ApiRecord): Promise<ApiRecord>;
|
|
3296
|
+
listGovernanceIncidents(entityId: string): Promise<ApiRecord[]>;
|
|
3297
|
+
resolveGovernanceIncident(incidentId: string, data: ApiRecord): Promise<ApiRecord>;
|
|
3298
|
+
getGovernanceProfile(entityId: string): Promise<ApiRecord>;
|
|
3291
3299
|
listAgendaItems(meetingId: string, entityId: string): Promise<AgendaItemResponse[]>;
|
|
3292
3300
|
listVotes(meetingId: string, itemId: string, entityId: string): Promise<VoteResponse[]>;
|
|
3293
3301
|
getEntityDocuments(entityId: string): Promise<DocumentResponse[]>;
|
|
@@ -3307,8 +3315,12 @@ declare class CorpAPIClient {
|
|
|
3307
3315
|
runPayroll(data: ApiRecord): Promise<ApiRecord>;
|
|
3308
3316
|
submitPayment(data: ApiRecord): Promise<ApiRecord>;
|
|
3309
3317
|
openBankAccount(data: ApiRecord): Promise<ApiRecord>;
|
|
3318
|
+
activateBankAccount(bankAccountId: string, entityId: string): Promise<ApiRecord>;
|
|
3310
3319
|
classifyContractor(data: ApiRecord): Promise<ApiRecord>;
|
|
3311
3320
|
reconcileLedger(data: ApiRecord): Promise<ApiRecord>;
|
|
3321
|
+
getFinancialStatements(entityId: string, params?: Record<string, string>): Promise<ApiRecord>;
|
|
3322
|
+
getDilutionPreview(entityId: string, roundId: string): Promise<ApiRecord>;
|
|
3323
|
+
getControlMap(entityId: string, rootEntityId: string): Promise<ApiRecord>;
|
|
3312
3324
|
listTaxFilings(entityId: string): Promise<ApiRecord[]>;
|
|
3313
3325
|
listDeadlines(entityId: string): Promise<ApiRecord[]>;
|
|
3314
3326
|
listContractorClassifications(entityId: string): Promise<ApiRecord[]>;
|
|
@@ -3346,6 +3358,10 @@ declare class CorpAPIClient {
|
|
|
3346
3358
|
sendAgentMessage(id: string, message: string): Promise<ApiRecord>;
|
|
3347
3359
|
addAgentSkill(id: string, data: ApiRecord): Promise<ApiRecord>;
|
|
3348
3360
|
listSupportedModels(): Promise<ApiRecord[]>;
|
|
3361
|
+
getAgentExecution(agentId: string, executionId: string): Promise<ApiRecord>;
|
|
3362
|
+
getAgentExecutionResult(agentId: string, executionId: string): Promise<ApiRecord>;
|
|
3363
|
+
getAgentExecutionLogs(agentId: string, executionId: string): Promise<ApiRecord>;
|
|
3364
|
+
killAgentExecution(agentId: string, executionId: string): Promise<ApiRecord>;
|
|
3349
3365
|
createGovernanceBody(data: ApiRecord): Promise<ApiRecord>;
|
|
3350
3366
|
createGovernanceSeat(bodyId: string, entityId: string, data: ApiRecord): Promise<ApiRecord>;
|
|
3351
3367
|
listWorkItems(entityId: string, params?: Record<string, string>): Promise<ApiRecord[]>;
|
|
@@ -3356,8 +3372,18 @@ declare class CorpAPIClient {
|
|
|
3356
3372
|
releaseWorkItem(entityId: string, workItemId: string): Promise<ApiRecord>;
|
|
3357
3373
|
cancelWorkItem(entityId: string, workItemId: string): Promise<ApiRecord>;
|
|
3358
3374
|
listApiKeys(): Promise<ApiRecord[]>;
|
|
3375
|
+
createApiKey(data: ApiRecord): Promise<ApiRecord>;
|
|
3376
|
+
revokeApiKey(keyId: string): Promise<void>;
|
|
3377
|
+
rotateApiKey(keyId: string): Promise<ApiRecord>;
|
|
3359
3378
|
assignObligation(obligationId: string, contactId: string): Promise<ApiRecord>;
|
|
3360
3379
|
getConfig(): Promise<ApiRecord>;
|
|
3380
|
+
listServiceCatalog(): Promise<ApiRecord[]>;
|
|
3381
|
+
createServiceRequest(data: ApiRecord): Promise<ApiRecord>;
|
|
3382
|
+
getServiceRequest(id: string, entityId: string): Promise<ApiRecord>;
|
|
3383
|
+
listServiceRequests(entityId: string): Promise<ApiRecord[]>;
|
|
3384
|
+
beginServiceCheckout(id: string, data: ApiRecord): Promise<ApiRecord>;
|
|
3385
|
+
fulfillServiceRequest(id: string, data: ApiRecord): Promise<ApiRecord>;
|
|
3386
|
+
cancelServiceRequest(id: string, data: ApiRecord): Promise<ApiRecord>;
|
|
3361
3387
|
submitFeedback(message: string, category?: string, email?: string): Promise<{
|
|
3362
3388
|
feedback_id: string;
|
|
3363
3389
|
submitted_at: string;
|
|
@@ -3589,4 +3615,16 @@ type WorkItemStatus = (typeof WorkItemStatus)[number];
|
|
|
3589
3615
|
declare const WorkflowType: readonly ["transfer", "fundraising"];
|
|
3590
3616
|
type WorkflowType = (typeof WorkflowType)[number];
|
|
3591
3617
|
|
|
3592
|
-
|
|
3618
|
+
declare function generateFernetKey(): string;
|
|
3619
|
+
declare function generateSecret(length?: number): string;
|
|
3620
|
+
declare function loadEnvFile(path: string): void;
|
|
3621
|
+
declare function ensureEnvFile(envPath: string): void;
|
|
3622
|
+
|
|
3623
|
+
declare function resolveBinaryPath(processUrl: string): string;
|
|
3624
|
+
interface ProcessRequestOptions {
|
|
3625
|
+
dataDir?: string;
|
|
3626
|
+
}
|
|
3627
|
+
declare function processRequest(processUrl: string, method: string, pathWithQuery: string, headers: Record<string, string>, body?: string, options?: ProcessRequestOptions): Response;
|
|
3628
|
+
declare function resetCache(): void;
|
|
3629
|
+
|
|
3630
|
+
export { type AcceptEquityRoundRequest, type AcceptRoundRequest, AccountType, type AddFounderRequest, type AddFounderResponse, type AddSecurityRequest, type AgendaItemResponse, AgendaItemStatus, AgendaItemType, type AgentResponse, AgentStatus, AntiDilutionMethod, type ApiRecord, type ApplyEquityRoundTermsRequest, type ApplyRoundTermsRequest, AssigneeType, type AttachResolutionDocumentRequest, AuthoritySource, AuthorityTier, BankAccountStatus, BankAccountType, type BoardApproveEquityRoundRequest, type BoardApproveRoundRequest, BodyStatus, BodyType, CapTableAccess, CapTableBasis, type CapTableHolderSummary, type CapTableInstrument, type CapTableInstrumentSummary, type CapTableResponse, type CastVoteRequest, ClassificationResult, type ComputeResolutionRequest, ContactCategory, type ContactProfileResponse, type ContactResponse, ContactStatus, ContactType, ContractStatus, ContractTemplateType, ControlType, type ConveneMeetingRequest, type ConvertEntityRequest, CorpAPIClient, type CorpConfig, type CreateAgentRequest, type CreateContactRequest, type CreateEquityRoundRequest, type CreateExecutionIntentRequest, type CreateFormationRequest, type CreatePendingFormationRequest, type CreateRoundRequest, Currency, DeadlineSeverity, DeadlineStatus, type DigestSummary, type DigestTriggerResponse, type DissolveEntityRequest, DistributionStatus, DistributionType, DocumentRequestStatus, type DocumentResponse, DocumentStatus, type DocumentSummary, DocumentType, EntityType, type EquityRoundResponse, EquityRoundStatus, EscalationStatus, type ExecuteRoundConversionRequest, type FinalizeAgendaItemRequest, type FormationGatesResponse, type FormationResponse, FormationState, FormationStatus, type FormationStatusResponse, type FormationWithCapTableResponse, GENERATED_TOOL_DEFINITIONS, GlAccountCode, GovernanceAuditEventType, type GovernanceBodyResponse, GovernanceMode, type GovernanceSeatResponse, GovernanceTriggerSource, GovernanceTriggerType, GoverningDocType, GrantType, HolderType, HttpMethod, IncidentSeverity, IncidentStatus, InstrumentKind, InstrumentStatus, type IntentResponse, IntentStatus, InvestorType, type InvoiceResponse, InvoiceStatus, type IssueStagedRoundResponse, JournalEntryStatus, type LLMResponse, LegalEntityRole, type MeetingResponse, MeetingStatus, MeetingType, MemberRole, NetworkEgress, type ObligationResponse, ObligationStatus, type ObligationsSummaryResponse, OfficerTitle, PaymentMethod, PaymentStatus, PayrollStatus, type PendingFormationResponse, PositionStatus, type PreviewRoundConversionRequest, type ProcessRequestOptions, QuorumStatus, QuorumThreshold, READ_ONLY_TOOLS, ReceiptStatus, ReconciliationStatus, Recurrence, ReferenceKind, type ResolutionResponse, ResolutionType, RiskLevel, type RoundResponse, SYSTEM_PROMPT_BASE, SafeStatus, SafeType, type ScheduleMeetingRequest, Scope, SeatRole, SeatStatus, SessionExpiredError, Side, type StartStagedRoundRequest, TOOL_DEFINITIONS, TOOL_REGISTRY, TaxFilingStatus, type ToolCall, type ToolContext, TransactionPacketStatus, TransferStatus, TransferType, TransfereeRights, Transport, type UpdateAgentRequest, type UpdateContactRequest, ValuationMethodology, ValuationStatus, ValuationType, type VoteResponse, VoteValue, VotingMethod, WorkItemActorTypeValue, WorkItemStatus, WorkflowType, type WorkspaceContactSummary, type WorkspaceEntitySummary, type WorkspaceStatusResponse, type WrittenConsentRequest, type WrittenConsentResponse, describeToolCall, ensureEnvFile, ensureSafeInstrument, executeTool, formatConfigSection, generateFernetKey, generateSecret, isWriteTool, loadEnvFile, processRequest, provisionWorkspace, resetCache, resolveBinaryPath };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,239 @@
|
|
|
1
|
+
// src/process-transport.ts
|
|
2
|
+
import { execFileSync } from "child_process";
|
|
3
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
4
|
+
import { resolve, join } from "path";
|
|
5
|
+
import { homedir } from "os";
|
|
6
|
+
import { createRequire } from "module";
|
|
7
|
+
|
|
8
|
+
// src/env.ts
|
|
9
|
+
import { readFileSync, writeFileSync, existsSync } from "fs";
|
|
10
|
+
import { randomBytes } from "crypto";
|
|
11
|
+
var ENV_TEMPLATE = `# Corporation API server configuration
|
|
12
|
+
# Generated by: corp serve
|
|
13
|
+
|
|
14
|
+
# Required \u2014 secret for signing JWTs
|
|
15
|
+
JWT_SECRET={{JWT_SECRET}}
|
|
16
|
+
|
|
17
|
+
# Required \u2014 Fernet key for encrypting secrets at rest (base64url, 32 bytes)
|
|
18
|
+
SECRETS_MASTER_KEY={{SECRETS_MASTER_KEY}}
|
|
19
|
+
|
|
20
|
+
# Required \u2014 bearer token for internal worker-to-server auth
|
|
21
|
+
INTERNAL_WORKER_TOKEN={{INTERNAL_WORKER_TOKEN}}
|
|
22
|
+
|
|
23
|
+
# Server port (default: 8000)
|
|
24
|
+
# PORT=8000
|
|
25
|
+
|
|
26
|
+
# Data directory for git repos (default: ./data/repos)
|
|
27
|
+
# DATA_DIR=./data/repos
|
|
28
|
+
|
|
29
|
+
# Redis URL for agent job queue (optional)
|
|
30
|
+
# REDIS_URL=redis://localhost:6379/0
|
|
31
|
+
|
|
32
|
+
# LLM proxy upstream (default: https://openrouter.ai/api/v1)
|
|
33
|
+
# LLM_UPSTREAM_URL=https://openrouter.ai/api/v1
|
|
34
|
+
|
|
35
|
+
# PEM-encoded Ed25519 key for signing git commits (optional)
|
|
36
|
+
# COMMIT_SIGNING_KEY=
|
|
37
|
+
|
|
38
|
+
# Max agent queue depth (default: 1000)
|
|
39
|
+
# MAX_QUEUE_DEPTH=1000
|
|
40
|
+
`;
|
|
41
|
+
function generateFernetKey() {
|
|
42
|
+
return randomBytes(32).toString("base64url") + "=";
|
|
43
|
+
}
|
|
44
|
+
function generateSecret(length = 32) {
|
|
45
|
+
return randomBytes(length).toString("hex");
|
|
46
|
+
}
|
|
47
|
+
function loadEnvFile(path) {
|
|
48
|
+
if (!existsSync(path)) return;
|
|
49
|
+
const content = readFileSync(path, "utf-8");
|
|
50
|
+
for (const line of content.split("\n")) {
|
|
51
|
+
const trimmed = line.trim();
|
|
52
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
53
|
+
const eqIdx = trimmed.indexOf("=");
|
|
54
|
+
if (eqIdx === -1) continue;
|
|
55
|
+
const key = trimmed.slice(0, eqIdx).trim();
|
|
56
|
+
const value = trimmed.slice(eqIdx + 1).trim().replace(/^["']|["']$/g, "");
|
|
57
|
+
if (!process.env[key]) {
|
|
58
|
+
process.env[key] = value;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function ensureEnvFile(envPath) {
|
|
63
|
+
if (existsSync(envPath)) return;
|
|
64
|
+
console.log("No .env file found. Generating one with dev defaults...\n");
|
|
65
|
+
const content = ENV_TEMPLATE.replace("{{JWT_SECRET}}", generateSecret()).replace("{{SECRETS_MASTER_KEY}}", generateFernetKey()).replace("{{INTERNAL_WORKER_TOKEN}}", generateSecret());
|
|
66
|
+
writeFileSync(envPath, content, "utf-8");
|
|
67
|
+
console.log(` Created ${envPath}
|
|
68
|
+
`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// src/process-transport.ts
|
|
72
|
+
var require2 = createRequire(import.meta.url);
|
|
73
|
+
var cachedBinaryPath;
|
|
74
|
+
function resolveBinaryPath(processUrl) {
|
|
75
|
+
if (cachedBinaryPath !== void 0) return cachedBinaryPath;
|
|
76
|
+
const parsed = new URL(processUrl);
|
|
77
|
+
if (parsed.pathname && parsed.pathname !== "/") {
|
|
78
|
+
cachedBinaryPath = parsed.pathname;
|
|
79
|
+
return cachedBinaryPath;
|
|
80
|
+
}
|
|
81
|
+
const envBin = process.env.CORP_SERVER_BIN;
|
|
82
|
+
if (envBin && existsSync2(envBin)) {
|
|
83
|
+
cachedBinaryPath = envBin;
|
|
84
|
+
return cachedBinaryPath;
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
const server = require2("@thecorporation/server");
|
|
88
|
+
const pkgPath = server.getBinaryPath?.();
|
|
89
|
+
if (pkgPath) {
|
|
90
|
+
cachedBinaryPath = pkgPath;
|
|
91
|
+
return pkgPath;
|
|
92
|
+
}
|
|
93
|
+
} catch {
|
|
94
|
+
}
|
|
95
|
+
cachedBinaryPath = resolve("services/api-rs/target/release/api-rs");
|
|
96
|
+
return cachedBinaryPath;
|
|
97
|
+
}
|
|
98
|
+
function parseStatusFromStderr(stderr) {
|
|
99
|
+
const lines = stderr.split("\n");
|
|
100
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
101
|
+
const match = lines[i].match(/^HTTP (\d+)$/);
|
|
102
|
+
if (match) return parseInt(match[1], 10);
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
var STATUS_TEXT = {
|
|
107
|
+
200: "OK",
|
|
108
|
+
201: "Created",
|
|
109
|
+
204: "No Content",
|
|
110
|
+
400: "Bad Request",
|
|
111
|
+
401: "Unauthorized",
|
|
112
|
+
403: "Forbidden",
|
|
113
|
+
404: "Not Found",
|
|
114
|
+
409: "Conflict",
|
|
115
|
+
422: "Unprocessable Entity",
|
|
116
|
+
500: "Internal Server Error"
|
|
117
|
+
};
|
|
118
|
+
function buildProcessResponse(status, body) {
|
|
119
|
+
return {
|
|
120
|
+
status,
|
|
121
|
+
ok: status >= 200 && status < 300,
|
|
122
|
+
statusText: STATUS_TEXT[status] ?? String(status),
|
|
123
|
+
headers: new Headers({ "content-type": "application/json" }),
|
|
124
|
+
json: async () => JSON.parse(body),
|
|
125
|
+
text: async () => body,
|
|
126
|
+
body: null,
|
|
127
|
+
bodyUsed: false,
|
|
128
|
+
redirected: false,
|
|
129
|
+
type: "basic",
|
|
130
|
+
url: "",
|
|
131
|
+
clone: () => buildProcessResponse(status, body),
|
|
132
|
+
arrayBuffer: async () => new TextEncoder().encode(body).buffer,
|
|
133
|
+
blob: async () => new Blob([body]),
|
|
134
|
+
formData: async () => {
|
|
135
|
+
throw new Error("not supported");
|
|
136
|
+
},
|
|
137
|
+
bytes: async () => new TextEncoder().encode(body)
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
var CORP_CONFIG_DIR = process.env.CORP_CONFIG_DIR || join(homedir(), ".corp");
|
|
141
|
+
function readJsonFileSafe(path) {
|
|
142
|
+
try {
|
|
143
|
+
if (!existsSync2(path)) return null;
|
|
144
|
+
return JSON.parse(readFileSync2(path, "utf-8"));
|
|
145
|
+
} catch {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function loadServerSecretsFromAuth() {
|
|
150
|
+
const auth = readJsonFileSafe(join(CORP_CONFIG_DIR, "auth.json"));
|
|
151
|
+
if (!auth) return null;
|
|
152
|
+
const ss = auth.server_secrets;
|
|
153
|
+
if (!ss || typeof ss !== "object") return null;
|
|
154
|
+
const s = ss;
|
|
155
|
+
if (typeof s.jwt_secret === "string" && typeof s.secrets_master_key === "string" && typeof s.internal_worker_token === "string") {
|
|
156
|
+
return { jwt_secret: s.jwt_secret, secrets_master_key: s.secrets_master_key, internal_worker_token: s.internal_worker_token };
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
function loadDataDirFromConfig() {
|
|
161
|
+
const cfg = readJsonFileSafe(join(CORP_CONFIG_DIR, "config.json"));
|
|
162
|
+
if (!cfg) return void 0;
|
|
163
|
+
const dataDir = typeof cfg.data_dir === "string" ? cfg.data_dir : void 0;
|
|
164
|
+
return dataDir || void 0;
|
|
165
|
+
}
|
|
166
|
+
var envLoaded = false;
|
|
167
|
+
function ensureEnv() {
|
|
168
|
+
if (envLoaded) return;
|
|
169
|
+
const secrets = loadServerSecretsFromAuth();
|
|
170
|
+
if (secrets) {
|
|
171
|
+
if (!process.env.JWT_SECRET) process.env.JWT_SECRET = secrets.jwt_secret;
|
|
172
|
+
if (!process.env.SECRETS_MASTER_KEY) process.env.SECRETS_MASTER_KEY = secrets.secrets_master_key;
|
|
173
|
+
if (!process.env.INTERNAL_WORKER_TOKEN) process.env.INTERNAL_WORKER_TOKEN = secrets.internal_worker_token;
|
|
174
|
+
envLoaded = true;
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const envPath = resolve(process.cwd(), ".env");
|
|
178
|
+
ensureEnvFile(envPath);
|
|
179
|
+
loadEnvFile(envPath);
|
|
180
|
+
envLoaded = true;
|
|
181
|
+
}
|
|
182
|
+
function processRequest(processUrl, method, pathWithQuery, headers, body, options) {
|
|
183
|
+
ensureEnv();
|
|
184
|
+
const binPath = resolveBinaryPath(processUrl);
|
|
185
|
+
const args = ["--skip-validation", "call"];
|
|
186
|
+
const dataDir = options?.dataDir ?? loadDataDirFromConfig();
|
|
187
|
+
if (dataDir) {
|
|
188
|
+
args.push("--data-dir", dataDir);
|
|
189
|
+
}
|
|
190
|
+
args.push(method, pathWithQuery);
|
|
191
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
192
|
+
args.push("-H", `${key}: ${value}`);
|
|
193
|
+
}
|
|
194
|
+
if (body) {
|
|
195
|
+
args.push("--stdin");
|
|
196
|
+
}
|
|
197
|
+
try {
|
|
198
|
+
const stdout = execFileSync(binPath, args, {
|
|
199
|
+
input: body ?? void 0,
|
|
200
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
201
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
202
|
+
env: process.env
|
|
203
|
+
});
|
|
204
|
+
return buildProcessResponse(200, stdout.toString("utf-8"));
|
|
205
|
+
} catch (err) {
|
|
206
|
+
const execErr = err;
|
|
207
|
+
if (execErr.stdout === void 0 && execErr.stderr === void 0) {
|
|
208
|
+
throw new Error(
|
|
209
|
+
`No api-rs binary found. Install @thecorporation/server or set CORP_SERVER_BIN.
|
|
210
|
+
Attempted: ${binPath}
|
|
211
|
+
Error: ${execErr.message ?? String(err)}`
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
const stderr = execErr.stderr?.toString("utf-8") ?? "";
|
|
215
|
+
const stdout = execErr.stdout?.toString("utf-8") ?? "";
|
|
216
|
+
const status = parseStatusFromStderr(stderr);
|
|
217
|
+
if (status !== null) {
|
|
218
|
+
return buildProcessResponse(status, stdout);
|
|
219
|
+
}
|
|
220
|
+
const isConfigError = stderr.includes("panic") || stderr.includes("INTERNAL_WORKER_TOKEN") || stderr.includes("JWT_SECRET") || stderr.includes("SECRETS_MASTER_KEY");
|
|
221
|
+
if (isConfigError) {
|
|
222
|
+
throw new Error("Server configuration incomplete. Run 'corp setup' to configure local mode.");
|
|
223
|
+
}
|
|
224
|
+
throw new Error(`api-rs process failed:
|
|
225
|
+
${stderr || stdout || String(err)}`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function resetCache() {
|
|
229
|
+
cachedBinaryPath = void 0;
|
|
230
|
+
envLoaded = false;
|
|
231
|
+
}
|
|
232
|
+
|
|
1
233
|
// src/api-client.ts
|
|
2
234
|
var SessionExpiredError = class extends Error {
|
|
3
|
-
constructor() {
|
|
4
|
-
super("Your API key is no longer valid. Run 'corp setup' to re-authenticate.");
|
|
235
|
+
constructor(detail) {
|
|
236
|
+
super(detail || "Your API key is no longer valid. Run 'corp setup' to re-authenticate.");
|
|
5
237
|
this.name = "SessionExpiredError";
|
|
6
238
|
}
|
|
7
239
|
};
|
|
@@ -42,7 +274,8 @@ async function provisionWorkspace(apiUrl, name) {
|
|
|
42
274
|
});
|
|
43
275
|
if (!resp.ok) {
|
|
44
276
|
const detail = await extractErrorMessage(resp);
|
|
45
|
-
|
|
277
|
+
const prefix = resp.status >= 500 ? "Server error" : resp.status === 404 ? "Not found" : resp.status === 422 ? "Validation error" : `HTTP ${resp.status}`;
|
|
278
|
+
throw new Error(`Provision failed (${prefix}): ${detail}`);
|
|
46
279
|
}
|
|
47
280
|
return resp.json();
|
|
48
281
|
}
|
|
@@ -51,7 +284,7 @@ var CorpAPIClient = class {
|
|
|
51
284
|
apiKey;
|
|
52
285
|
workspaceId;
|
|
53
286
|
constructor(apiUrl, apiKey, workspaceId) {
|
|
54
|
-
this.apiUrl = apiUrl.replace(/\/+$/, "");
|
|
287
|
+
this.apiUrl = apiUrl.startsWith("process://") ? apiUrl : apiUrl.replace(/\/+$/, "");
|
|
55
288
|
this.apiKey = apiKey;
|
|
56
289
|
this.workspaceId = workspaceId;
|
|
57
290
|
}
|
|
@@ -63,20 +296,27 @@ var CorpAPIClient = class {
|
|
|
63
296
|
};
|
|
64
297
|
}
|
|
65
298
|
async request(method, path, body, params) {
|
|
66
|
-
let
|
|
299
|
+
let fullPath = path;
|
|
67
300
|
if (params) {
|
|
68
301
|
const qs = new URLSearchParams(params).toString();
|
|
69
|
-
if (qs)
|
|
302
|
+
if (qs) fullPath += `?${qs}`;
|
|
303
|
+
}
|
|
304
|
+
if (this.apiUrl.startsWith("process://")) {
|
|
305
|
+
const hdrs = this.headers();
|
|
306
|
+
const bodyStr = body !== void 0 ? JSON.stringify(body) : void 0;
|
|
307
|
+
return processRequest(this.apiUrl, method, fullPath, hdrs, bodyStr);
|
|
70
308
|
}
|
|
309
|
+
const url = `${this.apiUrl}${fullPath}`;
|
|
71
310
|
const opts = { method, headers: this.headers() };
|
|
72
311
|
if (body !== void 0) opts.body = JSON.stringify(body);
|
|
73
312
|
return fetch(url, opts);
|
|
74
313
|
}
|
|
75
314
|
async throwIfError(resp) {
|
|
76
|
-
if (resp.status === 401) throw new SessionExpiredError();
|
|
77
315
|
if (!resp.ok) {
|
|
78
316
|
const detail = await extractErrorMessage(resp);
|
|
79
|
-
|
|
317
|
+
if (resp.status === 401) throw new SessionExpiredError(detail);
|
|
318
|
+
const prefix = resp.status >= 500 ? "Server error" : resp.status === 404 ? "Not found" : resp.status === 422 ? "Validation error" : `HTTP ${resp.status}`;
|
|
319
|
+
throw new Error(`${prefix}: ${detail}`);
|
|
80
320
|
}
|
|
81
321
|
}
|
|
82
322
|
async get(path, params) {
|
|
@@ -285,6 +525,27 @@ var CorpAPIClient = class {
|
|
|
285
525
|
writtenConsent(data) {
|
|
286
526
|
return this.post("/v1/meetings/written-consent", data);
|
|
287
527
|
}
|
|
528
|
+
getGovernanceMode(entityId) {
|
|
529
|
+
return this.get("/v1/governance/mode", { entity_id: entityId });
|
|
530
|
+
}
|
|
531
|
+
setGovernanceMode(data) {
|
|
532
|
+
return this.post("/v1/governance/mode", data);
|
|
533
|
+
}
|
|
534
|
+
resignSeat(seatId, entityId) {
|
|
535
|
+
return this.post(`/v1/governance-seats/${pathSegment(seatId)}/resign`, { entity_id: entityId });
|
|
536
|
+
}
|
|
537
|
+
createGovernanceIncident(data) {
|
|
538
|
+
return this.post("/v1/governance/incidents", data);
|
|
539
|
+
}
|
|
540
|
+
listGovernanceIncidents(entityId) {
|
|
541
|
+
return this.get(`/v1/entities/${pathSegment(entityId)}/governance/incidents`);
|
|
542
|
+
}
|
|
543
|
+
resolveGovernanceIncident(incidentId, data) {
|
|
544
|
+
return this.post(`/v1/governance/incidents/${pathSegment(incidentId)}/resolve`, data);
|
|
545
|
+
}
|
|
546
|
+
getGovernanceProfile(entityId) {
|
|
547
|
+
return this.get(`/v1/entities/${pathSegment(entityId)}/governance/profile`);
|
|
548
|
+
}
|
|
288
549
|
listAgendaItems(meetingId, entityId) {
|
|
289
550
|
return this.get(`/v1/meetings/${pathSegment(meetingId)}/agenda-items`, { entity_id: entityId });
|
|
290
551
|
}
|
|
@@ -313,6 +574,11 @@ var CorpAPIClient = class {
|
|
|
313
574
|
return { entity_id: entityId, document_id: documentId };
|
|
314
575
|
}
|
|
315
576
|
getPreviewPdfUrl(entityId, documentId) {
|
|
577
|
+
if (this.apiUrl.startsWith("process://")) {
|
|
578
|
+
throw new Error(
|
|
579
|
+
"PDF preview is not available in local process transport mode.\n Use cloud mode (npx corp setup) or start a local HTTP server (npx corp serve) instead."
|
|
580
|
+
);
|
|
581
|
+
}
|
|
316
582
|
const qs = new URLSearchParams({ entity_id: entityId, document_id: documentId }).toString();
|
|
317
583
|
return `${this.apiUrl}/v1/documents/preview/pdf?${qs}`;
|
|
318
584
|
}
|
|
@@ -347,12 +613,25 @@ var CorpAPIClient = class {
|
|
|
347
613
|
openBankAccount(data) {
|
|
348
614
|
return this.post("/v1/treasury/bank-accounts", data);
|
|
349
615
|
}
|
|
616
|
+
activateBankAccount(bankAccountId, entityId) {
|
|
617
|
+
return this.postWithParams(`/v1/bank-accounts/${pathSegment(bankAccountId)}/activate`, {}, { entity_id: entityId });
|
|
618
|
+
}
|
|
350
619
|
classifyContractor(data) {
|
|
351
620
|
return this.post("/v1/contractors/classify", data);
|
|
352
621
|
}
|
|
353
622
|
reconcileLedger(data) {
|
|
354
623
|
return this.post("/v1/ledger/reconcile", data);
|
|
355
624
|
}
|
|
625
|
+
getFinancialStatements(entityId, params) {
|
|
626
|
+
return this.get("/v1/treasury/financial-statements", { entity_id: entityId, ...params ?? {} });
|
|
627
|
+
}
|
|
628
|
+
// --- Equity analytics ---
|
|
629
|
+
getDilutionPreview(entityId, roundId) {
|
|
630
|
+
return this.get("/v1/equity/dilution/preview", { entity_id: entityId, round_id: roundId });
|
|
631
|
+
}
|
|
632
|
+
getControlMap(entityId, rootEntityId) {
|
|
633
|
+
return this.get("/v1/equity/control-map", { entity_id: entityId, root_entity_id: rootEntityId });
|
|
634
|
+
}
|
|
356
635
|
// --- Tax ---
|
|
357
636
|
listTaxFilings(entityId) {
|
|
358
637
|
return this.get(`/v1/entities/${pathSegment(entityId)}/tax-filings`);
|
|
@@ -483,6 +762,18 @@ var CorpAPIClient = class {
|
|
|
483
762
|
listSupportedModels() {
|
|
484
763
|
return this.get("/v1/models");
|
|
485
764
|
}
|
|
765
|
+
async getAgentExecution(agentId, executionId) {
|
|
766
|
+
return this.get(`/v1/agents/${pathSegment(agentId)}/executions/${pathSegment(executionId)}`);
|
|
767
|
+
}
|
|
768
|
+
async getAgentExecutionResult(agentId, executionId) {
|
|
769
|
+
return this.get(`/v1/agents/${pathSegment(agentId)}/executions/${pathSegment(executionId)}/result`);
|
|
770
|
+
}
|
|
771
|
+
async getAgentExecutionLogs(agentId, executionId) {
|
|
772
|
+
return this.get(`/v1/agents/${pathSegment(agentId)}/executions/${pathSegment(executionId)}/logs`);
|
|
773
|
+
}
|
|
774
|
+
async killAgentExecution(agentId, executionId) {
|
|
775
|
+
return this.post(`/v1/agents/${pathSegment(agentId)}/executions/${pathSegment(executionId)}/kill`, {});
|
|
776
|
+
}
|
|
486
777
|
// --- Governance bodies ---
|
|
487
778
|
createGovernanceBody(data) {
|
|
488
779
|
return this.post("/v1/governance-bodies", data);
|
|
@@ -516,6 +807,15 @@ var CorpAPIClient = class {
|
|
|
516
807
|
listApiKeys() {
|
|
517
808
|
return this.get("/v1/api-keys", { workspace_id: this.workspaceId });
|
|
518
809
|
}
|
|
810
|
+
async createApiKey(data) {
|
|
811
|
+
return this.post("/v1/api-keys", data);
|
|
812
|
+
}
|
|
813
|
+
async revokeApiKey(keyId) {
|
|
814
|
+
return this.del(`/v1/api-keys/${pathSegment(keyId)}`);
|
|
815
|
+
}
|
|
816
|
+
async rotateApiKey(keyId) {
|
|
817
|
+
return this.post(`/v1/api-keys/${pathSegment(keyId)}/rotate`, {});
|
|
818
|
+
}
|
|
519
819
|
// --- Obligations ---
|
|
520
820
|
assignObligation(obligationId, contactId) {
|
|
521
821
|
return this.patch(`/v1/obligations/${pathSegment(obligationId)}/assign`, { contact_id: contactId });
|
|
@@ -524,6 +824,28 @@ var CorpAPIClient = class {
|
|
|
524
824
|
getConfig() {
|
|
525
825
|
return this.get("/v1/config");
|
|
526
826
|
}
|
|
827
|
+
// --- Services ---
|
|
828
|
+
listServiceCatalog() {
|
|
829
|
+
return this.get("/v1/services/catalog");
|
|
830
|
+
}
|
|
831
|
+
createServiceRequest(data) {
|
|
832
|
+
return this.post("/v1/services/requests", data);
|
|
833
|
+
}
|
|
834
|
+
getServiceRequest(id, entityId) {
|
|
835
|
+
return this.get(`/v1/services/requests/${pathSegment(id)}`, { entity_id: entityId });
|
|
836
|
+
}
|
|
837
|
+
listServiceRequests(entityId) {
|
|
838
|
+
return this.get(`/v1/entities/${pathSegment(entityId)}/service-requests`);
|
|
839
|
+
}
|
|
840
|
+
beginServiceCheckout(id, data) {
|
|
841
|
+
return this.post(`/v1/services/requests/${pathSegment(id)}/checkout`, data);
|
|
842
|
+
}
|
|
843
|
+
fulfillServiceRequest(id, data) {
|
|
844
|
+
return this.post(`/v1/services/requests/${pathSegment(id)}/fulfill`, data);
|
|
845
|
+
}
|
|
846
|
+
cancelServiceRequest(id, data) {
|
|
847
|
+
return this.post(`/v1/services/requests/${pathSegment(id)}/cancel`, data);
|
|
848
|
+
}
|
|
527
849
|
// --- Feedback ---
|
|
528
850
|
submitFeedback(message, category, email) {
|
|
529
851
|
return this.post("/v1/feedback", { message, category, email });
|
|
@@ -533,15 +855,17 @@ var CorpAPIClient = class {
|
|
|
533
855
|
const resp = await this.request("POST", "/v1/workspaces/link", { external_id: externalId, provider });
|
|
534
856
|
if (!resp.ok) {
|
|
535
857
|
const detail = await extractErrorMessage(resp);
|
|
536
|
-
|
|
858
|
+
if (resp.status === 401) throw new SessionExpiredError(detail);
|
|
859
|
+
const prefix = resp.status >= 500 ? "Server error" : resp.status === 404 ? "Not found" : resp.status === 422 ? "Validation error" : `HTTP ${resp.status}`;
|
|
860
|
+
throw new Error(`${prefix}: ${detail}`);
|
|
537
861
|
}
|
|
538
862
|
return resp.json();
|
|
539
863
|
}
|
|
540
864
|
};
|
|
541
865
|
|
|
542
866
|
// src/tools.ts
|
|
543
|
-
import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
|
|
544
|
-
import { join } from "path";
|
|
867
|
+
import { readFileSync as readFileSync3, writeFileSync as writeFileSync2, mkdirSync, existsSync as existsSync3 } from "fs";
|
|
868
|
+
import { join as join2 } from "path";
|
|
545
869
|
|
|
546
870
|
// src/tool-defs.generated.ts
|
|
547
871
|
var GENERATED_TOOL_DEFINITIONS = [
|
|
@@ -1472,14 +1796,14 @@ var documentActions = {
|
|
|
1472
1796
|
};
|
|
1473
1797
|
var checklistActions = {
|
|
1474
1798
|
get: async (_args, _client, ctx) => {
|
|
1475
|
-
const path =
|
|
1476
|
-
if (
|
|
1799
|
+
const path = join2(ctx.dataDir, "checklist.md");
|
|
1800
|
+
if (existsSync3(path)) return { checklist: readFileSync3(path, "utf-8") };
|
|
1477
1801
|
return { checklist: null, message: "No checklist yet." };
|
|
1478
1802
|
},
|
|
1479
1803
|
update: async (args, _client, ctx) => {
|
|
1480
|
-
const path =
|
|
1804
|
+
const path = join2(ctx.dataDir, "checklist.md");
|
|
1481
1805
|
mkdirSync(ctx.dataDir, { recursive: true });
|
|
1482
|
-
|
|
1806
|
+
writeFileSync2(path, args.checklist);
|
|
1483
1807
|
return { status: "updated", checklist: args.checklist };
|
|
1484
1808
|
}
|
|
1485
1809
|
};
|
|
@@ -2073,10 +2397,17 @@ export {
|
|
|
2073
2397
|
WorkItemStatus,
|
|
2074
2398
|
WorkflowType,
|
|
2075
2399
|
describeToolCall,
|
|
2400
|
+
ensureEnvFile,
|
|
2076
2401
|
ensureSafeInstrument,
|
|
2077
2402
|
executeTool,
|
|
2078
2403
|
formatConfigSection,
|
|
2404
|
+
generateFernetKey,
|
|
2405
|
+
generateSecret,
|
|
2079
2406
|
isWriteTool,
|
|
2080
|
-
|
|
2407
|
+
loadEnvFile,
|
|
2408
|
+
processRequest,
|
|
2409
|
+
provisionWorkspace,
|
|
2410
|
+
resetCache,
|
|
2411
|
+
resolveBinaryPath
|
|
2081
2412
|
};
|
|
2082
2413
|
//# sourceMappingURL=index.js.map
|