skedyul 1.7.8 → 1.7.11
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/.build-stamp +1 -1
- package/dist/cli/index.js +164 -69
- package/dist/config/types/batch-operation.d.ts +77 -6
- package/dist/dedicated/server.js +164 -69
- package/dist/esm/index.mjs +185 -69
- package/dist/index.d.ts +1 -1
- package/dist/index.js +187 -69
- package/dist/schemas.d.ts +37 -0
- package/dist/server/route-handlers/handlers.d.ts +2 -2
- package/dist/server.js +164 -69
- package/dist/serverless/server.mjs +164 -69
- package/dist/types/batch-operation.d.ts +6 -3
- package/dist/types/index.d.ts +1 -1
- package/dist/types/invocation.d.ts +16 -1
- package/package.json +2 -2
package/dist/dedicated/server.js
CHANGED
|
@@ -1988,6 +1988,39 @@ async function handleMcpBatchRoute(req, ctx) {
|
|
|
1988
1988
|
}
|
|
1989
1989
|
};
|
|
1990
1990
|
}
|
|
1991
|
+
function isBatchOperationFailure(result) {
|
|
1992
|
+
return result != null && typeof result === "object" && result.success === false && typeof result.error === "object" && result.error != null;
|
|
1993
|
+
}
|
|
1994
|
+
function toStringEnv(env) {
|
|
1995
|
+
const out = {};
|
|
1996
|
+
for (const [key, value] of Object.entries(env)) {
|
|
1997
|
+
if (value !== void 0) {
|
|
1998
|
+
out[key] = value;
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
return out;
|
|
2002
|
+
}
|
|
2003
|
+
function stripBillingFields(result) {
|
|
2004
|
+
const {
|
|
2005
|
+
billing: _billing,
|
|
2006
|
+
success: _success,
|
|
2007
|
+
error: _error,
|
|
2008
|
+
retry: _retry,
|
|
2009
|
+
...domain
|
|
2010
|
+
} = result;
|
|
2011
|
+
return domain;
|
|
2012
|
+
}
|
|
2013
|
+
function softFailureResponse(error, retry, billing) {
|
|
2014
|
+
return {
|
|
2015
|
+
status: 200,
|
|
2016
|
+
body: {
|
|
2017
|
+
success: false,
|
|
2018
|
+
error,
|
|
2019
|
+
...retry ? { retry } : {},
|
|
2020
|
+
billing: normalizeBilling(billing)
|
|
2021
|
+
}
|
|
2022
|
+
};
|
|
2023
|
+
}
|
|
1991
2024
|
async function handleBatchOperationRoute(req, ctx) {
|
|
1992
2025
|
const bodyResult = parseJsonBody(req);
|
|
1993
2026
|
if (!bodyResult.success) {
|
|
@@ -1996,49 +2029,80 @@ async function handleBatchOperationRoute(req, ctx) {
|
|
|
1996
2029
|
const body = bodyResult.data;
|
|
1997
2030
|
const registry = ctx.batchOperationRegistry;
|
|
1998
2031
|
if (!registry) {
|
|
1999
|
-
return {
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
}
|
|
2005
|
-
};
|
|
2032
|
+
return softFailureResponse({
|
|
2033
|
+
code: "NOT_FOUND",
|
|
2034
|
+
message: "No batch operations registered",
|
|
2035
|
+
category: "validation"
|
|
2036
|
+
});
|
|
2006
2037
|
}
|
|
2007
2038
|
const operation = registry[body.handle];
|
|
2008
2039
|
if (!operation) {
|
|
2009
|
-
return {
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
}
|
|
2015
|
-
};
|
|
2040
|
+
return softFailureResponse({
|
|
2041
|
+
code: "NOT_FOUND",
|
|
2042
|
+
message: `Batch operation not found: ${body.handle}`,
|
|
2043
|
+
category: "validation"
|
|
2044
|
+
});
|
|
2016
2045
|
}
|
|
2017
2046
|
const context = body.context;
|
|
2018
2047
|
if (!context?.workplaceId || !context?.appInstallationId || !context?.appId) {
|
|
2019
|
-
return {
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
}
|
|
2025
|
-
};
|
|
2048
|
+
return softFailureResponse({
|
|
2049
|
+
code: "VALIDATION_ERROR",
|
|
2050
|
+
message: "Missing context (workplaceId, appInstallationId, and appId required)",
|
|
2051
|
+
category: "validation"
|
|
2052
|
+
});
|
|
2026
2053
|
}
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2054
|
+
if (body.method !== "setup" && body.method !== "iterate") {
|
|
2055
|
+
return softFailureResponse({
|
|
2056
|
+
code: "VALIDATION_ERROR",
|
|
2057
|
+
message: `Unknown method: ${body.method}`,
|
|
2058
|
+
category: "validation"
|
|
2059
|
+
});
|
|
2060
|
+
}
|
|
2061
|
+
const requestEnv = body.env ?? {};
|
|
2062
|
+
const mergedEnv = toStringEnv(buildToolExecutionEnv(requestEnv));
|
|
2063
|
+
const originalEnv = { ...process.env };
|
|
2064
|
+
Object.assign(process.env, mergedEnv);
|
|
2065
|
+
const log = createContextLogger();
|
|
2066
|
+
const app = context.app ?? {
|
|
2067
|
+
id: context.appId,
|
|
2068
|
+
versionId: context.appId
|
|
2069
|
+
};
|
|
2070
|
+
const workplace = context.workplace ?? {
|
|
2071
|
+
id: context.workplaceId,
|
|
2072
|
+
subdomain: ""
|
|
2073
|
+
};
|
|
2074
|
+
const invocation = body.invocation ?? {
|
|
2075
|
+
invocationId: `${body.handle}-${body.method}-${Date.now()}`,
|
|
2076
|
+
invocationType: "batch_operation",
|
|
2077
|
+
batchOperationHandle: body.handle,
|
|
2078
|
+
batchOperationMethod: body.method,
|
|
2079
|
+
appInstallationId: context.appInstallationId
|
|
2038
2080
|
};
|
|
2039
2081
|
const requestConfig = {
|
|
2040
|
-
baseUrl:
|
|
2041
|
-
apiToken:
|
|
2082
|
+
baseUrl: mergedEnv.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
|
|
2083
|
+
apiToken: mergedEnv.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
|
|
2084
|
+
};
|
|
2085
|
+
const rateLimitContext = {
|
|
2086
|
+
app,
|
|
2087
|
+
appInstallationId: context.appInstallationId,
|
|
2088
|
+
invocation,
|
|
2089
|
+
preAcquiredLeases: parsePreAcquiredLeases(
|
|
2090
|
+
mergedEnv.SKEDYUL_RATE_LIMIT_LEASES
|
|
2091
|
+
),
|
|
2092
|
+
heldMutexQueueKeys: parseHeldMutexQueueKeys(
|
|
2093
|
+
mergedEnv.SKEDYUL_HELD_MUTEX_QUEUE_KEYS
|
|
2094
|
+
)
|
|
2095
|
+
};
|
|
2096
|
+
const opContextBase = {
|
|
2097
|
+
workplaceId: context.workplaceId,
|
|
2098
|
+
appInstallationId: context.appInstallationId,
|
|
2099
|
+
appId: context.appId,
|
|
2100
|
+
app,
|
|
2101
|
+
workplace,
|
|
2102
|
+
input: body.input,
|
|
2103
|
+
env: mergedEnv,
|
|
2104
|
+
invocation,
|
|
2105
|
+
log
|
|
2042
2106
|
};
|
|
2043
2107
|
try {
|
|
2044
2108
|
if (body.method === "setup") {
|
|
@@ -2047,67 +2111,98 @@ async function handleBatchOperationRoute(req, ctx) {
|
|
|
2047
2111
|
status: 200,
|
|
2048
2112
|
body: {
|
|
2049
2113
|
success: true,
|
|
2050
|
-
result: {
|
|
2114
|
+
result: {
|
|
2115
|
+
state: {},
|
|
2116
|
+
total: void 0,
|
|
2117
|
+
cascade: operation.cascade
|
|
2118
|
+
},
|
|
2119
|
+
billing: normalizeBilling(void 0)
|
|
2051
2120
|
}
|
|
2052
2121
|
};
|
|
2053
2122
|
}
|
|
2054
|
-
const
|
|
2055
|
-
return
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
input: body.input,
|
|
2060
|
-
env,
|
|
2061
|
-
log
|
|
2123
|
+
const raw2 = await runWithConfig(requestConfig, async () => {
|
|
2124
|
+
return runWithRateLimitExecutionContext(rateLimitContext, async () => {
|
|
2125
|
+
return runWithLogContext({ invocation }, async () => {
|
|
2126
|
+
return operation.setup(opContextBase);
|
|
2127
|
+
});
|
|
2062
2128
|
});
|
|
2063
2129
|
});
|
|
2130
|
+
if (isBatchOperationFailure(raw2)) {
|
|
2131
|
+
return softFailureResponse(raw2.error, raw2.retry, raw2.billing);
|
|
2132
|
+
}
|
|
2133
|
+
const setupResult = raw2;
|
|
2134
|
+
const domain2 = stripBillingFields(
|
|
2135
|
+
setupResult
|
|
2136
|
+
);
|
|
2064
2137
|
return {
|
|
2065
2138
|
status: 200,
|
|
2066
2139
|
body: {
|
|
2067
2140
|
success: true,
|
|
2068
|
-
result
|
|
2141
|
+
result: {
|
|
2142
|
+
...domain2,
|
|
2143
|
+
// Expose definition cascade to the platform workflow
|
|
2144
|
+
cascade: operation.cascade ?? domain2.cascade
|
|
2145
|
+
},
|
|
2146
|
+
billing: normalizeBilling(setupResult.billing)
|
|
2069
2147
|
}
|
|
2070
2148
|
};
|
|
2071
2149
|
}
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
log
|
|
2150
|
+
const iterateBody = body;
|
|
2151
|
+
const raw = await runWithConfig(requestConfig, async () => {
|
|
2152
|
+
return runWithRateLimitExecutionContext(rateLimitContext, async () => {
|
|
2153
|
+
return runWithLogContext({ invocation }, async () => {
|
|
2154
|
+
return operation.iterate({
|
|
2155
|
+
...opContextBase,
|
|
2156
|
+
state: iterateBody.state,
|
|
2157
|
+
page: iterateBody.page,
|
|
2158
|
+
cursor: iterateBody.cursor,
|
|
2159
|
+
limit: iterateBody.limit,
|
|
2160
|
+
cascadeEntities: iterateBody.cascadeEntities
|
|
2161
|
+
});
|
|
2085
2162
|
});
|
|
2086
2163
|
});
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
success: true,
|
|
2091
|
-
result
|
|
2092
|
-
}
|
|
2093
|
-
};
|
|
2164
|
+
});
|
|
2165
|
+
if (isBatchOperationFailure(raw)) {
|
|
2166
|
+
return softFailureResponse(raw.error, raw.retry, raw.billing);
|
|
2094
2167
|
}
|
|
2168
|
+
const iterateResult = raw;
|
|
2169
|
+
const domain = stripBillingFields(
|
|
2170
|
+
iterateResult
|
|
2171
|
+
);
|
|
2095
2172
|
return {
|
|
2096
|
-
status:
|
|
2173
|
+
status: 200,
|
|
2097
2174
|
body: {
|
|
2098
|
-
success:
|
|
2099
|
-
|
|
2175
|
+
success: true,
|
|
2176
|
+
result: domain,
|
|
2177
|
+
billing: normalizeBilling(iterateResult.billing)
|
|
2100
2178
|
}
|
|
2101
2179
|
};
|
|
2102
2180
|
} catch (err) {
|
|
2103
|
-
|
|
2181
|
+
if (err instanceof RateLimitExceededError) {
|
|
2182
|
+
return softFailureResponse(
|
|
2183
|
+
{
|
|
2184
|
+
code: "RATE_LIMITED",
|
|
2185
|
+
message: err.message,
|
|
2186
|
+
category: "external"
|
|
2187
|
+
},
|
|
2188
|
+
{ allowed: true, afterMs: err.retryAfterMs }
|
|
2189
|
+
);
|
|
2190
|
+
}
|
|
2191
|
+
log.error("Batch operation failed", err);
|
|
2104
2192
|
return {
|
|
2105
2193
|
status: 500,
|
|
2106
2194
|
body: {
|
|
2107
2195
|
success: false,
|
|
2108
|
-
error:
|
|
2196
|
+
error: {
|
|
2197
|
+
code: "INTERNAL_ERROR",
|
|
2198
|
+
message: err instanceof Error ? err.message : String(err),
|
|
2199
|
+
category: "internal"
|
|
2200
|
+
},
|
|
2201
|
+
billing: normalizeBilling(void 0)
|
|
2109
2202
|
}
|
|
2110
2203
|
};
|
|
2204
|
+
} finally {
|
|
2205
|
+
process.env = originalEnv;
|
|
2111
2206
|
}
|
|
2112
2207
|
}
|
|
2113
2208
|
function createNotFoundResponse() {
|
package/dist/esm/index.mjs
CHANGED
|
@@ -41,6 +41,17 @@ function createWorkflowStepContext(params) {
|
|
|
41
41
|
workflowStepId: params.workflowStepId
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
|
+
function createBatchOperationContext(params) {
|
|
45
|
+
return {
|
|
46
|
+
invocationId: params.invocationId,
|
|
47
|
+
invocationType: "batch_operation",
|
|
48
|
+
batchOperationHandle: params.batchOperationHandle,
|
|
49
|
+
batchOperationMethod: params.batchOperationMethod,
|
|
50
|
+
appInstallationId: params.appInstallationId,
|
|
51
|
+
workflowId: params.workflowId,
|
|
52
|
+
workflowRunId: params.workflowRunId
|
|
53
|
+
};
|
|
54
|
+
}
|
|
44
55
|
|
|
45
56
|
// src/types/tool-context.ts
|
|
46
57
|
function isProvisionContext(ctx) {
|
|
@@ -1912,8 +1923,15 @@ var BatchOperationSetupResultSchema = z8.object({
|
|
|
1912
1923
|
state: z8.record(z8.string(), z8.unknown()).optional(),
|
|
1913
1924
|
total: z8.number().int().nonnegative().optional()
|
|
1914
1925
|
});
|
|
1926
|
+
var BatchCascadePhaseSchema = z8.object({
|
|
1927
|
+
entity: z8.string(),
|
|
1928
|
+
order: z8.number().int(),
|
|
1929
|
+
wave: z8.enum(["setup", "page"]),
|
|
1930
|
+
requires: z8.array(z8.string()).optional()
|
|
1931
|
+
});
|
|
1915
1932
|
var BatchOperationIterateResultSchema = z8.object({
|
|
1916
1933
|
items: z8.array(z8.record(z8.string(), z8.unknown())),
|
|
1934
|
+
itemsByEntity: z8.record(z8.string(), z8.array(z8.record(z8.string(), z8.unknown()))).optional(),
|
|
1917
1935
|
pagination: BatchPaginationSchema,
|
|
1918
1936
|
state: z8.record(z8.string(), z8.unknown()).optional()
|
|
1919
1937
|
});
|
|
@@ -1922,6 +1940,7 @@ var BatchOperationDefinitionSchema = z8.object({
|
|
|
1922
1940
|
label: z8.string(),
|
|
1923
1941
|
description: z8.string().optional(),
|
|
1924
1942
|
entity: z8.string(),
|
|
1943
|
+
cascade: z8.array(BatchCascadePhaseSchema).optional(),
|
|
1925
1944
|
maxConcurrent: z8.number().int().positive().optional(),
|
|
1926
1945
|
pageSize: z8.number().int().positive().optional(),
|
|
1927
1946
|
icon: z8.string().optional()
|
|
@@ -5464,6 +5483,39 @@ async function handleMcpBatchRoute(req, ctx) {
|
|
|
5464
5483
|
}
|
|
5465
5484
|
};
|
|
5466
5485
|
}
|
|
5486
|
+
function isBatchOperationFailure(result) {
|
|
5487
|
+
return result != null && typeof result === "object" && result.success === false && typeof result.error === "object" && result.error != null;
|
|
5488
|
+
}
|
|
5489
|
+
function toStringEnv(env) {
|
|
5490
|
+
const out = {};
|
|
5491
|
+
for (const [key, value] of Object.entries(env)) {
|
|
5492
|
+
if (value !== void 0) {
|
|
5493
|
+
out[key] = value;
|
|
5494
|
+
}
|
|
5495
|
+
}
|
|
5496
|
+
return out;
|
|
5497
|
+
}
|
|
5498
|
+
function stripBillingFields(result) {
|
|
5499
|
+
const {
|
|
5500
|
+
billing: _billing,
|
|
5501
|
+
success: _success,
|
|
5502
|
+
error: _error,
|
|
5503
|
+
retry: _retry,
|
|
5504
|
+
...domain
|
|
5505
|
+
} = result;
|
|
5506
|
+
return domain;
|
|
5507
|
+
}
|
|
5508
|
+
function softFailureResponse(error, retry, billing) {
|
|
5509
|
+
return {
|
|
5510
|
+
status: 200,
|
|
5511
|
+
body: {
|
|
5512
|
+
success: false,
|
|
5513
|
+
error,
|
|
5514
|
+
...retry ? { retry } : {},
|
|
5515
|
+
billing: normalizeBilling(billing)
|
|
5516
|
+
}
|
|
5517
|
+
};
|
|
5518
|
+
}
|
|
5467
5519
|
async function handleBatchOperationRoute(req, ctx) {
|
|
5468
5520
|
const bodyResult = parseJsonBody(req);
|
|
5469
5521
|
if (!bodyResult.success) {
|
|
@@ -5472,49 +5524,80 @@ async function handleBatchOperationRoute(req, ctx) {
|
|
|
5472
5524
|
const body = bodyResult.data;
|
|
5473
5525
|
const registry = ctx.batchOperationRegistry;
|
|
5474
5526
|
if (!registry) {
|
|
5475
|
-
return {
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
|
|
5480
|
-
}
|
|
5481
|
-
};
|
|
5527
|
+
return softFailureResponse({
|
|
5528
|
+
code: "NOT_FOUND",
|
|
5529
|
+
message: "No batch operations registered",
|
|
5530
|
+
category: "validation"
|
|
5531
|
+
});
|
|
5482
5532
|
}
|
|
5483
5533
|
const operation = registry[body.handle];
|
|
5484
5534
|
if (!operation) {
|
|
5485
|
-
return {
|
|
5486
|
-
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
}
|
|
5491
|
-
};
|
|
5535
|
+
return softFailureResponse({
|
|
5536
|
+
code: "NOT_FOUND",
|
|
5537
|
+
message: `Batch operation not found: ${body.handle}`,
|
|
5538
|
+
category: "validation"
|
|
5539
|
+
});
|
|
5492
5540
|
}
|
|
5493
5541
|
const context = body.context;
|
|
5494
5542
|
if (!context?.workplaceId || !context?.appInstallationId || !context?.appId) {
|
|
5495
|
-
return {
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
}
|
|
5501
|
-
};
|
|
5543
|
+
return softFailureResponse({
|
|
5544
|
+
code: "VALIDATION_ERROR",
|
|
5545
|
+
message: "Missing context (workplaceId, appInstallationId, and appId required)",
|
|
5546
|
+
category: "validation"
|
|
5547
|
+
});
|
|
5502
5548
|
}
|
|
5503
|
-
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
|
|
5511
|
-
|
|
5512
|
-
|
|
5513
|
-
|
|
5549
|
+
if (body.method !== "setup" && body.method !== "iterate") {
|
|
5550
|
+
return softFailureResponse({
|
|
5551
|
+
code: "VALIDATION_ERROR",
|
|
5552
|
+
message: `Unknown method: ${body.method}`,
|
|
5553
|
+
category: "validation"
|
|
5554
|
+
});
|
|
5555
|
+
}
|
|
5556
|
+
const requestEnv = body.env ?? {};
|
|
5557
|
+
const mergedEnv = toStringEnv(buildToolExecutionEnv(requestEnv));
|
|
5558
|
+
const originalEnv = { ...process.env };
|
|
5559
|
+
Object.assign(process.env, mergedEnv);
|
|
5560
|
+
const log = createContextLogger();
|
|
5561
|
+
const app = context.app ?? {
|
|
5562
|
+
id: context.appId,
|
|
5563
|
+
versionId: context.appId
|
|
5564
|
+
};
|
|
5565
|
+
const workplace2 = context.workplace ?? {
|
|
5566
|
+
id: context.workplaceId,
|
|
5567
|
+
subdomain: ""
|
|
5568
|
+
};
|
|
5569
|
+
const invocation = body.invocation ?? {
|
|
5570
|
+
invocationId: `${body.handle}-${body.method}-${Date.now()}`,
|
|
5571
|
+
invocationType: "batch_operation",
|
|
5572
|
+
batchOperationHandle: body.handle,
|
|
5573
|
+
batchOperationMethod: body.method,
|
|
5574
|
+
appInstallationId: context.appInstallationId
|
|
5514
5575
|
};
|
|
5515
5576
|
const requestConfig = {
|
|
5516
|
-
baseUrl:
|
|
5517
|
-
apiToken:
|
|
5577
|
+
baseUrl: mergedEnv.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
|
|
5578
|
+
apiToken: mergedEnv.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
|
|
5579
|
+
};
|
|
5580
|
+
const rateLimitContext = {
|
|
5581
|
+
app,
|
|
5582
|
+
appInstallationId: context.appInstallationId,
|
|
5583
|
+
invocation,
|
|
5584
|
+
preAcquiredLeases: parsePreAcquiredLeases(
|
|
5585
|
+
mergedEnv.SKEDYUL_RATE_LIMIT_LEASES
|
|
5586
|
+
),
|
|
5587
|
+
heldMutexQueueKeys: parseHeldMutexQueueKeys(
|
|
5588
|
+
mergedEnv.SKEDYUL_HELD_MUTEX_QUEUE_KEYS
|
|
5589
|
+
)
|
|
5590
|
+
};
|
|
5591
|
+
const opContextBase = {
|
|
5592
|
+
workplaceId: context.workplaceId,
|
|
5593
|
+
appInstallationId: context.appInstallationId,
|
|
5594
|
+
appId: context.appId,
|
|
5595
|
+
app,
|
|
5596
|
+
workplace: workplace2,
|
|
5597
|
+
input: body.input,
|
|
5598
|
+
env: mergedEnv,
|
|
5599
|
+
invocation,
|
|
5600
|
+
log
|
|
5518
5601
|
};
|
|
5519
5602
|
try {
|
|
5520
5603
|
if (body.method === "setup") {
|
|
@@ -5523,67 +5606,98 @@ async function handleBatchOperationRoute(req, ctx) {
|
|
|
5523
5606
|
status: 200,
|
|
5524
5607
|
body: {
|
|
5525
5608
|
success: true,
|
|
5526
|
-
result: {
|
|
5609
|
+
result: {
|
|
5610
|
+
state: {},
|
|
5611
|
+
total: void 0,
|
|
5612
|
+
cascade: operation.cascade
|
|
5613
|
+
},
|
|
5614
|
+
billing: normalizeBilling(void 0)
|
|
5527
5615
|
}
|
|
5528
5616
|
};
|
|
5529
5617
|
}
|
|
5530
|
-
const
|
|
5531
|
-
return
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
|
|
5535
|
-
input: body.input,
|
|
5536
|
-
env,
|
|
5537
|
-
log
|
|
5618
|
+
const raw2 = await runWithConfig(requestConfig, async () => {
|
|
5619
|
+
return runWithRateLimitExecutionContext(rateLimitContext, async () => {
|
|
5620
|
+
return runWithLogContext({ invocation }, async () => {
|
|
5621
|
+
return operation.setup(opContextBase);
|
|
5622
|
+
});
|
|
5538
5623
|
});
|
|
5539
5624
|
});
|
|
5625
|
+
if (isBatchOperationFailure(raw2)) {
|
|
5626
|
+
return softFailureResponse(raw2.error, raw2.retry, raw2.billing);
|
|
5627
|
+
}
|
|
5628
|
+
const setupResult = raw2;
|
|
5629
|
+
const domain2 = stripBillingFields(
|
|
5630
|
+
setupResult
|
|
5631
|
+
);
|
|
5540
5632
|
return {
|
|
5541
5633
|
status: 200,
|
|
5542
5634
|
body: {
|
|
5543
5635
|
success: true,
|
|
5544
|
-
result
|
|
5636
|
+
result: {
|
|
5637
|
+
...domain2,
|
|
5638
|
+
// Expose definition cascade to the platform workflow
|
|
5639
|
+
cascade: operation.cascade ?? domain2.cascade
|
|
5640
|
+
},
|
|
5641
|
+
billing: normalizeBilling(setupResult.billing)
|
|
5545
5642
|
}
|
|
5546
5643
|
};
|
|
5547
5644
|
}
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
|
|
5551
|
-
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
log
|
|
5645
|
+
const iterateBody = body;
|
|
5646
|
+
const raw = await runWithConfig(requestConfig, async () => {
|
|
5647
|
+
return runWithRateLimitExecutionContext(rateLimitContext, async () => {
|
|
5648
|
+
return runWithLogContext({ invocation }, async () => {
|
|
5649
|
+
return operation.iterate({
|
|
5650
|
+
...opContextBase,
|
|
5651
|
+
state: iterateBody.state,
|
|
5652
|
+
page: iterateBody.page,
|
|
5653
|
+
cursor: iterateBody.cursor,
|
|
5654
|
+
limit: iterateBody.limit,
|
|
5655
|
+
cascadeEntities: iterateBody.cascadeEntities
|
|
5656
|
+
});
|
|
5561
5657
|
});
|
|
5562
5658
|
});
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
success: true,
|
|
5567
|
-
result
|
|
5568
|
-
}
|
|
5569
|
-
};
|
|
5659
|
+
});
|
|
5660
|
+
if (isBatchOperationFailure(raw)) {
|
|
5661
|
+
return softFailureResponse(raw.error, raw.retry, raw.billing);
|
|
5570
5662
|
}
|
|
5663
|
+
const iterateResult = raw;
|
|
5664
|
+
const domain = stripBillingFields(
|
|
5665
|
+
iterateResult
|
|
5666
|
+
);
|
|
5571
5667
|
return {
|
|
5572
|
-
status:
|
|
5668
|
+
status: 200,
|
|
5573
5669
|
body: {
|
|
5574
|
-
success:
|
|
5575
|
-
|
|
5670
|
+
success: true,
|
|
5671
|
+
result: domain,
|
|
5672
|
+
billing: normalizeBilling(iterateResult.billing)
|
|
5576
5673
|
}
|
|
5577
5674
|
};
|
|
5578
5675
|
} catch (err) {
|
|
5579
|
-
|
|
5676
|
+
if (err instanceof RateLimitExceededError) {
|
|
5677
|
+
return softFailureResponse(
|
|
5678
|
+
{
|
|
5679
|
+
code: "RATE_LIMITED",
|
|
5680
|
+
message: err.message,
|
|
5681
|
+
category: "external"
|
|
5682
|
+
},
|
|
5683
|
+
{ allowed: true, afterMs: err.retryAfterMs }
|
|
5684
|
+
);
|
|
5685
|
+
}
|
|
5686
|
+
log.error("Batch operation failed", err);
|
|
5580
5687
|
return {
|
|
5581
5688
|
status: 500,
|
|
5582
5689
|
body: {
|
|
5583
5690
|
success: false,
|
|
5584
|
-
error:
|
|
5691
|
+
error: {
|
|
5692
|
+
code: "INTERNAL_ERROR",
|
|
5693
|
+
message: err instanceof Error ? err.message : String(err),
|
|
5694
|
+
category: "internal"
|
|
5695
|
+
},
|
|
5696
|
+
billing: normalizeBilling(void 0)
|
|
5585
5697
|
}
|
|
5586
5698
|
};
|
|
5699
|
+
} finally {
|
|
5700
|
+
process.env = originalEnv;
|
|
5587
5701
|
}
|
|
5588
5702
|
}
|
|
5589
5703
|
function createNotFoundResponse() {
|
|
@@ -8582,6 +8696,7 @@ export {
|
|
|
8582
8696
|
AssociationSchema,
|
|
8583
8697
|
AuthenticationError,
|
|
8584
8698
|
BaseEventPayloadSchema,
|
|
8699
|
+
BatchCascadePhaseSchema,
|
|
8585
8700
|
BatchOperationDefinitionSchema,
|
|
8586
8701
|
BatchOperationIterateResultSchema,
|
|
8587
8702
|
BatchOperationSetupResultSchema,
|
|
@@ -8813,6 +8928,7 @@ export {
|
|
|
8813
8928
|
computeSkewedExpectedMinorUnits,
|
|
8814
8929
|
configure,
|
|
8815
8930
|
createAuthError,
|
|
8931
|
+
createBatchOperationContext,
|
|
8816
8932
|
createConflictError,
|
|
8817
8933
|
createContextLogger,
|
|
8818
8934
|
createErrorResponse,
|
package/dist/index.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export type { CRMContext, SenderContext, ThreadContextItem, ThreadInfo, SandboxC
|
|
|
35
35
|
export { MemoryEntryTypeSchema, MemoryEntrySchema, WorkingMemoryConfigSchema, SemanticMemoryConfigSchema, ExternalMemoryConfigSchema, MemoryConfigSchema, MemoryScopeSchema, MemoryQueryOptionsSchema, ConversationSummarySchema, AgentObservationSchema, ExternalDataCacheSchema, MemoryService, InMemoryStore, createInMemoryService, } from './memory';
|
|
36
36
|
export type { MemoryEntryType, MemoryEntry, WorkingMemoryConfig as MemoryWorkingConfig, SemanticMemoryConfig as MemorySemanticConfig, ExternalMemoryConfig as MemoryExternalConfig, MemoryConfig, MemoryScope, MemoryQueryOptions, ConversationSummary, AgentObservation, ExternalDataCache, MemoryStore, } from './memory';
|
|
37
37
|
export type { CRMFieldType, CRMFieldRequirement, CRMFieldOption, CRMFieldDefinition, CRMFieldSchema, CRMModelSchema, CRMCardinality, CRMOnDelete, CRMRelationshipLink, CRMRelationshipSchema, CRMSchema, CRMSchemaValidationResult, } from './schemas';
|
|
38
|
-
export type { SkedyulConfig, SerializableSkedyulConfig, InstallConfig, ProvisionConfig, BaseDefinition, Scope, FieldOwner, Visibility, ComputeLayer, StructuredFilter, FilterOperator, FilterCondition, FieldOption, EnvVariable, EnvSchema, FieldType, Cardinality, OnDelete, InlineFieldDefinition, FieldVisibility, FieldDefinition, ModelDefinition, RelationshipLink, RelationshipDefinition, CapabilityType, ChannelCapability, ChannelBatchCapability, ChannelFieldPermissions, ChannelField, ChannelDefinition, WorkflowActionInput, WorkflowAction, WorkflowDefinition, AgentDefinition, NavigationItem, NavigationSection, NavigationSidebar, BreadcrumbItem, NavigationBreadcrumb, NavigationConfig, ContextMode, ContextItemModel, ContextItemTool, ContextItem, ContextDefinition, FormStyleProps, ButtonVariant, ButtonSize, ButtonProps, RelationshipExtension, FormHeader, FormActionDefinition, ActionDefinition, ModalFormDefinition, InputComponent, TextareaComponent, SelectComponent, ComboboxComponent, CheckboxComponent, DatePickerComponent, TimePickerComponent, StatusIndicator, FieldSettingComponent, ImageSettingComponent, FileSettingComponent, ListItemTemplate, ListComponent, EmptyFormComponent, AlertComponent, FormComponent, FormLayoutColumn, FormLayoutRow, FormLayoutConfig, FormProps, CardHeader, CardBlock, ListBlock, BlockDefinition, SetupStepDefinition, SetupStepKind, PageType, PageDefinition, HttpMethod, WebhookRequest, WebhookHandlerContext, WebhookHandlerResponse, WebhookHandlerFn, WebhookHandlerDefinition, Webhooks, WebhookHandlerMetadata, ModelDependency, ChannelDependency, WorkflowDependency, ResourceDependency, } from './config';
|
|
38
|
+
export type { SkedyulConfig, SerializableSkedyulConfig, InstallConfig, ProvisionConfig, BaseDefinition, Scope, FieldOwner, Visibility, ComputeLayer, StructuredFilter, FilterOperator, FilterCondition, FieldOption, EnvVariable, EnvSchema, FieldType, Cardinality, OnDelete, InlineFieldDefinition, FieldVisibility, FieldDefinition, ModelDefinition, RelationshipLink, RelationshipDefinition, CapabilityType, ChannelCapability, ChannelBatchCapability, ChannelFieldPermissions, ChannelField, ChannelDefinition, WorkflowActionInput, WorkflowAction, WorkflowDefinition, AgentDefinition, NavigationItem, NavigationSection, NavigationSidebar, BreadcrumbItem, NavigationBreadcrumb, NavigationConfig, ContextMode, ContextItemModel, ContextItemTool, ContextItem, ContextDefinition, FormStyleProps, ButtonVariant, ButtonSize, ButtonProps, RelationshipExtension, FormHeader, FormActionDefinition, ActionDefinition, ModalFormDefinition, InputComponent, TextareaComponent, SelectComponent, ComboboxComponent, CheckboxComponent, DatePickerComponent, TimePickerComponent, StatusIndicator, FieldSettingComponent, ImageSettingComponent, FileSettingComponent, ListItemTemplate, ListComponent, EmptyFormComponent, AlertComponent, FormComponent, FormLayoutColumn, FormLayoutRow, FormLayoutConfig, FormProps, CardHeader, CardBlock, ListBlock, BlockDefinition, SetupStepDefinition, SetupStepKind, BatchCascadePhase, BatchOperationDefinition, BatchOperationContext, BatchOperationIterateResult, BatchOperationSetupResult, PageType, PageDefinition, HttpMethod, WebhookRequest, WebhookHandlerContext, WebhookHandlerResponse, WebhookHandlerFn, WebhookHandlerDefinition, Webhooks, WebhookHandlerMetadata, ModelDependency, ChannelDependency, WorkflowDependency, ResourceDependency, } from './config';
|
|
39
39
|
export { compileAgent, compileWorkflow } from './compiler';
|
|
40
40
|
export type { ValidationError, ValidationWarning, ResolvedPersona, ResolvedTool, EventConfig as CompilerEventConfig, IRMemoryConfig, PolicyConfig, IRRuntimeConfig, AgentIR, WorkflowStepIR, WorkflowIR, CompilationResult, } from './compiler';
|
|
41
41
|
export { TimeStampSchema, DayOfWeekSchema, TimeWindowSlotSchema, WaitUnitSchema, WaitInputRelativeSchema, WaitInputAbsoluteSchema, WaitInputSchema, } from './scheduling/types';
|