@granular-software/sdk 0.4.19 → 0.4.20
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/README.md +10 -0
- package/dist/agent-evals.d.mts +1 -1
- package/dist/agent-evals.d.ts +1 -1
- package/dist/agent-evals.js +116 -17
- package/dist/agent-evals.js.map +1 -1
- package/dist/agent-evals.mjs +116 -17
- package/dist/agent-evals.mjs.map +1 -1
- package/dist/cli/index.js +114 -14
- package/dist/{client-BQw_gUK3.d.mts → client-DWYdWpS-.d.mts} +61 -5
- package/dist/{client-BQw_gUK3.d.ts → client-DWYdWpS-.d.ts} +61 -5
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +110 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +110 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -8941,7 +8941,7 @@ function manifestGuideEndToEndSection() {
|
|
|
8941
8941
|
| 2 | \`granular build\` | Manifest **uploaded**; ontology version created or reused; build run compiles it; errors surface here |
|
|
8942
8942
|
| 3 | (Optional) Run your **effects host** \u2014 e.g. \`npx tsx granular-effects.ts\` \u2014 calling \`registerEffects(sandboxId, \u2026)\` | Effect **handlers** attached in **your** process |
|
|
8943
8943
|
| 4 | \`new Granular({ apiKey })\` then \`connect({ ontology, environment, userId, permissions })\` | **\`Environment\`** for that ontology environment slot |
|
|
8944
|
-
| 5 | \`recordObject\` / \`recordObjects\` | **Records** stored with correct fields and relationship keys |
|
|
8944
|
+
| 5 | \`recordObject\` / \`recordObjects\` | **Records** stored with correct fields and relationship keys. \`recordObjects\` chunks to the control plane (default 100 rows/request); pass \`onChunkComplete\` / \`concurrency\` for UI progress. For async bulk loads use \`enqueueRecordImport\` + import status APIs. |
|
|
8945
8945
|
| 6 | \`submitJob(\`\u2026\`)\` with imports from \`./sandbox-tools\` | **Jobs** run; may call **effects** \u2192 your handlers execute and return results |
|
|
8946
8946
|
|
|
8947
8947
|
**Accuracy tip:** After changing the manifest, always **re-build** before assuming generated types, \`./sandbox-tools\` names, or effect signatures match the file on disk.`;
|
|
@@ -14961,8 +14961,8 @@ ${effectMetamodelTable}
|
|
|
14961
14961
|
|-----|---------|
|
|
14962
14962
|
| \`environmentId\`, \`sandboxId\`, \`apiEndpoint\`, \u2026 | Session context. |
|
|
14963
14963
|
| \`applyManifest(manifest)\` | Apply manifest operations at runtime (alternative to CLI build for dynamic ontologies). |
|
|
14964
|
-
| \`recordObject\` / \`recordObjects\` | Upsert instances and relationships. |
|
|
14965
|
-
| \`enqueueRecordImport\`, \`listRecordImports\`, \`getRecordImportSummary\`, \u2026 |
|
|
14964
|
+
| \`recordObject\` / \`recordObjects\` | Upsert instances and relationships. \`recordObjects\` uses chunked HTTP batch writes (default 100 rows/chunk); optional \`onChunkComplete\`, \`batchSize\`, \`concurrency\`. |
|
|
14965
|
+
| \`enqueueRecordImport\`, \`listRecordImports\`, \`getRecordImportSummary\`, \u2026 | **Async** bulk import (worker queue + aggregate progress). Prefer when loads are huge and fire-and-forget is OK. |
|
|
14966
14966
|
| \`graphql(query, variables?)\` | **GraphQL** \u2014 see dedicated subsection below. |
|
|
14967
14967
|
| \`defineRelationship\`, \`getRelationships\`, \`attach\`, \`detach\`, \`listRelated\` | Imperative relationship operations (same ideas as manifest \`defineRelationship\`). |
|
|
14968
14968
|
| \`submitJob(code)\` | Run code in the sandbox; import from \`./sandbox-tools\`. |
|
|
@@ -15502,6 +15502,7 @@ edit granular.json -> granular build -> granular document -> run tests -> option
|
|
|
15502
15502
|
|
|
15503
15503
|
- Default auth story: \`granular login\`. Manual \`.env.local\` editing is fallback guidance only.
|
|
15504
15504
|
- Read \`GRANULAR_SANDBOX.md\` before writing \`recordObject\` payloads or relationship keys.
|
|
15505
|
+
- Large ingests: use \`recordObjects(rows, { onChunkComplete, concurrency })\` for synchronous chunked writes with progress, or \`enqueueRecordImport\` + \`getRecordImport\` for async queue-based bulk loads.
|
|
15505
15506
|
- Build failures should be mapped to the exact class, relationship, or effect declaration that caused them.
|
|
15506
15507
|
- If the user starts from the control plane UI, converge back to the same repo state and the same CLI commands.
|
|
15507
15508
|
`
|
|
@@ -18867,6 +18868,28 @@ var STANDARD_MODULES_OPERATIONS = [
|
|
|
18867
18868
|
var BUILTIN_MODULES = {
|
|
18868
18869
|
"standard_modules": STANDARD_MODULES_OPERATIONS
|
|
18869
18870
|
};
|
|
18871
|
+
var DEFAULT_DIRECT_RECORD_OBJECTS_REQUEST_BATCH_SIZE = 100;
|
|
18872
|
+
var MAX_RECORD_OBJECTS_CONCURRENCY = 16;
|
|
18873
|
+
var DEFAULT_DIRECT_RECORD_OBJECTS_RETRY_COUNT = 3;
|
|
18874
|
+
var DEFAULT_DIRECT_RECORD_OBJECTS_RETRY_DELAY_MS = 1e3;
|
|
18875
|
+
function planRecordObjectsChunks(records, batchSize) {
|
|
18876
|
+
const total = records.length;
|
|
18877
|
+
const size = Math.max(1, Math.min(batchSize, total));
|
|
18878
|
+
const chunkCount = Math.ceil(total / size);
|
|
18879
|
+
const plans = [];
|
|
18880
|
+
for (let offset = 0, chunkIndex = 0; offset < total; offset += size, chunkIndex += 1) {
|
|
18881
|
+
const slice = records.slice(offset, offset + size);
|
|
18882
|
+
plans.push({ chunkIndex, chunkCount, offset, slice });
|
|
18883
|
+
}
|
|
18884
|
+
return plans;
|
|
18885
|
+
}
|
|
18886
|
+
function sleep(ms) {
|
|
18887
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
18888
|
+
}
|
|
18889
|
+
function isRetryableRecordObjectsError(error2) {
|
|
18890
|
+
const message = error2 instanceof Error ? error2.message : String(error2);
|
|
18891
|
+
return /worker restarted mid-request|econnreset|network|socket connection was closed unexpectedly|timed out/i.test(message);
|
|
18892
|
+
}
|
|
18870
18893
|
function computeEffectKey2(effect) {
|
|
18871
18894
|
const attachedClass = effect.className?.trim();
|
|
18872
18895
|
if (!attachedClass) {
|
|
@@ -19824,24 +19847,101 @@ var Environment = class extends Session {
|
|
|
19824
19847
|
/**
|
|
19825
19848
|
* Batch version of `recordObject()`.
|
|
19826
19849
|
*
|
|
19827
|
-
* Sends
|
|
19828
|
-
*
|
|
19850
|
+
* Sends rows through the control-plane **`/records/batch`** endpoint in **chunks** (default
|
|
19851
|
+
* **100** records per HTTP request) so individual requests stay bounded and gateway timeouts are
|
|
19852
|
+
* unlikely. Each chunk is retried on transient network / worker errors.
|
|
19853
|
+
*
|
|
19854
|
+
* Use the optional second argument to:
|
|
19855
|
+
* - **`batchSize`** — rows per POST (smaller = more progress events; larger = fewer round trips).
|
|
19856
|
+
* - **`concurrency`** — run up to N chunk POSTs in parallel (capped at 16) when you want lower wall time.
|
|
19857
|
+
* - **`onChunkComplete`** — hook for UIs after each chunk succeeds (row order in the returned array
|
|
19858
|
+
* always matches `records`; chunk **completion** order may differ when `concurrency > 1`).
|
|
19859
|
+
*
|
|
19860
|
+
* For **asynchronous** ingestion with worker-side batching and aggregate counters (`queued`,
|
|
19861
|
+
* `completed`, …), use **`enqueueRecordImport`** and poll **`getRecordImport`** /
|
|
19862
|
+
* **`getRecordImportSummary`** — best for very large fire-and-forget loads when immediate
|
|
19863
|
+
* synchronous commit of every row is not required.
|
|
19829
19864
|
*/
|
|
19830
|
-
async recordObjects(records) {
|
|
19865
|
+
async recordObjects(records, options) {
|
|
19831
19866
|
if (!Array.isArray(records) || records.length === 0) {
|
|
19832
19867
|
return [];
|
|
19833
19868
|
}
|
|
19834
|
-
const
|
|
19835
|
-
|
|
19836
|
-
|
|
19837
|
-
|
|
19838
|
-
|
|
19839
|
-
|
|
19869
|
+
const batchSize = Math.max(
|
|
19870
|
+
1,
|
|
19871
|
+
Math.min(
|
|
19872
|
+
records.length,
|
|
19873
|
+
options?.batchSize ?? DEFAULT_DIRECT_RECORD_OBJECTS_REQUEST_BATCH_SIZE
|
|
19874
|
+
)
|
|
19840
19875
|
);
|
|
19841
|
-
|
|
19876
|
+
const concurrency = Math.min(
|
|
19877
|
+
MAX_RECORD_OBJECTS_CONCURRENCY,
|
|
19878
|
+
Math.max(1, options?.concurrency ?? 1)
|
|
19879
|
+
);
|
|
19880
|
+
const plans = planRecordObjectsChunks(records, batchSize);
|
|
19881
|
+
const total = records.length;
|
|
19882
|
+
const results = new Array(total);
|
|
19883
|
+
const onChunk = options?.onChunkComplete;
|
|
19884
|
+
for (let waveStart = 0; waveStart < plans.length; waveStart += concurrency) {
|
|
19885
|
+
const wave = plans.slice(waveStart, waveStart + concurrency);
|
|
19886
|
+
await Promise.all(
|
|
19887
|
+
wave.map(async (plan) => {
|
|
19888
|
+
const { items, durationMs } = await this.executeRecordObjectsChunk(plan.slice);
|
|
19889
|
+
if (items.length !== plan.slice.length) {
|
|
19890
|
+
throw new Error(
|
|
19891
|
+
`recordObjects: chunk ${plan.chunkIndex + 1} returned ${items.length} results, expected ${plan.slice.length}`
|
|
19892
|
+
);
|
|
19893
|
+
}
|
|
19894
|
+
for (let index = 0; index < items.length; index += 1) {
|
|
19895
|
+
results[plan.offset + index] = items[index];
|
|
19896
|
+
}
|
|
19897
|
+
if (onChunk) {
|
|
19898
|
+
const info2 = {
|
|
19899
|
+
chunkIndex: plan.chunkIndex,
|
|
19900
|
+
totalChunks: plan.chunkCount,
|
|
19901
|
+
offset: plan.offset,
|
|
19902
|
+
recordCount: plan.slice.length,
|
|
19903
|
+
durationMs,
|
|
19904
|
+
results: items
|
|
19905
|
+
};
|
|
19906
|
+
await onChunk(info2);
|
|
19907
|
+
}
|
|
19908
|
+
})
|
|
19909
|
+
);
|
|
19910
|
+
}
|
|
19911
|
+
return results;
|
|
19912
|
+
}
|
|
19913
|
+
async executeRecordObjectsChunk(chunk) {
|
|
19914
|
+
const wallStart = Date.now();
|
|
19915
|
+
let lastError;
|
|
19916
|
+
for (let attempt = 1; attempt <= DEFAULT_DIRECT_RECORD_OBJECTS_RETRY_COUNT; attempt += 1) {
|
|
19917
|
+
try {
|
|
19918
|
+
const response = await this.controlPlaneRequest(
|
|
19919
|
+
`/control/environments/${this.environmentId}/records/batch`,
|
|
19920
|
+
{
|
|
19921
|
+
method: "POST",
|
|
19922
|
+
body: JSON.stringify({ records: chunk })
|
|
19923
|
+
}
|
|
19924
|
+
);
|
|
19925
|
+
const items = Array.isArray(response.items) ? response.items : [];
|
|
19926
|
+
return { items, durationMs: Date.now() - wallStart };
|
|
19927
|
+
} catch (error2) {
|
|
19928
|
+
lastError = error2;
|
|
19929
|
+
if (!isRetryableRecordObjectsError(error2) || attempt === DEFAULT_DIRECT_RECORD_OBJECTS_RETRY_COUNT) {
|
|
19930
|
+
throw error2;
|
|
19931
|
+
}
|
|
19932
|
+
await sleep(DEFAULT_DIRECT_RECORD_OBJECTS_RETRY_DELAY_MS * attempt);
|
|
19933
|
+
}
|
|
19934
|
+
}
|
|
19935
|
+
throw lastError instanceof Error ? lastError : new Error(String(lastError));
|
|
19842
19936
|
}
|
|
19843
19937
|
/**
|
|
19844
|
-
* Queue a background record import for this environment.
|
|
19938
|
+
* Queue a background record import for this environment (async worker pipeline).
|
|
19939
|
+
*
|
|
19940
|
+
* **vs `recordObjects`:** this path accepts the full payload in one request, returns an
|
|
19941
|
+
* **`importId`**, and processes rows in the background — use **`getRecordImport`** /
|
|
19942
|
+
* **`getRecordImportSummary`** for progress. Choose it for large bulk loads where you do not
|
|
19943
|
+
* need every row committed before the HTTP call returns. Use **`recordObjects`** when you need
|
|
19944
|
+
* synchronous upserts and fine-grained chunk progress via **`onChunkComplete`**.
|
|
19845
19945
|
*/
|
|
19846
19946
|
async enqueueRecordImport(records, options = {}) {
|
|
19847
19947
|
return this.controlPlaneRequest(
|
|
@@ -862,6 +862,43 @@ interface RecordObjectResult {
|
|
|
862
862
|
/** Whether the instance was newly created (false = updated) */
|
|
863
863
|
created: boolean;
|
|
864
864
|
}
|
|
865
|
+
/**
|
|
866
|
+
* Metadata for one completed HTTP chunk in `recordObjects()`.
|
|
867
|
+
* Chunk indices follow input order; when concurrency is greater than 1, completion order may differ.
|
|
868
|
+
*/
|
|
869
|
+
interface RecordObjectsChunkInfo {
|
|
870
|
+
/** Zero-based chunk index */
|
|
871
|
+
chunkIndex: number;
|
|
872
|
+
totalChunks: number;
|
|
873
|
+
/** Zero-based offset into the original `records` array */
|
|
874
|
+
offset: number;
|
|
875
|
+
/** Number of records in this chunk */
|
|
876
|
+
recordCount: number;
|
|
877
|
+
/** Wall time for this chunk’s POST (including retries) */
|
|
878
|
+
durationMs: number;
|
|
879
|
+
/** Acknowledgements for this chunk, in the same order as the slice sent */
|
|
880
|
+
results: RecordObjectResult[];
|
|
881
|
+
}
|
|
882
|
+
/**
|
|
883
|
+
* Optional tuning for `recordObjects()` — batching, parallelism, and progress hooks.
|
|
884
|
+
*/
|
|
885
|
+
interface RecordObjectsOptions {
|
|
886
|
+
/**
|
|
887
|
+
* Max records per HTTP POST to the control-plane batch endpoint. Default 100.
|
|
888
|
+
* Smaller values: more round trips and finer `onChunkComplete` updates.
|
|
889
|
+
* Larger values: fewer requests (watch request size/timeouts).
|
|
890
|
+
*/
|
|
891
|
+
batchSize?: number;
|
|
892
|
+
/**
|
|
893
|
+
* How many chunk POSTs may run concurrently. Default 1 (strictly sequential).
|
|
894
|
+
* Values above 1 can reduce wall time when the server can overlap work; capped at 16.
|
|
895
|
+
*/
|
|
896
|
+
concurrency?: number;
|
|
897
|
+
/**
|
|
898
|
+
* Called after each chunk succeeds (after retries). Useful for UI progress bars.
|
|
899
|
+
*/
|
|
900
|
+
onChunkComplete?: (info: RecordObjectsChunkInfo) => void | Promise<void>;
|
|
901
|
+
}
|
|
865
902
|
type RecordImportStatus = 'queued' | 'processing' | 'completed' | 'failed' | 'canceled';
|
|
866
903
|
type RecordImportItemStatus = 'queued' | 'processing' | 'completed' | 'failed' | 'canceled';
|
|
867
904
|
interface RecordImportStats {
|
|
@@ -1682,12 +1719,31 @@ declare class Environment extends Session {
|
|
|
1682
1719
|
/**
|
|
1683
1720
|
* Batch version of `recordObject()`.
|
|
1684
1721
|
*
|
|
1685
|
-
* Sends
|
|
1686
|
-
*
|
|
1722
|
+
* Sends rows through the control-plane **`/records/batch`** endpoint in **chunks** (default
|
|
1723
|
+
* **100** records per HTTP request) so individual requests stay bounded and gateway timeouts are
|
|
1724
|
+
* unlikely. Each chunk is retried on transient network / worker errors.
|
|
1725
|
+
*
|
|
1726
|
+
* Use the optional second argument to:
|
|
1727
|
+
* - **`batchSize`** — rows per POST (smaller = more progress events; larger = fewer round trips).
|
|
1728
|
+
* - **`concurrency`** — run up to N chunk POSTs in parallel (capped at 16) when you want lower wall time.
|
|
1729
|
+
* - **`onChunkComplete`** — hook for UIs after each chunk succeeds (row order in the returned array
|
|
1730
|
+
* always matches `records`; chunk **completion** order may differ when `concurrency > 1`).
|
|
1731
|
+
*
|
|
1732
|
+
* For **asynchronous** ingestion with worker-side batching and aggregate counters (`queued`,
|
|
1733
|
+
* `completed`, …), use **`enqueueRecordImport`** and poll **`getRecordImport`** /
|
|
1734
|
+
* **`getRecordImportSummary`** — best for very large fire-and-forget loads when immediate
|
|
1735
|
+
* synchronous commit of every row is not required.
|
|
1687
1736
|
*/
|
|
1688
|
-
recordObjects(records: RecordObjectOptions[]): Promise<RecordObjectResult[]>;
|
|
1737
|
+
recordObjects(records: RecordObjectOptions[], options?: RecordObjectsOptions): Promise<RecordObjectResult[]>;
|
|
1738
|
+
private executeRecordObjectsChunk;
|
|
1689
1739
|
/**
|
|
1690
|
-
* Queue a background record import for this environment.
|
|
1740
|
+
* Queue a background record import for this environment (async worker pipeline).
|
|
1741
|
+
*
|
|
1742
|
+
* **vs `recordObjects`:** this path accepts the full payload in one request, returns an
|
|
1743
|
+
* **`importId`**, and processes rows in the background — use **`getRecordImport`** /
|
|
1744
|
+
* **`getRecordImportSummary`** for progress. Choose it for large bulk loads where you do not
|
|
1745
|
+
* need every row committed before the HTTP call returns. Use **`recordObjects`** when you need
|
|
1746
|
+
* synchronous upserts and fine-grained chunk progress via **`onChunkComplete`**.
|
|
1691
1747
|
*/
|
|
1692
1748
|
enqueueRecordImport(records: RecordObjectOptions[], options?: {
|
|
1693
1749
|
batchSize?: number;
|
|
@@ -1992,4 +2048,4 @@ declare class Granular {
|
|
|
1992
2048
|
private request;
|
|
1993
2049
|
}
|
|
1994
2050
|
|
|
1995
|
-
export { type EffectInvocationMode as $, type AccessTokenProvider as A, type BuildPolicy as B, type ConnectOptions as C, type DomainState as D, type EffectHandlerContext as E, type Manifest as F, Granular as G, type ManifestListResponse as H, type InstanceToolHandler as I, type BuildStatus as J, type Build as K, type Version as L, type ManifestEffectMetamodelSpec as M, type BuildListResponse as N, type SemanticVersionDiffEntry as O, type Prompt as P, type SemanticVersionDiff as Q, type ResolvedEffectBehaviors as R, type SessionHeapEntry as S, type ToolWithHandler as T, type User as U, type VersionTracking as V, WSClient as W, type ResolvedEffectPostCondition as X, type ResolvedEffectDryRun as Y, type ResolvedEffectReverse as Z, type ResolvedEffectApprovalRequired as _, type SessionHeapList as a, type
|
|
2051
|
+
export { type EffectInvocationMode as $, type AccessTokenProvider as A, type BuildPolicy as B, type ConnectOptions as C, type DomainState as D, type EffectHandlerContext as E, type Manifest as F, Granular as G, type ManifestListResponse as H, type InstanceToolHandler as I, type BuildStatus as J, type Build as K, type Version as L, type ManifestEffectMetamodelSpec as M, type BuildListResponse as N, type SemanticVersionDiffEntry as O, type Prompt as P, type SemanticVersionDiff as Q, type ResolvedEffectBehaviors as R, type SessionHeapEntry as S, type ToolWithHandler as T, type User as U, type VersionTracking as V, WSClient as W, type ResolvedEffectPostCondition as X, type ResolvedEffectDryRun as Y, type ResolvedEffectReverse as Z, type ResolvedEffectApprovalRequired as _, type SessionHeapList as a, type ManifestContent as a$, type EffectInvocationMetadata as a0, type EffectSchema as a1, type EffectWithHandler as a2, type PublishEffectsResult as a3, type ToolInfo as a4, type EffectInfo as a5, type ToolsChangedEvent as a6, type EffectsChangedEvent as a7, type EffectHandler as a8, type InstanceEffectHandler as a9, type RecordObjectsOptions as aA, type RecordImportStatus as aB, type RecordImportItemStatus as aC, type RecordImportStats as aD, type RecordImportItem as aE, type RecordImport as aF, type EnvironmentRecordImportSummary as aG, type ManifestPropertySpec as aH, type ManifestValidationOperator as aI, type ManifestEnumRuleSpec as aJ, type ManifestFilterBySpec as aK, type ManifestValidationRuleSpec as aL, type ManifestStateMachineStateSpec as aM, type ManifestStateMachineTransitionSpec as aN, type ManifestStateMachineSpec as aO, type ManifestPostConditionSpec as aP, type ManifestDryRunSpec as aQ, type ManifestReverseSpec as aR, type ManifestApprovalRequiredSpec as aS, type ManifestRelationshipDef as aT, type ManifestEffectSchema as aU, type ManifestEffectDeclaration as aV, type ManifestEventTypeDef as aW, type ManifestEventStreamDef as aX, type ManifestOperation as aY, type ManifestImport as aZ, type ManifestVolume as a_, type JobStatus as aa, type JobFeedbackSentiment as ab, type JobFeedbackToolCall as ac, type JobFeedbackMetadata as ad, type JobFeedbackInput as ae, type JobFeedbackRecord as af, type JobSubmitResult as ag, type Job as ah, type SessionHeapFieldType as ai, type SessionHeapFieldValue as aj, type SessionHeapVariable as ak, type WSDisconnectInfo as al, type WSReconnectErrorInfo as am, type WSClientOptions as an, type RPCRequest as ao, type RPCResponse as ap, type SyncMessage as aq, type RPCRequestFromServer as ar, type ToolInvokeParams as as, type ToolResultParams as at, type ModelRef as au, type RelationshipInfo as av, type DefineRelationshipOptions as aw, type RecordObjectOptions as ax, type RecordObjectResult as ay, type RecordObjectsChunkInfo as az, type SessionHeapSnapshot as b, type GraphQLResult as b0, type APIError as b1, type DeleteResponse as b2, type StreamEvent as b3, type StreamSubscription as b4, type StreamStats as b5, Environment as c, Session as d, type ToolSchema as e, type PublishToolsResult as f, type ToolHandler as g, type EndpointMode as h, type GranularOptions as i, type GranularAuth as j, type RecordUserOptions as k, type Subject as l, type ConversationSessionInfo as m, type Sandbox as n, type CreateSandboxData as o, type SandboxListResponse as p, type PermissionRules as q, type PermissionProfile as r, type CreatePermissionProfileData as s, type PermissionProfileListResponse as t, type Assignment as u, type AssignmentListResponse as v, type VersionTag as w, type EnvironmentData as x, type CreateEnvironmentData as y, type EnvironmentListResponse as z };
|
|
@@ -862,6 +862,43 @@ interface RecordObjectResult {
|
|
|
862
862
|
/** Whether the instance was newly created (false = updated) */
|
|
863
863
|
created: boolean;
|
|
864
864
|
}
|
|
865
|
+
/**
|
|
866
|
+
* Metadata for one completed HTTP chunk in `recordObjects()`.
|
|
867
|
+
* Chunk indices follow input order; when concurrency is greater than 1, completion order may differ.
|
|
868
|
+
*/
|
|
869
|
+
interface RecordObjectsChunkInfo {
|
|
870
|
+
/** Zero-based chunk index */
|
|
871
|
+
chunkIndex: number;
|
|
872
|
+
totalChunks: number;
|
|
873
|
+
/** Zero-based offset into the original `records` array */
|
|
874
|
+
offset: number;
|
|
875
|
+
/** Number of records in this chunk */
|
|
876
|
+
recordCount: number;
|
|
877
|
+
/** Wall time for this chunk’s POST (including retries) */
|
|
878
|
+
durationMs: number;
|
|
879
|
+
/** Acknowledgements for this chunk, in the same order as the slice sent */
|
|
880
|
+
results: RecordObjectResult[];
|
|
881
|
+
}
|
|
882
|
+
/**
|
|
883
|
+
* Optional tuning for `recordObjects()` — batching, parallelism, and progress hooks.
|
|
884
|
+
*/
|
|
885
|
+
interface RecordObjectsOptions {
|
|
886
|
+
/**
|
|
887
|
+
* Max records per HTTP POST to the control-plane batch endpoint. Default 100.
|
|
888
|
+
* Smaller values: more round trips and finer `onChunkComplete` updates.
|
|
889
|
+
* Larger values: fewer requests (watch request size/timeouts).
|
|
890
|
+
*/
|
|
891
|
+
batchSize?: number;
|
|
892
|
+
/**
|
|
893
|
+
* How many chunk POSTs may run concurrently. Default 1 (strictly sequential).
|
|
894
|
+
* Values above 1 can reduce wall time when the server can overlap work; capped at 16.
|
|
895
|
+
*/
|
|
896
|
+
concurrency?: number;
|
|
897
|
+
/**
|
|
898
|
+
* Called after each chunk succeeds (after retries). Useful for UI progress bars.
|
|
899
|
+
*/
|
|
900
|
+
onChunkComplete?: (info: RecordObjectsChunkInfo) => void | Promise<void>;
|
|
901
|
+
}
|
|
865
902
|
type RecordImportStatus = 'queued' | 'processing' | 'completed' | 'failed' | 'canceled';
|
|
866
903
|
type RecordImportItemStatus = 'queued' | 'processing' | 'completed' | 'failed' | 'canceled';
|
|
867
904
|
interface RecordImportStats {
|
|
@@ -1682,12 +1719,31 @@ declare class Environment extends Session {
|
|
|
1682
1719
|
/**
|
|
1683
1720
|
* Batch version of `recordObject()`.
|
|
1684
1721
|
*
|
|
1685
|
-
* Sends
|
|
1686
|
-
*
|
|
1722
|
+
* Sends rows through the control-plane **`/records/batch`** endpoint in **chunks** (default
|
|
1723
|
+
* **100** records per HTTP request) so individual requests stay bounded and gateway timeouts are
|
|
1724
|
+
* unlikely. Each chunk is retried on transient network / worker errors.
|
|
1725
|
+
*
|
|
1726
|
+
* Use the optional second argument to:
|
|
1727
|
+
* - **`batchSize`** — rows per POST (smaller = more progress events; larger = fewer round trips).
|
|
1728
|
+
* - **`concurrency`** — run up to N chunk POSTs in parallel (capped at 16) when you want lower wall time.
|
|
1729
|
+
* - **`onChunkComplete`** — hook for UIs after each chunk succeeds (row order in the returned array
|
|
1730
|
+
* always matches `records`; chunk **completion** order may differ when `concurrency > 1`).
|
|
1731
|
+
*
|
|
1732
|
+
* For **asynchronous** ingestion with worker-side batching and aggregate counters (`queued`,
|
|
1733
|
+
* `completed`, …), use **`enqueueRecordImport`** and poll **`getRecordImport`** /
|
|
1734
|
+
* **`getRecordImportSummary`** — best for very large fire-and-forget loads when immediate
|
|
1735
|
+
* synchronous commit of every row is not required.
|
|
1687
1736
|
*/
|
|
1688
|
-
recordObjects(records: RecordObjectOptions[]): Promise<RecordObjectResult[]>;
|
|
1737
|
+
recordObjects(records: RecordObjectOptions[], options?: RecordObjectsOptions): Promise<RecordObjectResult[]>;
|
|
1738
|
+
private executeRecordObjectsChunk;
|
|
1689
1739
|
/**
|
|
1690
|
-
* Queue a background record import for this environment.
|
|
1740
|
+
* Queue a background record import for this environment (async worker pipeline).
|
|
1741
|
+
*
|
|
1742
|
+
* **vs `recordObjects`:** this path accepts the full payload in one request, returns an
|
|
1743
|
+
* **`importId`**, and processes rows in the background — use **`getRecordImport`** /
|
|
1744
|
+
* **`getRecordImportSummary`** for progress. Choose it for large bulk loads where you do not
|
|
1745
|
+
* need every row committed before the HTTP call returns. Use **`recordObjects`** when you need
|
|
1746
|
+
* synchronous upserts and fine-grained chunk progress via **`onChunkComplete`**.
|
|
1691
1747
|
*/
|
|
1692
1748
|
enqueueRecordImport(records: RecordObjectOptions[], options?: {
|
|
1693
1749
|
batchSize?: number;
|
|
@@ -1992,4 +2048,4 @@ declare class Granular {
|
|
|
1992
2048
|
private request;
|
|
1993
2049
|
}
|
|
1994
2050
|
|
|
1995
|
-
export { type EffectInvocationMode as $, type AccessTokenProvider as A, type BuildPolicy as B, type ConnectOptions as C, type DomainState as D, type EffectHandlerContext as E, type Manifest as F, Granular as G, type ManifestListResponse as H, type InstanceToolHandler as I, type BuildStatus as J, type Build as K, type Version as L, type ManifestEffectMetamodelSpec as M, type BuildListResponse as N, type SemanticVersionDiffEntry as O, type Prompt as P, type SemanticVersionDiff as Q, type ResolvedEffectBehaviors as R, type SessionHeapEntry as S, type ToolWithHandler as T, type User as U, type VersionTracking as V, WSClient as W, type ResolvedEffectPostCondition as X, type ResolvedEffectDryRun as Y, type ResolvedEffectReverse as Z, type ResolvedEffectApprovalRequired as _, type SessionHeapList as a, type
|
|
2051
|
+
export { type EffectInvocationMode as $, type AccessTokenProvider as A, type BuildPolicy as B, type ConnectOptions as C, type DomainState as D, type EffectHandlerContext as E, type Manifest as F, Granular as G, type ManifestListResponse as H, type InstanceToolHandler as I, type BuildStatus as J, type Build as K, type Version as L, type ManifestEffectMetamodelSpec as M, type BuildListResponse as N, type SemanticVersionDiffEntry as O, type Prompt as P, type SemanticVersionDiff as Q, type ResolvedEffectBehaviors as R, type SessionHeapEntry as S, type ToolWithHandler as T, type User as U, type VersionTracking as V, WSClient as W, type ResolvedEffectPostCondition as X, type ResolvedEffectDryRun as Y, type ResolvedEffectReverse as Z, type ResolvedEffectApprovalRequired as _, type SessionHeapList as a, type ManifestContent as a$, type EffectInvocationMetadata as a0, type EffectSchema as a1, type EffectWithHandler as a2, type PublishEffectsResult as a3, type ToolInfo as a4, type EffectInfo as a5, type ToolsChangedEvent as a6, type EffectsChangedEvent as a7, type EffectHandler as a8, type InstanceEffectHandler as a9, type RecordObjectsOptions as aA, type RecordImportStatus as aB, type RecordImportItemStatus as aC, type RecordImportStats as aD, type RecordImportItem as aE, type RecordImport as aF, type EnvironmentRecordImportSummary as aG, type ManifestPropertySpec as aH, type ManifestValidationOperator as aI, type ManifestEnumRuleSpec as aJ, type ManifestFilterBySpec as aK, type ManifestValidationRuleSpec as aL, type ManifestStateMachineStateSpec as aM, type ManifestStateMachineTransitionSpec as aN, type ManifestStateMachineSpec as aO, type ManifestPostConditionSpec as aP, type ManifestDryRunSpec as aQ, type ManifestReverseSpec as aR, type ManifestApprovalRequiredSpec as aS, type ManifestRelationshipDef as aT, type ManifestEffectSchema as aU, type ManifestEffectDeclaration as aV, type ManifestEventTypeDef as aW, type ManifestEventStreamDef as aX, type ManifestOperation as aY, type ManifestImport as aZ, type ManifestVolume as a_, type JobStatus as aa, type JobFeedbackSentiment as ab, type JobFeedbackToolCall as ac, type JobFeedbackMetadata as ad, type JobFeedbackInput as ae, type JobFeedbackRecord as af, type JobSubmitResult as ag, type Job as ah, type SessionHeapFieldType as ai, type SessionHeapFieldValue as aj, type SessionHeapVariable as ak, type WSDisconnectInfo as al, type WSReconnectErrorInfo as am, type WSClientOptions as an, type RPCRequest as ao, type RPCResponse as ap, type SyncMessage as aq, type RPCRequestFromServer as ar, type ToolInvokeParams as as, type ToolResultParams as at, type ModelRef as au, type RelationshipInfo as av, type DefineRelationshipOptions as aw, type RecordObjectOptions as ax, type RecordObjectResult as ay, type RecordObjectsChunkInfo as az, type SessionHeapSnapshot as b, type GraphQLResult as b0, type APIError as b1, type DeleteResponse as b2, type StreamEvent as b3, type StreamSubscription as b4, type StreamStats as b5, Environment as c, Session as d, type ToolSchema as e, type PublishToolsResult as f, type ToolHandler as g, type EndpointMode as h, type GranularOptions as i, type GranularAuth as j, type RecordUserOptions as k, type Subject as l, type ConversationSessionInfo as m, type Sandbox as n, type CreateSandboxData as o, type SandboxListResponse as p, type PermissionRules as q, type PermissionProfile as r, type CreatePermissionProfileData as s, type PermissionProfileListResponse as t, type Assignment as u, type AssignmentListResponse as v, type VersionTag as w, type EnvironmentData as x, type CreateEnvironmentData as y, type EnvironmentListResponse as z };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as ToolWithHandler, E as EffectHandlerContext, M as ManifestEffectMetamodelSpec, R as ResolvedEffectBehaviors, S as SessionHeapEntry, a as SessionHeapList, b as SessionHeapSnapshot, P as Prompt } from './client-
|
|
2
|
-
export {
|
|
1
|
+
import { T as ToolWithHandler, E as EffectHandlerContext, M as ManifestEffectMetamodelSpec, R as ResolvedEffectBehaviors, S as SessionHeapEntry, a as SessionHeapList, b as SessionHeapSnapshot, P as Prompt } from './client-DWYdWpS-.mjs';
|
|
2
|
+
export { b1 as APIError, A as AccessTokenProvider, u as Assignment, v as AssignmentListResponse, K as Build, N as BuildListResponse, B as BuildPolicy, J as BuildStatus, C as ConnectOptions, m as ConversationSessionInfo, y as CreateEnvironmentData, s as CreatePermissionProfileData, o as CreateSandboxData, aw as DefineRelationshipOptions, b2 as DeleteResponse, D as DomainState, a8 as EffectHandler, a5 as EffectInfo, a0 as EffectInvocationMetadata, $ as EffectInvocationMode, a1 as EffectSchema, a2 as EffectWithHandler, a7 as EffectsChangedEvent, h as EndpointMode, c as Environment, x as EnvironmentData, z as EnvironmentListResponse, aG as EnvironmentRecordImportSummary, G as Granular, j as GranularAuth, i as GranularOptions, b0 as GraphQLResult, a9 as InstanceEffectHandler, I as InstanceToolHandler, ah as Job, ae as JobFeedbackInput, ad as JobFeedbackMetadata, af as JobFeedbackRecord, ab as JobFeedbackSentiment, ac as JobFeedbackToolCall, aa as JobStatus, ag as JobSubmitResult, F as Manifest, aS as ManifestApprovalRequiredSpec, a$ as ManifestContent, aQ as ManifestDryRunSpec, aV as ManifestEffectDeclaration, aU as ManifestEffectSchema, aJ as ManifestEnumRuleSpec, aX as ManifestEventStreamDef, aW as ManifestEventTypeDef, aK as ManifestFilterBySpec, aZ as ManifestImport, H as ManifestListResponse, aY as ManifestOperation, aP as ManifestPostConditionSpec, aH as ManifestPropertySpec, aT as ManifestRelationshipDef, aR as ManifestReverseSpec, aO as ManifestStateMachineSpec, aM as ManifestStateMachineStateSpec, aN as ManifestStateMachineTransitionSpec, aI as ManifestValidationOperator, aL as ManifestValidationRuleSpec, a_ as ManifestVolume, au as ModelRef, r as PermissionProfile, t as PermissionProfileListResponse, q as PermissionRules, a3 as PublishEffectsResult, f as PublishToolsResult, ao as RPCRequest, ar as RPCRequestFromServer, ap as RPCResponse, aF as RecordImport, aE as RecordImportItem, aC as RecordImportItemStatus, aD as RecordImportStats, aB as RecordImportStatus, ax as RecordObjectOptions, ay as RecordObjectResult, az as RecordObjectsChunkInfo, aA as RecordObjectsOptions, k as RecordUserOptions, av as RelationshipInfo, _ as ResolvedEffectApprovalRequired, Y as ResolvedEffectDryRun, X as ResolvedEffectPostCondition, Z as ResolvedEffectReverse, n as Sandbox, p as SandboxListResponse, Q as SemanticVersionDiff, O as SemanticVersionDiffEntry, d as Session, ai as SessionHeapFieldType, aj as SessionHeapFieldValue, ak as SessionHeapVariable, b3 as StreamEvent, b5 as StreamStats, b4 as StreamSubscription, l as Subject, aq as SyncMessage, g as ToolHandler, a4 as ToolInfo, as as ToolInvokeParams, at as ToolResultParams, e as ToolSchema, a6 as ToolsChangedEvent, U as User, L as Version, w as VersionTag, V as VersionTracking, W as WSClient, an as WSClientOptions, al as WSDisconnectInfo, am as WSReconnectErrorInfo } from './client-DWYdWpS-.mjs';
|
|
3
3
|
export { BuildGranularAgentSystemPromptInput, GeneratedJobCodeIssue, GranularAgentExecutionCheckpoint, GranularAgentHeapSummaryOptions, GranularAgentSessionContext, GranularAgentToolInfo, GranularAgentWorkflowFocus, HarnessContinuationDecision, HarnessControllerBudgets, HarnessProjectionOptions, HarnessPromptLike, HarnessVerifierSnapshot, HarnessVerifierSnapshotInput, buildContinuationInstruction, buildGranularAgentCheckpointBlock, buildGranularAgentDomainBlock, buildGranularAgentHeapBlock, buildGranularAgentLoopBlock, buildGranularAgentSessionBlock, buildGranularAgentSystemPrompt, buildGranularAgentToolBlock, buildGranularAgentWorkflowBlock, createHarnessVerifierSnapshot, evaluateContinuation, getCurrentClosureId, getExclusivePromptTarget, hasOpenPrompt, projectHeapSummary, projectLoopSummary, projectWorkflowFocus, projectWorkflowSummary, reviewGeneratedJobCode } from './agent-harness.mjs';
|
|
4
4
|
import '@automerge/automerge';
|
|
5
5
|
import '@automerge/automerge/slim';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as ToolWithHandler, E as EffectHandlerContext, M as ManifestEffectMetamodelSpec, R as ResolvedEffectBehaviors, S as SessionHeapEntry, a as SessionHeapList, b as SessionHeapSnapshot, P as Prompt } from './client-
|
|
2
|
-
export {
|
|
1
|
+
import { T as ToolWithHandler, E as EffectHandlerContext, M as ManifestEffectMetamodelSpec, R as ResolvedEffectBehaviors, S as SessionHeapEntry, a as SessionHeapList, b as SessionHeapSnapshot, P as Prompt } from './client-DWYdWpS-.js';
|
|
2
|
+
export { b1 as APIError, A as AccessTokenProvider, u as Assignment, v as AssignmentListResponse, K as Build, N as BuildListResponse, B as BuildPolicy, J as BuildStatus, C as ConnectOptions, m as ConversationSessionInfo, y as CreateEnvironmentData, s as CreatePermissionProfileData, o as CreateSandboxData, aw as DefineRelationshipOptions, b2 as DeleteResponse, D as DomainState, a8 as EffectHandler, a5 as EffectInfo, a0 as EffectInvocationMetadata, $ as EffectInvocationMode, a1 as EffectSchema, a2 as EffectWithHandler, a7 as EffectsChangedEvent, h as EndpointMode, c as Environment, x as EnvironmentData, z as EnvironmentListResponse, aG as EnvironmentRecordImportSummary, G as Granular, j as GranularAuth, i as GranularOptions, b0 as GraphQLResult, a9 as InstanceEffectHandler, I as InstanceToolHandler, ah as Job, ae as JobFeedbackInput, ad as JobFeedbackMetadata, af as JobFeedbackRecord, ab as JobFeedbackSentiment, ac as JobFeedbackToolCall, aa as JobStatus, ag as JobSubmitResult, F as Manifest, aS as ManifestApprovalRequiredSpec, a$ as ManifestContent, aQ as ManifestDryRunSpec, aV as ManifestEffectDeclaration, aU as ManifestEffectSchema, aJ as ManifestEnumRuleSpec, aX as ManifestEventStreamDef, aW as ManifestEventTypeDef, aK as ManifestFilterBySpec, aZ as ManifestImport, H as ManifestListResponse, aY as ManifestOperation, aP as ManifestPostConditionSpec, aH as ManifestPropertySpec, aT as ManifestRelationshipDef, aR as ManifestReverseSpec, aO as ManifestStateMachineSpec, aM as ManifestStateMachineStateSpec, aN as ManifestStateMachineTransitionSpec, aI as ManifestValidationOperator, aL as ManifestValidationRuleSpec, a_ as ManifestVolume, au as ModelRef, r as PermissionProfile, t as PermissionProfileListResponse, q as PermissionRules, a3 as PublishEffectsResult, f as PublishToolsResult, ao as RPCRequest, ar as RPCRequestFromServer, ap as RPCResponse, aF as RecordImport, aE as RecordImportItem, aC as RecordImportItemStatus, aD as RecordImportStats, aB as RecordImportStatus, ax as RecordObjectOptions, ay as RecordObjectResult, az as RecordObjectsChunkInfo, aA as RecordObjectsOptions, k as RecordUserOptions, av as RelationshipInfo, _ as ResolvedEffectApprovalRequired, Y as ResolvedEffectDryRun, X as ResolvedEffectPostCondition, Z as ResolvedEffectReverse, n as Sandbox, p as SandboxListResponse, Q as SemanticVersionDiff, O as SemanticVersionDiffEntry, d as Session, ai as SessionHeapFieldType, aj as SessionHeapFieldValue, ak as SessionHeapVariable, b3 as StreamEvent, b5 as StreamStats, b4 as StreamSubscription, l as Subject, aq as SyncMessage, g as ToolHandler, a4 as ToolInfo, as as ToolInvokeParams, at as ToolResultParams, e as ToolSchema, a6 as ToolsChangedEvent, U as User, L as Version, w as VersionTag, V as VersionTracking, W as WSClient, an as WSClientOptions, al as WSDisconnectInfo, am as WSReconnectErrorInfo } from './client-DWYdWpS-.js';
|
|
3
3
|
export { BuildGranularAgentSystemPromptInput, GeneratedJobCodeIssue, GranularAgentExecutionCheckpoint, GranularAgentHeapSummaryOptions, GranularAgentSessionContext, GranularAgentToolInfo, GranularAgentWorkflowFocus, HarnessContinuationDecision, HarnessControllerBudgets, HarnessProjectionOptions, HarnessPromptLike, HarnessVerifierSnapshot, HarnessVerifierSnapshotInput, buildContinuationInstruction, buildGranularAgentCheckpointBlock, buildGranularAgentDomainBlock, buildGranularAgentHeapBlock, buildGranularAgentLoopBlock, buildGranularAgentSessionBlock, buildGranularAgentSystemPrompt, buildGranularAgentToolBlock, buildGranularAgentWorkflowBlock, createHarnessVerifierSnapshot, evaluateContinuation, getCurrentClosureId, getExclusivePromptTarget, hasOpenPrompt, projectHeapSummary, projectLoopSummary, projectWorkflowFocus, projectWorkflowSummary, reviewGeneratedJobCode } from './agent-harness.js';
|
|
4
4
|
import '@automerge/automerge';
|
|
5
5
|
import '@automerge/automerge/slim';
|
package/dist/index.js
CHANGED
|
@@ -11251,6 +11251,28 @@ var STANDARD_MODULES_OPERATIONS = [
|
|
|
11251
11251
|
var BUILTIN_MODULES = {
|
|
11252
11252
|
"standard_modules": STANDARD_MODULES_OPERATIONS
|
|
11253
11253
|
};
|
|
11254
|
+
var DEFAULT_DIRECT_RECORD_OBJECTS_REQUEST_BATCH_SIZE = 100;
|
|
11255
|
+
var MAX_RECORD_OBJECTS_CONCURRENCY = 16;
|
|
11256
|
+
var DEFAULT_DIRECT_RECORD_OBJECTS_RETRY_COUNT = 3;
|
|
11257
|
+
var DEFAULT_DIRECT_RECORD_OBJECTS_RETRY_DELAY_MS = 1e3;
|
|
11258
|
+
function planRecordObjectsChunks(records, batchSize) {
|
|
11259
|
+
const total = records.length;
|
|
11260
|
+
const size = Math.max(1, Math.min(batchSize, total));
|
|
11261
|
+
const chunkCount = Math.ceil(total / size);
|
|
11262
|
+
const plans = [];
|
|
11263
|
+
for (let offset = 0, chunkIndex = 0; offset < total; offset += size, chunkIndex += 1) {
|
|
11264
|
+
const slice = records.slice(offset, offset + size);
|
|
11265
|
+
plans.push({ chunkIndex, chunkCount, offset, slice });
|
|
11266
|
+
}
|
|
11267
|
+
return plans;
|
|
11268
|
+
}
|
|
11269
|
+
function sleep(ms) {
|
|
11270
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
11271
|
+
}
|
|
11272
|
+
function isRetryableRecordObjectsError(error) {
|
|
11273
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
11274
|
+
return /worker restarted mid-request|econnreset|network|socket connection was closed unexpectedly|timed out/i.test(message);
|
|
11275
|
+
}
|
|
11254
11276
|
function computeEffectKey2(effect) {
|
|
11255
11277
|
const attachedClass = effect.className?.trim();
|
|
11256
11278
|
if (!attachedClass) {
|
|
@@ -12208,24 +12230,101 @@ var Environment = class extends Session {
|
|
|
12208
12230
|
/**
|
|
12209
12231
|
* Batch version of `recordObject()`.
|
|
12210
12232
|
*
|
|
12211
|
-
* Sends
|
|
12212
|
-
*
|
|
12233
|
+
* Sends rows through the control-plane **`/records/batch`** endpoint in **chunks** (default
|
|
12234
|
+
* **100** records per HTTP request) so individual requests stay bounded and gateway timeouts are
|
|
12235
|
+
* unlikely. Each chunk is retried on transient network / worker errors.
|
|
12236
|
+
*
|
|
12237
|
+
* Use the optional second argument to:
|
|
12238
|
+
* - **`batchSize`** — rows per POST (smaller = more progress events; larger = fewer round trips).
|
|
12239
|
+
* - **`concurrency`** — run up to N chunk POSTs in parallel (capped at 16) when you want lower wall time.
|
|
12240
|
+
* - **`onChunkComplete`** — hook for UIs after each chunk succeeds (row order in the returned array
|
|
12241
|
+
* always matches `records`; chunk **completion** order may differ when `concurrency > 1`).
|
|
12242
|
+
*
|
|
12243
|
+
* For **asynchronous** ingestion with worker-side batching and aggregate counters (`queued`,
|
|
12244
|
+
* `completed`, …), use **`enqueueRecordImport`** and poll **`getRecordImport`** /
|
|
12245
|
+
* **`getRecordImportSummary`** — best for very large fire-and-forget loads when immediate
|
|
12246
|
+
* synchronous commit of every row is not required.
|
|
12213
12247
|
*/
|
|
12214
|
-
async recordObjects(records) {
|
|
12248
|
+
async recordObjects(records, options) {
|
|
12215
12249
|
if (!Array.isArray(records) || records.length === 0) {
|
|
12216
12250
|
return [];
|
|
12217
12251
|
}
|
|
12218
|
-
const
|
|
12219
|
-
|
|
12220
|
-
|
|
12221
|
-
|
|
12222
|
-
|
|
12223
|
-
|
|
12252
|
+
const batchSize = Math.max(
|
|
12253
|
+
1,
|
|
12254
|
+
Math.min(
|
|
12255
|
+
records.length,
|
|
12256
|
+
options?.batchSize ?? DEFAULT_DIRECT_RECORD_OBJECTS_REQUEST_BATCH_SIZE
|
|
12257
|
+
)
|
|
12224
12258
|
);
|
|
12225
|
-
|
|
12259
|
+
const concurrency = Math.min(
|
|
12260
|
+
MAX_RECORD_OBJECTS_CONCURRENCY,
|
|
12261
|
+
Math.max(1, options?.concurrency ?? 1)
|
|
12262
|
+
);
|
|
12263
|
+
const plans = planRecordObjectsChunks(records, batchSize);
|
|
12264
|
+
const total = records.length;
|
|
12265
|
+
const results = new Array(total);
|
|
12266
|
+
const onChunk = options?.onChunkComplete;
|
|
12267
|
+
for (let waveStart = 0; waveStart < plans.length; waveStart += concurrency) {
|
|
12268
|
+
const wave = plans.slice(waveStart, waveStart + concurrency);
|
|
12269
|
+
await Promise.all(
|
|
12270
|
+
wave.map(async (plan) => {
|
|
12271
|
+
const { items, durationMs } = await this.executeRecordObjectsChunk(plan.slice);
|
|
12272
|
+
if (items.length !== plan.slice.length) {
|
|
12273
|
+
throw new Error(
|
|
12274
|
+
`recordObjects: chunk ${plan.chunkIndex + 1} returned ${items.length} results, expected ${plan.slice.length}`
|
|
12275
|
+
);
|
|
12276
|
+
}
|
|
12277
|
+
for (let index = 0; index < items.length; index += 1) {
|
|
12278
|
+
results[plan.offset + index] = items[index];
|
|
12279
|
+
}
|
|
12280
|
+
if (onChunk) {
|
|
12281
|
+
const info = {
|
|
12282
|
+
chunkIndex: plan.chunkIndex,
|
|
12283
|
+
totalChunks: plan.chunkCount,
|
|
12284
|
+
offset: plan.offset,
|
|
12285
|
+
recordCount: plan.slice.length,
|
|
12286
|
+
durationMs,
|
|
12287
|
+
results: items
|
|
12288
|
+
};
|
|
12289
|
+
await onChunk(info);
|
|
12290
|
+
}
|
|
12291
|
+
})
|
|
12292
|
+
);
|
|
12293
|
+
}
|
|
12294
|
+
return results;
|
|
12295
|
+
}
|
|
12296
|
+
async executeRecordObjectsChunk(chunk) {
|
|
12297
|
+
const wallStart = Date.now();
|
|
12298
|
+
let lastError;
|
|
12299
|
+
for (let attempt = 1; attempt <= DEFAULT_DIRECT_RECORD_OBJECTS_RETRY_COUNT; attempt += 1) {
|
|
12300
|
+
try {
|
|
12301
|
+
const response = await this.controlPlaneRequest(
|
|
12302
|
+
`/control/environments/${this.environmentId}/records/batch`,
|
|
12303
|
+
{
|
|
12304
|
+
method: "POST",
|
|
12305
|
+
body: JSON.stringify({ records: chunk })
|
|
12306
|
+
}
|
|
12307
|
+
);
|
|
12308
|
+
const items = Array.isArray(response.items) ? response.items : [];
|
|
12309
|
+
return { items, durationMs: Date.now() - wallStart };
|
|
12310
|
+
} catch (error) {
|
|
12311
|
+
lastError = error;
|
|
12312
|
+
if (!isRetryableRecordObjectsError(error) || attempt === DEFAULT_DIRECT_RECORD_OBJECTS_RETRY_COUNT) {
|
|
12313
|
+
throw error;
|
|
12314
|
+
}
|
|
12315
|
+
await sleep(DEFAULT_DIRECT_RECORD_OBJECTS_RETRY_DELAY_MS * attempt);
|
|
12316
|
+
}
|
|
12317
|
+
}
|
|
12318
|
+
throw lastError instanceof Error ? lastError : new Error(String(lastError));
|
|
12226
12319
|
}
|
|
12227
12320
|
/**
|
|
12228
|
-
* Queue a background record import for this environment.
|
|
12321
|
+
* Queue a background record import for this environment (async worker pipeline).
|
|
12322
|
+
*
|
|
12323
|
+
* **vs `recordObjects`:** this path accepts the full payload in one request, returns an
|
|
12324
|
+
* **`importId`**, and processes rows in the background — use **`getRecordImport`** /
|
|
12325
|
+
* **`getRecordImportSummary`** for progress. Choose it for large bulk loads where you do not
|
|
12326
|
+
* need every row committed before the HTTP call returns. Use **`recordObjects`** when you need
|
|
12327
|
+
* synchronous upserts and fine-grained chunk progress via **`onChunkComplete`**.
|
|
12229
12328
|
*/
|
|
12230
12329
|
async enqueueRecordImport(records, options = {}) {
|
|
12231
12330
|
return this.controlPlaneRequest(
|