stackyapper_run_code. Instead of
calling tools one at a time and reading every response, the client writes a
short JavaScript script. The script calls your connected apps, filters and
combines the results, and returns only the summary. One run can make up to 12
discovery or read calls and return a compact summary instead of every raw
response.ok: false. If code
mode access is removed, the run stops and its result is withheld.async function. Use await and end with
return. The returned value, converted to JSON, is the result. A script pasted
inside a single Markdown code fence is accepted as-is.tools object:| Call | What it does |
tools.search({ query }) | Find tools by describing the task. |
tools.schemas({ tool_names }) | Get the exact arguments for tools you found. Each schema includes a TypeScript-style signature. |
tools.connections({ service }) | List connections for an app when there is more than one. |
tools.call({ tool_name, arguments, connection_id }) | Run a read tool. connection_id is only needed when an app has several connections. |
tools.budget() | Check the remaining calls, read bytes, and time. The snapshot uses no app tool-call slot; at most 32 checks are allowed. |
Promise.all(...). At most two calls run at once;
all calls share the same run limits. Keep dependent reads and continuation pages
sequential. Await every call before returning.ok:123456const result = await tools.call({ tool_name: 'cw_get_ticket', arguments: { ticketId: 42 } }); if (!result.ok) { // result.error = { code, message, retryable } return { ticket: null, unavailable: result.error.message }; } return { summary: result.data.summary, status: result.data.status?.name };
{ ok: true, data }: data is the tool's result.{ ok: false, error: { code, message, retryable } }: the call failed, but
the script keeps running. Treat that source as unavailable, not empty.tool_unavailable (the tool doesn't exist or isn't
available to you), tool_call_timeout (the app didn't answer in time),
read_limit (the result was withheld because the run reached its 1 MiB read
limit), and the app's own error codes. tool_call_busy means earlier calls still occupy both
slots, including an app request that timed out but has not finished stopping.
Return what you have and identify that source as unavailable.tools.schemas returns each tool's JSON Schema plus a compact signature, for
example:12(args: { after?: string; pageSize?: number; sourceType?: string }) => { alerts: unknown[]; pagination: { next_page_token: string | null; complete: boolean; upstream_count: number; returned_count: number } }
…. Read
the full schema for those details.?. Don't invent tool names or arguments. Search,
then read the schema.await tools.budget() before starting another page. Its data contains
calls_remaining, read_bytes_remaining, and time_remaining_ms. The time
leaves two seconds for finishing. At most 32 budget checks are allowed per run. Checks use no tool-call slot, but their
responses count toward the read limit. Await outstanding calls before checking;
the snapshot does not reserve capacity or guarantee that the next page fits.
Keep a page cap and allow room for a slow or large response.resume as an object with the exact filters, chosen connection, next
safe provider cursor, and summary accumulated so far. Stackyapper wraps it in
continuation: { version: 1, workspace_id, state } in the response. Pass that
whole envelope as the next stackyapper_run_code call's continuation argument.
The script can read its state as input; input is null in a fresh run.sources list with a source label, status, pages_read,
records_examined, and reason. Use complete only when the requested scope
and the app's completion rules are established; partial for known remaining
or omitted results; unavailable for a failed read; and unknown when you
cannot establish completeness. These are observations reported by the script.
A successful run does not establish a complete answer, and reading zero records
successfully differs from being unable to read a source.console.log, info, warn, error, and debug work. Output is returned
with the result, including when a script fails, which makes a failed script
easy to fix. Output is limited to 50 lines and 8,000 characters, with at most
1,000 characters per line. It is never stored.tools.search and tools.schemas return in your workspace.
If your workspace renamed its AI tools, they use your prefix.next_page_token together with the accumulated count
matching upstream_count ends the snapshot. Here, pagination.complete describes
a collection returned in one page; it can stay false on the last of several pages.partial and pass the continuation into another run. A changed snapshot
requires restarting and discarding the old summary. This example remembers at
most 128 cursors across runs and rejects repeats before counting a page.
Reaching that history cap requires a narrower query. Other tools have different
completion rules; follow their schemas and app guidance.const scope = { tool_name: 'ninja_list_alerts', connection_id: 'YOUR_DISCOVERED_CONNECTION_ID', arguments: {pageSize: 50}, }; const record = v => v !== null && typeof v === 'object' && !Array.isArray(v); // JSON clients may reorder object members; array order and values still matter. const canonical = v => Array.isArray(v) ? v.map(canonical) : record(v) ? Object.fromEntries(Object.keys(v).sort().map(key => [key, canonical(v[key])])) : v; if (input && JSON.stringify(canonical(input.scope)) !== JSON.stringify(canonical(scope))) throw new Error('query scope changed'); const state = input ?? {scope, next: null, pages: 0, records: 0, seen_tokens: [], upstream_count: null}; if (!record(state) || !Number.isSafeInteger(state.pages) || state.pages < 0 || !Number.isSafeInteger(state.records) || state.records < 0 || !(state.next === null || typeof state.next === 'string' && state.next.length > 0) || !Array.isArray(state.seen_tokens) || state.seen_tokens.length > 128 || state.seen_tokens.some(token => typeof token !== 'string' || !token.length) || new Set(state.seen_tokens).size !== state.seen_tokens.length || state.seen_tokens.length !== state.pages || (state.pages > 0 && state.seen_tokens[state.pages - 1] !== state.next) || !(state.upstream_count === null || Number.isSafeInteger(state.upstream_count) && state.upstream_count >= state.records)) throw new Error('invalid checkpoint'); let status = state.pages ? 'partial' : 'unknown', reason = 'page_cap'; for (let pages = 0; pages < 3; pages++) { const budget = await tools.budget(); if (!budget.ok) {reason = budget.error.code; break;} if (budget.data.calls_remaining < 1 || budget.data.read_bytes_remaining < 8192 || budget.data.time_remaining_ms < 5000) {reason = 'run_budget'; break;} const page = await tools.call({tool_name:scope.tool_name,connection_id:scope.connection_id, arguments:{...scope.arguments,...(state.next === null ? {} : {after:state.next})}}); if (!page.ok) {status = 'unavailable'; reason = page.error.code; break;} const data = page.data, pagination = data && data.pagination; if (!record(data) || !Array.isArray(data.alerts) || !record(pagination) || typeof pagination.complete !== 'boolean' || pagination.mode !== 'local_snapshot' || !Number.isSafeInteger(pagination.upstream_count) || pagination.upstream_count < 0 || pagination.returned_count !== data.alerts.length || data.truncated === true) { status = 'unknown'; reason = 'invalid_or_truncated_page'; break; } const next = pagination.next_page_token; if (!(next === null || typeof next === 'string' && next.length > 0) || (next !== null && state.seen_tokens.includes(next)) || (pagination.complete === true && next !== null)) { status = 'unknown'; reason = 'invalid_continuation'; break; } const total = state.records + data.alerts.length; if ((state.upstream_count !== null && state.upstream_count !== pagination.upstream_count) || total > pagination.upstream_count || (next === null && total !== pagination.upstream_count) || (next !== null && total >= pagination.upstream_count)) { status = 'unknown'; reason = 'snapshot_count_mismatch'; break; } if (next !== null && state.seen_tokens.length >= 128) { status = 'partial'; reason = 'cursor_history_cap'; break; } // Commit a page only after validating its result and continuation. state.pages++; state.records = total; state.upstream_count = pagination.upstream_count; if (next === null) { status = 'complete'; reason = 'end_of_snapshot'; break; } status = 'partial'; state.seen_tokens.push(next); state.next = next; } const resumable = reason === 'page_cap' || reason === 'run_budget'; return {sources:[{source:'alerts',status,pages_read:state.pages, records_examined:state.records,reason}],summary:{records:state.records}, resume:resumable ? state : null};
1234567891011121314const [tickets, alerts] = await Promise.all([ tools.call({ tool_name: 'cw_search_tickets', arguments: { conditions: 'closedFlag=false AND priority/name contains "Priority 1"', pageSize: 50 }, }), tools.call({ tool_name: 'ninja_list_alerts', arguments: { pageSize: 100 } }), ]); return { openP1TicketsOnFirstPage: tickets.ok ? tickets.data.length : null, ticketsComplete: tickets.ok ? false : null, // This example fetches one page, not the full total. alertsRead: alerts.ok ? alerts.data.alerts.length : null, alertsComplete: alerts.ok ? alerts.data.pagination.complete === true : null, unavailable: [tickets, alerts].filter((r) => !r.ok).map((r) => r.error.message), };
| Limit | Value |
| Script size | 16 KiB |
| Continuation envelope | 32 KiB |
| Budget checks per run | 32 |
| Tool calls per run | 12 (including search and schema calls) |
| Tool calls at the same time | 2 |
| Time per tool call | 20 seconds, always leaving 2 seconds for the script to finish |
| Time per run | 30 seconds |
| Tool results read per run | 1 MiB in total |
| Returned result | 64 KiB. Larger results are truncated and marked truncated. Results over 1 MiB stop the run. |
| Memory | 16 MiB |
| Runs at the same time | 2 per workspace |
| Runs per day | 500 per workspace, resetting at midnight UTC |
result_preview and says it is
incomplete.ok: false with the code read_limit. The script keeps
running, so it can still return what it already gathered and say the result is
incomplete.console output. Calls
that already finished may have happened; nothing is retried automatically.| Reason | What to do |
| The script failed at line N | Fix the error shown. Syntax errors are reported the same way. |
| More than 32 budget checks | Check once before each page or batch. |
| More than 12 tool calls | Check the budget before another page. Move discovery outside the script or resume in another run. |
| Passed the 30-second limit | Make fewer or faster calls, or split the work into two runs. |
| Tool results passed 1 MiB | Request smaller pages or fewer fields. Handle read_limit errors so the script returns a partial result instead. |
| Returned more than 1 MiB | Return a smaller summary. |
| The client cancelled | Start a new run if the result is still needed. |
| Code mode access was turned off | Refresh your tools and contact support if access is expected. |
| A call had an invalid shape | Check the script API and discovered schema. |
| Too many promise jobs | Reduce the work scheduled by the script. |
| An internal tool call or access check failed, or the sandbox was unavailable | Read the error before trying again. Contact support if it persists. |
| Used its work budget or memory | Simplify loops over large results, or keep fewer values. |
| Returned before awaiting every call | await every tools call, or await independent calls with Promise.all(...). At most two run at once; fetch dependent pages sequentially. |
| Code mode is busy in this workspace | Two runs are already in progress. Try again shortly. |
| Today's limit reached | The workspace has used its 500 runs for today (UTC). |
| Invalid continuation | Use an envelope from this workspace or start a fresh task. |
| Missing scope, tenant, or connection | Check the selected connection and its setup. Repeating the same run does not repair access. |
| A read requires confirmation | Use the normal tool and approval flow. Code mode cannot confirm it. |
artifact_handoff: suggested tool bindings and
schema signatures your agent can use to draft a saved
artifact. It contains no app data, credentials, or
connection IDs, and it isn't saved. The run is not a data source; a saved
artifact uses its own declared tools for later reads.