@widgetic/creator 0.4.31 → 0.4.33
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/CreatorApp.svelte +254 -83
- package/dist/components/DesignQuickEdit.svelte +80 -10
- package/dist/host/creatorHost.d.ts +28 -0
- package/dist/host/creatorHost.js +36 -0
- package/dist/i18n/labels.d.ts +5 -0
- package/dist/i18n/labels.js +16 -0
- package/dist/i18n/language.d.ts +9 -2
- package/dist/i18n/messages.d.ts +8 -1
- package/dist/i18n/messages.js +10 -1
- package/dist/utils/designIntentResolver.js +7 -0
- package/dist/utils/designQuickEditValues.d.ts +4 -7
- package/dist/utils/designQuickEditValues.js +7 -8
- package/dist/utils/generationRequestFields.d.ts +45 -0
- package/dist/utils/generationRequestFields.js +41 -0
- package/dist/utils/teamEditingRefusals.d.ts +74 -0
- package/dist/utils/teamEditingRefusals.js +102 -0
- package/package.json +3 -3
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The three fields of a generation request (`POST /agent/code/generate`) that a request carries only when there is something
|
|
3
|
+
* to say, and that an editor session (a partner's customer) may not carry at all.
|
|
4
|
+
*
|
|
5
|
+
* - `baseCommitSha`: the older version the person chose to build on, when it is not the head of the code.
|
|
6
|
+
* - `expectedHeadSha`: the head they chose that version on, so the API can refuse the request, before it charges anything,
|
|
7
|
+
* when newer code was saved since (a teammate, another window).
|
|
8
|
+
* - `textDocuments`: the words of the Markdown and text files attached to the message.
|
|
9
|
+
*
|
|
10
|
+
* Two things about how they travel, which the generated API client made visible when it was regenerated (1.0.46):
|
|
11
|
+
*
|
|
12
|
+
* 1. A field that is there with `null` is a field. The client writes `baseCommitSha: null` into the body when it is given
|
|
13
|
+
* `null`, and the gateway's door for an editor session refuses a body with a field it does not list, whatever the value. So
|
|
14
|
+
* a field with nothing to say is left out, not sent empty.
|
|
15
|
+
* 2. The gateway's list of what an editor session may send in a generation does not have these three (the list is what the
|
|
16
|
+
* generation reads for a visitor: the request is refused whole, `403 EDITOR_SESSION_FIELD_NOT_ALLOWED`, and the visitor
|
|
17
|
+
* cannot generate at all). The client of the modules until now (1.0.29) did not know the three fields and dropped them
|
|
18
|
+
* without a word, so with a session's token the AI has always built on the latest code from the message alone. It still
|
|
19
|
+
* does; the creator now says so by leaving them out (`mayNameVersionOrDocumentsInGeneration(token)` of
|
|
20
|
+
* `host/creatorHost.ts` is the question; a Shopify store's token is not a session's, has no such door, and so names them).
|
|
21
|
+
*
|
|
22
|
+
* It is plain TypeScript with no Svelte in it, so a test can hold it to both.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* The fields to add to a generation request: none for an editor session, and for any other token only the ones that have
|
|
26
|
+
* something to say. The head to compare with goes only with a chosen version (it is the head that version was chosen on).
|
|
27
|
+
*/
|
|
28
|
+
export function generationVersionAndDocumentFields(input) {
|
|
29
|
+
const fields = {};
|
|
30
|
+
if (!input.mayNameVersionOrDocuments)
|
|
31
|
+
return fields;
|
|
32
|
+
if (input.baseCommitSha) {
|
|
33
|
+
fields.baseCommitSha = input.baseCommitSha;
|
|
34
|
+
if (input.expectedHeadSha)
|
|
35
|
+
fields.expectedHeadSha = input.expectedHeadSha;
|
|
36
|
+
}
|
|
37
|
+
if (input.textDocuments && input.textDocuments.length > 0) {
|
|
38
|
+
fields.textDocuments = [...input.textDocuments];
|
|
39
|
+
}
|
|
40
|
+
return fields;
|
|
41
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Translate } from '@widgetic/design-system/i18n';
|
|
2
|
+
import type { CreatorMessageKey } from '../i18n/messages.js';
|
|
3
|
+
/**
|
|
4
|
+
* What the API says when it turns a request away because of what somebody else is doing in the same widget.
|
|
5
|
+
*
|
|
6
|
+
* A widget's code has one author at a time. While a generation runs, a second generation and a restore of a checkpoint are
|
|
7
|
+
* refused with `409 BUSINESS_STATE_CONFLICT` and `error.details.reason: 'generation_in_progress'`: `heldBy` says whether the
|
|
8
|
+
* run is the caller's own (`'you'`: another window, another device, an app) or somebody else's (`'another_member'`), and
|
|
9
|
+
* never a name; `startedAt` says since when; `operationId`, given only to the person who started the run, is the run to
|
|
10
|
+
* follow. A generation of a chosen older version, and a restore of a checkpoint, can say which head of the code the person
|
|
11
|
+
* saw (`expectedHeadSha`); newer code saved since is refused with `409` and `details.reason: 'repository_head_changed'`
|
|
12
|
+
* (`expectedHeadSha`, `currentHeadSha`) before anything is charged, deleted or written. A restore that cannot read the head
|
|
13
|
+
* it was asked to compare with is `503 SERVICE_UNAVAILABLE`: a head that cannot be read is no confirmation.
|
|
14
|
+
*
|
|
15
|
+
* This reads those answers, and says what each means in the visitor's words. It is plain TypeScript with no Svelte in it,
|
|
16
|
+
* so a test can hold it to the shapes the API gives (the gateway's `generationLockRoutes.test.ts` and
|
|
17
|
+
* `restoreCheckpointRoute.test.ts` are the other half of that agreement).
|
|
18
|
+
*/
|
|
19
|
+
/** Who holds the widget's code, as far as the API says. The API never names a person, so neither does the creator. */
|
|
20
|
+
export type GenerationHolder = 'you' | 'another_member' | 'unknown';
|
|
21
|
+
/** A run holds the widget's code. */
|
|
22
|
+
export interface GenerationInProgressRefusal {
|
|
23
|
+
kind: 'generation_in_progress';
|
|
24
|
+
heldBy: GenerationHolder;
|
|
25
|
+
/** When the run that holds the widget began, when the API said. */
|
|
26
|
+
startedAt: Date | null;
|
|
27
|
+
/** The run to follow. The API gives it only to the person who started the run, and only when it knows it. */
|
|
28
|
+
operationId: string | null;
|
|
29
|
+
}
|
|
30
|
+
/** Newer code was saved after the person looked at the head the request names. */
|
|
31
|
+
export interface RepositoryHeadChangedRefusal {
|
|
32
|
+
kind: 'repository_head_changed';
|
|
33
|
+
/** The head the person saw, when the API repeated it. */
|
|
34
|
+
expectedHeadSha: string | null;
|
|
35
|
+
/** The head now, when the API said. */
|
|
36
|
+
currentHeadSha: string | null;
|
|
37
|
+
}
|
|
38
|
+
/** What a refused request comes to. `other` is anything this file does not know: the caller keeps what it did before. */
|
|
39
|
+
export type TeamEditingRefusal = GenerationInProgressRefusal | RepositoryHeadChangedRefusal
|
|
40
|
+
/** The restore could not read the head of the code to compare it with the one the person saw (503): nothing was restored. */
|
|
41
|
+
| {
|
|
42
|
+
kind: 'latest_code_unreadable';
|
|
43
|
+
} | {
|
|
44
|
+
kind: 'other';
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Reads an answer the API gave: its HTTP status, and its JSON body (`{ success: false, error: { code, message, details } }`).
|
|
48
|
+
* Anything that is not one of the refusals above is `other`; a body that is not the gateway's (a proxy's page, nothing at all)
|
|
49
|
+
* is `other` too, whatever the status.
|
|
50
|
+
*/
|
|
51
|
+
export declare function readTeamEditingRefusal(status: number | undefined, body: unknown): TeamEditingRefusal;
|
|
52
|
+
/**
|
|
53
|
+
* Reads what the generated client threw (`ResponseError`, with the native `Response` on it). The body is read from a copy, so
|
|
54
|
+
* whoever else reads the answer (the page's limit reporter, the creator's own message) still can. A failure that is not an
|
|
55
|
+
* answer of the API (the network, an abort) is `other`.
|
|
56
|
+
*/
|
|
57
|
+
export declare function readTeamEditingRefusalOf(error: unknown): Promise<TeamEditingRefusal>;
|
|
58
|
+
/**
|
|
59
|
+
* The operation of the person's own generation that a refusal points at, or null when there is none to follow: the API gives
|
|
60
|
+
* an operation id only to the person who started the run, and only when it knows the run.
|
|
61
|
+
*/
|
|
62
|
+
export declare function operationToFollow(refusal: TeamEditingRefusal): string | null;
|
|
63
|
+
/**
|
|
64
|
+
* What a visitor reads when a generation they asked for was refused because a run holds the widget. Who holds it is told as far as
|
|
65
|
+
* the API told it: a teammate (with the time the run began), the person's own other window or app, or just "another generation".
|
|
66
|
+
*/
|
|
67
|
+
export declare function generationRefusalText(refusal: GenerationInProgressRefusal, t: Translate<CreatorMessageKey>, locale: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* What a visitor reads when a restore of a checkpoint was refused before anything was deleted. `other` has no text here: a
|
|
70
|
+
* refusal this file does not know is shown the way every other failure of the restore is.
|
|
71
|
+
*/
|
|
72
|
+
export declare function restoreRefusalText(refusal: TeamEditingRefusal, t: Translate<CreatorMessageKey>): string | null;
|
|
73
|
+
/** The head of the code, when it is one the API accepts as `expectedHeadSha` (7 to 40 hexadecimal digits); otherwise null, and nothing is compared. */
|
|
74
|
+
export declare function headCommitForComparison(sha: string | null | undefined): string | null;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { clockTimeText } from '../i18n/labels.js';
|
|
2
|
+
import { httpStatusOfFailure } from './generationSharing.js';
|
|
3
|
+
const KNOWN_HOLDERS = ['you', 'another_member', 'unknown'];
|
|
4
|
+
/** The id of an operation as the API writes it in a path: no space, slash or query in it. */
|
|
5
|
+
const OPERATION_ID_PATTERN = /^[A-Za-z0-9._-]{1,128}$/;
|
|
6
|
+
/** A commit id as the API writes it: 7 to 40 hexadecimal digits. */
|
|
7
|
+
const COMMIT_ID_PATTERN = /^[0-9a-f]{7,40}$/i;
|
|
8
|
+
const asRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value) ? value : null;
|
|
9
|
+
/**
|
|
10
|
+
* Reads an answer the API gave: its HTTP status, and its JSON body (`{ success: false, error: { code, message, details } }`).
|
|
11
|
+
* Anything that is not one of the refusals above is `other`; a body that is not the gateway's (a proxy's page, nothing at all)
|
|
12
|
+
* is `other` too, whatever the status.
|
|
13
|
+
*/
|
|
14
|
+
export function readTeamEditingRefusal(status, body) {
|
|
15
|
+
const root = asRecord(body);
|
|
16
|
+
const error = asRecord(root?.error) ?? root;
|
|
17
|
+
if (status === 503) {
|
|
18
|
+
return error?.code === 'SERVICE_UNAVAILABLE' ? { kind: 'latest_code_unreadable' } : { kind: 'other' };
|
|
19
|
+
}
|
|
20
|
+
if (status !== 409)
|
|
21
|
+
return { kind: 'other' };
|
|
22
|
+
const details = asRecord(error?.details);
|
|
23
|
+
if (details?.reason === 'generation_in_progress') {
|
|
24
|
+
const heldBy = KNOWN_HOLDERS.find((holder) => holder === details.heldBy) ?? 'unknown';
|
|
25
|
+
const startedAtMs = typeof details.startedAt === 'string' ? Date.parse(details.startedAt) : Number.NaN;
|
|
26
|
+
const operationId = typeof details.operationId === 'string' && OPERATION_ID_PATTERN.test(details.operationId) ? details.operationId : null;
|
|
27
|
+
return {
|
|
28
|
+
kind: 'generation_in_progress',
|
|
29
|
+
heldBy,
|
|
30
|
+
startedAt: Number.isFinite(startedAtMs) ? new Date(startedAtMs) : null,
|
|
31
|
+
operationId,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (details?.reason === 'repository_head_changed') {
|
|
35
|
+
const commitIdOf = (value) => (typeof value === 'string' && COMMIT_ID_PATTERN.test(value) ? value : null);
|
|
36
|
+
return {
|
|
37
|
+
kind: 'repository_head_changed',
|
|
38
|
+
expectedHeadSha: commitIdOf(details.expectedHeadSha),
|
|
39
|
+
currentHeadSha: commitIdOf(details.currentHeadSha),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return { kind: 'other' };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Reads what the generated client threw (`ResponseError`, with the native `Response` on it). The body is read from a copy, so
|
|
46
|
+
* whoever else reads the answer (the page's limit reporter, the creator's own message) still can. A failure that is not an
|
|
47
|
+
* answer of the API (the network, an abort) is `other`.
|
|
48
|
+
*/
|
|
49
|
+
export async function readTeamEditingRefusalOf(error) {
|
|
50
|
+
const status = httpStatusOfFailure(error);
|
|
51
|
+
if (status !== 409 && status !== 503)
|
|
52
|
+
return { kind: 'other' };
|
|
53
|
+
const response = error?.response;
|
|
54
|
+
let body = null;
|
|
55
|
+
try {
|
|
56
|
+
body = await response?.clone().json();
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// Not JSON, or already read: the status alone says what it can, and a 409 that says nothing more is `other`.
|
|
60
|
+
}
|
|
61
|
+
return readTeamEditingRefusal(status, body);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The operation of the person's own generation that a refusal points at, or null when there is none to follow: the API gives
|
|
65
|
+
* an operation id only to the person who started the run, and only when it knows the run.
|
|
66
|
+
*/
|
|
67
|
+
export function operationToFollow(refusal) {
|
|
68
|
+
return refusal.kind === 'generation_in_progress' && refusal.heldBy === 'you' ? refusal.operationId : null;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* What a visitor reads when a generation they asked for was refused because a run holds the widget. Who holds it is told as far as
|
|
72
|
+
* the API told it: a teammate (with the time the run began), the person's own other window or app, or just "another generation".
|
|
73
|
+
*/
|
|
74
|
+
export function generationRefusalText(refusal, t, locale) {
|
|
75
|
+
if (refusal.heldBy === 'you')
|
|
76
|
+
return t('creator.codegen.yourGenerationRunsElsewhere');
|
|
77
|
+
if (refusal.heldBy === 'another_member' && refusal.startedAt) {
|
|
78
|
+
return t('creator.codegen.teammateIsGeneratingSince', { time: clockTimeText(refusal.startedAt, locale) });
|
|
79
|
+
}
|
|
80
|
+
return t('creator.codegen.generationRunningInTheWidget');
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* What a visitor reads when a restore of a checkpoint was refused before anything was deleted. `other` has no text here: a
|
|
84
|
+
* refusal this file does not know is shown the way every other failure of the restore is.
|
|
85
|
+
*/
|
|
86
|
+
export function restoreRefusalText(refusal, t) {
|
|
87
|
+
switch (refusal.kind) {
|
|
88
|
+
case 'generation_in_progress':
|
|
89
|
+
return t('creator.version.restoreRefusedWhileGenerating');
|
|
90
|
+
case 'repository_head_changed':
|
|
91
|
+
return t('creator.version.restoreRefusedNewerCode');
|
|
92
|
+
case 'latest_code_unreadable':
|
|
93
|
+
return t('creator.version.restoreRefusedLatestCodeUnknown');
|
|
94
|
+
default:
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** The head of the code, when it is one the API accepts as `expectedHeadSha` (7 to 40 hexadecimal digits); otherwise null, and nothing is compared. */
|
|
99
|
+
export function headCommitForComparison(sha) {
|
|
100
|
+
const trimmed = typeof sha === 'string' ? sha.trim() : '';
|
|
101
|
+
return COMMIT_ID_PATTERN.test(trimmed) ? trimmed : null;
|
|
102
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@widgetic/creator",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.33",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"@sveltejs/kit": "^2.20.0",
|
|
8
|
-
"@widgetic/api-sdk": "^1.0.
|
|
8
|
+
"@widgetic/api-sdk": "^1.0.46",
|
|
9
9
|
"@widgetic/cache-layer": "^0.1.2",
|
|
10
10
|
"@widgetic/canvas": "^0.5.27",
|
|
11
11
|
"@widgetic/chat": "^0.1.17",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"@tailwindcss/postcss": "^4.1.4",
|
|
73
73
|
"@tailwindcss/typography": "^0.5.15",
|
|
74
74
|
"@types/node": "26.4.0",
|
|
75
|
-
"@widgetic/api-sdk": "^1.0.
|
|
75
|
+
"@widgetic/api-sdk": "^1.0.46",
|
|
76
76
|
"@widgetic/cache-layer": "^0.1.2",
|
|
77
77
|
"@widgetic/canvas": "^0.5.27",
|
|
78
78
|
"@widgetic/chat": "^0.1.17",
|