@blocks-network/sdk 0.1.68 → 0.1.70

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 CHANGED
@@ -480,6 +480,7 @@ import { TaskClient, textPart } from '@blocks-network/sdk';
480
480
  const session = await client.sendMessage({
481
481
  agentName: 'multi_stream_agent',
482
482
  requestParts: [textPart('start')],
483
+ stream: true, // request-task streaming is opt-in (BLOCKS-181)
483
484
  });
484
485
 
485
486
  // Option 1 — react to each stream as it is announced
@@ -512,6 +513,7 @@ loops. Tune the window per session:
512
513
  const session = await client.sendMessage({
513
514
  agentName: 'llm_streamer',
514
515
  requestParts: [textPart('stream please')],
516
+ stream: true, // request-task streaming is opt-in (BLOCKS-181)
515
517
  drainWindowMs: 5_000, // 5 seconds
516
518
  });
517
519
 
@@ -1 +1 @@
1
- import{preflightAuthOrThrow as r}from"./auth-provider.js";import{CURRENT_PROTOCOL_VERSION as t,PROTOCOL_VERSION_HEADER as e}from"./protocol-version.js";import{captureAffinity as o,injectAffinity as n}from"./write-affinity.js";export async function withRetry(r,t=3,e=500){let o;for(let n=0;n<t;n++)try{return await r()}catch(r){o=r;const i=String(r);if(!(i.includes("ENOTFOUND")||i.includes("ETIMEDOUT")||i.includes("ECONNRESET")||i.includes("NetworkIssues"))||n===t-1)throw r;const a=e*Math.pow(2,n)+100*Math.random();await new Promise(r=>setTimeout(r,a))}throw o}export function rpcEndpoint(r,t){return t?`${t.replace(/\/+$/,"")}/api/v1/rpc`:`https://ps.pndsn.com/v1/blocks/sub-key/${r}/rpc`}export class RpcError extends Error{constructor(r,t,e){super(`[RPC] ${r}`),this.name="RpcError",this.rpcMessage=r,this.code=t,this.data=e}}export class BillingModeMismatchError extends RpcError{constructor(r,t,e,o,n){super(r,o,n),this.name="BillingModeMismatchError",this.expected=t,this.got=e}}export async function callRpc(i,a,s){const c=rpcEndpoint(i.subscribeKey,i.baseUrl),d=`rpc-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,u=r=>{const o={"Content-Type":"application/json",[e]:t},a=i.authProvider?.getAuthHeader();return a&&(o.Authorization=a),r&&n(o),o},h={jsonrpc:"2.0",id:d,method:a,params:s},p=async()=>{let r;if(i.agentAuth?r=await i.agentAuth.authenticatedFetch(c,{method:"POST",headers:u(!1),body:JSON.stringify(h)}):(r=await fetch(c,{method:"POST",headers:u(!0),body:JSON.stringify(h)}),o(r.headers)),!r.ok)throw new RpcError(`HTTP ${r.status}`,r.status);const t=await r.json();if(t.error){const r=t.error.data?.message??t.error.message??"Unknown RPC error",e=function(r,t,e){if(!e||"object"!=typeof e)return null;const o=e;if("BillingModeMismatch"!==o.code)return null;const n=o.details;if(!n||"object"!=typeof n)return null;const i=n;return"free"!==i.expected&&"paid"!==i.expected||"free"!==i.got&&"paid"!==i.got?null:new BillingModeMismatchError(r,i.expected,i.got,t,e)}(r,t.error.code,t.error.data);if(e)throw e;throw new RpcError(r,t.error.code,t.error.data)}return t.result};return await r(i.authProvider),i.authProvider?.ensureReady&&await i.authProvider.ensureReady(),withRetry(async()=>{try{return await p()}catch(r){if(r instanceof RpcError&&401===r.code&&i.authProvider&&!i.agentAuth){if(await i.authProvider.onAuthFailure())return p()}throw r}})}
1
+ import{preflightAuthOrThrow as r}from"./auth-provider.js";import{CURRENT_PROTOCOL_VERSION as t,PROTOCOL_VERSION_HEADER as e}from"./protocol-version.js";import{captureAffinity as o,injectAffinity as n}from"./write-affinity.js";export async function withRetry(r,t=3,e=500){let o;for(let n=0;n<t;n++)try{return await r()}catch(r){o=r;const i=String(r);if(!(i.includes("ENOTFOUND")||i.includes("ETIMEDOUT")||i.includes("ECONNRESET")||i.includes("NetworkIssues"))||n===t-1)throw r;const a=e*Math.pow(2,n)+100*Math.random();await new Promise(r=>setTimeout(r,a))}throw o}export function rpcEndpoint(r,t){return t?`${t.replace(/\/+$/,"")}/api/v1/rpc`:`https://ps.pndsn.com/v1/blocks/sub-key/${r}/rpc`}export class RpcError extends Error{constructor(r,t,e){super(`[RPC] ${r}`),this.name="RpcError",this.rpcMessage=r,this.code=t,this.data=e}}const i=new Set(["EMBEDDED_JWT_REVOKED","EMBEDDED_JWT_LOGOUT","EMBEDDED_JWT_KILLED","EMBEDDED_JWT_SCOPE_DRIFT","AGENT_OUT_OF_SCOPE"]);export class BillingModeMismatchError extends RpcError{constructor(r,t,e,o,n){super(r,o,n),this.name="BillingModeMismatchError",this.expected=t,this.got=e}}export async function callRpc(a,s,c){const u=rpcEndpoint(a.subscribeKey,a.baseUrl),d=`rpc-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,h=r=>{const o={"Content-Type":"application/json",[e]:t},i=a.authProvider?.getAuthHeader();return i&&(o.Authorization=i),r&&n(o),o},p={jsonrpc:"2.0",id:d,method:s,params:c},l=async()=>{let r;if(a.agentAuth?r=await a.agentAuth.authenticatedFetch(u,{method:"POST",headers:h(!1),body:JSON.stringify(p)}):(r=await fetch(u,{method:"POST",headers:h(!0),body:JSON.stringify(p)}),o(r.headers)),!r.ok)throw new RpcError(`HTTP ${r.status}`,r.status);const t=await r.json();if(t.error){const r=t.error.data?.message??t.error.message??"Unknown RPC error",e=function(r,t,e){if(!e||"object"!=typeof e)return null;const o=e;if("BillingModeMismatch"!==o.code)return null;const n=o.details;if(!n||"object"!=typeof n)return null;const i=n;return"free"!==i.expected&&"paid"!==i.expected||"free"!==i.got&&"paid"!==i.got?null:new BillingModeMismatchError(r,i.expected,i.got,t,e)}(r,t.error.code,t.error.data);if(e)throw e;throw new RpcError(r,t.error.code,t.error.data)}return t.result};return await r(a.authProvider),a.authProvider?.ensureReady&&await a.authProvider.ensureReady(),withRetry(async()=>{try{return await l()}catch(r){if(function(r){if(!(r instanceof RpcError))return!1;if(401===r.code)return!0;const t=r.data;return"string"==typeof t?.code&&i.has(t.code)}(r)&&a.authProvider&&!a.agentAuth){if(await a.authProvider.onAuthFailure())return l()}throw r}})}
@@ -94,8 +94,9 @@ export interface SendMessageParams {
94
94
  * Request live streaming for this task (request tasks only). When `true`,
95
95
  * the task streams token output if the agent supports it; when `false`,
96
96
  * streaming is suppressed and you receive only status updates and the
97
- * final result. Omitted leaves the server default in place. Ignored for
98
- * pipe tasks (pipe streaming is capability-driven). Sent as
97
+ * final result. Omitting it (`undefined`) applies the server default,
98
+ * which is no streaming — pass `stream: true` to opt in. Ignored for pipe
99
+ * tasks (pipe streaming is capability-driven). Sent as
99
100
  * `extensions.blocks.stream`.
100
101
  */
101
102
  stream?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocks-network/sdk",
3
- "version": "0.1.68",
3
+ "version": "0.1.70",
4
4
  "type": "module",
5
5
  "description": "Blocks Network SDK",
6
6
  "exports": {