@react-grab/ami 0.0.88 → 0.0.89
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/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/client.cjs +68 -36
- package/dist/client.global.js +21 -21
- package/dist/client.js +68 -36
- package/dist/server.cjs +4 -2
- package/dist/server.js +4 -2
- package/package.json +4 -3
package/dist/cli.cjs
CHANGED
|
@@ -101,7 +101,7 @@ var require_picocolors = __commonJS({
|
|
|
101
101
|
|
|
102
102
|
// src/cli.ts
|
|
103
103
|
var import_picocolors = __toESM(require_picocolors());
|
|
104
|
-
var VERSION = "0.0.
|
|
104
|
+
var VERSION = "0.0.89";
|
|
105
105
|
console.log(
|
|
106
106
|
`${import_picocolors.default.magenta("\u273F")} ${import_picocolors.default.bold("React Grab")} ${import_picocolors.default.gray(VERSION)} ${import_picocolors.default.dim("(Ami)")}`
|
|
107
107
|
);
|
package/dist/cli.js
CHANGED
|
@@ -99,7 +99,7 @@ var require_picocolors = __commonJS({
|
|
|
99
99
|
|
|
100
100
|
// src/cli.ts
|
|
101
101
|
var import_picocolors = __toESM(require_picocolors());
|
|
102
|
-
var VERSION = "0.0.
|
|
102
|
+
var VERSION = "0.0.89";
|
|
103
103
|
console.log(
|
|
104
104
|
`${import_picocolors.default.magenta("\u273F")} ${import_picocolors.default.bold("React Grab")} ${import_picocolors.default.gray(VERSION)} ${import_picocolors.default.dim("(Ami)")}`
|
|
105
105
|
);
|
package/dist/client.cjs
CHANGED
|
@@ -17364,11 +17364,60 @@ var q = async (e) => {
|
|
|
17364
17364
|
return { success: o2.success, patches: t2.patches, error: o2.error };
|
|
17365
17365
|
};
|
|
17366
17366
|
|
|
17367
|
+
// ../utils/dist/client.js
|
|
17368
|
+
var CONNECTION_CHECK_TTL_MS = 5e3;
|
|
17369
|
+
var STORAGE_KEY = "react-grab:agent-sessions";
|
|
17370
|
+
var isRecord = (value) => typeof value === "object" && value !== null;
|
|
17371
|
+
var getStoredAgentContext = (storage, sessionId, storageKey = STORAGE_KEY) => {
|
|
17372
|
+
const rawSessions = storage.getItem(storageKey);
|
|
17373
|
+
if (!rawSessions) throw new Error("No sessions to resume");
|
|
17374
|
+
let parsed;
|
|
17375
|
+
try {
|
|
17376
|
+
parsed = JSON.parse(rawSessions);
|
|
17377
|
+
} catch {
|
|
17378
|
+
throw new Error("Failed to parse stored sessions");
|
|
17379
|
+
}
|
|
17380
|
+
if (!isRecord(parsed)) throw new Error("Invalid stored sessions");
|
|
17381
|
+
const storedSession = parsed[sessionId];
|
|
17382
|
+
if (!isRecord(storedSession)) {
|
|
17383
|
+
throw new Error(`Session ${sessionId} not found`);
|
|
17384
|
+
}
|
|
17385
|
+
const context = storedSession.context;
|
|
17386
|
+
if (!isRecord(context)) throw new Error(`Session ${sessionId} is invalid`);
|
|
17387
|
+
const content = context.content;
|
|
17388
|
+
const prompt = context.prompt;
|
|
17389
|
+
if (typeof content !== "string" || typeof prompt !== "string") {
|
|
17390
|
+
throw new Error(`Session ${sessionId} is invalid`);
|
|
17391
|
+
}
|
|
17392
|
+
const options = context.options;
|
|
17393
|
+
const storedSessionId = context.sessionId;
|
|
17394
|
+
return {
|
|
17395
|
+
content,
|
|
17396
|
+
prompt,
|
|
17397
|
+
options,
|
|
17398
|
+
sessionId: typeof storedSessionId === "string" ? storedSessionId : void 0
|
|
17399
|
+
};
|
|
17400
|
+
};
|
|
17401
|
+
var createCachedConnectionChecker = (checkConnection, ttlMs = CONNECTION_CHECK_TTL_MS) => {
|
|
17402
|
+
let cache = null;
|
|
17403
|
+
return async () => {
|
|
17404
|
+
const now = Date.now();
|
|
17405
|
+
if (cache && now - cache.timestamp < ttlMs) return cache.result;
|
|
17406
|
+
try {
|
|
17407
|
+
const result = await checkConnection();
|
|
17408
|
+
cache = { result, timestamp: now };
|
|
17409
|
+
return result;
|
|
17410
|
+
} catch {
|
|
17411
|
+
cache = { result: false, timestamp: now };
|
|
17412
|
+
return false;
|
|
17413
|
+
}
|
|
17414
|
+
};
|
|
17415
|
+
};
|
|
17416
|
+
|
|
17367
17417
|
// src/constants.ts
|
|
17368
17418
|
var COMPLETED_STATUS = "COMPLETED_STATUS";
|
|
17369
17419
|
|
|
17370
17420
|
// src/client.ts
|
|
17371
|
-
var STORAGE_KEY = "react-grab:agent-sessions";
|
|
17372
17421
|
var TOKEN_STORAGE_KEY = "react-grab:ami-token";
|
|
17373
17422
|
var BRIDGE_TOKEN_STORAGE_KEY = "react-grab:ami-bridge-token";
|
|
17374
17423
|
var loadCachedAuth = () => {
|
|
@@ -17493,9 +17542,8 @@ ${context.content}`;
|
|
|
17493
17542
|
return { status: COMPLETED_STATUS, messages, chatId };
|
|
17494
17543
|
}
|
|
17495
17544
|
};
|
|
17496
|
-
var
|
|
17545
|
+
var isReactGrabApi = (value) => typeof value === "object" && value !== null && "setAgent" in value;
|
|
17497
17546
|
var createAmiAgentProvider = (projectId) => {
|
|
17498
|
-
let connectionCache = null;
|
|
17499
17547
|
let lastAgentMessages = null;
|
|
17500
17548
|
const sessionData = /* @__PURE__ */ new Map();
|
|
17501
17549
|
const getLatestProjectId = async (token) => {
|
|
@@ -17617,16 +17665,10 @@ var createAmiAgentProvider = (projectId) => {
|
|
|
17617
17665
|
},
|
|
17618
17666
|
resume: async function* (sessionId, signal, storage) {
|
|
17619
17667
|
const startTime = Date.now();
|
|
17620
|
-
const
|
|
17621
|
-
|
|
17622
|
-
|
|
17623
|
-
|
|
17624
|
-
const sessionsObject = JSON.parse(savedSessions);
|
|
17625
|
-
const session = sessionsObject[sessionId];
|
|
17626
|
-
if (!session) {
|
|
17627
|
-
throw new Error(`Session ${sessionId} not found`);
|
|
17628
|
-
}
|
|
17629
|
-
const context = session.context;
|
|
17668
|
+
const storedContext = getStoredAgentContext(storage, sessionId);
|
|
17669
|
+
const context = {
|
|
17670
|
+
content: storedContext.content,
|
|
17671
|
+
prompt: storedContext.prompt};
|
|
17630
17672
|
const auth = await getOrCreateAuth();
|
|
17631
17673
|
yield "Resuming...";
|
|
17632
17674
|
const statusQueue = [];
|
|
@@ -17724,21 +17766,10 @@ var createAmiAgentProvider = (projectId) => {
|
|
|
17724
17766
|
},
|
|
17725
17767
|
supportsResume: true,
|
|
17726
17768
|
supportsFollowUp: true,
|
|
17727
|
-
checkConnection: async () => {
|
|
17728
|
-
const
|
|
17729
|
-
|
|
17730
|
-
|
|
17731
|
-
}
|
|
17732
|
-
try {
|
|
17733
|
-
const response = await fetch(l, { method: "HEAD" });
|
|
17734
|
-
const result = response.ok;
|
|
17735
|
-
connectionCache = { result, timestamp: now };
|
|
17736
|
-
return result;
|
|
17737
|
-
} catch {
|
|
17738
|
-
connectionCache = { result: false, timestamp: now };
|
|
17739
|
-
return false;
|
|
17740
|
-
}
|
|
17741
|
-
},
|
|
17769
|
+
checkConnection: createCachedConnectionChecker(async () => {
|
|
17770
|
+
const response = await fetch(l, { method: "HEAD" });
|
|
17771
|
+
return response.ok;
|
|
17772
|
+
}, CONNECTION_CHECK_TTL_MS),
|
|
17742
17773
|
undo: async () => {
|
|
17743
17774
|
if (!lastAgentMessages) return;
|
|
17744
17775
|
try {
|
|
@@ -17755,24 +17786,25 @@ var createAmiAgentProvider = (projectId) => {
|
|
|
17755
17786
|
var attachAgent = async () => {
|
|
17756
17787
|
if (typeof window === "undefined") return;
|
|
17757
17788
|
const provider = createAmiAgentProvider();
|
|
17758
|
-
const attach = (
|
|
17759
|
-
|
|
17789
|
+
const attach = (api) => {
|
|
17790
|
+
api.setAgent({ provider, storage: sessionStorage });
|
|
17760
17791
|
};
|
|
17761
|
-
const
|
|
17762
|
-
if (
|
|
17763
|
-
attach(
|
|
17792
|
+
const existingApi = window.__REACT_GRAB__;
|
|
17793
|
+
if (isReactGrabApi(existingApi)) {
|
|
17794
|
+
attach(existingApi);
|
|
17764
17795
|
return;
|
|
17765
17796
|
}
|
|
17766
17797
|
window.addEventListener(
|
|
17767
17798
|
"react-grab:init",
|
|
17768
17799
|
(event) => {
|
|
17769
|
-
|
|
17770
|
-
|
|
17800
|
+
if (!(event instanceof CustomEvent)) return;
|
|
17801
|
+
if (!isReactGrabApi(event.detail)) return;
|
|
17802
|
+
attach(event.detail);
|
|
17771
17803
|
},
|
|
17772
17804
|
{ once: true }
|
|
17773
17805
|
);
|
|
17774
17806
|
const apiAfterListener = window.__REACT_GRAB__;
|
|
17775
|
-
if (apiAfterListener) {
|
|
17807
|
+
if (isReactGrabApi(apiAfterListener)) {
|
|
17776
17808
|
attach(apiAfterListener);
|
|
17777
17809
|
}
|
|
17778
17810
|
};
|