@granular-software/sdk 0.4.20 → 0.4.21
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 +34 -4
- package/dist/agent-evals.d.mts +1 -1
- package/dist/agent-evals.d.ts +1 -1
- package/dist/agent-evals.js +53 -19
- package/dist/agent-evals.js.map +1 -1
- package/dist/agent-evals.mjs +53 -19
- package/dist/agent-evals.mjs.map +1 -1
- package/dist/agent-harness.js +5 -2
- package/dist/agent-harness.js.map +1 -1
- package/dist/agent-harness.mjs +5 -2
- package/dist/agent-harness.mjs.map +1 -1
- package/dist/cli/index.js +48 -17
- package/dist/{client-DWYdWpS-.d.mts → client-DLGC0mJk.d.mts} +7 -2
- package/dist/{client-DWYdWpS-.d.ts → client-DLGC0mJk.d.ts} +7 -2
- package/dist/index.d.mts +18 -3
- package/dist/index.d.ts +18 -3
- package/dist/index.js +56 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4660,10 +4660,15 @@ var Session = class {
|
|
|
4660
4660
|
* ```typescript
|
|
4661
4661
|
* import { Author, Book, global_search } from './sandbox-tools';
|
|
4662
4662
|
*
|
|
4663
|
-
* const
|
|
4663
|
+
* const totalAuthors = await Author.count();
|
|
4664
|
+
* const firstAuthorsPage = await Author.page({ page: 1, perPage: 10, saveAs: 'recent_authors' });
|
|
4665
|
+
* const authors = firstAuthorsPage.items;
|
|
4664
4666
|
* const tolkien = await Author.get({ path: 'author_tolkien' });
|
|
4665
4667
|
* const bio = await tolkien.get_bio({ detailed: true });
|
|
4666
4668
|
* const books = await tolkien.get_books();
|
|
4669
|
+
* for await (const author of Author.iterate({ perPage: 100, maxItems: 500 })) {
|
|
4670
|
+
* console.log(author.id);
|
|
4671
|
+
* }
|
|
4667
4672
|
* ```
|
|
4668
4673
|
*
|
|
4669
4674
|
* Effect calls (instance methods, static methods, global functions) trigger
|
|
@@ -11221,9 +11226,9 @@ var STANDARD_MODULES_OPERATIONS = [
|
|
|
11221
11226
|
{ create: "class", extends: "entity", has: {} },
|
|
11222
11227
|
{ create: "user", extends: "entity", has: { email: { value: void 0 }, firstName: { value: void 0 }, lastName: { value: void 0 } } },
|
|
11223
11228
|
{ create: "company", extends: "entity", has: { name: { value: void 0 }, website: { value: void 0 } } },
|
|
11224
|
-
{ create: "string", has: {
|
|
11225
|
-
{ create: "number", has: {
|
|
11226
|
-
{ create: "boolean", has: {
|
|
11229
|
+
{ create: "string", has: {} },
|
|
11230
|
+
{ create: "number", has: {} },
|
|
11231
|
+
{ create: "boolean", has: {} },
|
|
11227
11232
|
{ create: "tool_parameter", has: { name: { value: void 0 }, type: { value: "string" }, description: { value: void 0 }, required: { value: false } } }
|
|
11228
11233
|
];
|
|
11229
11234
|
var BUILTIN_MODULES = {
|
|
@@ -11233,6 +11238,8 @@ var DEFAULT_DIRECT_RECORD_OBJECTS_REQUEST_BATCH_SIZE = 100;
|
|
|
11233
11238
|
var MAX_RECORD_OBJECTS_CONCURRENCY = 16;
|
|
11234
11239
|
var DEFAULT_DIRECT_RECORD_OBJECTS_RETRY_COUNT = 3;
|
|
11235
11240
|
var DEFAULT_DIRECT_RECORD_OBJECTS_RETRY_DELAY_MS = 1e3;
|
|
11241
|
+
var LOCAL_CONTROL_REQUEST_RETRY_COUNT = 4;
|
|
11242
|
+
var LOCAL_CONTROL_REQUEST_RETRY_DELAY_MS = 500;
|
|
11236
11243
|
function planRecordObjectsChunks(records, batchSize) {
|
|
11237
11244
|
const total = records.length;
|
|
11238
11245
|
const size = Math.max(1, Math.min(batchSize, total));
|
|
@@ -11247,6 +11254,17 @@ function planRecordObjectsChunks(records, batchSize) {
|
|
|
11247
11254
|
function sleep(ms) {
|
|
11248
11255
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
11249
11256
|
}
|
|
11257
|
+
function isLocalControlUrl(url) {
|
|
11258
|
+
try {
|
|
11259
|
+
const parsed = new URL(url);
|
|
11260
|
+
return parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost" || parsed.hostname === "::1";
|
|
11261
|
+
} catch {
|
|
11262
|
+
return false;
|
|
11263
|
+
}
|
|
11264
|
+
}
|
|
11265
|
+
function isRetryableLocalWorkerRestart(status, body, url) {
|
|
11266
|
+
return isLocalControlUrl(url) && (status === 503 && body.includes("Your worker restarted mid-request") || status === 500 && body.includes("Network connection lost"));
|
|
11267
|
+
}
|
|
11250
11268
|
function isRetryableRecordObjectsError(error) {
|
|
11251
11269
|
const message = error instanceof Error ? error.message : String(error);
|
|
11252
11270
|
return /worker restarted mid-request|econnreset|network|socket connection was closed unexpectedly|timed out/i.test(message);
|
|
@@ -13270,23 +13288,36 @@ var Granular = class _Granular {
|
|
|
13270
13288
|
if (this.debugHttp) {
|
|
13271
13289
|
console.log(`[SDK] Requesting: ${url}`);
|
|
13272
13290
|
}
|
|
13273
|
-
|
|
13274
|
-
|
|
13275
|
-
|
|
13276
|
-
|
|
13277
|
-
|
|
13278
|
-
|
|
13279
|
-
|
|
13291
|
+
for (let attempt = 1; attempt <= LOCAL_CONTROL_REQUEST_RETRY_COUNT; attempt += 1) {
|
|
13292
|
+
const response = await fetch(url, {
|
|
13293
|
+
...options,
|
|
13294
|
+
headers: {
|
|
13295
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
13296
|
+
"Content-Type": "application/json",
|
|
13297
|
+
"Connection": "close",
|
|
13298
|
+
...options.headers
|
|
13299
|
+
}
|
|
13300
|
+
});
|
|
13301
|
+
if (response.ok) {
|
|
13302
|
+
if (response.status === 204) {
|
|
13303
|
+
return { deleted: true };
|
|
13304
|
+
}
|
|
13305
|
+
return response.json();
|
|
13280
13306
|
}
|
|
13281
|
-
});
|
|
13282
|
-
if (!response.ok) {
|
|
13283
13307
|
const errorText = await response.text();
|
|
13308
|
+
const retryable = isRetryableLocalWorkerRestart(response.status, errorText, url);
|
|
13309
|
+
if (retryable && attempt < LOCAL_CONTROL_REQUEST_RETRY_COUNT) {
|
|
13310
|
+
if (this.debugHttp) {
|
|
13311
|
+
console.warn(
|
|
13312
|
+
`[SDK] Retrying local control request after worker restart (${attempt}/${LOCAL_CONTROL_REQUEST_RETRY_COUNT - 1} retries used): ${url}`
|
|
13313
|
+
);
|
|
13314
|
+
}
|
|
13315
|
+
await sleep(LOCAL_CONTROL_REQUEST_RETRY_DELAY_MS * attempt);
|
|
13316
|
+
continue;
|
|
13317
|
+
}
|
|
13284
13318
|
throw new Error(`Granular API Error (${response.status}): ${errorText}`);
|
|
13285
13319
|
}
|
|
13286
|
-
|
|
13287
|
-
return { deleted: true };
|
|
13288
|
-
}
|
|
13289
|
-
return response.json();
|
|
13320
|
+
throw new Error(`Granular API Error: exhausted retries for ${url}`);
|
|
13290
13321
|
}
|
|
13291
13322
|
};
|
|
13292
13323
|
|
|
@@ -14212,7 +14243,10 @@ ${loopBlock}
|
|
|
14212
14243
|
- Only use classes, methods, and parameter shapes that are explicitly declared in those typedefs.
|
|
14213
14244
|
- Never invent helper methods such as \`find(...)\` or unsupported parameters such as \`id\` when the typedefs require \`path\`.
|
|
14214
14245
|
- Use \`ClassName.get({ path })\` only when you already know an object's graph path.
|
|
14215
|
-
- Use \`ClassName.
|
|
14246
|
+
- Use \`ClassName.count()\` when you only need a total.
|
|
14247
|
+
- Use \`ClassName.page({ page, perPage, saveAs })\` when you need both records and pagination metadata like \`totalCount\` or \`hasMore\`.
|
|
14248
|
+
- Use \`ClassName.list({ page, perPage, saveAs })\` to load one typed page of records. \`limit\` is only a legacy alias for \`perPage\`.
|
|
14249
|
+
- Use \`for await (const item of ClassName.iterate({ perPage, maxItems }))\` for large batch jobs so you do not materialize the whole result set at once.
|
|
14216
14250
|
- Instance methods: \`await instance.method_name(params)\`.
|
|
14217
14251
|
- Static methods: \`await ClassName.static_method(params)\`.
|
|
14218
14252
|
- Global effects: \`await effect_name(params)\`.
|
|
@@ -14224,7 +14258,7 @@ ${loopBlock}
|
|
|
14224
14258
|
- Status fields are free-form operational strings, not strict enums. Normalize spelling mentally and do not rely on brittle hard-coded sets that miss variants like \`in-progress\`, \`in_progress\`, \`awaiting-part\`, or \`approval-submitted\`.
|
|
14225
14259
|
- Do not discard a case, work order, part request, or shipment only because its status string does not match your preferred "open" spelling. If the record is otherwise the clear match, inspect it.
|
|
14226
14260
|
- Reuse \`heap.getVar(name)\`, \`heap.setVar(name, value)\`, and \`heap.deleteVar(name)\` only when it clearly helps the next step. Do not mirror data into the heap just for completeness.
|
|
14227
|
-
- Prefer \`heap.setVar(name, value)\` for scalars or one selected instance. Prefer \`ClassName.list({ saveAs })\` for
|
|
14261
|
+
- Prefer \`heap.setVar(name, value)\` for scalars or one selected instance. Prefer \`ClassName.list({ page, perPage, saveAs })\` for reusable list pages instead of \`heap.setVar(name, array)\`.
|
|
14228
14262
|
- Never write an empty array into the heap. If a filtered list is empty, keep it local or clear the previous heap value with \`heap.deleteVar(name)\`.
|
|
14229
14263
|
- Prefer heap-backed state that represents the current choice or recommendation. Avoid storing extra scalar bookkeeping unless it is needed for the next concrete step.
|
|
14230
14264
|
- Only store true sandbox instances, typed lists of sandbox instances, or scalars in the heap. Results returned by static effects like availability/search helpers are often plain JSON, not sandbox instances.
|
|
@@ -14460,6 +14494,6 @@ function resolveJobPresentation({
|
|
|
14460
14494
|
};
|
|
14461
14495
|
}
|
|
14462
14496
|
|
|
14463
|
-
export { Environment, Granular, Session, WSClient, buildContinuationInstruction, buildGranularAgentCheckpointBlock, buildGranularAgentDomainBlock, buildGranularAgentHeapBlock, buildGranularAgentLoopBlock, buildGranularAgentSessionBlock, buildGranularAgentSystemPrompt, buildGranularAgentToolBlock, buildGranularAgentWorkflowBlock, createHarnessVerifierSnapshot, evaluateContinuation, extractPromptTokens, getCurrentClosureId, getExclusivePromptTarget, hasOpenPrompt, invokeRegisteredEffect, normalizeEffectBehaviors, normalizePrompt, normalizePromptText, normalizePromptType, projectHeapSummary, projectLoopSummary, projectWorkflowFocus, projectWorkflowSummary, resolveJobPresentation, resolvePromptAnswer, reviewGeneratedJobCode, scorePromptChoiceMatch };
|
|
14497
|
+
export { Environment, Granular, Session, WSClient, buildContinuationInstruction, buildGranularAgentCheckpointBlock, buildGranularAgentDomainBlock, buildGranularAgentHeapBlock, buildGranularAgentLoopBlock, buildGranularAgentSessionBlock, buildGranularAgentSystemPrompt, buildGranularAgentToolBlock, buildGranularAgentWorkflowBlock, createHarnessVerifierSnapshot, evaluateContinuation, extractPromptTokens, getCurrentClosureId, getExclusivePromptTarget, hasOpenPrompt, invokeRegisteredEffect, isLocalApiUrl, normalizeEffectBehaviors, normalizePrompt, normalizePromptText, normalizePromptType, projectHeapSummary, projectLoopSummary, projectWorkflowFocus, projectWorkflowSummary, resolveApiUrl, resolveAuthTokenForApiUrl, resolveJobPresentation, resolvePromptAnswer, reviewGeneratedJobCode, scorePromptChoiceMatch };
|
|
14464
14498
|
//# sourceMappingURL=index.mjs.map
|
|
14465
14499
|
//# sourceMappingURL=index.mjs.map
|