@picassohq/cli 1.0.2 → 1.0.3
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/build-info.json +1 -1
- package/dist/index.js +1398 -1375
- package/package.json +1 -1
- package/runtime/dsh/picasso-ecosystem.cordis.patch.yml +16 -0
- package/runtime/engine-manifest.json +2 -2
- package/runtime/packages/picasso-commands/index.js +1 -1
- package/runtime/packages/picasso-lean-context/index.js +45 -1
- package/runtime/plugins/picasso-commands/index.js +1 -1
- package/runtime/plugins/picasso-lean-context/index.js +45 -1
- package/runtime/relay/main.mjs +84 -10
- package/runtime/relay/versions-routes.mjs +6 -0
package/package.json
CHANGED
|
@@ -84,6 +84,22 @@
|
|
|
84
84
|
config:
|
|
85
85
|
maxTasks: 256
|
|
86
86
|
defaultEnabled: true
|
|
87
|
+
# Searching past sessions (`session_search`, `session_event_search`, mounted below as `tool-session-query`). dsh-base
|
|
88
|
+
# ships the full-text index off (`openAt: never`), so every search failed with SESSION_QUERY_SEARCH_DISABLED while
|
|
89
|
+
# Tier 1 advertised the tools. `first-search` opens the index on the first search only (no startup cost, no SQLite
|
|
90
|
+
# import until then); each search reconciles it with the session store, so the first one indexes the existing
|
|
91
|
+
# sessions and later ones read only new or changed logs. The tools return only sessions whose `cwd` equals the
|
|
92
|
+
# caller's. An index file must have exactly one owner process (a second process opening it while another writes it
|
|
93
|
+
# fails that open for the rest of its life), and every TUI thread runs its own engine on the shared engine home, so
|
|
94
|
+
# each engine process leases its own durable slot, `<engine home>/session-search/cli-<n>.sqlite`, passed in as
|
|
95
|
+
# PICASSO_SESSION_SEARCH_DB (packages/core/src/dsh/session-search-index.ts); with no free slot it is '' and the index
|
|
96
|
+
# lives in memory. The Mac relay keeps its own single index (apps/desktop-helper/src/dsh-host.ts
|
|
97
|
+
# sessionQueryPatchRow). A row replaces the whole `config`, so `path` is restated. PICASSO_SESSION_SEARCH=0 turns
|
|
98
|
+
# search off on both surfaces.
|
|
99
|
+
- id: session-query-sqlite
|
|
100
|
+
config:
|
|
101
|
+
path: !!js "process.env.PICASSO_SESSION_SEARCH_DB || ':memory:'"
|
|
102
|
+
openAt: !!js "process.env.PICASSO_SESSION_SEARCH === '0' ? 'never' : 'first-search'"
|
|
87
103
|
- insert:
|
|
88
104
|
- id: picasso-ecosystem
|
|
89
105
|
name: cordis:group
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"name": "@picasso/commands-bridge",
|
|
78
78
|
"version": "0.1.0",
|
|
79
79
|
"files": {
|
|
80
|
-
"index.js": "
|
|
80
|
+
"index.js": "5414674dc20aa1a8d84a8ac4f4df119d1db33181ed3c901b09f41d2a97e2eb79",
|
|
81
81
|
"package.json": "463b0792f1be2badf714f4c01eaccd714718c59d28c5cea4dbbb5a409ea62bd0",
|
|
82
82
|
"fresh-review.js": "7e8b7e0079bb2f2be3b6d7d9cec2456b34c69b5e7c9d13cf32ab83f3e355c8ab"
|
|
83
83
|
}
|
|
@@ -144,7 +144,7 @@
|
|
|
144
144
|
"name": "@picasso/lean-context",
|
|
145
145
|
"version": "0.1.0",
|
|
146
146
|
"files": {
|
|
147
|
-
"index.js": "
|
|
147
|
+
"index.js": "430f86c339475ad3bd6b6b3e952f6eabe9365238af0dcbe8ab13dbd6c8c91dd0",
|
|
148
148
|
"package.json": "3f48eb73b4a3e92a2b4d6562a235f733db7368c6450ad6bc6323504109110c90",
|
|
149
149
|
"read-image-recovery.js": "536a476dd842f8e647ebcd67fcc24d66c6f3b255a04cc932c07dcbd216ffdb50",
|
|
150
150
|
"timeline.js": "ddde3cd2cb7dfa90877b9b80250c470983ec773711410200302d08c94e811eeb"
|
|
@@ -4754,6 +4754,32 @@ function formatSchemaOnError(toolName, errorMsg, schema) {
|
|
|
4754
4754
|
return `${cleanError}${schemaBlock}`;
|
|
4755
4755
|
}
|
|
4756
4756
|
|
|
4757
|
+
/**
|
|
4758
|
+
* Session-history failures that mean the feature itself is unavailable (not a bad argument), by the engine's
|
|
4759
|
+
* `SessionQueryError` code, as the one plain line both the model and the person see. Keyed by code, with the engine
|
|
4760
|
+
* tool boundary's fixed message as a fallback when a result carries no error identity.
|
|
4761
|
+
*/
|
|
4762
|
+
export const SESSION_QUERY_UNAVAILABLE = Object.freeze({
|
|
4763
|
+
SESSION_QUERY_SEARCH_DISABLED: "Searching past sessions isn't turned on.",
|
|
4764
|
+
SESSION_QUERY_INDEX_FAILED: "Searching past sessions isn't available right now.",
|
|
4765
|
+
SESSION_QUERY_PERSISTENCE_FAILED: "Past sessions can't be read right now.",
|
|
4766
|
+
});
|
|
4767
|
+
const SESSION_QUERY_UNAVAILABLE_BY_MESSAGE = new Map([
|
|
4768
|
+
["session search is disabled in this deployment", SESSION_QUERY_UNAVAILABLE.SESSION_QUERY_SEARCH_DISABLED],
|
|
4769
|
+
["session search index is unavailable", SESSION_QUERY_UNAVAILABLE.SESSION_QUERY_INDEX_FAILED],
|
|
4770
|
+
["session history storage is unavailable", SESSION_QUERY_UNAVAILABLE.SESSION_QUERY_PERSISTENCE_FAILED],
|
|
4771
|
+
]);
|
|
4772
|
+
const SESSION_QUERY_UNAVAILABLE_LINES = new Set(Object.values(SESSION_QUERY_UNAVAILABLE));
|
|
4773
|
+
|
|
4774
|
+
/** The plain line for a failed `session_*` call whose cause is that history search is unavailable, else undefined. */
|
|
4775
|
+
export function sessionQueryUnavailableLine(toolName, result) {
|
|
4776
|
+
if (!/^session_/.test(String(toolName ?? "")) || !isRecord(result) || result.isError !== true) return undefined;
|
|
4777
|
+
const code = result.error?.info?.code;
|
|
4778
|
+
if (typeof code === "string" && Object.hasOwn(SESSION_QUERY_UNAVAILABLE, code)) return SESSION_QUERY_UNAVAILABLE[code];
|
|
4779
|
+
const message = String(result.error?.message ?? "").replace(/^Error:\s*/u, "").trim();
|
|
4780
|
+
return SESSION_QUERY_UNAVAILABLE_BY_MESSAGE.get(message);
|
|
4781
|
+
}
|
|
4782
|
+
|
|
4757
4783
|
/** `queries` -> `query`, `urls` -> `url`, `paths` -> `path`: the singular a model naturally writes for a list field. */
|
|
4758
4784
|
function singularOf(key) {
|
|
4759
4785
|
if (/ies$/u.test(key)) return `${key.slice(0, -3)}y`;
|
|
@@ -5475,7 +5501,10 @@ export function apply(ctx, config = {}, deps = {}) {
|
|
|
5475
5501
|
outcome.error?.message ??
|
|
5476
5502
|
(Array.isArray(outcome.content) ? outcome.content.map((c) => c?.text).join("\n") : "") ??
|
|
5477
5503
|
`Tool "${targetName}" failed.`;
|
|
5478
|
-
|
|
5504
|
+
// An unavailable feature is not an argument problem: the plain line goes back alone, without the schema.
|
|
5505
|
+
const enriched = SESSION_QUERY_UNAVAILABLE_LINES.has(String(rawErr).trim())
|
|
5506
|
+
? String(rawErr).trim()
|
|
5507
|
+
: formatSchemaOnError(targetName, rawErr, cachedSchema);
|
|
5479
5508
|
return {
|
|
5480
5509
|
ok: false,
|
|
5481
5510
|
isError: true,
|
|
@@ -5999,6 +6028,21 @@ export function apply(ctx, config = {}, deps = {}) {
|
|
|
5999
6028
|
};
|
|
6000
6029
|
ensureDelegationFastPath();
|
|
6001
6030
|
|
|
6031
|
+
// A `session_*` call that failed because history search is unavailable (configured off, the index could not open,
|
|
6032
|
+
// the session store unreadable) settles as one plain line, with no error identity, so neither the model nor the
|
|
6033
|
+
// Mac/TUI tool row shows the raw `SessionQueryError · SESSION_QUERY_*` code. Runs for direct calls, `run_code`
|
|
6034
|
+
// sub-calls and `tool_call`'s nested dispatch alike (each goes through the engine's post-execute).
|
|
6035
|
+
ctx?.on?.(
|
|
6036
|
+
"tools/post-execute",
|
|
6037
|
+
async (exec, result, next) => {
|
|
6038
|
+
const downstream = typeof next === "function" ? await next() : { kind: "accept" };
|
|
6039
|
+
const line = sessionQueryUnavailableLine(exec?.name, result);
|
|
6040
|
+
if (line === undefined) return downstream;
|
|
6041
|
+
return { kind: "block", feedback: [{ type: "text", text: line }] };
|
|
6042
|
+
},
|
|
6043
|
+
{ global: true },
|
|
6044
|
+
);
|
|
6045
|
+
|
|
6002
6046
|
// `read_image` on a misnamed image (PNG/HEIC saved as .jpg) or a HEIC/TIFF file: the engine trusts the extension and
|
|
6003
6047
|
// refuses; this around-dispatch wrapper re-reads by the real format (sips converts what the wire cannot carry). Runs
|
|
6004
6048
|
// only after the engine body failed with a format code; Tier 1 is untouched (read-image-recovery.js). Off with
|
|
@@ -4754,6 +4754,32 @@ function formatSchemaOnError(toolName, errorMsg, schema) {
|
|
|
4754
4754
|
return `${cleanError}${schemaBlock}`;
|
|
4755
4755
|
}
|
|
4756
4756
|
|
|
4757
|
+
/**
|
|
4758
|
+
* Session-history failures that mean the feature itself is unavailable (not a bad argument), by the engine's
|
|
4759
|
+
* `SessionQueryError` code, as the one plain line both the model and the person see. Keyed by code, with the engine
|
|
4760
|
+
* tool boundary's fixed message as a fallback when a result carries no error identity.
|
|
4761
|
+
*/
|
|
4762
|
+
export const SESSION_QUERY_UNAVAILABLE = Object.freeze({
|
|
4763
|
+
SESSION_QUERY_SEARCH_DISABLED: "Searching past sessions isn't turned on.",
|
|
4764
|
+
SESSION_QUERY_INDEX_FAILED: "Searching past sessions isn't available right now.",
|
|
4765
|
+
SESSION_QUERY_PERSISTENCE_FAILED: "Past sessions can't be read right now.",
|
|
4766
|
+
});
|
|
4767
|
+
const SESSION_QUERY_UNAVAILABLE_BY_MESSAGE = new Map([
|
|
4768
|
+
["session search is disabled in this deployment", SESSION_QUERY_UNAVAILABLE.SESSION_QUERY_SEARCH_DISABLED],
|
|
4769
|
+
["session search index is unavailable", SESSION_QUERY_UNAVAILABLE.SESSION_QUERY_INDEX_FAILED],
|
|
4770
|
+
["session history storage is unavailable", SESSION_QUERY_UNAVAILABLE.SESSION_QUERY_PERSISTENCE_FAILED],
|
|
4771
|
+
]);
|
|
4772
|
+
const SESSION_QUERY_UNAVAILABLE_LINES = new Set(Object.values(SESSION_QUERY_UNAVAILABLE));
|
|
4773
|
+
|
|
4774
|
+
/** The plain line for a failed `session_*` call whose cause is that history search is unavailable, else undefined. */
|
|
4775
|
+
export function sessionQueryUnavailableLine(toolName, result) {
|
|
4776
|
+
if (!/^session_/.test(String(toolName ?? "")) || !isRecord(result) || result.isError !== true) return undefined;
|
|
4777
|
+
const code = result.error?.info?.code;
|
|
4778
|
+
if (typeof code === "string" && Object.hasOwn(SESSION_QUERY_UNAVAILABLE, code)) return SESSION_QUERY_UNAVAILABLE[code];
|
|
4779
|
+
const message = String(result.error?.message ?? "").replace(/^Error:\s*/u, "").trim();
|
|
4780
|
+
return SESSION_QUERY_UNAVAILABLE_BY_MESSAGE.get(message);
|
|
4781
|
+
}
|
|
4782
|
+
|
|
4757
4783
|
/** `queries` -> `query`, `urls` -> `url`, `paths` -> `path`: the singular a model naturally writes for a list field. */
|
|
4758
4784
|
function singularOf(key) {
|
|
4759
4785
|
if (/ies$/u.test(key)) return `${key.slice(0, -3)}y`;
|
|
@@ -5475,7 +5501,10 @@ export function apply(ctx, config = {}, deps = {}) {
|
|
|
5475
5501
|
outcome.error?.message ??
|
|
5476
5502
|
(Array.isArray(outcome.content) ? outcome.content.map((c) => c?.text).join("\n") : "") ??
|
|
5477
5503
|
`Tool "${targetName}" failed.`;
|
|
5478
|
-
|
|
5504
|
+
// An unavailable feature is not an argument problem: the plain line goes back alone, without the schema.
|
|
5505
|
+
const enriched = SESSION_QUERY_UNAVAILABLE_LINES.has(String(rawErr).trim())
|
|
5506
|
+
? String(rawErr).trim()
|
|
5507
|
+
: formatSchemaOnError(targetName, rawErr, cachedSchema);
|
|
5479
5508
|
return {
|
|
5480
5509
|
ok: false,
|
|
5481
5510
|
isError: true,
|
|
@@ -5999,6 +6028,21 @@ export function apply(ctx, config = {}, deps = {}) {
|
|
|
5999
6028
|
};
|
|
6000
6029
|
ensureDelegationFastPath();
|
|
6001
6030
|
|
|
6031
|
+
// A `session_*` call that failed because history search is unavailable (configured off, the index could not open,
|
|
6032
|
+
// the session store unreadable) settles as one plain line, with no error identity, so neither the model nor the
|
|
6033
|
+
// Mac/TUI tool row shows the raw `SessionQueryError · SESSION_QUERY_*` code. Runs for direct calls, `run_code`
|
|
6034
|
+
// sub-calls and `tool_call`'s nested dispatch alike (each goes through the engine's post-execute).
|
|
6035
|
+
ctx?.on?.(
|
|
6036
|
+
"tools/post-execute",
|
|
6037
|
+
async (exec, result, next) => {
|
|
6038
|
+
const downstream = typeof next === "function" ? await next() : { kind: "accept" };
|
|
6039
|
+
const line = sessionQueryUnavailableLine(exec?.name, result);
|
|
6040
|
+
if (line === undefined) return downstream;
|
|
6041
|
+
return { kind: "block", feedback: [{ type: "text", text: line }] };
|
|
6042
|
+
},
|
|
6043
|
+
{ global: true },
|
|
6044
|
+
);
|
|
6045
|
+
|
|
6002
6046
|
// `read_image` on a misnamed image (PNG/HEIC saved as .jpg) or a HEIC/TIFF file: the engine trusts the extension and
|
|
6003
6047
|
// refuses; this around-dispatch wrapper re-reads by the real format (sips converts what the wire cannot carry). Runs
|
|
6004
6048
|
// only after the engine body failed with a format code; Tier 1 is untouched (read-image-recovery.js). Off with
|
package/runtime/relay/main.mjs
CHANGED
|
@@ -1443,9 +1443,11 @@ function validateSettings(value) {
|
|
|
1443
1443
|
if (value[key] !== void 0 && typeof value[key] !== "string")
|
|
1444
1444
|
throw new Error(`${key} must be a string`);
|
|
1445
1445
|
}
|
|
1446
|
-
const
|
|
1447
|
-
|
|
1448
|
-
|
|
1446
|
+
for (const key of ["colorTheme", "terminalColorTheme"]) {
|
|
1447
|
+
const id = value[key];
|
|
1448
|
+
if (id !== void 0 && (typeof id !== "string" || !COLOR_THEME_ID_PATTERN.test(id))) {
|
|
1449
|
+
throw new Error(`${key} must be a theme id (lowercase letters, digits and dashes)`);
|
|
1450
|
+
}
|
|
1449
1451
|
}
|
|
1450
1452
|
if (value["worktreeDefault"] !== void 0 && !WORKTREE_DEFAULT_VALUES.includes(value["worktreeDefault"])) {
|
|
1451
1453
|
throw new Error(`worktreeDefault must be one of ${WORKTREE_DEFAULT_VALUES.join(", ")}`);
|
|
@@ -5810,6 +5812,9 @@ function httpError(method, path, status, body) {
|
|
|
5810
5812
|
if (status === 403 && error === "account_suspended") {
|
|
5811
5813
|
return new CloudSessionSyncError("Your Picasso account is suspended. Contact support@picassohq.com.", "cloud-sessions/suspended", { status });
|
|
5812
5814
|
}
|
|
5815
|
+
if (status === 403 && error === "premium_required") {
|
|
5816
|
+
return new CloudSessionSyncError(CLOUD_SESSION_SYNC_PREMIUM_MESSAGE, "cloud-sessions/premium-required", { status });
|
|
5817
|
+
}
|
|
5813
5818
|
if (status === 403) {
|
|
5814
5819
|
return new CloudSessionSyncError(`${method} ${path} was refused (${error ?? "forbidden"}).`, "cloud-sessions/forbidden", {
|
|
5815
5820
|
status
|
|
@@ -5888,13 +5893,18 @@ async function defaultFetch(url, init) {
|
|
|
5888
5893
|
}
|
|
5889
5894
|
return fetchFn(url, init);
|
|
5890
5895
|
}
|
|
5891
|
-
var CloudSessionSyncError, CloudSessionSyncClient;
|
|
5896
|
+
var CLOUD_SESSION_SYNC_AVAILABILITY, CLOUD_SESSION_SYNC_PREMIUM_MESSAGE, CloudSessionSyncError, CloudSessionSyncClient;
|
|
5892
5897
|
var init_cloud_client = __esm({
|
|
5893
5898
|
"../../packages/sessions/dist/cloud-client.js"() {
|
|
5894
5899
|
"use strict";
|
|
5895
5900
|
init_dist();
|
|
5896
5901
|
init_sharing();
|
|
5897
5902
|
init_sync();
|
|
5903
|
+
CLOUD_SESSION_SYNC_AVAILABILITY = Object.freeze({
|
|
5904
|
+
available: false,
|
|
5905
|
+
reason: "premium_coming_soon"
|
|
5906
|
+
});
|
|
5907
|
+
CLOUD_SESSION_SYNC_PREMIUM_MESSAGE = "Synced sessions (upload each session to your account after every turn) are available with Premium (coming soon).";
|
|
5898
5908
|
CloudSessionSyncError = class extends Error {
|
|
5899
5909
|
code;
|
|
5900
5910
|
status;
|
|
@@ -5910,12 +5920,17 @@ var init_cloud_client = __esm({
|
|
|
5910
5920
|
CloudSessionSyncClient = class {
|
|
5911
5921
|
#options;
|
|
5912
5922
|
#fetch;
|
|
5923
|
+
/** Latched by a 403 `premium_required`: no further upload request from this client. */
|
|
5924
|
+
#premiumRequired = false;
|
|
5913
5925
|
constructor(options) {
|
|
5914
5926
|
this.#options = options;
|
|
5915
5927
|
this.#fetch = options.fetch ?? defaultFetch;
|
|
5916
5928
|
}
|
|
5917
5929
|
/** Uploads the local session's full event list with `PUT /v1/sessions/:id/sync`. */
|
|
5918
5930
|
async upload(sessionId) {
|
|
5931
|
+
if (this.#premiumRequired) {
|
|
5932
|
+
return { status: "skipped", reason: "premium-required" };
|
|
5933
|
+
}
|
|
5919
5934
|
const gate = await this.#gate();
|
|
5920
5935
|
if (gate.status === "skipped") {
|
|
5921
5936
|
return gate;
|
|
@@ -5941,7 +5956,16 @@ var init_cloud_client = __esm({
|
|
|
5941
5956
|
session: { ...session, ownerId },
|
|
5942
5957
|
events: records
|
|
5943
5958
|
};
|
|
5944
|
-
|
|
5959
|
+
let response;
|
|
5960
|
+
try {
|
|
5961
|
+
response = await this.#request(gate.signedIn, "PUT", `/v1/sessions/${encodeURIComponent(sessionId)}/sync`, body);
|
|
5962
|
+
} catch (error) {
|
|
5963
|
+
if (error instanceof CloudSessionSyncError && error.code === "cloud-sessions/premium-required") {
|
|
5964
|
+
this.#premiumRequired = true;
|
|
5965
|
+
return { status: "skipped", reason: "premium-required" };
|
|
5966
|
+
}
|
|
5967
|
+
throw error;
|
|
5968
|
+
}
|
|
5945
5969
|
const parsed = parseUploadResponse(response.body);
|
|
5946
5970
|
if (parsed.conflict === void 0) {
|
|
5947
5971
|
return { status: "uploaded", sessionId, eventCount: parsed.eventCount, uploadedThrough: parsed.uploadedThrough };
|
|
@@ -5988,6 +6012,9 @@ var init_cloud_client = __esm({
|
|
|
5988
6012
|
return { status: "fetched", snapshot: parseSnapshot(response.body) };
|
|
5989
6013
|
}
|
|
5990
6014
|
async #gate() {
|
|
6015
|
+
if (!(this.#options.available ?? CLOUD_SESSION_SYNC_AVAILABILITY.available)) {
|
|
6016
|
+
return { status: "skipped", reason: "premium-coming-soon" };
|
|
6017
|
+
}
|
|
5991
6018
|
const settings = await (this.#options.readSettings ?? (() => defaultReadSettings(this.#options.env ?? process.env)))();
|
|
5992
6019
|
if (!cloudSessionSyncEnabled(settings)) {
|
|
5993
6020
|
return { status: "skipped", reason: "disabled" };
|
|
@@ -16270,10 +16297,11 @@ ${all.join("\n")}
|
|
|
16270
16297
|
function sessionQueryPatchRow(env2) {
|
|
16271
16298
|
const home2 = env2["DSH_HOME"];
|
|
16272
16299
|
const dbPath = home2 && home2 !== "/" ? `${home2}/session-query.sqlite` : ":memory:";
|
|
16300
|
+
const openAt = env2["PICASSO_SESSION_SEARCH"] === "0" ? "never" : "first-search";
|
|
16273
16301
|
return `- id: session-query-sqlite
|
|
16274
16302
|
config:
|
|
16275
16303
|
path: ${JSON.stringify(dbPath)}
|
|
16276
|
-
openAt:
|
|
16304
|
+
openAt: ${openAt}`;
|
|
16277
16305
|
}
|
|
16278
16306
|
var SUBAGENT_APPROVAL_TRANSFORM = `function picassoSubagentApproval(url, result) {
|
|
16279
16307
|
if (!url.endsWith('dsh-subagent/lib/index.js')) return result;
|
|
@@ -18012,16 +18040,24 @@ const MANAGED_ERROR_HINTS = {
|
|
|
18012
18040
|
budget_exceeded: 'the budget for this session, goal or day has been reached',
|
|
18013
18041
|
account_suspended: 'this Picasso account is suspended; sign in with another account: picasso auth login',
|
|
18014
18042
|
unauthorized: 'you are signed out; run picasso auth login',
|
|
18043
|
+
managed_daily_limit_reached: 'the daily managed usage limit for this account has been reached; it resets at 00:00 UTC',
|
|
18044
|
+
managed_access_blocked: 'managed models are turned off for this account; contact support',
|
|
18045
|
+
managed_daily_limit_unavailable: 'Picasso could not check the daily usage limit; try again in a moment',
|
|
18015
18046
|
};
|
|
18016
18047
|
|
|
18017
18048
|
function managedFailure(status, payload) {
|
|
18018
18049
|
// A 401 with no body is still a sign-out.
|
|
18019
18050
|
const serverError = typeof payload?.error === 'string' ? payload.error : status === 401 ? 'unauthorized' : undefined;
|
|
18020
18051
|
const label = serverError ?? ('HTTP ' + status);
|
|
18021
|
-
|
|
18052
|
+
// The daily-limit refusals carry a message written for the person (caps, reset time): it stands in for the hint.
|
|
18053
|
+
const serverMessage = typeof payload?.message === 'string' ? payload.message.trim() : '';
|
|
18054
|
+
const ownMessage = (serverError === 'managed_daily_limit_reached' || serverError === 'managed_access_blocked' || serverError === 'managed_daily_limit_unavailable') && serverMessage.length > 0;
|
|
18055
|
+
const hint = ownMessage ? serverMessage : serverError === undefined || !Object.hasOwn(MANAGED_ERROR_HINTS, serverError) ? undefined : MANAGED_ERROR_HINTS[serverError];
|
|
18022
18056
|
const message = 'managed provider request failed: ' + label + (hint === undefined ? '' : ' (' + hint + ')');
|
|
18023
18057
|
// A recognised policy refusal is not a bad credential, even when it arrives as a 403. A suspended account is.
|
|
18024
|
-
|
|
18058
|
+
// The daily limit lasts until 00:00 UTC: QUOTA, which the engine does not retry.
|
|
18059
|
+
const code = serverError === 'managed_daily_limit_reached' ? 'QUOTA'
|
|
18060
|
+
: status === 429 ? 'RATE_LIMIT'
|
|
18025
18061
|
: status === 401 || (status === 403 && (serverError === 'account_suspended' || hint === undefined)) ? 'INVALID_CREDENTIAL'
|
|
18026
18062
|
: 'PROVIDER_ERROR';
|
|
18027
18063
|
return { message, code, details: serverError === undefined ? { status } : { status, serverError } };
|
|
@@ -18548,13 +18584,20 @@ function failStream(res) {
|
|
|
18548
18584
|
}
|
|
18549
18585
|
function failureOutcome(upstream, text3) {
|
|
18550
18586
|
let code;
|
|
18587
|
+
let message;
|
|
18551
18588
|
try {
|
|
18552
18589
|
const parsed = JSON.parse(text3);
|
|
18553
18590
|
if (typeof parsed.error === "string") code = parsed.error;
|
|
18591
|
+
if (typeof parsed.message === "string" && parsed.message.trim() !== "") message = parsed.message.trim();
|
|
18554
18592
|
} catch {
|
|
18555
18593
|
}
|
|
18556
18594
|
const retryAfter2 = retryAfterSeconds(upstream.headers.get("retry-after"));
|
|
18557
|
-
return {
|
|
18595
|
+
return {
|
|
18596
|
+
status: upstream.status,
|
|
18597
|
+
...code === void 0 ? {} : { code },
|
|
18598
|
+
...retryAfter2 === void 0 ? {} : { retryAfter: retryAfter2 },
|
|
18599
|
+
...message === void 0 ? {} : { message }
|
|
18600
|
+
};
|
|
18558
18601
|
}
|
|
18559
18602
|
function retryAfterSeconds(value, now = Date.now()) {
|
|
18560
18603
|
if (value === null || value.trim() === "") return void 0;
|
|
@@ -18605,9 +18648,27 @@ var MANAGED_UNAVAILABLE = {
|
|
|
18605
18648
|
code: "managed_unavailable",
|
|
18606
18649
|
message: "Picasso's free model is not available in this app session. Restart Picasso, " + BYO_FIX + "."
|
|
18607
18650
|
};
|
|
18651
|
+
var MANAGED_DAILY_LIMIT_TEXT = {
|
|
18652
|
+
reached: "You've reached today's Picasso limit. It resets at 00:00 UTC.",
|
|
18653
|
+
blocked: "Managed models are turned off for this account. Contact support.",
|
|
18654
|
+
unavailable: "Picasso couldn't check today's usage limit. Try again in a moment."
|
|
18655
|
+
};
|
|
18608
18656
|
function managedRelayError(outcome) {
|
|
18609
18657
|
if (outcome.status >= 200 && outcome.status < 300) return void 0;
|
|
18610
18658
|
if (outcome.status === 401 || outcome.code === "unauthorized") return MANAGED_SIGNED_OUT;
|
|
18659
|
+
if (outcome.code === "managed_daily_limit_reached") {
|
|
18660
|
+
return {
|
|
18661
|
+
code: outcome.code,
|
|
18662
|
+
message: `${outcome.message ?? MANAGED_DAILY_LIMIT_TEXT.reached} To keep working now, add your own provider key in Settings \u203A Providers.`,
|
|
18663
|
+
...outcome.retryAfter === void 0 ? {} : { retryAfter: outcome.retryAfter }
|
|
18664
|
+
};
|
|
18665
|
+
}
|
|
18666
|
+
if (outcome.code === "managed_access_blocked") {
|
|
18667
|
+
return { code: outcome.code, message: outcome.message ?? MANAGED_DAILY_LIMIT_TEXT.blocked };
|
|
18668
|
+
}
|
|
18669
|
+
if (outcome.code === "managed_daily_limit_unavailable") {
|
|
18670
|
+
return { code: outcome.code, message: outcome.message ?? MANAGED_DAILY_LIMIT_TEXT.unavailable };
|
|
18671
|
+
}
|
|
18611
18672
|
if (outcome.status === 429) {
|
|
18612
18673
|
const wait = outcome.retryAfter === void 0 ? "Try again shortly" : `Try again in ${outcome.retryAfter} s`;
|
|
18613
18674
|
return {
|
|
@@ -24017,7 +24078,9 @@ function desktopCloudSessions(options) {
|
|
|
24017
24078
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
24018
24079
|
const log = options.log ?? ((line) => console.error(`picasso-helper: ${line}`));
|
|
24019
24080
|
const readSettings = async () => (await readStore(options.settingsFile, SETTINGS_SPEC)).value;
|
|
24081
|
+
const available = options.available ?? CLOUD_SESSION_SYNC_AVAILABILITY.available;
|
|
24020
24082
|
const client = options.client ?? new CloudSessionSyncClient({
|
|
24083
|
+
available,
|
|
24021
24084
|
store: options.store ?? helperSessionStore(env2),
|
|
24022
24085
|
env: env2,
|
|
24023
24086
|
client: clientId(env2),
|
|
@@ -24028,6 +24091,7 @@ function desktopCloudSessions(options) {
|
|
|
24028
24091
|
now
|
|
24029
24092
|
});
|
|
24030
24093
|
const records = [];
|
|
24094
|
+
let premiumRequiredRecorded = false;
|
|
24031
24095
|
const inFlight = /* @__PURE__ */ new Map();
|
|
24032
24096
|
const record2 = (entry) => {
|
|
24033
24097
|
records.unshift(entry);
|
|
@@ -24044,7 +24108,13 @@ function desktopCloudSessions(options) {
|
|
|
24044
24108
|
return;
|
|
24045
24109
|
}
|
|
24046
24110
|
if (result.status === "skipped") {
|
|
24047
|
-
if (result.reason
|
|
24111
|
+
if (result.reason === "disabled" || result.reason === "premium-coming-soon") return;
|
|
24112
|
+
if (result.reason === "premium-required") {
|
|
24113
|
+
if (premiumRequiredRecorded) return;
|
|
24114
|
+
premiumRequiredRecorded = true;
|
|
24115
|
+
log("cloud-sessions.upload.skipped reason=premium-required");
|
|
24116
|
+
}
|
|
24117
|
+
record2({ sessionId, outcome: "skipped", at: now().toISOString(), reason: result.reason });
|
|
24048
24118
|
return;
|
|
24049
24119
|
}
|
|
24050
24120
|
record2({
|
|
@@ -24068,6 +24138,7 @@ function desktopCloudSessions(options) {
|
|
|
24068
24138
|
if ("reply" in fetched) {
|
|
24069
24139
|
if (fetched.reply.status !== 200) return fetched;
|
|
24070
24140
|
const reason = fetched.reply.body.reason;
|
|
24141
|
+
if (reason === "premium-coming-soon") return { reply: premiumComingSoon() };
|
|
24071
24142
|
return {
|
|
24072
24143
|
reply: reason === "signed-out" ? fail3(401, "cloud-sessions/signed-out", "Sign in to continue a synced session.") : fail3(409, "cloud-sessions/disabled", "Turn on session sync to continue a synced session.")
|
|
24073
24144
|
};
|
|
@@ -24105,9 +24176,11 @@ function desktopCloudSessions(options) {
|
|
|
24105
24176
|
return { status: 200, body: listed.status === "listed" ? { status: "listed", sessions: listed.sessions } : listed };
|
|
24106
24177
|
}
|
|
24107
24178
|
if (action === "settings" && method === "GET") {
|
|
24179
|
+
if (!available) return { status: 200, body: { enabled: false, available: false, reason: "premium_coming_soon" } };
|
|
24108
24180
|
return { status: 200, body: { enabled: (await readSettings()).settings.sync.cloudSessions === true } };
|
|
24109
24181
|
}
|
|
24110
24182
|
if (action === "settings" && method === "PUT") {
|
|
24183
|
+
if (!available) return premiumComingSoon();
|
|
24111
24184
|
if (typeof body["enabled"] !== "boolean") {
|
|
24112
24185
|
return fail3(400, "cloud-sessions/invalid-enabled", "enabled must be true or false.");
|
|
24113
24186
|
}
|
|
@@ -24184,6 +24257,7 @@ function errorCode(error) {
|
|
|
24184
24257
|
return typeof code === "string" && /^[A-Za-z0-9_./-]{1,64}$/u.test(code) ? code : "cloud-sessions/unknown";
|
|
24185
24258
|
}
|
|
24186
24259
|
var fail3 = (status, code, message) => ({ status, body: { error: { code, message } } });
|
|
24260
|
+
var premiumComingSoon = () => fail3(409, "cloud-sessions/premium-coming-soon", CLOUD_SESSION_SYNC_PREMIUM_MESSAGE);
|
|
24187
24261
|
|
|
24188
24262
|
// src/diagnostics.ts
|
|
24189
24263
|
init_dist2();
|
|
@@ -1148,6 +1148,12 @@ import { basename as basename3, dirname as dirname8, join as join21 } from "node
|
|
|
1148
1148
|
// ../../packages/sessions/dist/sharing.js
|
|
1149
1149
|
import { createHash as createHash2 } from "node:crypto";
|
|
1150
1150
|
|
|
1151
|
+
// ../../packages/sessions/dist/cloud-client.js
|
|
1152
|
+
var CLOUD_SESSION_SYNC_AVAILABILITY = Object.freeze({
|
|
1153
|
+
available: false,
|
|
1154
|
+
reason: "premium_coming_soon"
|
|
1155
|
+
});
|
|
1156
|
+
|
|
1151
1157
|
// ../../packages/sessions/dist/lease.js
|
|
1152
1158
|
import { execFile as execFile3 } from "node:child_process";
|
|
1153
1159
|
import { existsSync as existsSync7, readdirSync as readdirSync5 } from "node:fs";
|