@native-engagement/sdk 0.0.0-stage → 0.8.0

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
@@ -1,3 +1,25 @@
1
- # Temporary Holding Version
1
+ # Native Engagement SDK
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Authenticated JavaScript and TypeScript access to Native Engagement's canonical HTTPS contracts. Requires Node.js 24.22.1 or newer in the 24 LTS line. This package contains the remote client; local execution, desktop processes and channel credentials remain with their authorized owners.
4
+
5
+ ```sh
6
+ npm install @native-engagement/sdk@beta
7
+ ```
8
+
9
+ ```js
10
+ import { RemoteNativeEngagementSdk } from '@native-engagement/sdk';
11
+
12
+ const client = new RemoteNativeEngagementSdk({
13
+ baseUrl: 'https://engagement.shipkitx.com',
14
+ accessToken: () => process.env.NATIVE_ENGAGEMENT_BEARER_TOKEN ?? ''
15
+ });
16
+ console.log(await client.contracts());
17
+ // For an authorized operation, obtain its schema and provide its exact input:
18
+ // await client.query({ name: 'conversation.list', payload: { ... } });
19
+ ```
20
+
21
+ The service validates identity, tenant membership, account permissions and current grants. Installing this package grants no business access. Supply a short-lived authorized access token through a protected environment or your token provider; never commit credentials. Writes require an idempotencyKey. Unknown external effects must be inspected using their original operation, rather than resubmitted.
22
+
23
+ Exports: RemoteNativeEngagementSdk, RemoteNativeEngagementError and their TypeScript types. SDK responses preserve the service's structured result and error semantics.
24
+
25
+ This beta is distributed with license `UNLICENSED`; publication does not grant an open-source license. Product documentation: https://engagement.shipkitx.com/downloads
@@ -0,0 +1 @@
1
+ No third-party runtime code is bundled. Node.js built-in modules are provided by the host.
@@ -0,0 +1,91 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ export interface AgentStackScope {
4
+ readonly authorityRef: string;
5
+ readonly sourcePrincipal: Readonly<{
6
+ issuer: string;
7
+ subject: string;
8
+ }>;
9
+ readonly tenantId: string;
10
+ readonly workspaceId: string;
11
+ readonly projectId: string;
12
+ readonly businessAgentId: string;
13
+ readonly businessAgentVersionId: string;
14
+ /** 经签名的上游服务凭据租约 ID;正式生产端配对要求此字段以隔离轮换后的旧断言。 */
15
+ readonly sourceCredentialId?: string;
16
+ }
17
+ export interface TenantContextInput {
18
+ readonly tenantId?: string | undefined;
19
+ readonly principalRef?: string | undefined;
20
+ readonly actorRef?: string | undefined;
21
+ readonly authorizationScopes?: readonly string[] | undefined;
22
+ readonly projectRef?: string | undefined;
23
+ readonly workspaceRef?: string | undefined;
24
+ /** Signature-verified JWT issuer, never a caller-supplied business payload. */
25
+ readonly identityIssuer?: string | undefined;
26
+ /** Signature-verified JWT subject, never a caller-supplied business payload. */
27
+ readonly identitySubject?: string | undefined;
28
+ /** 只由验证签名的 Agent Stack 适配器产生,HTTP 业务 payload 不得提供。 */
29
+ readonly agentStack?: AgentStackScope | undefined;
30
+ }
31
+ declare const EXECUTION_NODE_PROTOCOL = "ne-execution-node/1.0";
32
+ export interface NodeProof {
33
+ protocol: typeof EXECUTION_NODE_PROTOCOL;
34
+ tenantId: string;
35
+ serviceOrigin: string;
36
+ installationRef: string;
37
+ keyFingerprint: string;
38
+ nodeRef: string | null;
39
+ nodeGeneration: number;
40
+ nodeSessionRef: string | null;
41
+ sessionGeneration: number;
42
+ requestNonce: string;
43
+ bodyDigest: string;
44
+ signature: string;
45
+ }
46
+ export interface ContractExecutionRequest {
47
+ /** Transport possession proof is separate from verified identity. */
48
+ readonly transportProof?: NodeProof | undefined;
49
+ readonly name: string;
50
+ readonly payload?: Readonly<Record<string, unknown>> | undefined;
51
+ readonly context?: TenantContextInput | undefined;
52
+ }
53
+ export type TokenProvider = () => string | Promise<string>;
54
+ export interface RemoteSdkOptions {
55
+ readonly nodeProof?: (method: string, route: string, payload: Readonly<Record<string, unknown>>) => NodeProof;
56
+ readonly baseUrl: string;
57
+ readonly accessToken: TokenProvider;
58
+ readonly fetchImpl?: typeof fetch;
59
+ /** Bound JSON response memory; 16 MiB by default, at most 64 MiB. */
60
+ readonly maximumResponseBytes?: number;
61
+ /** Only an optional tenant selector, never a source of authorization. */
62
+ readonly tenantId?: string;
63
+ }
64
+ export declare class RemoteNativeEngagementError extends Error {
65
+ readonly code: string;
66
+ readonly status: number;
67
+ readonly details: Readonly<Record<string, unknown>>;
68
+ readonly retryable: boolean;
69
+ readonly hint: string;
70
+ readonly retryAfterSeconds: number | undefined;
71
+ readonly reasonCode: string | undefined;
72
+ constructor(code: string, message: string, status: number, details?: Readonly<Record<string, unknown>>);
73
+ }
74
+ /**
75
+ * Public Agent SDK. For each operation, present a bearer credential to the
76
+ * service, which verifies identity and tenant. This client accepts no
77
+ * caller-provided principalRef or authorizationScopes.
78
+ */
79
+ export declare class RemoteNativeEngagementSdk {
80
+ #private;
81
+ constructor(options: RemoteSdkOptions);
82
+ contracts(): Promise<unknown>;
83
+ schema(name: string): Promise<unknown>;
84
+ query(request: Pick<ContractExecutionRequest, "name" | "payload">, signal?: AbortSignal): Promise<unknown>;
85
+ command(request: Pick<ContractExecutionRequest, "name" | "payload">, signal?: AbortSignal): Promise<unknown>;
86
+ search(payload: Readonly<Record<string, unknown>>): Promise<unknown>;
87
+ enquiry(payload: Readonly<Record<string, unknown>>): Promise<unknown>;
88
+ agentStackPreflight(payload: Readonly<Record<string, unknown>>): Promise<unknown>;
89
+ }
90
+
91
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ function l(t){return t==="SEND_BUDGET_EXHAUSTED"?{retryable:!0,hint:"WAIT_FOR_ACCOUNT_BUDGET_AND_RETRY_SAME_KEY"}:t==="SEND_GATE_DISABLED"?{retryable:!1,hint:"REQUIRE_ACCOUNT_OWNER_TO_ENABLE_SENDING"}:t==="SEND_RESERVATION_REQUIRED"?{retryable:!1,hint:"CANCEL_AND_REVIEW_A_NEW_RESERVED_INTENT"}:["AUTH_VERIFICATION_UNAVAILABLE","AGENT_STACK_AUTHORITY_UNAVAILABLE","REDIS_RATE_LIMIT_UNAVAILABLE","SERVICE_NOT_CONFIGURED","RATE_LIMIT_EXCEEDED"].includes(t)?{retryable:!0,hint:"WAIT_AND_RETRY_SAME_IDEMPOTENCY_KEY"}:["AUTH_TOKEN_EXPIRED","AUTHENTICATION_REQUIRED","AUTH_TOKEN_REVOKED"].includes(t)?{retryable:!1,hint:"REAUTHENTICATE_AND_RECHECK_CURRENT_AUTHORITY"}:["ENTITY_CONFLICT","SEARCH_CURSOR_STALE","HOST_INBOX_CURSOR_STALE"].includes(t)?{retryable:!1,hint:"READ_CURRENT_STATE_AND_REPLAN"}:t==="IDEMPOTENCY_CONFLICT"?{retryable:!1,hint:"RESTORE_ORIGINAL_INPUT_FOR_KEY"}:["HOST_EXECUTION_FAILED","HOST_BRIDGE_UNAVAILABLE"].includes(t)?{retryable:!1,hint:"VERIFY_KNOWN_OPERATION_BEFORE_ANY_SEND"}:t==="SUPPRESSED"?{retryable:!1,hint:"STOP_CONTACT_AND_REQUIRE_HUMAN_REVIEW"}:t.startsWith("AUTH")||t==="TENANT_NOT_PROVISIONED"?{retryable:!1,hint:"REQUIRE_OPERATOR_AUTHORITY_REVIEW"}:{retryable:!1,hint:"FIX_INPUT_OR_INSPECT_STATE_BEFORE_RETRY"}}var f=class extends Error{code;statusCode;details;constructor(e,r,o,s={}){super(r),this.code=e,this.statusCode=o,this.details=s,this.name="NativeEngagementError"}};function p(t,e){if(!t||typeof t!="object"||Array.isArray(t))throw new f("VALIDATION_FAILED",`${e} must be an object.`,400,{field:e});return t}function I(t){let e=p(t??{},"payload"),r=e.idempotencyKey;if(typeof r!="string"||!r.trim()||r.length>1024*1024)throw new f("VALIDATION_FAILED","Every command requires a bounded idempotencyKey.",400,{field:"idempotencyKey"});return e}async function h(t,e=2*1024*1024){if(Number(t.headers.get("content-length"))>e||!t.body)throw Error("NODE_REMOTE_RESPONSE_TOO_LARGE");let r=t.body.getReader(),o=[],s=0;try{for(;;){let n=await r.read();if(n.done)break;if(s+=n.value.byteLength,s>e)throw Error("NODE_REMOTE_RESPONSE_TOO_LARGE");o.push(n.value)}let a=new Uint8Array(s),c=0;for(let n of o)a.set(n,c),c+=n.byteLength;return JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(a))}finally{await r.cancel().catch(()=>{}),r.releaseLock()}}var E=class extends Error{constructor(r,o,s,a={}){super(o);this.code=r;this.status=s;this.details=a;this.name="RemoteNativeEngagementError";let c=l(r);this.retryable=c.retryable,this.hint=c.hint;let n=a.retryAfterSeconds,d=a.reasonCode;this.retryAfterSeconds=Number.isInteger(n)&&Number(n)>=0&&Number(n)<=3600?Number(n):void 0,this.reasonCode=typeof d=="string"&&/^[A-Z][A-Z_]{1,120}$/.test(d)?d:void 0}code;status;details;retryable;hint;retryAfterSeconds;reasonCode};function R(t){let e;try{e=new URL(t)}catch{throw new Error("Invalid native-engagement service URL.")}let r=e.hostname==="127.0.0.1"||e.hostname==="localhost"||e.hostname==="[::1]";if(!(e.protocol==="https:"||e.protocol==="http:"&&r)||e.username||e.password||e.search||e.hash||e.pathname!=="/")throw new Error("native-engagement requires HTTPS or HTTP loopback without URL credentials.");return e.origin}var A=class{#o;#i;#s;#r;#t;#n;constructor(e){if(this.#o=R(e.baseUrl),this.#i=e.accessToken,this.#s=e.fetchImpl??fetch,this.#n=e.tenantId,this.#r=e.nodeProof,this.#t=e.maximumResponseBytes??16*1024*1024,!Number.isSafeInteger(this.#t)||this.#t<1024||this.#t>64*1024*1024)throw Error("Invalid maximum JSON response size.")}async#e(e,r,o,s=!0,a=3e4,c){let n={accept:"application/json","content-type":"application/json"};if(s){let i=await this.#i();if(!/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(i))throw new E("AUTHENTICATION_REQUIRED","An access token is required for the remote operation.",401);n.authorization=`Bearer ${i}`,this.#n&&(n["x-tenant-id"]=this.#n)}this.#r&&/^\/v1\/(query|command)\/execution\.node\./.test(r)&&(n["x-execution-node-proof"]=Buffer.from(JSON.stringify(this.#r(e,r,o??{}))).toString("base64url"));let d=await this.#s(`${this.#o}${r}`,{method:e,headers:n,...e==="POST"?{body:JSON.stringify(o??{})}:{},redirect:"error",signal:c?AbortSignal.any([c,AbortSignal.timeout(a)]):AbortSignal.timeout(a)}),u;try{u=await h(d,this.#r&&r.includes("/execution.node.")?2*1024*1024:this.#t)}catch{throw new E("REMOTE_RESPONSE_INVALID","The service did not return valid JSON.",d.status)}if(!d.ok){let i=u&&typeof u=="object"&&"error"in u?u.error:void 0;throw new E(i?.code??"REMOTE_REQUEST_FAILED",i?.message??"The native-engagement service rejected the request.",d.status,i?.details&&typeof i.details=="object"&&!Array.isArray(i.details)?i.details:{})}return u}contracts(){return this.#e("GET","/v1/contracts",void 0,!1)}schema(e){return this.#e("GET",`/v1/contracts/${encodeURIComponent(e)}`,void 0,!1)}query(e,r){let o=["channel.status.inspect","profile.host.inspect","wechat.session.inspect","wechat.thread.observe","browser.session.inspect","browser.thread.observe"].includes(e.name)?12e4:3e4;return this.#e("POST",`/v1/query/${encodeURIComponent(e.name)}`,e.payload,!0,o,r)}command(e,r){try{I(e.payload)}catch{throw new E("VALIDATION_FAILED","Every command requires a bounded idempotencyKey.",400)}let o=["conversation.source.sync","conversation.source.rebase","wechat.conversation.sync","wechat.thread.link","wechat.watch.resume"].includes(e.name)||e.name==="asset.speech.synthesize"?12e4:["message.text.execute","message.text.verify","wechat.message.execute","wechat.message.verify"].includes(e.name)?18e4:["asset.parse","message.attachment.capture","work.content.prepare","work.mail.content.prepare","work.source.content.prepare"].includes(e.name)?2e5:3e4;return this.#e("POST",`/v1/command/${encodeURIComponent(e.name)}`,e.payload,!0,o,r)}search(e){return this.#e("POST","/v1/search",e)}enquiry(e){return this.#e("POST","/v1/enquiry",e)}agentStackPreflight(e){return this.#e("POST","/v1/integrations/agent-stack/preflight",e)}};export{E as RemoteNativeEngagementError,A as RemoteNativeEngagementSdk};
package/package.json CHANGED
@@ -1,6 +1,32 @@
1
1
  {
2
2
  "name": "@native-engagement/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.8.0",
4
+ "type": "module",
5
+ "description": "Authenticated remote TypeScript client for Native Engagement",
6
+ "engines": {
7
+ "node": ">=24.22.1 <25"
8
+ },
9
+ "license": "UNLICENSED",
10
+ "files": [
11
+ "dist",
12
+ "README.md",
13
+ "release.json",
14
+ "THIRD_PARTY_LICENSES.txt"
15
+ ],
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/SENLIN746/native-engagement.git"
19
+ },
20
+ "homepage": "https://engagement.shipkitx.com/downloads",
21
+ "publishConfig": {
22
+ "access": "public",
23
+ "tag": "beta"
24
+ },
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.js"
30
+ }
31
+ }
32
+ }
package/release.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "sourceCommit": "5402e30207f693b0a0e28cb49e54720b402e1db9",
4
+ "channel": "beta",
5
+ "bundledComponents": [],
6
+ "lockSha256": "421cbab359e454443023383a61d63b1fc9f562e79c4e7c5174b09bdfb640d76c"
7
+ }